diff options
author | Harald Musum <musum@oath.com> | 2018-02-21 14:39:11 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-02-21 14:39:11 +0100 |
commit | 0e691200aa65c0988ec495742fb29b34f5d94104 (patch) | |
tree | b285f49b8ef4caa62e7d8937d0692de613f5f720 /node-admin | |
parent | fcfdd914e1e90906a8106f4f32480dbcc5e18ce3 (diff) |
Set CONTAINER_ENVIRONMENT_SETTINGS envirnment variable
Set environment variable in container (use json, so we can add stuff
as we go along, we probably need more data here). Set node type
so we can use that in entry point to have different behavior for
tenant nodes and config server nodes
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); + } + } } |