Search in sources :

Example 1 with ContainerControllerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester in project vespa by vespa-engine.

the class ApplicationApiTest method deployment_succeeds_when_correct_domain_is_used.

@Test
public void deployment_succeeds_when_correct_domain_is_used() throws IOException {
    ContainerControllerTester controllerTester = new ContainerControllerTester(container, responseFiles);
    ContainerTester tester = controllerTester.containerTester();
    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(DeploymentJobs.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, Optional.of(screwdriverProjectId))).screwdriverIdentity(screwdriverId), new File("deploy-result.json"));
}
Also used : ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) ScrewdriverId(com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) ContainerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerTester) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Application(com.yahoo.vespa.hosted.controller.Application) File(java.io.File) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 2 with ContainerControllerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester in project vespa by vespa-engine.

the class ApplicationApiTest method testJobStatusReportingOutOfCapacity.

@Test
public void testJobStatusReportingOutOfCapacity() {
    ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
    tester.containerTester().updateSystemVersion();
    long projectId = 1;
    Application app = tester.createApplication();
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("corp-us-east-1").build();
    // Report job failing with out of capacity
    BuildJob job = new BuildJob(report -> notifyCompletion(report, tester), tester.artifactRepository()).application(app).projectId(projectId);
    job.type(DeploymentJobs.JobType.component).uploadArtifact(applicationPackage).submit();
    tester.deploy(app, applicationPackage, TEST_ZONE, projectId);
    job.type(DeploymentJobs.JobType.systemTest).submit();
    tester.deploy(app, applicationPackage, STAGING_ZONE, projectId);
    job.type(DeploymentJobs.JobType.stagingTest).error(DeploymentJobs.JobError.outOfCapacity).submit();
    // Appropriate error is recorded
    JobStatus jobStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.stagingTest);
    assertFalse(jobStatus.isSuccess());
    assertEquals(DeploymentJobs.JobError.outOfCapacity, jobStatus.jobError().get());
}
Also used : JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) BuildJob(com.yahoo.vespa.hosted.controller.deployment.BuildJob) Application(com.yahoo.vespa.hosted.controller.Application) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 3 with ContainerControllerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester in project vespa by vespa-engine.

the class ApplicationApiTest method testJobStatusReporting.

@Test
public void testJobStatusReporting() throws Exception {
    ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
    addUserToHostedOperatorRole(HostedAthenzIdentities.from(HOSTED_VESPA_OPERATOR));
    tester.containerTester().updateSystemVersion();
    long projectId = 1;
    Application app = tester.createApplication();
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("corp-us-east-1").build();
    // system version from mock config server client
    Version vespaVersion = new Version("6.1");
    BuildJob job = new BuildJob(report -> notifyCompletion(report, tester), tester.artifactRepository()).application(app).projectId(projectId);
    job.type(DeploymentJobs.JobType.component).uploadArtifact(applicationPackage).submit();
    tester.deploy(app, applicationPackage, TEST_ZONE, projectId);
    job.type(DeploymentJobs.JobType.systemTest).submit();
    // Notifying about unknown job fails
    Request request = request("/application/v4/tenant/tenant1/application/application1/jobreport", POST).data(asJson(job.type(DeploymentJobs.JobType.productionUsEast3).report())).userIdentity(HOSTED_VESPA_OPERATOR).get();
    tester.containerTester().assertResponse(request, new File("jobreport-unexpected-completion.json"), 400);
    // ... and assert it was recorded
    JobStatus recordedStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.component);
    assertNotNull("Status was recorded", recordedStatus);
    assertTrue(recordedStatus.isSuccess());
    assertEquals(vespaVersion, recordedStatus.lastCompleted().get().version());
    recordedStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.productionApNortheast2);
    assertNull("Status of never-triggered jobs is empty", recordedStatus);
    Response response;
    response = container.handleRequest(request("/screwdriver/v1/jobsToRun", GET).get());
    assertTrue("Response contains system-test", response.getBodyAsString().contains(DeploymentJobs.JobType.systemTest.jobName()));
    assertTrue("Response contains staging-test", response.getBodyAsString().contains(DeploymentJobs.JobType.stagingTest.jobName()));
    assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries());
    // Check that GET didn't affect the enqueued jobs.
    response = container.handleRequest(request("/screwdriver/v1/jobsToRun", GET).get());
    assertTrue("Response contains system-test", response.getBodyAsString().contains(DeploymentJobs.JobType.systemTest.jobName()));
    assertTrue("Response contains staging-test", response.getBodyAsString().contains(DeploymentJobs.JobType.stagingTest.jobName()));
    assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries());
}
Also used : JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) Response(com.yahoo.application.container.handler.Response) ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) Version(com.yahoo.component.Version) Request(com.yahoo.application.container.handler.Request) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) BuildJob(com.yahoo.vespa.hosted.controller.deployment.BuildJob) Application(com.yahoo.vespa.hosted.controller.Application) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) File(java.io.File) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 4 with ContainerControllerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester in project vespa by vespa-engine.

the class ControllerApiTest method testUpgraderApi.

