diff options
author | Harald Musum <musum@oath.com> | 2018-04-06 15:47:35 +0200 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-04-06 15:47:35 +0200 |
commit | cf5544c7c11f21a4a64defd963bb54c76758cbd0 (patch) | |
tree | 9405f7cde1f3e997fbf54746d692705d5372c444 | |
parent | 67e98ccb86f0fa4838a4b2112fd7c0c654972cab (diff) |
Deploy with one API call to config server when in CD and being user tenant
4 files changed, 91 insertions, 6 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerClient.java index 852629768c5..c38bcb7e65d 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerClient.java @@ -29,6 +29,11 @@ public interface ConfigServerClient { PreparedApplication prepare(DeploymentId applicationInstance, DeployOptions deployOptions, Set<String> rotationCnames, Set<String> rotationNames, byte[] content); + // TODO: Remove default implementation + default PreparedApplication deploy(DeploymentId applicationInstance, DeployOptions deployOptions, Set<String> rotationCnames, Set<String> rotationNames, byte[] content) { + throw new UnsupportedOperationException("Not implemented yet"); + } + List<String> getNodeQueryHost(DeploymentId applicationInstance, String type) throws NoInstanceException; void restart(DeploymentId applicationInstance, Optional<Hostname> hostname) throws NoInstanceException; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index 83ae5f5332f..c6fadb45161 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -8,6 +8,7 @@ import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.application.api.ValidationId; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; import com.yahoo.vespa.athenz.api.NToken; import com.yahoo.vespa.curator.Lock; @@ -330,10 +331,17 @@ public class ApplicationController { // Carry out deployment options = withVersion(version, options); - ConfigServerClient.PreparedApplication preparedApplication = - configServer.prepare(new DeploymentId(applicationId, zone), options, cnames, rotationNames, - applicationPackage.zippedContent()); - preparedApplication.activate(); + + + ConfigServerClient.PreparedApplication preparedApplication; + DeploymentId deploymentId = new DeploymentId(applicationId, zone); + // TODO: Using deploy() only for user tenants in CD for now + if (controller.system().equals(SystemName.cd) && deploymentId.applicationId().tenant().value().startsWith(Tenant.userPrefix)) { + preparedApplication = configServer.deploy(deploymentId, options, cnames, rotationNames, applicationPackage.zippedContent()); + } else { + preparedApplication = configServer.prepare(deploymentId, options, cnames, rotationNames, applicationPackage.zippedContent()); + preparedApplication.activate(); + } application = application.withNewDeployment(zone, applicationVersion, version, clock.instant()); store(application); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java index 08f96195d2a..d0e378a74d5 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java @@ -121,7 +121,52 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS } }; } - + + @Override + public PreparedApplication deploy(DeploymentId deployment, DeployOptions deployOptions, Set<String> rotationCnames, + Set<String> rotationNames, byte[] content) { + lastPrepareVersion = deployOptions.vespaVersion.map(Version::new).orElse(null); + if (prepareException != null) { + RuntimeException prepareException = this.prepareException; + this.prepareException = null; + throw prepareException; + } + applicationActivated.put(deployment.applicationId(), false); + applicationInstances.put(deployment.applicationId(), UUID.randomUUID() + ":4080"); + + return new PreparedApplication() { + @Override + public void activate() { /* Nothing to do, done in */} + + @Override + public List<Log> messages() { + Log warning = new Log(); + warning.level = "WARNING"; + warning.time = 1; + warning.message = "The warning"; + + Log info = new Log(); + info.level = "INFO"; + info.time = 2; + info.message = "The info"; + + return Arrays.asList(warning, info); + } + + @Override + public PrepareResponse prepareResponse() { + applicationActivated.put(deployment.applicationId(), true); + + PrepareResponse prepareResponse = new PrepareResponse(); + prepareResponse.message = "foo"; + prepareResponse.configChangeActions = new ConfigChangeActions(Collections.emptyList(), + Collections.emptyList()); + prepareResponse.tenant = new TenantId("tenant"); + return prepareResponse; + } + }; + } + @Override public List<String> getNodeQueryHost(DeploymentId deployment, String type) { if (applicationInstances.containsKey(deployment.applicationId())) { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java index 2dacadaaa3e..4d0a17a74f4 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java @@ -1,7 +1,6 @@ // 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.controller.restapi.application; -import com.google.common.base.Functions; import com.yahoo.application.container.handler.Request; import com.yahoo.application.container.handler.Response; import com.yahoo.component.Version; @@ -423,6 +422,34 @@ public class ApplicationApiTest extends ControllerContainerTest { new File("deploy-result.json")); } + + // Tests deployment to config server when using just on API call + // For now this depends on a switch in ApplicationController that does this for by- tenants in CD only + @Test + public void testDeployDirectlyUsingOneCallForDeploy() throws Exception { + // Setup + ContainerControllerTester controllerTester = new ContainerControllerTester(container, responseFiles); + ContainerTester tester = controllerTester.containerTester(); + tester.updateSystemVersion(); + UserId userId = new UserId("new_user"); + createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, userId); + + // Create tenant + // PUT (create) the authenticated user + byte[] data = new byte[0]; + tester.assertResponse(request("/application/v4/user?user=new_user&domain=by", PUT) + .data(data) + .userIdentity(userId), // Normalized to by-new-user by API + new File("create-user-response.json")); + + // POST (deploy) an application to a dev zone + HttpEntity entity = createApplicationDeployData(applicationPackage, Optional.empty()); + tester.assertResponse(request("/application/v4/tenant/by-new-user/application/application1/environment/dev/region/cd-us-central-1/instance/default", POST) + .data(entity) + .userIdentity(userId), + new File("deploy-result.json")); + } + @Test public void testSortsDeploymentsAndJobs() throws Exception { // Setup |