diff options
10 files changed, 60 insertions, 33 deletions
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 1f52d9db818..a20d502dbfb 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 @@ -42,9 +42,17 @@ public class VespaModelFactory implements ModelFactory { private final ConfigModelRegistry configModelRegistry; private final Zone zone; private final Clock clock; + private final Version version; + /** Creates a factory for vespa models for this version of the source */ @Inject public VespaModelFactory(ComponentRegistry<ConfigModelPlugin> pluginRegistry, Zone zone) { + this(Version.fromIntValues(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), pluginRegistry, zone); + } + + /** Creates a factory for vespa models of a particular version */ + public VespaModelFactory(Version version, ComponentRegistry<ConfigModelPlugin> pluginRegistry, Zone zone) { + this.version = version; List<ConfigModelBuilder> modelBuilders = new ArrayList<>(); for (ConfigModelPlugin plugin : pluginRegistry.allComponents()) { if (plugin instanceof ConfigModelBuilder) { @@ -55,11 +63,15 @@ public class VespaModelFactory implements ModelFactory { this.zone = zone; this.clock = Clock.systemUTC(); } - + public VespaModelFactory(ConfigModelRegistry configModelRegistry) { this(configModelRegistry, Clock.systemUTC()); } public VespaModelFactory(ConfigModelRegistry configModelRegistry, Clock clock) { + this(Version.fromIntValues(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), configModelRegistry, clock); + } + public VespaModelFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock) { + this.version = version; if (configModelRegistry == null) { this.configModelRegistry = new NullConfigModelRegistry(); log.info("Will not load config models from plugins, as no registry is available"); @@ -72,9 +84,7 @@ public class VespaModelFactory implements ModelFactory { /** Returns the version this model is build for */ @Override - public Version getVersion() { - return Version.fromIntValues(VespaVersion.major, VespaVersion.minor, VespaVersion.micro); - } + public Version getVersion() { return version; } @Override public Model createModel(ModelContext modelContext) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java index 61382af6a30..51995eb98cf 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java @@ -136,7 +136,7 @@ public class Deployment implements com.yahoo.config.provision.Deployment { transaction.add(deactivateCurrentActivateNew(localSessionRepo.getActiveSession(session.getApplicationId()), session, ignoreSessionStaleFailure)); if (hostProvisioner.isPresent()) { - hostProvisioner.get().activate(transaction, session.getApplicationId(), session.getProvisionInfo().getHosts()); + hostProvisioner.get().activate(transaction, session.getApplicationId(), session.getAllocatedHosts().getHosts()); } transaction.commit(); session.waitUntilActivated(timeoutBudget); 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 d9c25914b6b..ea769688813 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 @@ -115,7 +115,7 @@ public class PreparedModelsBuilder extends ModelsBuilder<PreparedModelsBuilder.P } // This method is an excellent demonstration of what happens when one is too liberal with Optional - // -bratseth, who had to write this :-/ + // -bratseth, who had to write the below :-\ private Optional<HostProvisioner> createHostProvisioner(Optional<AllocatedHosts> allocatedHosts) { Optional<HostProvisioner> nodeRepositoryProvisioner = createNodeRepositoryProvisioner(properties); if ( ! allocatedHosts.isPresent()) return nodeRepositoryProvisioner; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java index 673dc7ae568..308ca31f278 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java @@ -33,7 +33,7 @@ import java.util.Optional; * @author Ulf Lilleengen */ // This is really the store of an application, whether it is active or in an edit session -// TODO: Separate the "application store" and "session" aspects - the latter belongs in the HTTP layer +// TODO: Separate the "application store" and "session" aspects - the latter belongs in the HTTP layer -bratseth public class LocalSession extends Session implements Comparable<LocalSession> { private final ApplicationPackage applicationPackage; @@ -171,8 +171,8 @@ public class LocalSession extends Session implements Comparable<LocalSession> { public Version getVespaVersion() { return zooKeeperClient.readVespaVersion(); } - public AllocatedHosts getProvisionInfo() { - return zooKeeperClient.getProvisionInfo(); + public AllocatedHosts getAllocatedHosts() { + return zooKeeperClient.getAllocatedHosts(); } @Override diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java index 83727de1726..09fc83e225d 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java @@ -30,8 +30,7 @@ import java.util.concurrent.TimeUnit; * Zookeeper client for a specific session. Can be used to read and write session status * and create and get prepare and active barrier. * - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class SessionZooKeeperClient { @@ -188,7 +187,7 @@ public class SessionZooKeeperClient { return rootPath.append(CREATE_TIME_PATH).getAbsolute(); } - AllocatedHosts getProvisionInfo() { + AllocatedHosts getAllocatedHosts() { return loadApplicationPackage().getAllocatedHosts() .orElseThrow(() -> new IllegalStateException("Allocated hosts does not exists")); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java index 2ca120cb96b..5fea15a7b10 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java @@ -69,7 +69,7 @@ public class DeployTester { private ApplicationId id; public DeployTester(String appPath) { - this(appPath, Collections.singletonList(createDefaultModelFactory(Clock.systemUTC()))); + this(appPath, Collections.singletonList(createModelFactory(Clock.systemUTC()))); } public DeployTester(String appPath, List<ModelFactory> modelFactories) { @@ -80,7 +80,7 @@ public class DeployTester { public DeployTester(String appPath, ConfigserverConfig configserverConfig) { this(appPath, - Collections.singletonList(createDefaultModelFactory(Clock.systemUTC())), + Collections.singletonList(createModelFactory(Clock.systemUTC())), configserverConfig); } @@ -99,9 +99,16 @@ public class DeployTester { public Tenant tenant() { return tenants.defaultTenant(); } - /** Create the model factory which will be used in production */ - public static ModelFactory createDefaultModelFactory(Clock clock) { return new VespaModelFactory(new NullConfigModelRegistry(), clock); } - + /** Create a model factory for the version of this source*/ + public static ModelFactory createModelFactory(Clock clock) { + return new VespaModelFactory(new NullConfigModelRegistry(), clock); + } + + /** Create a model factory for a particular version */ + public static ModelFactory createModelFactory(Version version, Clock clock) { + return new VespaModelFactory(version, new NullConfigModelRegistry(), clock); + } + /** Create a model factory which always fails validation */ public static ModelFactory createFailingModelFactory(Version version) { return new FailingModelFactory(version); } @@ -109,20 +116,19 @@ public class DeployTester { * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet. */ public ApplicationId deployApp(String appName, Instant now) { - return deployApp(appName, Optional.empty(), now); + return deployApp(appName, null, now); } /** * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet. */ - public ApplicationId deployApp(String appName, Optional<String> vespaVersion, Instant now) { + public ApplicationId deployApp(String appName, String vespaVersion, Instant now) { Tenant tenant = tenant(); LocalSession session = tenant.getSessionFactory().createSession(testApp, appName, new TimeoutBudget(Clock.systemUTC(), Duration.ofSeconds(60))); ApplicationId id = ApplicationId.from(tenant.getName(), ApplicationName.from(appName), InstanceName.defaultName()); - PrepareParams.Builder paramsBuilder = new PrepareParams.Builder() - .applicationId(id); - if (vespaVersion.isPresent()) - paramsBuilder.vespaVersion(vespaVersion.get()); + PrepareParams.Builder paramsBuilder = new PrepareParams.Builder().applicationId(id); + if (vespaVersion != null) + paramsBuilder.vespaVersion(vespaVersion); session.prepare(new SilentDeployLogger(), paramsBuilder.build(), Optional.empty(), @@ -134,11 +140,11 @@ public class DeployTester { return id; } - public AllocatedHosts getProvisionInfoFromDeployedApp(ApplicationId applicationId) { + public AllocatedHosts getAllocatedHostsOf(ApplicationId applicationId) { Tenant tenant = tenant(); LocalSession session = tenant.getLocalSessionRepo().getSession(tenant.getApplicationRepo() .getSessionIdForApplication(applicationId)); - return session.getProvisionInfo(); + return session.getAllocatedHosts(); } public ApplicationId applicationId() { return id; } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java index 31e92cc9f93..44a39b5d4b4 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java @@ -32,7 +32,7 @@ public class HostedDeployTest { @Test public void testRedeployWithVersion() throws InterruptedException, IOException { DeployTester tester = new DeployTester("src/test/apps/hosted/", createConfigserverConfig()); - tester.deployApp("myApp", Optional.of("4.5.6"), Instant.now()); + tester.deployApp("myApp", "4.5.6", Instant.now()); Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive(); assertTrue(deployment.isPresent()); @@ -53,11 +53,23 @@ public class HostedDeployTest { } @Test + public void testDeployMultipleVersions() throws InterruptedException, IOException { + ManualClock clock = new ManualClock("2016-10-09T00:00:00"); + List<ModelFactory> modelFactories = new ArrayList<>(); + modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.1.0"), clock)); + modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.2.0"), clock)); + modelFactories.add(DeployTester.createModelFactory(Version.fromString("7.0.0"), clock)); + DeployTester tester = new DeployTester("src/test/apps/hosted/", modelFactories, createConfigserverConfig()); + ApplicationId app = tester.deployApp("myApp", Instant.now()); + assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size()); + } + + @Test public void testRedeployAfterExpiredValidationOverride() throws InterruptedException, IOException { // Old version of model fails, but application disables loading old models until 2016-10-10, so deployment works ManualClock clock = new ManualClock("2016-10-09T00:00:00"); List<ModelFactory> modelFactories = new ArrayList<>(); - modelFactories.add(DeployTester.createDefaultModelFactory(clock)); + modelFactories.add(DeployTester.createModelFactory(clock)); modelFactories.add(DeployTester.createFailingModelFactory(Version.fromIntValues(1, 0, 0))); // older than default DeployTester tester = new DeployTester("src/test/apps/validationOverride/", modelFactories, createConfigserverConfig()); tester.deployApp("myApp", clock.instant()); @@ -97,7 +109,7 @@ public class HostedDeployTest { public void testDeployWithDockerImage() throws InterruptedException, IOException { final String vespaVersion = "6.51.1"; DeployTester tester = new DeployTester("src/test/apps/hosted/", createConfigserverConfig()); - ApplicationId applicationId = tester.deployApp("myApp", Optional.of(vespaVersion), Instant.now()); + ApplicationId applicationId = tester.deployApp("myApp", vespaVersion, Instant.now()); assertProvisionInfo(vespaVersion, tester, applicationId); System.out.println("Redeploy"); @@ -109,7 +121,7 @@ public class HostedDeployTest { } private void assertProvisionInfo(String vespaVersion, DeployTester tester, ApplicationId applicationId) { - tester.getProvisionInfoFromDeployedApp(applicationId).getHosts().stream() + tester.getAllocatedHostsOf(applicationId).getHosts().stream() .forEach(h -> assertEquals(vespaVersion, h.membership().get().cluster().vespaVersion())); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/RedeployTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/RedeployTest.java index 5658e0fb2aa..49e40321321 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/RedeployTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/RedeployTest.java @@ -47,7 +47,7 @@ public class RedeployTest { @Test public void testNoRedeploy() { List<ModelFactory> modelFactories = new ArrayList<>(); - modelFactories.add(DeployTester.createDefaultModelFactory(Clock.systemUTC())); + modelFactories.add(DeployTester.createModelFactory(Clock.systemUTC())); modelFactories.add(DeployTester.createFailingModelFactory(Version.fromIntValues(1, 0, 0))); DeployTester tester = new DeployTester("ignored/app/path", modelFactories); ApplicationId id = ApplicationId.from(TenantName.from("default"), diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java index adb4defe1b7..e9417483932 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java @@ -120,7 +120,7 @@ public class LocalSessionTest { @Test(expected = IllegalStateException.class) public void require_that_no_provision_info_throws_exception() throws Exception { - createSession(TenantName.defaultName(), 3).getProvisionInfo(); + createSession(TenantName.defaultName(), 3).getAllocatedHosts(); } @Test @@ -132,7 +132,7 @@ public class LocalSessionTest { .tenant("tenant") .applicationName("foo").instanceName("quux").build(); doPrepare(session, new PrepareParams.Builder().applicationId(origId).build(), Instant.now()); - AllocatedHosts info = session.getProvisionInfo(); + AllocatedHosts info = session.getAllocatedHosts(); assertNotNull(info); assertThat(info.getHosts().size(), is(1)); assertTrue(info.getHosts().contains(new HostSpec("myhost", Collections.emptyList()))); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java index ddeb2e5dc75..412e7881a26 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java @@ -48,7 +48,7 @@ public class MockSessionZKClient extends SessionZooKeeperClient { } @Override - AllocatedHosts getProvisionInfo() { + AllocatedHosts getAllocatedHosts() { return info.orElseThrow(() -> new IllegalStateException("Could not find allocated hosts")); } |