diff --git a/common/openapi.yml b/common/openapi.yml index 6ea1a8c5..123dfb6d 100644 --- a/common/openapi.yml +++ b/common/openapi.yml @@ -731,9 +731,9 @@ components: PipelineRun: description: | - Object containing the job id, status, and user-provided description of a Pipeline Run. + Object containing the job id, status, user-provided description, time submitted, and (if run is complete) time completed of a Pipeline Run. type: object - required: [ pipelineName, displayName, description ] + required: [ jobId, status, timeSubmitted ] properties: jobId: $ref: '#/components/schemas/Id' @@ -741,6 +741,10 @@ components: $ref: "#/components/schemas/PipelineRunStatus" description: $ref: "#/components/schemas/PipelineRunDescription" + timeSubmitted: + $ref: "#/components/schemas/JobTimeSubmitted" + timeCompleted: + $ref: "#/components/schemas/JobTimeCompleted" PipelineRunDescription: description: | diff --git a/service/src/main/java/bio/terra/pipelines/app/controller/PipelineRunsApiController.java b/service/src/main/java/bio/terra/pipelines/app/controller/PipelineRunsApiController.java index 1094c119..8e15963b 100644 --- a/service/src/main/java/bio/terra/pipelines/app/controller/PipelineRunsApiController.java +++ b/service/src/main/java/bio/terra/pipelines/app/controller/PipelineRunsApiController.java @@ -198,7 +198,12 @@ public ResponseEntity getAllPipelineRuns( new ApiPipelineRun() .jobId(pipelineRun.getJobId()) .status(pipelineRun.getStatus().name()) - .description(pipelineRun.getDescription())) + .description(pipelineRun.getDescription()) + .timeSubmitted(pipelineRun.getCreated().toString()) + .timeCompleted( + pipelineRun.getStatus().isCompleted() + ? pipelineRun.getUpdated().toString() + : null)) .toList(); ApiGetPipelineRunsResponse apiGetPipelineRunsResponse = diff --git a/service/src/main/java/bio/terra/pipelines/common/utils/CommonPipelineRunStatusEnum.java b/service/src/main/java/bio/terra/pipelines/common/utils/CommonPipelineRunStatusEnum.java index 045cdb34..8f6951aa 100644 --- a/service/src/main/java/bio/terra/pipelines/common/utils/CommonPipelineRunStatusEnum.java +++ b/service/src/main/java/bio/terra/pipelines/common/utils/CommonPipelineRunStatusEnum.java @@ -10,4 +10,8 @@ public enum CommonPipelineRunStatusEnum { public boolean isSuccess() { return this == SUCCEEDED; } + + public boolean isCompleted() { + return this == SUCCEEDED || this == FAILED; + } } diff --git a/service/src/test/java/bio/terra/pipelines/controller/PipelineRunsApiControllerTest.java b/service/src/test/java/bio/terra/pipelines/controller/PipelineRunsApiControllerTest.java index 63cc623a..f984fa8b 100644 --- a/service/src/test/java/bio/terra/pipelines/controller/PipelineRunsApiControllerTest.java +++ b/service/src/test/java/bio/terra/pipelines/controller/PipelineRunsApiControllerTest.java @@ -585,9 +585,13 @@ void getAsyncResultEndpointHttp() { void getAllPipelineRunsWithNoPageToken() throws Exception { int limit = 5; String pageToken = null; - PipelineRun pipelineRun = getPipelineRunPreparing(); + PipelineRun pipelineRunPreparing = getPipelineRunPreparing(); + PipelineRun pipelineRunSucceeded = + getPipelineRunWithStatus(CommonPipelineRunStatusEnum.SUCCEEDED); + PipelineRun pipelineRunFailed = getPipelineRunWithStatus(CommonPipelineRunStatusEnum.FAILED); PageResponse> pageResponse = - new PageResponse<>(List.of(pipelineRun), null, null); + new PageResponse<>( + List.of(pipelineRunPreparing, pipelineRunSucceeded, pipelineRunFailed), null, null); // the mocks when(pipelineRunsServiceMock.findPipelineRunsPaginated( @@ -605,13 +609,38 @@ void getAllPipelineRunsWithNoPageToken() throws Exception { new ObjectMapper() .readValue(result.getResponse().getContentAsString(), ApiGetPipelineRunsResponse.class); - // response should include one pipeline run + // response should include three pipeline runs assertNull(response.getPageToken()); - assertEquals(1, response.getResults().size()); - ApiPipelineRun responsePipelineRun = response.getResults().get(0); - assertEquals(pipelineRun.getStatus().name(), responsePipelineRun.getStatus()); - assertEquals(pipelineRun.getDescription(), responsePipelineRun.getDescription()); - assertEquals(pipelineRun.getJobId(), responsePipelineRun.getJobId()); + assertEquals(3, response.getResults().size()); + + // preparing run should not have a completed time + ApiPipelineRun responsePipelineRun1 = response.getResults().get(0); + assertEquals(pipelineRunPreparing.getStatus().name(), responsePipelineRun1.getStatus()); + assertEquals(pipelineRunPreparing.getDescription(), responsePipelineRun1.getDescription()); + assertEquals(pipelineRunPreparing.getJobId(), responsePipelineRun1.getJobId()); + assertEquals( + pipelineRunPreparing.getCreated().toString(), responsePipelineRun1.getTimeSubmitted()); + assertNull(responsePipelineRun1.getTimeCompleted()); + + // succeeded run should have a completed time + ApiPipelineRun responsePipelineRun2 = response.getResults().get(1); + assertEquals(pipelineRunSucceeded.getStatus().name(), responsePipelineRun2.getStatus()); + assertEquals(pipelineRunSucceeded.getDescription(), responsePipelineRun2.getDescription()); + assertEquals(pipelineRunSucceeded.getJobId(), responsePipelineRun2.getJobId()); + assertEquals( + pipelineRunSucceeded.getCreated().toString(), responsePipelineRun2.getTimeSubmitted()); + assertEquals( + pipelineRunSucceeded.getUpdated().toString(), responsePipelineRun2.getTimeCompleted()); + + // failed run should have a completed time + ApiPipelineRun responsePipelineRun3 = response.getResults().get(2); + assertEquals(pipelineRunFailed.getStatus().name(), responsePipelineRun3.getStatus()); + assertEquals(pipelineRunFailed.getDescription(), responsePipelineRun3.getDescription()); + assertEquals(pipelineRunFailed.getJobId(), responsePipelineRun3.getJobId()); + assertEquals( + pipelineRunFailed.getCreated().toString(), responsePipelineRun3.getTimeSubmitted()); + assertEquals( + pipelineRunFailed.getUpdated().toString(), responsePipelineRun3.getTimeCompleted()); } @Test