Search in sources :

Example 1 with FlightMap

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

the class IngestUtils method getDataset.

public static Dataset getDataset(FlightContext context, DatasetService datasetService) {
    FlightMap inputParameters = context.getInputParameters();
    UUID datasetId = UUID.fromString(inputParameters.get(JobMapKeys.DATASET_ID.getKeyName(), String.class));
    return datasetService.retrieve(datasetId);
}
Also used : FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

Example 2 with FlightMap

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

the class CreateDatasetAssetStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    // TODO: Asset columns and tables need to match things in the dataset schema
    Dataset dataset = getDataset(context);
    FlightMap map = context.getWorkingMap();
    // get the dataset assets that already exist --asset name needs to be unique
    AssetSpecification newAssetSpecification = getNewAssetSpec(context, dataset);
    // add a fault that forces an exception to make sure the undo works
    try {
        configService.fault(ConfigEnum.CREATE_ASSET_FAULT, () -> {
            throw new RuntimeException("fault insertion");
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    try {
        assetDao.create(newAssetSpecification, dataset.getId());
    } catch (InvalidAssetException e) {
        FlightUtils.setErrorResponse(context, e.getMessage(), HttpStatus.BAD_REQUEST);
        map.put(DatasetWorkingMapKeys.ASSET_NAME_COLLISION, true);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
    }
    map.put(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.CREATED);
    return StepResult.getStepResultSuccess();
}
Also used : Dataset(bio.terra.service.dataset.Dataset) FlightMap(bio.terra.stairway.FlightMap) AssetSpecification(bio.terra.service.dataset.AssetSpecification) StepResult(bio.terra.stairway.StepResult) InvalidAssetException(bio.terra.service.dataset.exception.InvalidAssetException) InvalidAssetException(bio.terra.service.dataset.exception.InvalidAssetException)

Example 3 with FlightMap

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

the class CreateDatasetAuthzBqJobUserStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    UUID datasetId = workingMap.get(DatasetWorkingMapKeys.DATASET_ID, UUID.class);
    Map<IamRole, String> policies = workingMap.get(DatasetWorkingMapKeys.POLICY_EMAILS, Map.class);
    Dataset dataset = datasetService.retrieve(datasetId);
    DatasetModel datasetModel = datasetService.retrieveModel(dataset);
    // The underlying service provides retries so we do not need to retry this operation
    resourceService.grantPoliciesBqJobUser(datasetModel.getDataProject(), policies.values());
    return StepResult.getStepResultSuccess();
}
Also used : Dataset(bio.terra.service.dataset.Dataset) IamRole(bio.terra.service.iam.IamRole) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) DatasetModel(bio.terra.model.DatasetModel)

Example 4 with FlightMap

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

the class CreateDatasetAuthzIamStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    UUID datasetId = workingMap.get(DatasetWorkingMapKeys.DATASET_ID, UUID.class);
    try {
        iamClient.deleteDatasetResource(userReq, datasetId);
    } catch (UnauthorizedException ex) {
        // suppress exception
        logger.error("NEEDS CLEANUP: delete sam resource for dataset " + datasetId.toString(), ex);
    } catch (NotFoundException ex) {
    // if the SAM resource is not found, then it was likely not created -- continue undoing
    }
    return StepResult.getStepResultSuccess();
}
Also used : UnauthorizedException(bio.terra.common.exception.UnauthorizedException) NotFoundException(bio.terra.common.exception.NotFoundException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

Example 5 with FlightMap

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

the class CreateDatasetAuthzIamStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    UUID datasetId = workingMap.get(DatasetWorkingMapKeys.DATASET_ID, UUID.class);
    Map<IamRole, String> policyEmails = iamClient.createDatasetResource(userReq, datasetId);
    workingMap.put(DatasetWorkingMapKeys.POLICY_EMAILS, policyEmails);
    return StepResult.getStepResultSuccess();
}
Also used : IamRole(bio.terra.service.iam.IamRole) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

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