diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-28 13:44:10 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-28 13:44:10 +0200 |
commit | 36a72fe393ebd51f6ef4e486f463d560b93d18cd (patch) | |
tree | 1fb6b6bf23a442b6e10771fbfab6e954234cf732 /configserver | |
parent | 82049904c1ae9235eab7d11027dc85919819bee9 (diff) |
Explicitly pass the correct allocated hosts
Diffstat (limited to 'configserver')
5 files changed, 27 insertions, 40 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java index 6ef11ff7490..ae347f310dd 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java @@ -13,6 +13,7 @@ import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Version; import com.yahoo.config.provision.Zone; +import com.yahoo.lang.SettableOptional; import com.yahoo.log.LogLevel; import com.yahoo.vespa.config.server.GlobalComponentRegistry; import com.yahoo.vespa.config.server.tenant.Rotations; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java index 6d667947583..55b63126f04 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java @@ -12,6 +12,7 @@ import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.Version; import com.yahoo.config.provision.Zone; +import com.yahoo.lang.SettableOptional; import com.yahoo.vespa.config.server.ConfigServerSpec; import com.yahoo.vespa.config.server.deploy.ModelContextImpl; import com.yahoo.vespa.config.server.http.UnknownVespaVersionException; @@ -49,9 +50,16 @@ public abstract class ModelsBuilder<MODELRESULT extends ModelResult> { this.hosted = hosted; } + /** + * Builds all applicable model versions + * + * @param allocatedHosts the newest version (major and minor) (which is loaded first) decides the allocated hosts + * and assigns to this SettableOptional such that it can be used after this method returns + */ public List<MODELRESULT> buildModels(ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, ApplicationPackage applicationPackage, + SettableOptional<AllocatedHosts> allocatedHosts, Instant now) { Set<Version> versions = modelFactoryRegistry.allVersions(); @@ -69,8 +77,6 @@ public abstract class ModelsBuilder<MODELRESULT extends ModelResult> { .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); - // The newest version (major and minor) (which is loaded first) decides the allocated hosts - SettableOptional<AllocatedHosts> allocatedHosts = new SettableOptional<>(); List<MODELRESULT> allApplicationModels = new ArrayList<>(); for (int i = 0; i < majorVersions.size(); i++) { try { @@ -180,31 +186,4 @@ public abstract class ModelsBuilder<MODELRESULT extends ModelResult> { return Optional.empty(); } - /** An optional which contains a settable value */ - protected static final class SettableOptional<T> { - - private T value = null; - - /** Creates a new empty settable optional */ - private SettableOptional() {} - - /** Creates a new settable optional with the given value */ - private SettableOptional(T value) { this.value = value; } - - public boolean isPresent() { - return value != null; - } - - public T get() { - if (value == null) - throw new NoSuchElementException("No value present"); - return value; - } - - public void set(T value) { - this.value = value; - } - - } - } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/PreparedModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/PreparedModelsBuilder.java index d7610a7d817..cc382eb94d2 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/PreparedModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/PreparedModelsBuilder.java @@ -14,6 +14,7 @@ import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.Version; +import com.yahoo.lang.SettableOptional; import com.yahoo.log.LogLevel; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.host.HostValidator; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java index d5ed84f44f0..7466a85854a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.config.server.session; import com.yahoo.config.provision.*; +import com.yahoo.lang.SettableOptional; import com.yahoo.vespa.config.server.*; import com.yahoo.log.LogLevel; import com.yahoo.vespa.config.server.application.ApplicationSet; @@ -56,6 +57,7 @@ public class RemoteSession extends Session { return ApplicationSet.fromList(applicationLoader.buildModels(zooKeeperClient.readApplicationId(), zooKeeperClient.readVespaVersion(), zooKeeperClient.loadApplicationPackage(), + new SettableOptional(), clock.instant())); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java index ac9c43a6082..beb62cf3ac9 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java @@ -10,6 +10,7 @@ import com.yahoo.config.application.api.FileRegistry; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.model.api.ModelContext; import com.yahoo.config.provision.*; +import com.yahoo.lang.SettableOptional; import com.yahoo.log.LogLevel; import com.yahoo.path.Path; import com.yahoo.vespa.config.server.application.ApplicationSet; @@ -91,8 +92,8 @@ public class SessionPreparer { Preparation preparation = new Preparation(context, logger, params, currentActiveApplicationSet, tenantPath); preparation.preprocess(); try { - preparation.buildModels(now); - preparation.makeResult(); + AllocatedHosts allocatedHosts = preparation.buildModels(now); + preparation.makeResult(allocatedHosts); if ( ! params.isDryRun()) { preparation.writeStateZK(); preparation.writeRotZK(); @@ -176,13 +177,16 @@ public class SessionPreparer { checkTimeout("preprocess"); } - void buildModels(Instant now) { - this.modelResultList = preparedModelsBuilder.buildModels(applicationId, vespaVersion, applicationPackage, now); + AllocatedHosts buildModels(Instant now) { + SettableOptional<AllocatedHosts> allocatedHosts = new SettableOptional<>(); + this.modelResultList = preparedModelsBuilder.buildModels(applicationId, vespaVersion, + applicationPackage, allocatedHosts, now); checkTimeout("build models"); + return allocatedHosts.get(); } - void makeResult() { - this.prepareResult = new PrepareResult(modelResultList); + void makeResult(AllocatedHosts allocatedHosts) { + this.prepareResult = new PrepareResult(allocatedHosts, modelResultList); checkTimeout("making result from models"); } @@ -194,7 +198,7 @@ public class SessionPreparer { vespaVersion, logger, prepareResult.getFileRegistries(), - prepareResult.getProvisionInfo()); + prepareResult.allocatedHosts()); checkTimeout("write state to zookeeper"); } @@ -250,9 +254,11 @@ public class SessionPreparer { /** The result of preparation over all model versions */ private static class PrepareResult { + private final AllocatedHosts allocatedHosts; private final ImmutableList<PreparedModelsBuilder.PreparedModelResult> results; - public PrepareResult(List<PreparedModelsBuilder.PreparedModelResult> results) { + public PrepareResult(AllocatedHosts allocatedHosts, List<PreparedModelsBuilder.PreparedModelResult> results) { + this.allocatedHosts = allocatedHosts; this.results = ImmutableList.copyOf(results); } @@ -260,9 +266,7 @@ public class SessionPreparer { public List<PreparedModelsBuilder.PreparedModelResult> asList() { return results; } /** Returns the host allocations resulting from this preparation. */ - public AllocatedHosts getProvisionInfo() { - return results.asList().get(0).getModel().allocatedHosts(); // All have the same hosts allocated - } + public AllocatedHosts allocatedHosts() { return allocatedHosts; } public Map<Version, FileRegistry> getFileRegistries() { return results.stream() |