diff options
author | Harald Musum <musum@oath.com> | 2018-10-18 00:43:43 +0200 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-10-18 00:43:43 +0200 |
commit | 474dc26a6be41eb6a59b2d35ad3fccb392238d1d (patch) | |
tree | 9ef115317df2684a2618bc7ad77b94cf154c615a /configserver | |
parent | 049e890a72b362c87498ba2ad379a62ef2218de7 (diff) |
Simplify deploying app in tester
Do not depend on setting application id when deploying and simplify
deploying where possible
Diffstat (limited to 'configserver')
5 files changed, 42 insertions, 38 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java index 2ae8917e905..ef25effbc64 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java @@ -280,7 +280,7 @@ public class ApplicationRepositoryTest { .configDefinitionsDir(Files.createTempDir().getAbsolutePath()) .sessionLifetime(60)); DeployTester tester = new DeployTester(configserverConfig, clock); - tester.deployApp("src/test/apps/app", "myapp", Instant.now()); // session 2 (numbering starts at 2) + tester.deployApp("src/test/apps/app", clock.instant()); // session 2 (numbering starts at 2) clock.advance(Duration.ofSeconds(10)); Optional<Deployment> deployment2 = tester.redeployFromLocalActive(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java index 3fce8538ad6..205b69d1a1e 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java @@ -56,7 +56,7 @@ public class ConfigServerBootstrapTest { ConfigserverConfig configserverConfig = createConfigserverConfig(temporaryFolder); InMemoryProvisioner provisioner = new InMemoryProvisioner(true, "host0", "host1", "host3"); DeployTester tester = new DeployTester(configserverConfig, provisioner); - tester.deployApp("src/test/apps/hosted/", "myApp", Instant.now()); + tester.deployApp("src/test/apps/hosted/"); File versionFile = temporaryFolder.newFile(); VersionState versionState = new VersionState(versionFile); @@ -82,7 +82,7 @@ public class ConfigServerBootstrapTest { public void testBootstrapWhenRedeploymentFails() throws Exception { ConfigserverConfig configserverConfig = createConfigserverConfig(temporaryFolder); DeployTester tester = new DeployTester(configserverConfig); - tester.deployApp("src/test/apps/hosted/", "myApp", Instant.now()); + tester.deployApp("src/test/apps/hosted/"); File versionFile = temporaryFolder.newFile(); VersionState versionState = new VersionState(versionFile); @@ -125,7 +125,8 @@ public class ConfigServerBootstrapTest { DeployTester tester = new DeployTester(modelFactories, configserverConfig, Clock.systemUTC(), new Zone(Environment.dev, RegionName.defaultName()), provisioner, curator); - ApplicationId app = tester.deployApp("src/test/apps/app/", "myApp", vespaVersion, Instant.now()); + tester.deployApp("src/test/apps/app/", vespaVersion, Instant.now()); + ApplicationId applicationId = tester.applicationId(); File versionFile = temporaryFolder.newFile(); VersionState versionState = new VersionState(versionFile); @@ -134,7 +135,7 @@ public class ConfigServerBootstrapTest { // Ugly hack, but I see no other way of doing it: // Manipulate application version in zookeeper so that it is an older version than the model we know, which is // the case when upgrading on non-hosted installations - curator.set(Path.fromString("/config/v2/tenants/" + app.tenant().value() + "/sessions/2/version"), Utf8.toBytes("1.2.2")); + curator.set(Path.fromString("/config/v2/tenants/" + applicationId.tenant().value() + "/sessions/2/version"), Utf8.toBytes("1.2.2")); RpcServer rpcServer = createRpcServer(configserverConfig); VipStatus vipStatus = new VipStatus(); 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 b70947de0a6..0d2654d693e 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 @@ -15,12 +15,10 @@ import com.yahoo.config.model.deploy.DeployState; import com.yahoo.config.model.provision.InMemoryProvisioner; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.Capacity; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostFilter; import com.yahoo.config.provision.HostSpec; -import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ProvisionLogger; import com.yahoo.config.provision.Provisioner; @@ -31,6 +29,7 @@ import com.yahoo.transaction.NestedTransaction; import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TimeoutBudget; +import com.yahoo.vespa.config.server.http.v2.PrepareResult; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.session.LocalSession; @@ -60,13 +59,12 @@ import java.util.Optional; public class DeployTester { private static final TenantName tenantName = TenantName.from("deploytester"); + private static final ApplicationId applicationId = ApplicationId.from(tenantName.value(), "myApp", "default"); private final Clock clock; private final TenantRepository tenantRepository; private final ApplicationRepository applicationRepository; - private ApplicationId id; - public DeployTester() { this(Collections.singletonList(createModelFactory(Clock.systemUTC()))); } @@ -148,30 +146,33 @@ public class DeployTester { /** Create a model factory which always fails validation */ public static ModelFactory createFailingModelFactory(Version version) { return new FailingModelFactory(version); } - + + /** * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet. */ - public ApplicationId deployApp(String applicationPath, String appName, Instant now) { - return deployApp(applicationPath, appName, null, now); + public PrepareResult deployApp(String applicationPath) { + return deployApp(applicationPath, null, Instant.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 applicationPath, String appName, String vespaVersion, Instant now) { - Tenant tenant = tenant(); - TimeoutBudget timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(60)); - ApplicationId id = ApplicationId.from(tenant.getName(), ApplicationName.from(appName), InstanceName.defaultName()); - PrepareParams.Builder paramsBuilder = new PrepareParams.Builder().applicationId(id); + public PrepareResult deployApp(String applicationPath, Instant now) { + return deployApp(applicationPath, null, now); + } + + /** + * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet. + */ + public PrepareResult deployApp(String applicationPath, String vespaVersion, Instant now) { + PrepareParams.Builder paramsBuilder = new PrepareParams.Builder() + .applicationId(applicationId) + .timeoutBudget(new TimeoutBudget(clock, Duration.ofSeconds(60))); if (vespaVersion != null) paramsBuilder.vespaVersion(vespaVersion); - long sessionId = applicationRepository.createSession(id, timeoutBudget, new File(applicationPath)); - applicationRepository.prepare(tenant, sessionId, paramsBuilder.build(), now); - applicationRepository.activate(tenant, sessionId, timeoutBudget, false, false); - this.id = id; - return id; + return applicationRepository.deploy(new File(applicationPath), paramsBuilder.build(), false, false, now); } public AllocatedHosts getAllocatedHostsOf(ApplicationId applicationId) { @@ -181,10 +182,10 @@ public class DeployTester { return session.getAllocatedHosts(); } - public ApplicationId applicationId() { return id; } + public ApplicationId applicationId() { return applicationId; } public Optional<com.yahoo.config.provision.Deployment> redeployFromLocalActive() { - return redeployFromLocalActive(id); + return applicationRepository.deployFromLocalActive(applicationId); } public Optional<com.yahoo.config.provision.Deployment> redeployFromLocalActive(ApplicationId 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 02059513dff..9fec88b285e 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 @@ -43,9 +43,9 @@ public class HostedDeployTest { public void testRedeployWithVersion() { CountingModelFactory modelFactory = DeployTester.createModelFactory(Version.fromString("4.5.6"), Clock.systemUTC()); DeployTester tester = new DeployTester(Collections.singletonList(modelFactory), createConfigserverConfig()); - tester.deployApp("src/test/apps/hosted/", "myApp", "4.5.6", Instant.now()); + tester.deployApp("src/test/apps/hosted/", "4.5.6", Instant.now()); - Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive(); + Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive(tester.applicationId()); assertTrue(deployment.isPresent()); deployment.get().prepare(); deployment.get().activate(); @@ -55,7 +55,8 @@ public class HostedDeployTest { @Test public void testRedeploy() { DeployTester tester = new DeployTester(createConfigserverConfig()); - ApplicationId appId = tester.deployApp("src/test/apps/hosted/", "myApp", Instant.now()); + ApplicationId appId = tester.applicationId(); + tester.deployApp("src/test/apps/hosted/"); LocalSession s1 = tester.applicationRepository().getActiveSession(appId); System.out.println("First session: " + s1.getSessionId()); assertFalse(tester.applicationRepository().getActiveSession(appId).getMetaData().isInternalRedeploy()); @@ -77,8 +78,8 @@ public class HostedDeployTest { modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.2.0"), clock)); modelFactories.add(DeployTester.createModelFactory(Version.fromString("7.0.0"), clock)); DeployTester tester = new DeployTester(modelFactories, createConfigserverConfig(), clock, Zone.defaultZone()); - ApplicationId app = tester.deployApp("src/test/apps/hosted/", "myApp", "6.2.0", Instant.now()); - assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size()); + tester.deployApp("src/test/apps/hosted/", "6.2.0", Instant.now()); + assertEquals(3, tester.getAllocatedHostsOf(tester.applicationId()).getHosts().size()); } /** Test that only the minimal set of models are created (model versions used on hosts, the wanted version and the latest version) */ @@ -108,8 +109,8 @@ public class HostedDeployTest { DeployTester tester = new DeployTester(modelFactories, createConfigserverConfig(), clock, new Zone(Environment.dev, RegionName.defaultName()), provisioner); // Deploy with version that does not exist on hosts, the model for this version should also be created - ApplicationId app = tester.deployApp("src/test/apps/hosted/", "myApp", "7.0.0", Instant.now()); - assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size()); + tester.deployApp("src/test/apps/hosted/", "7.0.0", Instant.now()); + assertEquals(3, tester.getAllocatedHostsOf(tester.applicationId()).getHosts().size()); // Check >0 not ==0 as the session watcher thread is running and will redeploy models in the background assertTrue(factory600.creationCount() > 0); @@ -139,7 +140,7 @@ public class HostedDeployTest { DeployTester tester = new DeployTester(modelFactories, createConfigserverConfig(), clock, new Zone(Environment.dev, RegionName.defaultName()), provisioner); - tester.deployApp("src/test/apps/hosted-routing-app/", "myApp", "7.2.0", Instant.now()); + tester.deployApp("src/test/apps/hosted-routing-app/", "7.2.0", Instant.now()); assertTrue("Newest is always included", factory720.creationCount() > 0); } @@ -156,14 +157,15 @@ public class HostedDeployTest { DeployTester tester = new DeployTester(modelFactories, createConfigserverConfig(), Clock.systemUTC(), new Zone(Environment.prod, RegionName.defaultName()), provisioner); + ApplicationId applicationId = tester.applicationId(); // Deploy with oldest version - ApplicationId app = tester.deployApp("src/test/apps/hosted/", "myApp", "6.0.0", Instant.now()); - assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size()); + tester.deployApp("src/test/apps/hosted/", "6.0.0", Instant.now()); + assertEquals(3, tester.getAllocatedHostsOf(applicationId).getHosts().size()); // Deploy with version that does not exist on hosts and with app package that has no write access control, // validation of access control should not be done, since the app is already deployed in prod - app = tester.deployApp("src/test/apps/hosted-no-write-access-control", "myApp", "6.1.0", Instant.now()); - assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size()); + tester.deployApp("src/test/apps/hosted-no-write-access-control", "6.1.0", Instant.now()); + assertEquals(3, tester.getAllocatedHostsOf(applicationId).getHosts().size()); } @Test @@ -174,7 +176,7 @@ public class HostedDeployTest { modelFactories.add(DeployTester.createModelFactory(clock)); modelFactories.add(DeployTester.createFailingModelFactory(Version.fromIntValues(1, 0, 0))); // older than default DeployTester tester = new DeployTester(modelFactories, createConfigserverConfig()); - tester.deployApp("src/test/apps/validationOverride/", "myApp", clock.instant()); + tester.deployApp("src/test/apps/validationOverride/", clock.instant()); // Redeployment from local active works { 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 c6f4df74049..d3380157fb4 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 @@ -28,7 +28,7 @@ public class RedeployTest { @Test public void testRedeploy() { DeployTester tester = new DeployTester(); - tester.deployApp("src/test/apps/app", "myapp", Instant.now()); + tester.deployApp("src/test/apps/app"); Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive(); assertTrue(deployment.isPresent()); |