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