Search in sources :

Example 1 with ApiJobReport

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);
}
Also used : ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport)

Example 2 with ApiJobReport

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;
}
Also used : FlightState(bio.terra.stairway.FlightState) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ArrayList(java.util.ArrayList) FlightFilter(bio.terra.stairway.FlightFilter) StairwayException(bio.terra.stairway.exception.StairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException)

Example 3 with ApiJobReport

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()));
}
Also used : ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Example 4 with ApiJobReport

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);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) WorkspaceService(bio.terra.workspace.service.workspace.WorkspaceService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) JobStateFilter(bio.terra.workspace.service.workspace.model.JobStateFilter) ResourceValidationUtils(bio.terra.workspace.service.resource.ResourceValidationUtils) StewardshipType(bio.terra.workspace.service.resource.model.StewardshipType) ApiStewardshipType(bio.terra.workspace.generated.model.ApiStewardshipType) ApiJobStateFilter(bio.terra.workspace.generated.model.ApiJobStateFilter) ControllerValidationUtils(bio.terra.workspace.common.utils.ControllerValidationUtils) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob) JobService(bio.terra.workspace.service.job.JobService) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) Logger(org.slf4j.Logger) Alpha1Api(bio.terra.workspace.generated.controller.Alpha1Api) UUID(java.util.UUID) SamWorkspaceAction(bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction) AuthenticatedUserRequestFactory(bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) HttpStatus(org.springframework.http.HttpStatus) Alpha1Service(bio.terra.workspace.service.workspace.Alpha1Service) List(java.util.List) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) WsmResourceFamily(bio.terra.workspace.service.resource.model.WsmResourceFamily) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) FeatureConfiguration(bio.terra.workspace.app.configuration.external.FeatureConfiguration) ApiEnumerateJobsResult(bio.terra.workspace.generated.model.ApiEnumerateJobsResult) ApiResourceType(bio.terra.workspace.generated.model.ApiResourceType) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob) ArrayList(java.util.ArrayList) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ResponseEntity(org.springframework.http.ResponseEntity) ApiEnumerateJobsResult(bio.terra.workspace.generated.model.ApiEnumerateJobsResult) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob)

Example 5 with ApiJobReport

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;
}
Also used : ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ScheduledFuture(java.util.concurrent.ScheduledFuture) JobNotCompleteException(bio.terra.workspace.service.job.exception.JobNotCompleteException) StatusEnum(bio.terra.workspace.generated.model.ApiJobReport.StatusEnum) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) FlightState(bio.terra.stairway.FlightState) Path(java.nio.file.Path) InvalidResultStateException(bio.terra.workspace.service.job.exception.InvalidResultStateException) UUID(java.util.UUID) StairwayException(bio.terra.stairway.exception.StairwayException) SamWorkspaceAction(bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction) Executors(java.util.concurrent.Executors) Flight(bio.terra.stairway.Flight) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) List(java.util.List) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) FlightFilter(bio.terra.stairway.FlightFilter) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException) JobConfiguration(bio.terra.workspace.app.configuration.external.JobConfiguration) JobNotFoundException(bio.terra.workspace.service.job.exception.JobNotFoundException) Callable(java.util.concurrent.Callable) StairwayComponent(bio.terra.common.stairway.StairwayComponent) Stairway(bio.terra.stairway.Stairway) ArrayList(java.util.ArrayList) ApiErrorReport(bio.terra.workspace.generated.model.ApiErrorReport) WorkspaceFlightMapKeys(bio.terra.workspace.service.workspace.flight.WorkspaceFlightMapKeys) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) FlightFilterOp(bio.terra.stairway.FlightFilterOp) Traced(io.opencensus.contrib.spring.aop.Traced) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MdcHook(bio.terra.workspace.common.utils.MdcHook) FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) FlightBeanBag(bio.terra.workspace.common.utils.FlightBeanBag) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) Logger(org.slf4j.Logger) DuplicateJobIdException(bio.terra.workspace.service.job.exception.DuplicateJobIdException) StairwayDatabaseConfiguration(bio.terra.workspace.app.configuration.external.StairwayDatabaseConfiguration) FlightMap(bio.terra.stairway.FlightMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TracingHook(bio.terra.common.stairway.TracingHook) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) FlightStatus(bio.terra.stairway.FlightStatus) IngressConfiguration(bio.terra.workspace.app.configuration.external.IngressConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InvalidResultStateException(bio.terra.workspace.service.job.exception.InvalidResultStateException) StatusEnum(bio.terra.workspace.generated.model.ApiJobReport.StatusEnum) FlightStatus(bio.terra.stairway.FlightStatus) HttpStatus(org.springframework.http.HttpStatus) FlightMap(bio.terra.stairway.FlightMap)

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