Search in sources :

Example 21 with FlightMap

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

the class JobService method retrieveJobResultWorker.

private <T> JobResultWithStatus<T> retrieveJobResultWorker(String jobId, Class<T> resultClass) throws StairwayException, InterruptedException {
    FlightState flightState = stairway.getFlightState(jobId);
    FlightMap resultMap = flightState.getResultMap().orElse(null);
    if (resultMap == null) {
        throw new InvalidResultStateException("No result map returned from flight");
    }
    switch(flightState.getFlightStatus()) {
        case FATAL:
        case ERROR:
            if (flightState.getException().isPresent()) {
                Exception exception = flightState.getException().get();
                if (exception instanceof RuntimeException) {
                    throw (RuntimeException) exception;
                } else {
                    throw new JobResponseException("wrap non-runtime exception", exception);
                }
            }
            throw new InvalidResultStateException("Failed operation with no exception reported");
        case SUCCESS:
            HttpStatus statusCode = resultMap.get(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.class);
            if (statusCode == null) {
                statusCode = HttpStatus.OK;
            }
            return new JobResultWithStatus<T>().statusCode(statusCode).result(resultMap.get(JobMapKeys.RESPONSE.getKeyName(), resultClass));
        case RUNNING:
            throw new JobNotCompleteException("Attempt to retrieve job result before job is complete; job id: " + flightState.getFlightId());
        default:
            throw new InvalidResultStateException("Impossible case reached");
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) InvalidResultStateException(bio.terra.service.job.exception.InvalidResultStateException) HttpStatus(org.springframework.http.HttpStatus) FlightMap(bio.terra.stairway.FlightMap) JobNotCompleteException(bio.terra.service.job.exception.JobNotCompleteException) JobResponseException(bio.terra.service.job.exception.JobResponseException) JobServiceStartupException(bio.terra.service.job.exception.JobServiceStartupException) JobServiceShutdownException(bio.terra.service.job.exception.JobServiceShutdownException) JobNotCompleteException(bio.terra.service.job.exception.JobNotCompleteException) JobUnauthorizedException(bio.terra.service.job.exception.JobUnauthorizedException) InvalidResultStateException(bio.terra.service.job.exception.InvalidResultStateException) StairwayException(bio.terra.stairway.exception.StairwayException) FlightNotFoundException(bio.terra.stairway.exception.FlightNotFoundException) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) JobNotFoundException(bio.terra.service.job.exception.JobNotFoundException) JobResponseException(bio.terra.service.job.exception.JobResponseException) InternalStairwayException(bio.terra.service.job.exception.InternalStairwayException)

Example 22 with FlightMap

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

the class LoadService method getLoadTag.

public String getLoadTag(FlightContext context) {
    FlightMap inputParameters = context.getInputParameters();
    String loadTag = inputParameters.get(LoadMapKeys.LOAD_TAG, String.class);
    if (StringUtils.isEmpty(loadTag)) {
        FlightMap workingMap = context.getWorkingMap();
        loadTag = workingMap.get(LoadMapKeys.LOAD_TAG, String.class);
        if (StringUtils.isEmpty(loadTag)) {
            throw new LoadLockFailureException("Expected LOAD_TAG in working map or inputs, but did not find it");
        }
    }
    return loadTag;
}
Also used : LoadLockFailureException(bio.terra.service.load.exception.LoadLockFailureException) FlightMap(bio.terra.stairway.FlightMap)

Example 23 with FlightMap

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

the class LoadLockStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    String loadTag = loadService.getLoadTag(context);
    UUID loadId = loadService.lockLoad(loadTag, context.getFlightId());
    FlightMap workingMap = context.getWorkingMap();
    workingMap.put(LoadMapKeys.LOAD_ID, loadId.toString());
    return StepResult.getStepResultSuccess();
}
Also used : FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

Example 24 with FlightMap

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

the class SnapshotAuthzBqJobUserStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    Snapshot snapshot = snapshotService.retrieveByName(snapshotName);
    SnapshotDataProject projectForSnapshot = dataLocationService.getOrCreateProject(snapshot);
    Map<IamRole, String> policyMap = workingMap.get(SnapshotWorkingMapKeys.POLICY_MAP, Map.class);
    // Allow the custodian to make queries in this project.
    // The underlying service provides retries so we do not need to retry this operation
    resourceService.grantPoliciesBqJobUser(projectForSnapshot.getGoogleProjectId(), Collections.singletonList(policyMap.get(IamRole.CUSTODIAN)));
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) IamRole(bio.terra.service.iam.IamRole) FlightMap(bio.terra.stairway.FlightMap) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 25 with FlightMap

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

the class SnapshotAuthzFileAclStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    UUID snapshotId = workingMap.get(SnapshotWorkingMapKeys.SNAPSHOT_ID, UUID.class);
    Snapshot snapshot = snapshotService.retrieve(snapshotId);
    Map<IamRole, String> policies = workingMap.get(SnapshotWorkingMapKeys.POLICY_MAP, Map.class);
    String readersPolicyEmail = policies.get(IamRole.READER);
    // TODO: when we support multiple datasets, we can generate more than one copy of this
    // step: one for each dataset. That is because each dataset keeps its file dependencies
    // in its own scope. For now, we know there is exactly one dataset and we take shortcuts.
    SnapshotSource snapshotSource = snapshot.getSnapshotSources().get(0);
    String datasetId = snapshotSource.getDataset().getId().toString();
    Dataset dataset = datasetService.retrieve(UUID.fromString(datasetId));
    List<String> fileIds = fireStoreDao.getDatasetSnapshotFileIds(dataset, snapshotId.toString());
    try {
        gcsPdao.removeAclOnFiles(dataset, fileIds, readersPolicyEmail);
    } catch (StorageException ex) {
        // We don't let the exception stop us from continuing to remove the rest of the snapshot parts.
        // TODO: change this to whatever our alert-a-human log message is.
        logger.warn("NEEDS CLEANUP: Failed to remove snapshot reader ACLs from files", ex);
    }
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) Dataset(bio.terra.service.dataset.Dataset) SnapshotSource(bio.terra.service.snapshot.SnapshotSource) IamRole(bio.terra.service.iam.IamRole) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StorageException(com.google.cloud.storage.StorageException)

Aggregations

FlightMap (bio.terra.stairway.FlightMap)137 StepResult (bio.terra.stairway.StepResult)34 UUID (java.util.UUID)29 FlightState (bio.terra.stairway.FlightState)20 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)14 Test (org.junit.jupiter.api.Test)14 Dataset (bio.terra.service.dataset.Dataset)9 IOException (java.io.IOException)9 IamRole (bio.terra.service.iam.IamRole)8 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)8 HashMap (java.util.HashMap)8 DuplicateFlightIdException (bio.terra.stairway.exception.DuplicateFlightIdException)7 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)7 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)6 FileSystemAbortTransactionException (bio.terra.service.filedata.exception.FileSystemAbortTransactionException)5 Snapshot (bio.terra.service.snapshot.Snapshot)5 FlightNotFoundException (bio.terra.stairway.exception.FlightNotFoundException)5 StairwayExecutionException (bio.terra.stairway.exception.StairwayExecutionException)5 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)5