Search in sources :

Example 1 with InternalStairwayException

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

the class JobService method waitForJob.

public void waitForJob(String jobId) {
    try {
        int pollSeconds = jobConfig.getPollingIntervalSeconds();
        int pollCycles = jobConfig.getTimeoutSeconds() / jobConfig.getPollingIntervalSeconds();
        for (int i = 0; i < pollCycles; i++) {
            ScheduledFuture<FlightState> futureState = executor.schedule(new PollFlightTask(stairwayComponent.get(), jobId), pollSeconds, TimeUnit.SECONDS);
            FlightState state = futureState.get();
            if (state != null) {
                // Indicates job has completed, though not necessarily successfully.
                return;
            } else {
                // Indicates job has not completed yet, continue polling
                continue;
            }
        }
    } catch (InterruptedException | ExecutionException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    }
    // Indicates we timed out waiting for completion, throw exception
    throw new InternalStairwayException("Flight did not complete in the allowed wait time");
}
Also used : FlightState(bio.terra.stairway.FlightState) ExecutionException(java.util.concurrent.ExecutionException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException)

Example 2 with InternalStairwayException

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

the class JobService method verifyUserAccess.

/**
 * Ensure the user in the user request has permission to read the workspace associated with the
 * Job ID. Throws ForbiddenException if not.
 *
 * @param jobId - ID of running job
 * @param userRequest - original user request
 */
private void verifyUserAccess(String jobId, AuthenticatedUserRequest userRequest) {
    try {
        FlightState flightState = stairwayComponent.get().getFlightState(jobId);
        FlightMap inputParameters = flightState.getInputParameters();
        UUID workspaceId = inputParameters.get(WorkspaceFlightMapKeys.WORKSPACE_ID, UUID.class);
        flightBeanBag.getWorkspaceService().validateWorkspaceAndAction(userRequest, workspaceId, SamWorkspaceAction.READ);
    } catch (DatabaseOperationException | InterruptedException ex) {
        throw new InternalStairwayException("Stairway exception looking up the job", ex);
    } catch (FlightNotFoundException ex) {
        throw new JobNotFoundException("Job not found", ex);
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) JobNotFoundException(bio.terra.workspace.service.job.exception.JobNotFoundException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException)

Example 3 with InternalStairwayException

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

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

the class Alpha1Service method enumerateJobs.

/**
 * List Stairway flights related to a workspace. These inputs are translated into inputs to
 * Stairway's getFlights calls. The resulting flights are translated into enumerated jobs. The
 * jobs are ordered by submit time.
 *
 * @param workspaceId workspace we are listing in
 * @param userRequest authenticated user
 * @param limit max number of jobs to return
 * @param pageToken optional starting place in the result set; start at beginning if missing
 * @param cloudResourceType optional filter by cloud resource type
 * @param stewardshipType optional filter by stewardship type
 * @param resourceName optional filter by resource name
 * @param jobStateFilter optional filter by job state
 * @return POJO containing the results
 */
public EnumeratedJobs enumerateJobs(UUID workspaceId, AuthenticatedUserRequest userRequest, int limit, @Nullable String pageToken, @Nullable WsmResourceFamily cloudResourceType, @Nullable StewardshipType stewardshipType, @Nullable String resourceName, @Nullable JobStateFilter jobStateFilter) {
    features.alpha1EnabledCheck();
    // Readers can see the workspace jobs list
    workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.READ);
    FlightEnumeration flightEnumeration;
    try {
        FlightFilter filter = buildFlightFilter(workspaceId, cloudResourceType, stewardshipType, resourceName, jobStateFilter);
        flightEnumeration = stairwayComponent.get().getFlights(pageToken, limit, filter);
    } catch (StairwayException | InterruptedException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    }
    List<EnumeratedJob> jobList = new ArrayList<>();
    for (FlightState state : flightEnumeration.getFlightStateList()) {
        FlightMap inputMap = state.getInputParameters();
        OperationType operationType = (inputMap.containsKey(WorkspaceFlightMapKeys.OPERATION_TYPE)) ? inputMap.get(WorkspaceFlightMapKeys.OPERATION_TYPE, OperationType.class) : OperationType.UNKNOWN;
        WsmResource wsmResource = (inputMap.containsKey(ResourceKeys.RESOURCE)) ? inputMap.get(ResourceKeys.RESOURCE, new TypeReference<>() {
        }) : null;
        String jobDescription = (inputMap.containsKey(JobMapKeys.DESCRIPTION.getKeyName())) ? inputMap.get(JobMapKeys.DESCRIPTION.getKeyName(), String.class) : StringUtils.EMPTY;
        EnumeratedJob enumeratedJob = new EnumeratedJob().flightState(state).jobDescription(jobDescription).operationType(operationType).resource(wsmResource);
        jobList.add(enumeratedJob);
    }
    return new EnumeratedJobs().pageToken(flightEnumeration.getNextPageToken()).totalResults(flightEnumeration.getTotalFlights()).results(jobList);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) FlightEnumeration(bio.terra.stairway.FlightEnumeration) ArrayList(java.util.ArrayList) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) FlightState(bio.terra.stairway.FlightState) FlightFilter(bio.terra.stairway.FlightFilter) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) StairwayException(bio.terra.stairway.exception.StairwayException) FlightMap(bio.terra.stairway.FlightMap) OperationType(bio.terra.workspace.service.workspace.model.OperationType) TypeReference(com.fasterxml.jackson.core.type.TypeReference) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob)

Example 5 with InternalStairwayException

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

the class JobService method retrieveJob.

@Traced
public ApiJobReport retrieveJob(String jobId, AuthenticatedUserRequest userRequest) {
    try {
        // jobId=flightId
        verifyUserAccess(jobId, userRequest);
        FlightState flightState = stairwayComponent.get().getFlightState(jobId);
        return mapFlightStateToApiJobReport(flightState);
    } catch (StairwayException | InterruptedException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) StairwayException(bio.terra.stairway.exception.StairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

InternalStairwayException (bio.terra.workspace.service.job.exception.InternalStairwayException)6 FlightState (bio.terra.stairway.FlightState)5 StairwayException (bio.terra.stairway.exception.StairwayException)4 FlightFilter (bio.terra.stairway.FlightFilter)2 FlightMap (bio.terra.stairway.FlightMap)2 ApiJobReport (bio.terra.workspace.generated.model.ApiJobReport)2 ArrayList (java.util.ArrayList)2 FlightEnumeration (bio.terra.stairway.FlightEnumeration)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1 FlightNotFoundException (bio.terra.stairway.exception.FlightNotFoundException)1 ApiErrorReport (bio.terra.workspace.generated.model.ApiErrorReport)1 JobNotFoundException (bio.terra.workspace.service.job.exception.JobNotFoundException)1 WsmResource (bio.terra.workspace.service.resource.model.WsmResource)1 EnumeratedJob (bio.terra.workspace.service.workspace.model.EnumeratedJob)1 EnumeratedJobs (bio.terra.workspace.service.workspace.model.EnumeratedJobs)1 OperationType (bio.terra.workspace.service.workspace.model.OperationType)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Traced (io.opencensus.contrib.spring.aop.Traced)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1