Search in sources :

Example 26 with FlightMap

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

the class SnapshotAuthzFileAclStep method doStep.

@Override
public StepResult doStep(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 {
        if (configService.testInsertFault(SNAPSHOT_GRANT_FILE_ACCESS_FAULT)) {
            throw new StorageException(400, "Fake IAM failure", "badRequest", null);
        }
        gcsPdao.setAclOnFiles(dataset, fileIds, readersPolicyEmail);
    } catch (StorageException ex) {
        // we will log alot and retry on that.
        if (ex.getCode() == 400 && StringUtils.equals(ex.getReason(), "badRequest")) {
            logger.info("Maybe caught an ACL propagation error: " + ex.getMessage() + " reason: " + ex.getReason(), ex);
            return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, 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) StepResult(bio.terra.stairway.StepResult) StorageException(com.google.cloud.storage.StorageException)

Example 27 with FlightMap

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

the class SnapshotAuthzIamStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) {
    FlightMap workingMap = context.getWorkingMap();
    UUID snapshotId = workingMap.get(SnapshotWorkingMapKeys.SNAPSHOT_ID, UUID.class);
    try {
        sam.deleteSnapshotResource(userReq, snapshotId);
    // We do not need to remove the ACL from the files or BigQuery. It disappears
    // when SAM deletes the ACL. How 'bout that!
    } catch (UnauthorizedException ex) {
        // suppress exception
        logger.error("NEEDS CLEANUP: delete sam resource for snapshot " + snapshotId.toString());
        logger.warn(ex.getMessage());
    }
    return StepResult.getStepResultSuccess();
}
Also used : UnauthorizedException(bio.terra.common.exception.UnauthorizedException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

Example 28 with FlightMap

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

the class SnapshotAuthzTabularAclStep method doStep.

@Override
public StepResult doStep(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);
    try {
        if (configService.testInsertFault(SNAPSHOT_GRANT_ACCESS_FAULT)) {
            throw new BigQueryException(400, "IAM setPolicy fake failure", new BigQueryError("invalid", "fake", "IAM setPolicy fake failure"));
        }
        bigQueryPdao.addReaderGroupToSnapshot(snapshot, readersPolicyEmail);
    } catch (BigQueryException ex) {
        if (FlightUtils.isBigQueryIamPropagationError(ex)) {
            return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
        }
        throw new PdaoException("Caught BQ exception while granting read access to snapshot", ex);
    }
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) BigQueryError(com.google.cloud.bigquery.BigQueryError) PdaoException(bio.terra.common.exception.PdaoException) IamRole(bio.terra.service.iam.IamRole) FlightMap(bio.terra.stairway.FlightMap) BigQueryException(com.google.cloud.bigquery.BigQueryException) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult)

Example 29 with FlightMap

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

the class CreateSnapshotMetadataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    try {
        Snapshot snapshot = snapshotService.makeSnapshotFromSnapshotRequest(snapshotReq);
        UUID snapshotId = snapshotDao.createAndLock(snapshot, context.getFlightId());
        FlightMap workingMap = context.getWorkingMap();
        workingMap.put(SnapshotWorkingMapKeys.SNAPSHOT_ID, snapshotId);
        SnapshotSummary snapshotSummary = snapshotDao.retrieveSummaryById(snapshot.getId());
        SnapshotSummaryModel response = snapshotService.makeSummaryModelFromSummary(snapshotSummary);
        FlightUtils.setResponse(context, response, HttpStatus.CREATED);
        return StepResult.getStepResultSuccess();
    } catch (InvalidSnapshotException isEx) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, isEx);
    } catch (SnapshotNotFoundException ex) {
        FlightUtils.setErrorResponse(context, ex.toString(), HttpStatus.BAD_REQUEST);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, ex);
    }
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) SnapshotSummary(bio.terra.service.snapshot.SnapshotSummary) InvalidSnapshotException(bio.terra.service.snapshot.exception.InvalidSnapshotException) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult)

Example 30 with FlightMap

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

the class FlightStates method makeFlightCompletedState.

public static FlightState makeFlightCompletedState() {
    DatasetSummaryModel req = buildMinimalDatasetSummary();
    FlightMap resultMap = new FlightMap();
    resultMap.put(JobMapKeys.RESPONSE.getKeyName(), req);
    resultMap.put(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.I_AM_A_TEAPOT);
    resultMap.put(JobMapKeys.DESCRIPTION.getKeyName(), req.getDescription());
    FlightState flightState = new FlightState();
    flightState.setFlightId(testFlightId);
    flightState.setFlightStatus(FlightStatus.SUCCESS);
    flightState.setSubmitted(submittedTime);
    flightState.setInputParameters(resultMap);
    flightState.setResultMap(resultMap);
    flightState.setCompleted(completedTime);
    return flightState;
}
Also used : FlightState(bio.terra.stairway.FlightState) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) FlightMap(bio.terra.stairway.FlightMap)

Aggregations

FlightMap (bio.terra.stairway.FlightMap)156 StepResult (bio.terra.stairway.StepResult)47 UUID (java.util.UUID)29 FlightState (bio.terra.stairway.FlightState)20 Test (org.junit.jupiter.api.Test)19 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)13 IOException (java.io.IOException)11 Dataset (bio.terra.service.dataset.Dataset)9 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)9 HashMap (java.util.HashMap)9 IamRole (bio.terra.service.iam.IamRole)8 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)8 FlightContext (bio.terra.stairway.FlightContext)6 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 FileSystemAbortTransactionException (bio.terra.service.filedata.exception.FileSystemAbortTransactionException)5 Snapshot (bio.terra.service.snapshot.Snapshot)5 StairwayExecutionException (bio.terra.stairway.exception.StairwayExecutionException)5 ControlledBigQueryDatasetResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)5 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)5 StorageException (com.google.cloud.storage.StorageException)5