Search in sources :

Example 6 with StairwayException

use of bio.terra.stairway.exception.StairwayException 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 workspaceUuid 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 workspaceUuid, 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, workspaceUuid, SamConstants.SamWorkspaceAction.READ);
    FlightEnumeration flightEnumeration;
    try {
        FlightFilter filter = buildFlightFilter(workspaceUuid, 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 7 with StairwayException

use of bio.terra.stairway.exception.StairwayException in project terra-workspace-manager by DataBiosphere.

the class LaunchCloneAllResourcesFlightStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    validateRequiredEntries(context.getInputParameters(), JobMapKeys.AUTH_USER_INFO.getKeyName(), JobMapKeys.REQUEST.getKeyName());
    validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.RESOURCES_TO_CLONE, ControlledResourceKeys.CLONE_ALL_RESOURCES_FLIGHT_ID);
    final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
    @Nullable final var location = context.getInputParameters().get(ControlledResourceKeys.LOCATION, String.class);
    final var cloneAllResourcesFlightId = context.getWorkingMap().get(ControlledResourceKeys.CLONE_ALL_RESOURCES_FLIGHT_ID, String.class);
    final List<ResourceWithFlightId> resourcesAndFlightIds = context.getWorkingMap().get(ControlledResourceKeys.RESOURCES_TO_CLONE, new TypeReference<>() {
    });
    final var destinationWorkspace = context.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), Workspace.class);
    final Stairway stairway = context.getStairway();
    final FlightMap subflightInputParameters = new FlightMap();
    subflightInputParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
    subflightInputParameters.put(ControlledResourceKeys.RESOURCES_TO_CLONE, resourcesAndFlightIds);
    subflightInputParameters.put(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, destinationWorkspace.getWorkspaceId());
    subflightInputParameters.put(ControlledResourceKeys.LOCATION, location);
    // fields normally set by JobBuilder for identifying jobs
    subflightInputParameters.put(WorkspaceFlightMapKeys.WORKSPACE_ID, destinationWorkspace.getWorkspaceId().toString());
    subflightInputParameters.put(JobMapKeys.DESCRIPTION.getKeyName(), String.format("Clone all resources into workspace %s", destinationWorkspace.getWorkspaceId().toString()));
    // Build a CloneAllResourcesFlight
    try {
        stairway.submit(cloneAllResourcesFlightId, CloneAllResourcesFlight.class, subflightInputParameters);
    } catch (DuplicateFlightIdException e) {
        // exit early if flight is already going
        return StepResult.getStepResultSuccess();
    } catch (StairwayException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : Stairway(bio.terra.stairway.Stairway) FlightMap(bio.terra.stairway.FlightMap) StairwayException(bio.terra.stairway.exception.StairwayException) StepResult(bio.terra.stairway.StepResult) Nullable(javax.annotation.Nullable) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException)

Example 8 with StairwayException

use of bio.terra.stairway.exception.StairwayException in project jade-data-repo by DataBiosphere.

the class JobService method enumerateJobs.

public List<JobModel> enumerateJobs(int offset, int limit, AuthenticatedUserRequest userReq) {
    boolean canListAnyJob = checkUserCanListAnyJob(userReq);
    // if the user has access to all jobs, then fetch everything
    // otherwise, filter the jobs on the user
    List<FlightState> flightStateList;
    try {
        FlightFilter filter = new FlightFilter();
        if (!canListAnyJob) {
            filter.addFilterInputParameter(JobMapKeys.SUBJECT_ID.getKeyName(), FlightFilterOp.EQUAL, userReq.getSubjectId());
        }
        flightStateList = stairway.getFlights(offset, limit, filter);
    } catch (StairwayException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    } catch (InterruptedException ex) {
        throw new JobServiceShutdownException("Job service interrupted", ex);
    }
    List<JobModel> jobModelList = new ArrayList<>();
    for (FlightState flightState : flightStateList) {
        JobModel jobModel = mapFlightStateToJobModel(flightState);
        jobModelList.add(jobModel);
    }
    return jobModelList;
}
Also used : FlightState(bio.terra.stairway.FlightState) ArrayList(java.util.ArrayList) FlightFilter(bio.terra.stairway.FlightFilter) StairwayException(bio.terra.stairway.exception.StairwayException) InternalStairwayException(bio.terra.service.job.exception.InternalStairwayException) JobModel(bio.terra.model.JobModel) JobServiceShutdownException(bio.terra.service.job.exception.JobServiceShutdownException) InternalStairwayException(bio.terra.service.job.exception.InternalStairwayException)

Aggregations

StairwayException (bio.terra.stairway.exception.StairwayException)8 FlightState (bio.terra.stairway.FlightState)5 InternalStairwayException (bio.terra.workspace.service.job.exception.InternalStairwayException)4 InternalStairwayException (bio.terra.service.job.exception.InternalStairwayException)3 FlightFilter (bio.terra.stairway.FlightFilter)3 FlightMap (bio.terra.stairway.FlightMap)3 ArrayList (java.util.ArrayList)3 JobServiceShutdownException (bio.terra.service.job.exception.JobServiceShutdownException)2 JobServiceStartupException (bio.terra.service.job.exception.JobServiceStartupException)2 ApiJobReport (bio.terra.workspace.generated.model.ApiJobReport)2 JobModel (bio.terra.model.JobModel)1 InvalidResultStateException (bio.terra.service.job.exception.InvalidResultStateException)1 JobNotCompleteException (bio.terra.service.job.exception.JobNotCompleteException)1 JobNotFoundException (bio.terra.service.job.exception.JobNotFoundException)1 JobResponseException (bio.terra.service.job.exception.JobResponseException)1 JobUnauthorizedException (bio.terra.service.job.exception.JobUnauthorizedException)1 FlightEnumeration (bio.terra.stairway.FlightEnumeration)1 Stairway (bio.terra.stairway.Stairway)1 StepResult (bio.terra.stairway.StepResult)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1