Search in sources :

Example 6 with ApiJobReport

use of bio.terra.workspace.generated.model.ApiJobReport in project terra-workspace-manager by DataBiosphere.

the class JobService method retrieveAsyncJobResult.

/**
 * Retrieves the result of an asynchronous job.
 *
 * <p>Stairway has no concept of synchronous vs asynchronous flights. However, MC Terra has a
 * service-level standard result for asynchronous jobs which includes a ApiJobReport and either a
 * result or error if the job is complete. This is a convenience for callers who would otherwise
 * need to construct their own AsyncJobResult object.
 *
 * <p>Unlike retrieveJobResult, this will not throw for a flight in progress. Instead, it will
 * return a ApiJobReport without a result or error.
 */
public <T> AsyncJobResult<T> retrieveAsyncJobResult(String jobId, Class<T> resultClass, AuthenticatedUserRequest userRequest) {
    try {
        // jobId=flightId
        verifyUserAccess(jobId, userRequest);
        ApiJobReport jobReport = retrieveJob(jobId, userRequest);
        if (jobReport.getStatus().equals(StatusEnum.RUNNING)) {
            return new AsyncJobResult<T>().jobReport(jobReport);
        }
        JobResultOrException<T> resultOrException = retrieveJobResultWorker(jobId, resultClass);
        final ApiErrorReport errorReport;
        if (jobReport.getStatus().equals(StatusEnum.FAILED)) {
            errorReport = ErrorReportUtils.buildApiErrorReport(resultOrException.getException());
        } else {
            errorReport = null;
        }
        return new AsyncJobResult<T>().jobReport(jobReport).result(resultOrException.getResult()).errorReport(errorReport);
    } catch (StairwayException | InterruptedException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    }
}
Also used : ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ApiErrorReport(bio.terra.workspace.generated.model.ApiErrorReport) StairwayException(bio.terra.stairway.exception.StairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException)

Example 7 with ApiJobReport

use of bio.terra.workspace.generated.model.ApiJobReport in project terra-workspace-manager by DataBiosphere.

the class JobServiceTest method testEnumRange.

// Get some range and compare it with the fids
private void testEnumRange(List<String> fids, int offset, int limit) {
    List<ApiJobReport> jobList = jobService.enumerateJobs(offset, limit, testUser);
    assertThat(jobList, notNullValue());
    int index = offset;
    for (ApiJobReport job : jobList) {
        validateJobReport(job, index, fids);
        index++;
    }
}
Also used : ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport)

Aggregations

ApiJobReport (bio.terra.workspace.generated.model.ApiJobReport)7 StairwayException (bio.terra.stairway.exception.StairwayException)3 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)3 InternalStairwayException (bio.terra.workspace.service.job.exception.InternalStairwayException)3 ArrayList (java.util.ArrayList)3 FlightFilter (bio.terra.stairway.FlightFilter)2 FlightState (bio.terra.stairway.FlightState)2 ErrorReportUtils (bio.terra.workspace.common.utils.ErrorReportUtils)2 ApiErrorReport (bio.terra.workspace.generated.model.ApiErrorReport)2 SamWorkspaceAction (bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction)2 List (java.util.List)2 UUID (java.util.UUID)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 HttpStatus (org.springframework.http.HttpStatus)2 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