Search in sources :

Example 1 with JobResponseException

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

the class StairwayExceptionSerializer method serialize.

@Override
public String serialize(Exception rawException) {
    if (rawException == null) {
        return StringUtils.EMPTY;
    }
    Exception exception = rawException;
    // Wrap non-runtime exceptions so they can be rethrown later
    if (!(exception instanceof RuntimeException)) {
        exception = new JobResponseException(exception.getMessage(), exception);
    }
    StairwayExceptionFields fields = new StairwayExceptionFields().setClassName(exception.getClass().getName()).setMessage(exception.getMessage());
    if (exception instanceof ErrorReportException) {
        fields.setApiErrorReportException(true).setErrorDetails(((ErrorReportException) exception).getCauses()).setErrorCode(((ErrorReportException) exception).getStatusCode().value());
    } else {
        fields.setApiErrorReportException(false);
    }
    try {
        return objectMapper.writeValueAsString(fields);
    } catch (JsonProcessingException ex) {
        // JSON processing to fail.
        throw new ExceptionSerializerException("This should never happen", ex);
    }
}
Also used : ErrorReportException(bio.terra.common.exception.ErrorReportException) ExceptionSerializerException(bio.terra.workspace.service.job.exception.ExceptionSerializerException) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ExceptionSerializerException(bio.terra.workspace.service.job.exception.ExceptionSerializerException) ErrorReportException(bio.terra.common.exception.ErrorReportException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with JobResponseException

use of bio.terra.workspace.service.job.exception.JobResponseException 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

JobResponseException (bio.terra.workspace.service.job.exception.JobResponseException)2 ErrorReportException (bio.terra.common.exception.ErrorReportException)1 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 ExceptionSerializerException (bio.terra.workspace.service.job.exception.ExceptionSerializerException)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 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (java.util.concurrent.ExecutionException)1