Search in sources :

Example 6 with ApiGcpGcsBucketCreationParameters

use of bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CopyGcsBucketDefinitionStep method getDestinationCreationParameters.

private ApiGcpGcsBucketCreationParameters getDestinationCreationParameters(FlightMap inputParameters, FlightMap workingMap) {
    final ApiGcpGcsBucketCreationParameters sourceCreationParameters = workingMap.get(ControlledResourceKeys.CREATION_PARAMETERS, ApiGcpGcsBucketCreationParameters.class);
    final Optional<String> suppliedLocation = Optional.ofNullable(inputParameters.get(ControlledResourceKeys.LOCATION, String.class));
    // Override the location parameter if it was specified
    if (suppliedLocation.isPresent()) {
        return new ApiGcpGcsBucketCreationParameters().defaultStorageClass(sourceCreationParameters.getDefaultStorageClass()).lifecycle(sourceCreationParameters.getLifecycle()).name(sourceCreationParameters.getName()).location(suppliedLocation.get());
    } else {
        return sourceCreationParameters;
    }
}
Also used : ApiGcpGcsBucketCreationParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)

Example 7 with ApiGcpGcsBucketCreationParameters

use of bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters in project terra-workspace-manager by DataBiosphere.

the class RetrieveGcsBucketCloudAttributesStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
    final FlightMap workingMap = flightContext.getWorkingMap();
    final String projectId = gcpCloudContextService.getRequiredGcpProject(bucketResource.getWorkspaceId());
    // get the storage cow
    final StorageCow storageCow = crlService.createStorageCow(projectId);
    // get the existing bucket cow
    final BucketCow existingBucketCow = storageCow.get(bucketResource.getBucketName());
    if (existingBucketCow == null) {
        logger.error("Can't construct COW for pre-existing bucket {}", bucketResource.getBucketName());
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, null);
    }
    // get the attributes
    final BucketInfo existingBucketInfo = existingBucketCow.getBucketInfo();
    switch(retrievalMode) {
        case UPDATE_PARAMETERS:
            final ApiGcpGcsBucketUpdateParameters existingUpdateParameters = GcsApiConversions.toUpdateParameters(existingBucketInfo);
            workingMap.put(ControlledResourceKeys.PREVIOUS_UPDATE_PARAMETERS, existingUpdateParameters);
            break;
        case CREATION_PARAMETERS:
            final ApiGcpGcsBucketCreationParameters creationParameters = GcsApiConversions.toCreationParameters(existingBucketInfo);
            workingMap.put(ControlledResourceKeys.CREATION_PARAMETERS, creationParameters);
            break;
        default:
            throw new BadRequestException(String.format("Unsupported Retrieval mode %s", retrievalMode));
    }
    return StepResult.getStepResultSuccess();
}
Also used : BucketCow(bio.terra.cloudres.google.storage.BucketCow) BadRequestException(javax.ws.rs.BadRequestException) FlightMap(bio.terra.stairway.FlightMap) StorageCow(bio.terra.cloudres.google.storage.StorageCow) BucketInfo(com.google.cloud.storage.BucketInfo) StepResult(bio.terra.stairway.StepResult) ApiGcpGcsBucketCreationParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters) ApiGcpGcsBucketUpdateParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters)

Aggregations

ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)7 FlightMap (bio.terra.stairway.FlightMap)4 ControlledGcsBucketResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)3 ControlledResourceFields (bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)3 BucketInfo (com.google.cloud.storage.BucketInfo)3 Test (org.junit.jupiter.api.Test)3 StorageCow (bio.terra.cloudres.google.storage.StorageCow)2 StepResult (bio.terra.stairway.StepResult)2 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)2 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)2 UUID (java.util.UUID)2 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)2 BucketCow (bio.terra.cloudres.google.storage.BucketCow)1 BadRequestException (bio.terra.common.exception.BadRequestException)1 App (bio.terra.workspace.app.configuration.external.WsmApplicationConfiguration.App)1 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 ApiClonedControlledGcpGcsBucket (bio.terra.workspace.generated.model.ApiClonedControlledGcpGcsBucket)1 ApiCreatedControlledGcpGcsBucket (bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket)1 ApiGcpGcsBucketUpdateParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1