public static LogConfig fromDockerLoggingToCompositeLogConfig(Logging logging) { if (logging == null) { return null; } LogConfig logConfig = new LogConfig(); logConfig.type = logging.driver; logConfig.config = logging.options; return logConfig; }
private LogConfig prepareLogConfig(ContainerConfiguration configuration) { JsonElement jsonLogConfig = configuration.logConfiguration; LogConfig logConfig = new LogConfig(); if (jsonLogConfig == null || !jsonLogConfig.isJsonObject()) { // set default log configuration logConfig.type = "json-file"; logConfig.config = new HashMap<>(); logConfig.config.put("max-size", ClosureProps.MAX_LOG_FILE_SIZE); return logConfig; } JsonObject jsonObject = (JsonObject) jsonLogConfig; JsonElement typeElement = jsonObject.get("type"); if (typeElement == null || typeElement.isJsonNull()) { logConfig.type = "json-file"; } else { logConfig.type = typeElement.getAsString(); } Map<String, String> configMap = new HashMap<>(); JsonElement configElement = jsonObject.get("config"); if (configElement == null || configElement.isJsonNull()) { logConfig.config = configMap; return logConfig; } JsonObject jsonConfig = configElement.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : jsonConfig.entrySet()) { configMap.put(entry.getKey(), entry.getValue().getAsString()); } logConfig.config = configMap; return logConfig; }
.toArray(new PortBinding[0]); template.publishAll = true; LogConfig logConfig = new LogConfig(); logConfig.type = "json-file"; logConfig.config = Collections.emptyMap();
if (logConfigProperty != null && !logConfigProperty.isEmpty()) { try { LogConfig logConfig = new LogConfig(); logConfig.type = (String) logConfigProperty .get(ContainerDescriptionHelper.TYPE_PROPERTY);
@Test public void testEvaluateSingleBindingNestedTarget() { ContainerDescription firstDescription = new ContainerDescription(); firstDescription.name = "A"; firstDescription.logConfig = new LogConfig(); ContainerDescription secondDescription = new ContainerDescription(); secondDescription.name = "B"; secondDescription.hostname = "hostname"; List<Binding> bindings = Arrays.asList( binding(Arrays.asList("log_config", "type"), "B~hostname")); Binding.ComponentBinding componentBinding = new Binding.ComponentBinding("A", bindings); CompositeTemplate compositeTemplate = createCompositeTemplate(Arrays .asList(firstDescription, secondDescription), Arrays.asList(componentBinding)); BindingEvaluator.evaluateBindings(compositeTemplate); firstDescription = (ContainerDescription) compositeTemplate.components.get("A").data; secondDescription = (ContainerDescription) compositeTemplate.components.get("B").data; assertEquals(firstDescription.logConfig.type, secondDescription.hostname); }
@Test public void testEvaluateSingleBindingNestedSource() { ContainerDescription firstDescription = new ContainerDescription(); firstDescription.name = "A"; firstDescription.logConfig = new LogConfig(); firstDescription.logConfig.type = "type"; ContainerDescription secondDescription = new ContainerDescription(); secondDescription.name = "B"; List<Binding> bindings = Arrays .asList(binding(Arrays.asList("hostname"), "A~logConfig~type")); Binding.ComponentBinding componentBinding = new Binding.ComponentBinding("B", bindings); CompositeTemplate compositeTemplate = createCompositeTemplate(Arrays .asList(firstDescription, secondDescription), Arrays.asList(componentBinding)); BindingEvaluator.evaluateBindings(compositeTemplate); firstDescription = (ContainerDescription) compositeTemplate.components.get("A").data; secondDescription = (ContainerDescription) compositeTemplate.components.get("B").data; assertEquals(firstDescription.logConfig.type, secondDescription.hostname); }
@Test public void testDeserializeSerializeSimpleCompositeTemplate() throws IOException { String expectedContent = getContent("composite.simple.yaml"); CompositeTemplate template = deserializeCompositeTemplate(expectedContent); assertNull(template.id); assertNull(template.status); assertComponentTypes(template.components); assertContainersComponents(ResourceType.CONTAINER_TYPE.getContentType(), 1, template.components); assertContainersComponents(ResourceType.NETWORK_TYPE.getContentType(), 0, template.components); assertContainersComponents(ResourceType.VOLUME_TYPE.getContentType(), 0, template.components); template.id = "new-id"; template.status = Status.RETIRED; ContainerDescription helloData = (ContainerDescription) template.components .get("hello").data; helloData.healthConfig = new HealthConfig(); helloData.logConfig = new LogConfig(); String content = serializeCompositeTemplate(template); assertNotNull(content); assertFalse(content.contains("new-id")); assertFalse(content.contains(Status.RETIRED.toString())); assertFalse(content.contains("health_config")); assertFalse(content.contains("log_config")); }