diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-03-12 11:35:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-12 11:35:25 +0100 |
commit | c4a769061a5723823303babeac4a897ee773d6a3 (patch) | |
tree | 2e6c071b4bb8b3bcd00c791627b4cf4c279520d4 | |
parent | f317eace34bf4040c75fd10ac3f322b92b4b8876 (diff) | |
parent | ae75ef6bd2fa764342a162fa92d4480ec9421fa3 (diff) |
Merge pull request #12544 from vespa-engine/hmusum/use-docker-image-repo-in-nodespec
Propagate wanted docker image repo to NodeSpec
3 files changed, 44 insertions, 22 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java index a9b4e06ae1b..074b19d7238 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java @@ -77,6 +77,7 @@ public class DeployState implements ConfigDefinitionStore { private final ImportedMlModels importedModels; private final ValidationOverrides validationOverrides; private final Version wantedNodeVespaVersion; + private final Optional<String> wantedDockerImageRepo; private final Instant now; private final HostProvisioner provisioner; @@ -110,7 +111,8 @@ public class DeployState implements ConfigDefinitionStore { SemanticRules semanticRules, Instant now, Version wantedNodeVespaVersion, - boolean accessLoggingEnabledByDefault) { + boolean accessLoggingEnabledByDefault, + Optional<String> wantedDockerImageRepo) { this.logger = deployLogger; this.fileRegistry = fileRegistry; this.rankProfileRegistry = rankProfileRegistry; @@ -140,6 +142,7 @@ public class DeployState implements ConfigDefinitionStore { this.wantedNodeVespaVersion = wantedNodeVespaVersion; this.now = now; + this.wantedDockerImageRepo = wantedDockerImageRepo; } public static HostProvisioner getDefaultModelHostProvisioner(ApplicationPackage applicationPackage) { @@ -160,9 +163,7 @@ public class DeployState implements ConfigDefinitionStore { public final Optional<ConfigDefinition> getConfigDefinition(ConfigDefinitionKey defKey) { if (existingConfigDefs == null) { existingConfigDefs = new LinkedHashMap<>(); - if (configDefinitionRepo.isPresent()) { - existingConfigDefs.putAll(createLazyMapping(configDefinitionRepo.get())); - } + configDefinitionRepo.ifPresent(definitionRepo -> existingConfigDefs.putAll(createLazyMapping(definitionRepo))); existingConfigDefs.putAll(applicationPackage.getAllExistingConfigDefs()); } if ( ! existingConfigDefs.containsKey(defKey)) return Optional.empty(); @@ -260,6 +261,8 @@ public class DeployState implements ConfigDefinitionStore { public Version getWantedNodeVespaVersion() { return wantedNodeVespaVersion; } + public Optional<String> getWantedDockerImageRepo() { return wantedDockerImageRepo; } + public Instant now() { return now; } public Optional<EndpointCertificateSecrets> endpointCertificateSecrets() { return properties.endpointCertificateSecrets(); } @@ -297,6 +300,7 @@ public class DeployState implements ConfigDefinitionStore { private Instant now = Instant.now(); private Version wantedNodeVespaVersion = Vtag.currentVersion; private boolean accessLoggingEnabledByDefault = true; + private Optional<String> wantedDockerImageRepo = Optional.empty(); public Builder applicationPackage(ApplicationPackage applicationPackage) { this.applicationPackage = applicationPackage; @@ -368,6 +372,11 @@ public class DeployState implements ConfigDefinitionStore { return this; } + public Builder wantedDockerImageRepo(Optional<String> dockerImageRepo) { + this.wantedDockerImageRepo = dockerImageRepo; + return this; + } + /** * Whether access logging is enabled for an application without an accesslog element in services.xml. * True by default. @@ -404,7 +413,8 @@ public class DeployState implements ConfigDefinitionStore { semanticRules, now, wantedNodeVespaVersion, - accessLoggingEnabledByDefault); + accessLoggingEnabledByDefault, + wantedDockerImageRepo); } private SearchDocumentModel createSearchDocumentModel(RankProfileRegistry rankProfileRegistry, diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index 54807697da4..f0e119606bf 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -150,7 +150,8 @@ public class VespaModelFactory implements ModelFactory { .modelImporters(modelImporters) .zone(zone) .now(clock.instant()) - .wantedNodeVespaVersion(modelContext.wantedNodeVespaVersion()); + .wantedNodeVespaVersion(modelContext.wantedNodeVespaVersion()) + .wantedDockerImageRepo(modelContext.wantedDockerImageRepository()); modelContext.previousModel().ifPresent(builder::previousModel); return builder.build(validationParameters); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/NodesSpecification.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/NodesSpecification.java index 43f4637798a..f9e29fe3a28 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/NodesSpecification.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/NodesSpecification.java @@ -43,21 +43,21 @@ public class NodesSpecification { private final boolean required; private final boolean canFail; - + private final boolean exclusive; /** The resources each node should have, or empty to use the default */ private final Optional<NodeResources> resources; - /** The identifier of the custom docker image layer to use (not supported yet) */ - private final Optional<String> dockerImage; + /** The repo part of a docker image (without tag), optional */ + private final Optional<String> dockerImageRepo; /** The ID of the cluster referencing this node specification, if any */ private final Optional<String> combinedId; private NodesSpecification(boolean dedicated, int count, int groups, Version version, boolean required, boolean canFail, boolean exclusive, - Optional<NodeResources> resources, Optional<String> dockerImage, + Optional<NodeResources> resources, Optional<String> dockerImageRepo, Optional<String> combinedId) { this.dedicated = dedicated; this.count = count; @@ -67,12 +67,12 @@ public class NodesSpecification { this.canFail = canFail; this.exclusive = exclusive; this.resources = resources; - this.dockerImage = dockerImage; + this.dockerImageRepo = dockerImageRepo; this.combinedId = combinedId; } private NodesSpecification(boolean dedicated, boolean canFail, Version version, ModelElement nodesElement, - Optional<String> combinedId) { + Optional<String> combinedId, Optional<String> dockerImageRepo) { this(dedicated, nodesElement.integerAttribute("count", 1), nodesElement.integerAttribute("groups", 1), @@ -81,7 +81,7 @@ public class NodesSpecification { canFail, nodesElement.booleanAttribute("exclusive", false), getResources(nodesElement), - Optional.ofNullable(nodesElement.stringAttribute("docker-image")), + dockerImageToUse(nodesElement, dockerImageRepo), combinedId); } @@ -95,10 +95,11 @@ public class NodesSpecification { return containerIdReferencing(nodesElement); } - private static NodesSpecification create(boolean dedicated, boolean canFail, Version version, ModelElement nodesElement) { + private static NodesSpecification create(boolean dedicated, boolean canFail, Version version, + ModelElement nodesElement, Optional<String> dockerImage) { var resolvedElement = resolveElement(nodesElement); var combinedId = findCombinedId(nodesElement, resolvedElement); - return new NodesSpecification(dedicated, canFail, version, resolvedElement, combinedId); + return new NodesSpecification(dedicated, canFail, version, resolvedElement, combinedId, dockerImage); } /** Returns a requirement for dedicated nodes taken from the given <code>nodes</code> element */ @@ -106,7 +107,8 @@ public class NodesSpecification { return create(true, ! context.getDeployState().getProperties().isBootstrap(), context.getDeployState().getWantedNodeVespaVersion(), - nodesElement); + nodesElement, + context.getDeployState().getWantedDockerImageRepo()); } /** @@ -122,7 +124,7 @@ public class NodesSpecification { } /** - * Returns a requirement for undedicated or dedicated nodes taken from the <code>nodes</code> element + * Returns a requirement for non-dedicated or dedicated nodes taken from the <code>nodes</code> element * contained in the given parent element, or empty if the parent element is null, or the nodes elements * is not present. */ @@ -133,10 +135,14 @@ public class NodesSpecification { if (nodesElement == null) return Optional.empty(); return Optional.of(create(nodesElement.booleanAttribute("dedicated", false), ! context.getDeployState().getProperties().isBootstrap(), - context.getDeployState().getWantedNodeVespaVersion(), nodesElement)); + context.getDeployState().getWantedNodeVespaVersion(), + nodesElement, + context.getDeployState().getWantedDockerImageRepo())); } - /** Returns a requirement from <code>count</code> nondedicated nodes in one group */ + /** + * Returns a requirement from <code>count</code> non-dedicated nodes in one group + */ public static NodesSpecification nonDedicated(int count, ConfigModelContext context) { return new NodesSpecification(false, count, @@ -146,7 +152,7 @@ public class NodesSpecification { ! context.getDeployState().getProperties().isBootstrap(), false, Optional.empty(), - Optional.empty(), + context.getDeployState().getWantedDockerImageRepo(), Optional.empty()); } @@ -160,7 +166,7 @@ public class NodesSpecification { ! context.getDeployState().getProperties().isBootstrap(), false, Optional.empty(), - Optional.empty(), + context.getDeployState().getWantedDockerImageRepo(), Optional.empty()); } @@ -342,10 +348,15 @@ public class NodesSpecification { return new IllegalArgumentException("referenced service '" + referenceId + "' is not defined"); } + private static Optional<String> dockerImageToUse(ModelElement nodesElement, Optional<String> dockerImage) { + String dockerImageFromElement = nodesElement.stringAttribute("docker-image"); + return dockerImageFromElement == null ? dockerImage : Optional.of(dockerImageFromElement); + } + @Override public String toString() { return "specification of " + count + (dedicated ? " dedicated " : " ") + "nodes" + - (resources.isPresent() ? " with resources " + resources.get() : "") + + (resources.map(nodeResources -> " with resources " + nodeResources).orElse("")) + (groups > 1 ? " in " + groups + " groups" : ""); } |