Search in sources :

Example 1 with JobResponseException

use of bio.terra.service.job.exception.JobResponseException in project jade-data-repo by DataBiosphere.

the class JobService method retrieveJobResultWorker.

private <T> JobResultWithStatus<T> retrieveJobResultWorker(String jobId, Class<T> resultClass) throws StairwayException, InterruptedException {
    FlightState flightState = stairway.getFlightState(jobId);
    FlightMap resultMap = flightState.getResultMap().orElse(null);
    if (resultMap == null) {
        throw new InvalidResultStateException("No result map returned from flight");
    }
    switch(flightState.getFlightStatus()) {
        case FATAL:
        case ERROR:
            if (flightState.getException().isPresent()) {
                Exception exception = flightState.getException().get();
                if (exception instanceof RuntimeException) {
                    throw (RuntimeException) exception;
                } else {
                    throw new JobResponseException("wrap non-runtime exception", exception);
                }
            }
            throw new InvalidResultStateException("Failed operation with no exception reported");
        case SUCCESS:
            HttpStatus statusCode = resultMap.get(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.class);
            if (statusCode == null) {
                statusCode = HttpStatus.OK;
            }
            return new JobResultWithStatus<T>().statusCode(statusCode).result(resultMap.get(JobMapKeys.RESPONSE.getKeyName(), resultClass));
        case RUNNING:
            throw new JobNotCompleteException("Attempt to retrieve job result before job is complete; job id: " + flightState.getFlightId());
        default:
            throw new InvalidResultStateException("Impossible case reached");
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) InvalidResultStateException(bio.terra.service.job.exception.InvalidResultStateException) HttpStatus(org.springframework.http.HttpStatus) FlightMap(bio.terra.stairway.FlightMap) JobNotCompleteException(bio.terra.service.job.exception.JobNotCompleteException) JobResponseException(bio.terra.service.job.exception.JobResponseException) JobServiceStartupException(bio.terra.service.job.exception.JobServiceStartupException) JobServiceShutdownException(bio.terra.service.job.exception.JobServiceShutdownException) JobNotCompleteException(bio.terra.service.job.exception.JobNotCompleteException) JobUnauthorizedException(bio.terra.service.job.exception.JobUnauthorizedException) InvalidResultStateException(bio.terra.service.job.exception.InvalidResultStateException) StairwayException(bio.terra.stairway.exception.StairwayException) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) JobNotFoundException(bio.terra.service.job.exception.JobNotFoundException) JobResponseException(bio.terra.service.job.exception.JobResponseException) InternalStairwayException(bio.terra.service.job.exception.InternalStairwayException)

Aggregations

InternalStairwayException (bio.terra.service.job.exception.InternalStairwayException)1 InvalidResultStateException (bio.terra.service.job.exception.InvalidResultStateException)1 JobNotCompleteException (bio.terra.service.job.exception.JobNotCompleteException)1 JobNotFoundException (bio.terra.service.job.exception.JobNotFoundException)1 JobResponseException (bio.terra.service.job.exception.JobResponseException)1 JobServiceShutdownException (bio.terra.service.job.exception.JobServiceShutdownException)1 JobServiceStartupException (bio.terra.service.job.exception.JobServiceStartupException)1 JobUnauthorizedException (bio.terra.service.job.exception.JobUnauthorizedException)1 FlightMap (bio.terra.stairway.FlightMap)1 FlightState (bio.terra.stairway.FlightState)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1 FlightNotFoundException (bio.terra.stairway.exception.FlightNotFoundException)1 StairwayException (bio.terra.stairway.exception.StairwayException)1 HttpStatus (org.springframework.http.HttpStatus)1