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();
}
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();
}
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();
}
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);
}
}
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;
}
Aggregations