diff options
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java index c0d939b0d97..e311d5785e0 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java @@ -1,6 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.node.admin.docker; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.collections.Pair; import com.yahoo.system.ProcessExecuter; import com.yahoo.vespa.hosted.dockerapi.Container; @@ -114,7 +117,8 @@ public class DockerOperationsImpl implements DockerOperations { containerName, nodeSpec.hostname) .withManagedBy(MANAGER_NAME) - .withEnvironment("CONFIG_SERVER_ADDRESS", configServers) + .withEnvironment("CONFIG_SERVER_ADDRESS", configServers) // TODO: Remove when all images support CONTAINER_ENVIRONMENT_SETTINGS + .withEnvironment("CONTAINER_ENVIRONMENT_SETTINGS", createContainerEnvironmentSettings(environment, nodeSpec)) .withUlimit("nofile", 262_144, 262_144) .withUlimit("nproc", 32_768, 409_600) .withUlimit("core", -1, -1) @@ -340,4 +344,30 @@ public class DockerOperationsImpl implements DockerOperations { public void deleteUnusedDockerImages() { docker.deleteUnusedDockerImages(); } + + private String createContainerEnvironmentSettings(Environment environment, ContainerNodeSpec nodeSpec) { + ObjectMapper objectMapper = new ObjectMapper(); + + String configServers = environment.getConfigServerUris().stream() + .map(URI::getHost) + .collect(Collectors.joining(",")); + ContainerEnvironmentSettings settings = new ContainerEnvironmentSettings(); + settings.set("configServerAddresses", configServers); + settings.set("nodeType", nodeSpec.nodeType); + + try { + return objectMapper.writeValueAsString(settings); + } catch (JsonProcessingException e) { + throw new IllegalArgumentException("Could not write " + settings, e); + } + } + + private class ContainerEnvironmentSettings { + @JsonProperty(value="environmentVariables") + private final Map<String, Object> variables = new HashMap<>(); + + void set(String argument, Object value) { + variables.put(argument, value); + } + } } |