Search in sources :

Example 1 with Flight

use of bio.terra.stairway.Flight in project terra-workspace-manager by DataBiosphere.

the class JobService method mapFlightStateToApiJobReport.

public ApiJobReport mapFlightStateToApiJobReport(FlightState flightState) {
    FlightMap inputParameters = flightState.getInputParameters();
    String description = inputParameters.get(JobMapKeys.DESCRIPTION.getKeyName(), String.class);
    FlightStatus flightStatus = flightState.getFlightStatus();
    String submittedDate = flightState.getSubmitted().toString();
    ApiJobReport.StatusEnum jobStatus = getJobStatus(flightStatus);
    String completedDate = null;
    HttpStatus statusCode = HttpStatus.ACCEPTED;
    if (jobStatus != StatusEnum.RUNNING) {
        // If the job is completed, the JobReport should include a result code indicating success or
        // failure. For failed jobs, this code is the error code. For successful jobs, this is the
        // code specified by the flight if present, or a default of 200 if not.
        completedDate = flightState.getCompleted().get().toString();
        switch(jobStatus) {
            case FAILED:
                int errorCode = flightState.getException().map(e -> ErrorReportUtils.buildApiErrorReport(e).getStatusCode()).orElseThrow(() -> new InvalidResultStateException("Flight failed with no exception reported"));
                statusCode = HttpStatus.valueOf(errorCode);
                break;
            case SUCCEEDED:
                FlightMap resultMap = getResultMap(flightState);
                statusCode = resultMap.get(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.class);
                if (statusCode == null) {
                    statusCode = HttpStatus.OK;
                }
                break;
            default:
                throw new IllegalStateException("Cannot get status code of flight in unknown state " + jobStatus);
        }
    }
    ApiJobReport jobReport = new ApiJobReport().id(flightState.getFlightId()).description(description).status(jobStatus).statusCode(statusCode.value()).submitted(submittedDate).completed(completedDate).resultURL(resultUrlFromFlightState(flightState));
    return jobReport;
}
Also used : ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ScheduledFuture(java.util.concurrent.ScheduledFuture) JobNotCompleteException(bio.terra.workspace.service.job.exception.JobNotCompleteException) StatusEnum(bio.terra.workspace.generated.model.ApiJobReport.StatusEnum) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) FlightState(bio.terra.stairway.FlightState) Path(java.nio.file.Path) InvalidResultStateException(bio.terra.workspace.service.job.exception.InvalidResultStateException) UUID(java.util.UUID) StairwayException(bio.terra.stairway.exception.StairwayException) SamWorkspaceAction(bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction) Executors(java.util.concurrent.Executors) Flight(bio.terra.stairway.Flight) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) List(java.util.List) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) FlightFilter(bio.terra.stairway.FlightFilter) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException) JobConfiguration(bio.terra.workspace.app.configuration.external.JobConfiguration) JobNotFoundException(bio.terra.workspace.service.job.exception.JobNotFoundException) Callable(java.util.concurrent.Callable) StairwayComponent(bio.terra.common.stairway.StairwayComponent) Stairway(bio.terra.stairway.Stairway) ArrayList(java.util.ArrayList) ApiErrorReport(bio.terra.workspace.generated.model.ApiErrorReport) WorkspaceFlightMapKeys(bio.terra.workspace.service.workspace.flight.WorkspaceFlightMapKeys) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) FlightFilterOp(bio.terra.stairway.FlightFilterOp) Traced(io.opencensus.contrib.spring.aop.Traced) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MdcHook(bio.terra.workspace.common.utils.MdcHook) FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) FlightBeanBag(bio.terra.workspace.common.utils.FlightBeanBag) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) Logger(org.slf4j.Logger) DuplicateJobIdException(bio.terra.workspace.service.job.exception.DuplicateJobIdException) StairwayDatabaseConfiguration(bio.terra.workspace.app.configuration.external.StairwayDatabaseConfiguration) FlightMap(bio.terra.stairway.FlightMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TracingHook(bio.terra.common.stairway.TracingHook) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) FlightStatus(bio.terra.stairway.FlightStatus) IngressConfiguration(bio.terra.workspace.app.configuration.external.IngressConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InvalidResultStateException(bio.terra.workspace.service.job.exception.InvalidResultStateException) StatusEnum(bio.terra.workspace.generated.model.ApiJobReport.StatusEnum) FlightStatus(bio.terra.stairway.FlightStatus) HttpStatus(org.springframework.http.HttpStatus) FlightMap(bio.terra.stairway.FlightMap)

Aggregations

StairwayComponent (bio.terra.common.stairway.StairwayComponent)1 TracingHook (bio.terra.common.stairway.TracingHook)1 Flight (bio.terra.stairway.Flight)1 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)1 FlightFilter (bio.terra.stairway.FlightFilter)1 FlightFilterOp (bio.terra.stairway.FlightFilterOp)1 FlightMap (bio.terra.stairway.FlightMap)1 FlightState (bio.terra.stairway.FlightState)1 FlightStatus (bio.terra.stairway.FlightStatus)1 Stairway (bio.terra.stairway.Stairway)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1 DuplicateFlightIdException (bio.terra.stairway.exception.DuplicateFlightIdException)1 FlightNotFoundException (bio.terra.stairway.exception.FlightNotFoundException)1 StairwayException (bio.terra.stairway.exception.StairwayException)1 IngressConfiguration (bio.terra.workspace.app.configuration.external.IngressConfiguration)1 JobConfiguration (bio.terra.workspace.app.configuration.external.JobConfiguration)1 StairwayDatabaseConfiguration (bio.terra.workspace.app.configuration.external.StairwayDatabaseConfiguration)1 ErrorReportUtils (bio.terra.workspace.common.utils.ErrorReportUtils)1 FlightBeanBag (bio.terra.workspace.common.utils.FlightBeanBag)1 MdcHook (bio.terra.workspace.common.utils.MdcHook)1