diff options
author | Martin Polden <mpolden@mpolden.no> | 2018-02-26 15:15:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-26 15:15:22 +0100 |
commit | 784e50fff8f6658f2565633d5cec8619591311b5 (patch) | |
tree | db2e4ab7fb302c9d16937a20ac1e6d79d208c377 | |
parent | 5b93d0236a7db2995a158ad79b0c25e1fa8173f6 (diff) | |
parent | 43c44bae625950a80f93417f569a6cdc1684f306 (diff) |
Merge pull request #5149 from vespa-engine/bjorncs/remove-screwdriver-v1-jobreport
Remove /screwdriver/v1/jobreport api
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilter.java | 3 | ||||
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiHandler.java | 57 | ||||
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java | 138 | ||||
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/jobreport-unexpected-completion.json (renamed from controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/responses/unexpected-completion.json) | 0 | ||||
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilterTest.java | 1 | ||||
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiTest.java | 147 |
6 files changed, 139 insertions, 207 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilter.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilter.java index 5be7fe03319..8a539beb83a 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilter.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilter.java @@ -112,8 +112,7 @@ public class ControllerAuthorizationFilter implements SecurityRequestFilter { private static boolean isWhiteListedOperation(Path path, Method method) { return path.matches("/screwdriver/v1/jobsToRun") || // TODO EOL'ed API, remove this once api is gone path.matches("/application/v4/user") && method == PUT || // Create user tenant - path.matches("/application/v4/tenant/{tenant}") && method == POST || // Create tenant - path.matches("/screwdriver/v1/jobreport"); // TODO To be migrated to application/v4 + path.matches("/application/v4/tenant/{tenant}") && method == POST; // Create tenant } private static boolean isHostedOperatorOperation(Path path, Method method) { diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiHandler.java index 14f3e6b2f61..021672248c9 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiHandler.java @@ -5,26 +5,18 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.LoggingRequestHandler; -import com.yahoo.io.IOUtils; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.slime.Cursor; -import com.yahoo.slime.Inspector; import com.yahoo.slime.Slime; -import com.yahoo.vespa.config.SlimeUtils; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.BuildService.BuildJob; -import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobError; -import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobReport; import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType; -import com.yahoo.vespa.hosted.controller.application.SourceRevision; import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse; import com.yahoo.vespa.hosted.controller.restapi.Path; import com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse; -import com.yahoo.vespa.hosted.controller.restapi.StringResponse; import com.yahoo.vespa.hosted.controller.versions.VespaVersion; import com.yahoo.yolean.Exceptions; -import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Optional; @@ -82,9 +74,6 @@ public class ScrewdriverApiHandler extends LoggingRequestHandler { private HttpResponse post(HttpRequest request) { Path path = new Path(request.getUri().getPath()); - if (path.matches("/screwdriver/v1/jobreport")) { - return notifyJobCompletion(request); - } if (path.matches("/screwdriver/v1/trigger/tenant/{tenant}/application/{application}")) { return trigger(request, path.get("tenant"), path.get("application")); } @@ -147,52 +136,6 @@ public class ScrewdriverApiHandler extends LoggingRequestHandler { return new SlimeJsonResponse(slime); } - /** - * @deprecated Method migrated to application v4 - this method will be removed soon. - */ - @Deprecated - private HttpResponse notifyJobCompletion(HttpRequest request) { - controller.applications().notifyJobCompletion(toJobReport(toSlime(request.getData()).get())); - return new StringResponse("ok"); - } - - private Slime toSlime(InputStream jsonStream) { - try { - byte[] jsonBytes = IOUtils.readBytes(jsonStream, 1000 * 1000); - return SlimeUtils.jsonToSlime(jsonBytes); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private JobReport toJobReport(Inspector report) { - Optional<JobError> jobError = Optional.empty(); - if (report.field("jobError").valid()) { - jobError = Optional.of(JobError.valueOf(report.field("jobError").asString())); - } - return new JobReport( - ApplicationId.from( - report.field("tenant").asString(), - report.field("application").asString(), - report.field("instance").asString()), - JobType.fromJobName(report.field("jobName").asString()), - report.field("projectId").asLong(), - report.field("buildNumber").asLong(), - toSourceRevision(report.field("sourceRevision")), - jobError - ); - } - - private static Optional<SourceRevision> toSourceRevision(Inspector object) { - if (!object.field("repository").valid() || - !object.field("branch").valid() || - !object.field("commit").valid()) { - return Optional.empty(); - } - return Optional.of(new SourceRevision(object.field("repository").asString(), object.field("branch").asString(), - object.field("commit").asString())); - } - private static String asString(InputStream in) { Scanner scanner = new Scanner(in).useDelimiter("\\A"); if (scanner.hasNext()) { 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 ecc20110445..5f47d77fbbe 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 @@ -2,13 +2,19 @@ package com.yahoo.vespa.hosted.controller.restapi.application; import com.yahoo.application.container.handler.Request; +import com.yahoo.application.container.handler.Response; +import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.RegionName; +import com.yahoo.slime.Cursor; +import com.yahoo.slime.Slime; import com.yahoo.vespa.athenz.api.AthenzDomain; import com.yahoo.vespa.athenz.api.AthenzIdentity; import com.yahoo.vespa.athenz.api.AthenzUser; import com.yahoo.vespa.athenz.api.NToken; +import com.yahoo.vespa.config.SlimeUtils; import com.yahoo.vespa.hosted.controller.Application; import com.yahoo.vespa.hosted.controller.ConfigServerClientMock; import com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId; @@ -21,15 +27,18 @@ import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServ import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId; import com.yahoo.vespa.hosted.controller.api.integration.organization.MockOrganization; import com.yahoo.vespa.hosted.controller.api.integration.organization.User; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId; import com.yahoo.vespa.hosted.controller.application.ApplicationPackage; import com.yahoo.vespa.hosted.controller.application.ClusterInfo; import com.yahoo.vespa.hosted.controller.application.ClusterUtilization; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.DeploymentJobs; import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics; +import com.yahoo.vespa.hosted.controller.application.JobStatus; import com.yahoo.vespa.hosted.controller.athenz.mock.AthenzClientFactoryMock; import com.yahoo.vespa.hosted.controller.athenz.mock.AthenzDbMock; import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; +import com.yahoo.vespa.hosted.controller.deployment.BuildJob; import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester; import com.yahoo.vespa.hosted.controller.restapi.ContainerTester; import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest; @@ -57,6 +66,11 @@ import static com.yahoo.application.container.handler.Request.Method.DELETE; import static com.yahoo.application.container.handler.Request.Method.GET; import static com.yahoo.application.container.handler.Request.Method.POST; import static com.yahoo.application.container.handler.Request.Method.PUT; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bratseth @@ -80,6 +94,8 @@ public class ApplicationApiTest extends ControllerContainerTest { private static final UserId USER_ID = new UserId("myuser"); private static final UserId HOSTED_VESPA_OPERATOR = new UserId("johnoperator"); private static final NToken N_TOKEN = new NToken("dummy"); + private static final ZoneId TEST_ZONE = ZoneId.from(Environment.test, RegionName.from("us-east-1")); + private static final ZoneId STAGING_ZONE = ZoneId.from(Environment.staging, RegionName.from("us-east-3")); @Test public void testApplicationApi() throws Exception { @@ -772,6 +788,128 @@ public class ApplicationApiTest extends ControllerContainerTest { } + @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(); + + Version vespaVersion = new Version("6.1"); // system version from mock config server client + + BuildJob job = new BuildJob(this::notifyCompletion, 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", DELETE).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()); + + Thread.sleep(50); // ???? + // Check that the *first* DELETE has removed the enqueued jobs. + assertResponse(request("/screwdriver/v1/jobsToRun", DELETE).get(), 200, "[]"); + } + + @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(this::notifyCompletion, 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()); + } + + private void notifyCompletion(DeploymentJobs.JobReport report) { + assertResponse(request("/application/v4/tenant/tenant1/application/application1/jobreport", POST) + .userIdentity(HOSTED_VESPA_OPERATOR) + .data(asJson(report)) + .get(), + 200, "{\"message\":\"ok\"}"); + } + + private static byte[] asJson(DeploymentJobs.JobReport report) { + Slime slime = new Slime(); + Cursor cursor = slime.setObject(); + cursor.setLong("projectId", report.projectId()); + cursor.setString("jobName", report.jobType().jobName()); + cursor.setLong("buildNumber", report.buildNumber()); + report.jobError().ifPresent(jobError -> cursor.setString("jobError", jobError.name())); + report.sourceRevision().ifPresent(sr -> { + Cursor sourceRevision = cursor.setObject("sourceRevision"); + sourceRevision.setString("repository", sr.repository()); + sourceRevision.setString("branch", sr.branch()); + sourceRevision.setString("commit", sr.commit()); + }); + cursor.setString("tenant", report.applicationId().tenant().value()); + cursor.setString("application", report.applicationId().application().value()); + cursor.setString("instance", report.applicationId().instance().value()); + try { + return SlimeUtils.toJsonBytes(slime); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + private HttpEntity createApplicationDeployData(ApplicationPackage applicationPackage, Optional<Long> screwdriverJobId) { return createApplicationDeployData(Optional.of(applicationPackage), screwdriverJobId); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/responses/unexpected-completion.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/jobreport-unexpected-completion.json index 8ffd9511a96..8ffd9511a96 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/responses/unexpected-completion.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/jobreport-unexpected-completion.json diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilterTest.java index 497f865a2a5..c4863a0eb79 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/filter/ControllerAuthorizationFilterTest.java @@ -57,7 +57,6 @@ public class ControllerAuthorizationFilterTest { assertIsAllowed(invokeFilter(filter, createRequest(PUT, "/application/v4/user", USER))); assertIsAllowed(invokeFilter(filter, createRequest(POST, "/application/v4/tenant/john", USER))); assertIsAllowed(invokeFilter(filter, createRequest(DELETE, "/screwdriver/v1/jobsToRun", USER))); - assertIsAllowed(invokeFilter(filter, createRequest(DELETE, "/screwdriver/v1/jobreport", USER))); } @Test diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiTest.java index dfeabaf051c..36bfc246909 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/ScrewdriverApiTest.java @@ -2,24 +2,8 @@ package com.yahoo.vespa.hosted.controller.restapi.screwdriver; import com.yahoo.application.container.handler.Request; -import com.yahoo.application.container.handler.Response; -import com.yahoo.component.Version; -import com.yahoo.config.provision.Environment; -import com.yahoo.config.provision.RegionName; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.Slime; -import com.yahoo.vespa.athenz.api.AthenzIdentity; -import com.yahoo.vespa.athenz.api.AthenzUser; -import com.yahoo.vespa.config.SlimeUtils; import com.yahoo.vespa.hosted.controller.Application; -import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId; -import com.yahoo.vespa.hosted.controller.application.ApplicationPackage; -import com.yahoo.vespa.hosted.controller.application.DeploymentJobs; -import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobError; import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType; -import com.yahoo.vespa.hosted.controller.application.JobStatus; -import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; -import com.yahoo.vespa.hosted.controller.deployment.BuildJob; import com.yahoo.vespa.hosted.controller.deployment.BuildSystem; import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester; import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest; @@ -27,27 +11,18 @@ import com.yahoo.vespa.hosted.controller.versions.VersionStatus; import org.junit.Test; import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; /** * @author bratseth * @author jvenstad */ -// TODO Move /application/v4/.../jobreport specific testing to ApplicationApiTest public class ScrewdriverApiTest extends ControllerContainerTest { private static final String responseFiles = "src/test/java/com/yahoo/vespa/hosted/controller/restapi/screwdriver/responses/"; - private static final ZoneId testZone = ZoneId.from(Environment.test, RegionName.from("us-east-1")); - private static final ZoneId stagingZone = ZoneId.from(Environment.staging, RegionName.from("us-east-3")); - private static final AthenzIdentity HOSTED_VESPA_OPERATOR = AthenzUser.fromUserId("johnoperator"); @Test public void testGetReleaseStatus() throws Exception { @@ -62,98 +37,6 @@ public class ScrewdriverApiTest extends ControllerContainerTest { } @Test - public void testJobStatusReporting() throws Exception { - ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles); - addUserToHostedOperatorRole(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(); - - Version vespaVersion = new Version("6.1"); // system version from mock config server client - - BuildJob job = new BuildJob(this::notifyCompletion, tester.artifactRepository()) - .application(app) - .projectId(projectId); - job.type(JobType.component).uploadArtifact(applicationPackage).submit(); - tester.deploy(app, applicationPackage, testZone, projectId); - job.type(JobType.systemTest).submit(); - - // Notifying about unknown job fails - Request request = new Request("http://localhost:8080/application/v4/tenant/tenant1/application/application1/jobreport", - asJson(job.type(JobType.productionUsEast3).report()), - Request.Method.POST); - addIdentityToRequest(request, HOSTED_VESPA_OPERATOR); - tester.containerTester().assertResponse(request, new File("unexpected-completion.json"), 400); - - // ... and assert it was recorded - JobStatus recordedStatus = - tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(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(JobType.productionApNortheast2); - assertNull("Status of never-triggered jobs is empty", recordedStatus); - - Response response; - - response = container.handleRequest(new Request("http://localhost:8080/screwdriver/v1/jobsToRun", "", Request.Method.GET)); - assertTrue("Response contains system-test", response.getBodyAsString().contains(JobType.systemTest.jobName())); - assertTrue("Response contains staging-test", response.getBodyAsString().contains(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(new Request("http://localhost:8080/screwdriver/v1/jobsToRun", "", Request.Method.DELETE)); - assertTrue("Response contains system-test", response.getBodyAsString().contains(JobType.systemTest.jobName())); - assertTrue("Response contains staging-test", response.getBodyAsString().contains(JobType.stagingTest.jobName())); - assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries()); - - Thread.sleep(50); - // Check that the *first* DELETE has removed the enqueued jobs. - assertResponse(new Request("http://localhost:8080/screwdriver/v1/jobsToRun", "", Request.Method.DELETE), - 200, "[]"); - } - - @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(this::notifyCompletion, tester.artifactRepository()) - .application(app) - .projectId(projectId); - job.type(JobType.component).uploadArtifact(applicationPackage).submit(); - - tester.deploy(app, applicationPackage, testZone, projectId); - job.type(JobType.systemTest).submit(); - tester.deploy(app, applicationPackage, stagingZone, projectId); - job.type(JobType.stagingTest).error(JobError.outOfCapacity).submit(); - - // Appropriate error is recorded - JobStatus jobStatus = tester.controller().applications().get(app.id()) - .get() - .deploymentJobs() - .jobStatus() - .get(JobType.stagingTest); - assertFalse(jobStatus.isSuccess()); - assertEquals(JobError.outOfCapacity, jobStatus.jobError().get()); - } - - @Test public void testTriggerJobForApplication() { ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles); BuildSystem buildSystem = tester.controller().applications().deploymentTrigger().buildSystem(); @@ -195,34 +78,4 @@ public class ScrewdriverApiTest extends ControllerContainerTest { assertEquals(1L, buildSystem.jobs().get(0).projectId()); } - private void notifyCompletion(DeploymentJobs.JobReport report) { - assertResponse(new Request("http://localhost:8080/application/v4/tenant/tenant1/application/application1/jobreport", - asJson(report), - Request.Method.POST), - 200, "{\"message\":\"ok\"}"); - } - - private static byte[] asJson(DeploymentJobs.JobReport report) { - Slime slime = new Slime(); - Cursor cursor = slime.setObject(); - cursor.setLong("projectId", report.projectId()); - cursor.setString("jobName", report.jobType().jobName()); - cursor.setLong("buildNumber", report.buildNumber()); - report.jobError().ifPresent(jobError -> cursor.setString("jobError", jobError.name())); - report.sourceRevision().ifPresent(sr -> { - Cursor sourceRevision = cursor.setObject("sourceRevision"); - sourceRevision.setString("repository", sr.repository()); - sourceRevision.setString("branch", sr.branch()); - sourceRevision.setString("commit", sr.commit()); - }); - cursor.setString("tenant", report.applicationId().tenant().value()); - cursor.setString("application", report.applicationId().application().value()); - cursor.setString("instance", report.applicationId().instance().value()); - try { - return SlimeUtils.toJsonBytes(slime); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - } |