Search in sources :

Example 1 with JobNotCompleteException

use of bio.terra.workspace.service.job.exception.JobNotCompleteException in project terra-workspace-manager by DataBiosphere.

the class JobService method retrieveJobResultWorker.

private <T> JobResultOrException<T> retrieveJobResultWorker(String jobId, Class<T> resultClass) throws StairwayException, InterruptedException {
    FlightState flightState = stairwayComponent.get().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) {
                    return new JobResultOrException<T>().exception((RuntimeException) exception);
                } else {
                    return new JobResultOrException<T>().exception(new JobResponseException("wrap non-runtime exception", exception));
                }
            }
            throw new InvalidResultStateException("Failed operation with no exception reported");
        case SUCCESS:
            return new JobResultOrException<T>().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.workspace.service.job.exception.InvalidResultStateException) FlightMap(bio.terra.stairway.FlightMap) JobNotCompleteException(bio.terra.workspace.service.job.exception.JobNotCompleteException) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) JobNotCompleteException(bio.terra.workspace.service.job.exception.JobNotCompleteException) InvalidResultStateException(bio.terra.workspace.service.job.exception.InvalidResultStateException) StairwayException(bio.terra.stairway.exception.StairwayException) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException) JobNotFoundException(bio.terra.workspace.service.job.exception.JobNotFoundException) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) DuplicateJobIdException(bio.terra.workspace.service.job.exception.DuplicateJobIdException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

FlightMap (bio.terra.stairway.FlightMap)1 FlightState (bio.terra.stairway.FlightState)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 DuplicateJobIdException (bio.terra.workspace.service.job.exception.DuplicateJobIdException)1 InternalStairwayException (bio.terra.workspace.service.job.exception.InternalStairwayException)1 InvalidResultStateException (bio.terra.workspace.service.job.exception.InvalidResultStateException)1 JobNotCompleteException (bio.terra.workspace.service.job.exception.JobNotCompleteException)1 JobNotFoundException (bio.terra.workspace.service.job.exception.JobNotFoundException)1 JobResponseException (bio.terra.workspace.service.job.exception.JobResponseException)1 ExecutionException (java.util.concurrent.ExecutionException)1