diff options
author | andreer <andreer@oath.com> | 2019-01-17 16:24:59 +0100 |
---|---|---|
committer | andreer <andreer@oath.com> | 2019-01-17 16:24:59 +0100 |
commit | bc653fbba2314b1c7b42ef9ad81bec05d715dedd (patch) | |
tree | da57efe5e7553399f5b2d14ac613cbbfd3819ae1 /controller-server | |
parent | e87ecf42627da4fc1b38c6d8eeceadd1784558bc (diff) |
enable manually redeploying without specifying versions
Diffstat (limited to 'controller-server')
2 files changed, 60 insertions, 2 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 8f8a3ad7f55..1714294d2eb 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -862,9 +862,30 @@ public class ApplicationApiHandler extends LoggingRequestHandler { applicationPackage = Optional.of(controller.applications().getApplicationPackage(controller.applications().require(applicationId), applicationVersion.get())); } + + boolean deployDirectly = deployOptions.field("deployDirectly").asBool(); + Optional<Version> vespaVersion = optional("vespaVersion", deployOptions).map(Version::new); + + if(deployDirectly && !applicationPackage.isPresent() && !applicationVersion.isPresent() && !vespaVersion.isPresent()) { + // Redeploy the existing deployment with the same versions. + Optional<Deployment> deployment = controller.applications().get(applicationId) + .map(Application::deployments) + .flatMap(deployments -> Optional.ofNullable(deployments.get(zone))); + + if(!deployment.isPresent()) + throw new IllegalArgumentException("Can't redeploy application, no deployment currently exist"); + + applicationVersion = Optional.ofNullable(deployment.get().applicationVersion()); + if(!applicationVersion.isPresent()) + throw new IllegalArgumentException("Can't redeploy application, application version is unknown"); + + vespaVersion = Optional.ofNullable(deployment.get().version()); + applicationPackage = Optional.of(controller.applications().getApplicationPackage(controller.applications().require(applicationId), applicationVersion.get())); + } + // TODO: get rid of the json object - DeployOptions deployOptionsJsonClass = new DeployOptions(deployOptions.field("deployDirectly").asBool(), - optional("vespaVersion", deployOptions).map(Version::new), + DeployOptions deployOptionsJsonClass = new DeployOptions(deployDirectly, + vespaVersion, deployOptions.field("ignoreValidationErrors").asBool(), deployOptions.field("deployCurrentVersion").asBool()); ActivateResult result = controller.applications().deploy(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 5f17ea1c5c6..a2945cec045 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 @@ -1103,6 +1103,43 @@ public class ApplicationApiTest extends ControllerContainerTest { new File("deploy-result.json")); } + @Test + public void redeployment_succeeds_when_not_specifying_versions_or_application_package() { + // Setup + addUserToHostedOperatorRole(HostedAthenzIdentities.from(HOSTED_VESPA_OPERATOR)); + tester.computeVersionStatus(); + + ApplicationPackage applicationPackage = new ApplicationPackageBuilder() + .upgradePolicy("default") + .athenzIdentity(com.yahoo.config.provision.AthenzDomain.from("domain1"), com.yahoo.config.provision.AthenzService.from("service")) + .environment(Environment.prod) + .region("us-west-1") + .build(); + long screwdriverProjectId = 123; + ScrewdriverId screwdriverId = new ScrewdriverId(Long.toString(screwdriverProjectId)); + + createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID); + + Application application = controllerTester.createApplication(ATHENZ_TENANT_DOMAIN.getName(), "tenant1", "application1"); + controllerTester.authorize(ATHENZ_TENANT_DOMAIN, screwdriverId, ApplicationAction.deploy, application); + + // Allow systemtest to succeed by notifying completion of system test + controllerTester.jobCompletion(JobType.component) + .application(application.id()) + .projectId(screwdriverProjectId) + .uploadArtifact(applicationPackage) + .submit(); + tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/test/region/us-east-1/instance/default/", POST) + .data(createApplicationDeployData(applicationPackage, false)) + .screwdriverIdentity(screwdriverId), + new File("deploy-result.json")); + + tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/test/region/us-east-1/instance/default/", POST) + .data(createApplicationDeployData(Optional.empty(), true)) + .userIdentity(HOSTED_VESPA_OPERATOR), + new File("deploy-result.json")); + } + @Test public void testJobStatusReporting() { |