use of bio.terra.workspace.generated.model.ApiJobReport in project terra-workspace-manager by DataBiosphere.
the class JobServiceTest method testSingleRetrieval.
private void testSingleRetrieval(List<String> fids) {
ApiJobReport response = jobService.retrieveJob(fids.get(2), testUser);
assertThat(response, notNullValue());
validateJobReport(response, 2, fids);
}
use of bio.terra.workspace.generated.model.ApiJobReport in project terra-workspace-manager by DataBiosphere.
the class JobService method enumerateJobs.
public List<ApiJobReport> enumerateJobs(int offset, int limit, AuthenticatedUserRequest userRequest) {
List<FlightState> flightStateList;
try {
FlightFilter filter = new FlightFilter();
filter.addFilterInputParameter(JobMapKeys.SUBJECT_ID.getKeyName(), FlightFilterOp.EQUAL, userRequest.getSubjectId());
flightStateList = stairwayComponent.get().getFlights(offset, limit, filter);
} catch (StairwayException | InterruptedException stairwayEx) {
throw new InternalStairwayException(stairwayEx);
}
List<ApiJobReport> jobReportList = new ArrayList<>();
for (FlightState flightState : flightStateList) {
ApiJobReport jobReport = mapFlightStateToApiJobReport(flightState);
jobReportList.add(jobReport);
}
return jobReportList;
}
use of bio.terra.workspace.generated.model.ApiJobReport in project terra-workspace-manager by DataBiosphere.
the class JobsApiController method retrieveJob.
@Override
public ResponseEntity<ApiJobReport> retrieveJob(@PathVariable("jobId") String jobId) {
AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ApiJobReport jobReport = jobService.retrieveJob(jobId, userRequest);
return new ResponseEntity<>(jobReport, HttpStatus.valueOf(jobReport.getStatusCode()));
}
use of bio.terra.workspace.generated.model.ApiJobReport in project terra-workspace-manager by DataBiosphere.
the class Alpha1ApiController method enumerateJobs.
@Override
public ResponseEntity<ApiEnumerateJobsResult> enumerateJobs(UUID workspaceId, Integer limit, String pageToken, ApiResourceType resource, ApiStewardshipType stewardship, String name, ApiJobStateFilter jobState) {
// Make sure Alpha1 is enabled
features.alpha1EnabledCheck();
// Prepare the inputs
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControllerValidationUtils.validatePaginationParams(0, limit);
ResourceValidationUtils.validateOptionalResourceName(name);
// Make sure the caller has read access to the workspace
workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamWorkspaceAction.READ);
// Do the enumeration
EnumeratedJobs enumeratedJobs = alpha1Service.enumerateJobs(workspaceId, userRequest, limit, pageToken, WsmResourceFamily.fromApiOptional(resource), StewardshipType.fromApiOptional(stewardship), name, JobStateFilter.fromApi(jobState));
// Convert the result to API-speak
List<ApiEnumeratedJob> apiJobList = new ArrayList<>();
for (EnumeratedJob enumeratedJob : enumeratedJobs.getResults()) {
ApiJobReport jobReport = jobService.mapFlightStateToApiJobReport(enumeratedJob.getFlightState());
Optional<WsmResource> optResource = enumeratedJob.getResource();
ApiEnumeratedJob apiJob = new ApiEnumeratedJob().jobReport(jobReport).errorReport(enumeratedJob.getFlightState().getException().map(ErrorReportUtils::buildApiErrorReport).orElse(null)).jobDescription(enumeratedJob.getJobDescription()).operationType(enumeratedJob.getOperationType().toApiModel()).resourceType(optResource.map(r -> r.getResourceType().toApiModel()).orElse(null)).resource(optResource.map(WsmResource::toApiResourceUnion).orElse(null));
apiJobList.add(apiJob);
}
ApiEnumerateJobsResult result = new ApiEnumerateJobsResult().pageToken(enumeratedJobs.getPageToken()).totalResults(enumeratedJobs.getTotalResults()).results(apiJobList);
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of bio.terra.workspace.generated.model.ApiJobReport 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;
}
Aggregations