Search in sources :

Example 1 with FlightNotFoundException

use of bio.terra.stairway.exception.FlightNotFoundException 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 2 with FlightNotFoundException

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

the class LaunchCreateGcpContextFlightStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    validateRequiredEntries(context.getInputParameters(), ControlledResourceKeys.SOURCE_WORKSPACE_ID, JobMapKeys.AUTH_USER_INFO.getKeyName(), JobMapKeys.REQUEST.getKeyName());
    validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.CREATE_CLOUD_CONTEXT_FLIGHT_ID);
    final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
    final var destinationWorkspace = context.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), Workspace.class);
    final var cloudContextJobId = context.getWorkingMap().get(ControlledResourceKeys.CREATE_CLOUD_CONTEXT_FLIGHT_ID, String.class);
    boolean flightAlreadyExists;
    try {
        context.getStairway().getFlightState(cloudContextJobId);
        flightAlreadyExists = true;
    } catch (FlightNotFoundException e) {
        flightAlreadyExists = false;
    } catch (DatabaseOperationException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    // if we already have a flight, don't launch another one
    if (!flightAlreadyExists) {
        workspaceService.createGcpCloudContext(destinationWorkspace.getWorkspaceId(), cloudContextJobId, userRequest);
    }
    return StepResult.getStepResultSuccess();
}
Also used : FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) StepResult(bio.terra.stairway.StepResult)

Example 3 with FlightNotFoundException

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

the class JobService method verifyUserAccess.

private void verifyUserAccess(String jobId, AuthenticatedUserRequest userReq) {
    try {
        FlightState flightState = stairway.getFlightState(jobId);
        FlightMap inputParameters = flightState.getInputParameters();
        String flightSubjectId = inputParameters.get(JobMapKeys.SUBJECT_ID.getKeyName(), String.class);
        if (!StringUtils.equals(flightSubjectId, userReq.getSubjectId())) {
            throw new JobUnauthorizedException("Unauthorized");
        }
    } catch (DatabaseOperationException ex) {
        throw new InternalStairwayException("Stairway exception looking up the job", ex);
    } catch (FlightNotFoundException ex) {
        throw new JobNotFoundException("Job not found", ex);
    } catch (InterruptedException ex) {
        throw new JobServiceShutdownException("Job service interrupted", ex);
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) JobUnauthorizedException(bio.terra.service.job.exception.JobUnauthorizedException) JobNotFoundException(bio.terra.service.job.exception.JobNotFoundException) FlightMap(bio.terra.stairway.FlightMap) JobServiceShutdownException(bio.terra.service.job.exception.JobServiceShutdownException) InternalStairwayException(bio.terra.service.job.exception.InternalStairwayException)

Aggregations

DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)3 FlightNotFoundException (bio.terra.stairway.exception.FlightNotFoundException)3 FlightMap (bio.terra.stairway.FlightMap)2 FlightState (bio.terra.stairway.FlightState)2 InternalStairwayException (bio.terra.service.job.exception.InternalStairwayException)1 JobNotFoundException (bio.terra.service.job.exception.JobNotFoundException)1 JobServiceShutdownException (bio.terra.service.job.exception.JobServiceShutdownException)1 JobUnauthorizedException (bio.terra.service.job.exception.JobUnauthorizedException)1 StepResult (bio.terra.stairway.StepResult)1 InternalStairwayException (bio.terra.workspace.service.job.exception.InternalStairwayException)1 JobNotFoundException (bio.terra.workspace.service.job.exception.JobNotFoundException)1 UUID (java.util.UUID)1