@Test
public void testUpgraderApi() throws Exception {
    addUserToHostedOperatorRole(HOSTED_VESPA_OPERATOR);
    ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
    // Get current configuration
    tester.assertResponse(authenticatedRequest("http://localhost:8080/controller/v1/jobs/upgrader", new byte[0], Request.Method.GET), "{\"upgradesPerMinute\":0.5,\"confidenceOverrides\":[]}", 200);
    // Set invalid configuration
    tester.assertResponse(hostedOperatorRequest("http://localhost:8080/controller/v1/jobs/upgrader", "{\"upgradesPerMinute\":-1}", Request.Method.PATCH), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Upgrades per minute must be >= 0\"}", 400);
    // Ignores unrecognized field
    tester.assertResponse(hostedOperatorRequest("http://localhost:8080/controller/v1/jobs/upgrader", "{\"foo\":\"bar\"}", Request.Method.PATCH), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"No such modifiable field(s)\"}", 400);
    // Set upgrades per minute
    tester.assertResponse(hostedOperatorRequest("http://localhost:8080/controller/v1/jobs/upgrader", "{\"upgradesPerMinute\":42.0}", Request.Method.PATCH), "{\"upgradesPerMinute\":42.0,\"confidenceOverrides\":[]}", 200);
    // Override confidence
    tester.assertResponse(hostedOperatorRequest("http://localhost:8080/controller/v1/jobs/upgrader/confidence/6.42", "broken", Request.Method.POST), "{\"upgradesPerMinute\":42.0,\"confidenceOverrides\":[{\"6.42\":\"broken\"}]}", 200);
    // Override confidence for another version
    tester.assertResponse(hostedOperatorRequest("http://localhost:8080/controller/v1/jobs/upgrader/confidence/6.43", "broken", Request.Method.POST), "{\"upgradesPerMinute\":42.0,\"confidenceOverrides\":[{\"6.42\":\"broken\"},{\"6.43\":\"broken\"}]}", 200);
    // Remove first override
    tester.assertResponse(hostedOperatorRequest("http://localhost:8080/controller/v1/jobs/upgrader/confidence/6.42", "", Request.Method.DELETE), "{\"upgradesPerMinute\":42.0,\"confidenceOverrides\":[{\"6.43\":\"broken\"}]}", 200);
}
Also used : ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 5 with ContainerControllerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester in project vespa by vespa-engine.

the class DeploymentApiTest method testDeploymentApi.

@Test
public void testDeploymentApi() throws IOException {
    ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
    Version version = Version.fromString("5.0");
    tester.containerTester().updateSystemVersion(version);
    long projectId = 11;
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("corp-us-east-1").build();
    // 3 applications deploy on current system version
    Application failingApplication = tester.createApplication("domain1", "tenant1", "application1");
    Application productionApplication = tester.createApplication("domain2", "tenant2", "application2");
    Application applicationWithoutDeployment = tester.createApplication("domain3", "tenant3", "application3");
    deployCompletely(failingApplication, applicationPackage, projectId, true);
    deployCompletely(productionApplication, applicationPackage, projectId, true);
    // Deploy once so that job information is stored, then remove the deployment
    deployCompletely(applicationWithoutDeployment, applicationPackage, projectId, true);
    tester.controller().applications().deactivate(applicationWithoutDeployment, ZoneId.from("prod", "corp-us-east-1"));
    // New version released
    version = Version.fromString("5.1");
    tester.containerTester().updateSystemVersion(version);
    // Applications upgrade, 1/2 succeed
    tester.upgrader().maintain();
    tester.controller().applications().deploymentTrigger().triggerReadyJobs();
    deployCompletely(failingApplication, applicationPackage, projectId, false);
    deployCompletely(productionApplication, applicationPackage, projectId, true);
    tester.controller().updateVersionStatus(censorConfigServers(VersionStatus.compute(tester.controller()), tester.controller()));
    tester.assertResponse(authenticatedRequest("http://localhost:8080/deployment/v1/"), new File("root.json"));
}
Also used : ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) Version(com.yahoo.component.Version) VespaVersion(com.yahoo.vespa.hosted.controller.versions.VespaVersion) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Application(com.yahoo.vespa.hosted.controller.Application) File(java.io.File) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Aggregations

ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)14 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)12 Test (org.junit.Test)12 File (java.io.File)8 Application (com.yahoo.vespa.hosted.controller.Application)6 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)6 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)6 ContainerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerTester)5 HttpEntity (org.apache.http.HttpEntity)3 Request (com.yahoo.application.container.handler.Request)2 Version (com.yahoo.component.Version)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 ZoneRegistryMock (com.yahoo.vespa.hosted.controller.ZoneRegistryMock)2 ScrewdriverId (com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId)2 JobStatus (com.yahoo.vespa.hosted.controller.application.JobStatus)2 BuildJob (com.yahoo.vespa.hosted.controller.deployment.BuildJob)2 Before (org.junit.Before)2 Response (com.yahoo.application.container.handler.Response)1 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)1 ConfigServerProxyMock (com.yahoo.vespa.hosted.controller.ConfigServerProxyMock)1