Search in sources :

Example 1 with ApiGcpGcsBucketUpdateParameters

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

the class UpdateGcsBucketStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
    final FlightMap inputMap = flightContext.getInputParameters();
    final ApiGcpGcsBucketUpdateParameters updateParameters = inputMap.get(UPDATE_PARAMETERS, ApiGcpGcsBucketUpdateParameters.class);
    return updateBucket(updateParameters);
}
Also used : FlightMap(bio.terra.stairway.FlightMap) ApiGcpGcsBucketUpdateParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters)

Example 2 with ApiGcpGcsBucketUpdateParameters

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

the class ControlledResourceServiceTest method updateGcsBucketUndo.

@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void updateGcsBucketUndo() throws Exception {
    ControlledGcsBucketResource createdBucket = createDefaultSharedGcsBucket(workspace, user);
    Map<String, StepStatus> retrySteps = new HashMap<>();
    retrySteps.put(RetrieveControlledResourceMetadataStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(UpdateControlledResourceMetadataStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(RetrieveGcsBucketCloudAttributesStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(UpdateGcsBucketStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    jobService.setFlightDebugInfoForTest(FlightDebugInfo.newBuilder().undoStepFailures(retrySteps).lastStepFailure(true).build());
    // update the bucket
    String newName = "NEW_bucketname";
    String newDescription = "new resource description";
    // Service methods which wait for a flight to complete will throw an
    // InvalidResultStateException when that flight fails without a cause, which occurs when a
    // flight fails via debugInfo.
    assertThrows(InvalidResultStateException.class, () -> controlledResourceService.updateGcsBucket(createdBucket, ControlledResourceFixtures.BUCKET_UPDATE_PARAMETERS_2, user.getAuthenticatedRequest(), newName, newDescription));
    // check the properties stored on the cloud were not updated
    BucketInfo updatedBucket = crlService.createStorageCow(projectId).get(createdBucket.getBucketName()).getBucketInfo();
    ApiGcpGcsBucketUpdateParameters cloudParameters = GcsApiConversions.toUpdateParameters(updatedBucket);
    assertNotEquals(ControlledResourceFixtures.BUCKET_UPDATE_PARAMETERS_2, cloudParameters);
    // check the properties stored in WSM were not updated
    ControlledGcsBucketResource fetchedResource = controlledResourceService.getControlledResource(workspace.getWorkspaceId(), createdBucket.getResourceId(), user.getAuthenticatedRequest()).castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
    assertEquals(createdBucket.getName(), fetchedResource.getName());
    assertEquals(createdBucket.getDescription(), fetchedResource.getDescription());
}
Also used : UpdateControlledResourceMetadataStep(bio.terra.workspace.service.resource.controlled.flight.update.UpdateControlledResourceMetadataStep) UpdateGcsBucketStep(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.UpdateGcsBucketStep) HashMap(java.util.HashMap) RetrieveGcsBucketCloudAttributesStep(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.RetrieveGcsBucketCloudAttributesStep) StepStatus(bio.terra.stairway.StepStatus) RetrieveControlledResourceMetadataStep(bio.terra.workspace.service.resource.controlled.flight.update.RetrieveControlledResourceMetadataStep) BucketInfo(com.google.cloud.storage.BucketInfo) ApiGcpGcsBucketUpdateParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Example 3 with ApiGcpGcsBucketUpdateParameters

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

the class GcsApiConversionsTest method testToUpdateParameters.

@Test
public void testToUpdateParameters() {
    final ApiGcpGcsBucketUpdateParameters updateParameters1 = toUpdateParameters(GCS_BUCKET_INFO_1);
    assertEquals(ApiGcpGcsBucketDefaultStorageClass.STANDARD, updateParameters1.getDefaultStorageClass());
    final ApiGcpGcsBucketLifecycle wsmLifecycle = updateParameters1.getLifecycle();
    assertThat(wsmLifecycle.getRules(), hasSize(2));
    final ApiGcpGcsBucketLifecycleRule rule1 = wsmLifecycle.getRules().get(0);
    assertEquals(ApiGcpGcsBucketLifecycleRuleActionType.DELETE, rule1.getAction().getType());
    assertNull(rule1.getAction().getStorageClass());
    final ApiGcpGcsBucketLifecycleRule rule2 = wsmLifecycle.getRules().get(1);
    assertEquals(ApiGcpGcsBucketLifecycleRuleActionType.SET_STORAGE_CLASS, rule2.getAction().getType());
    assertEquals(ApiGcpGcsBucketDefaultStorageClass.STANDARD, rule2.getAction().getStorageClass());
}
Also used : ApiGcpGcsBucketLifecycleRule(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule) ApiGcpGcsBucketLifecycle(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycle) ApiGcpGcsBucketUpdateParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with ApiGcpGcsBucketUpdateParameters

use of bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters 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)

Example 5 with ApiGcpGcsBucketUpdateParameters

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

the class UpdateGcsBucketStep method undoStep.

// Restore the previous values of the update parameters
@Override
public StepResult undoStep(FlightContext flightContext) throws InterruptedException {
    final FlightMap workingMap = flightContext.getWorkingMap();
    final ApiGcpGcsBucketUpdateParameters previousUpdateParameters = workingMap.get(PREVIOUS_UPDATE_PARAMETERS, ApiGcpGcsBucketUpdateParameters.class);
    return updateBucket(previousUpdateParameters);
}
Also used : FlightMap(bio.terra.stairway.FlightMap) ApiGcpGcsBucketUpdateParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters)

Aggregations

ApiGcpGcsBucketUpdateParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters)5 FlightMap (bio.terra.stairway.FlightMap)3 BucketInfo (com.google.cloud.storage.BucketInfo)2 Test (org.junit.jupiter.api.Test)2 BucketCow (bio.terra.cloudres.google.storage.BucketCow)1 StorageCow (bio.terra.cloudres.google.storage.StorageCow)1 StepResult (bio.terra.stairway.StepResult)1 StepStatus (bio.terra.stairway.StepStatus)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)1 ApiGcpGcsBucketLifecycle (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycle)1 ApiGcpGcsBucketLifecycleRule (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule)1 ControlledGcsBucketResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)1 RetrieveGcsBucketCloudAttributesStep (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.RetrieveGcsBucketCloudAttributesStep)1 UpdateGcsBucketStep (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.UpdateGcsBucketStep)1 RetrieveControlledResourceMetadataStep (bio.terra.workspace.service.resource.controlled.flight.update.RetrieveControlledResourceMetadataStep)1 UpdateControlledResourceMetadataStep (bio.terra.workspace.service.resource.controlled.flight.update.UpdateControlledResourceMetadataStep)1 HashMap (java.util.HashMap)1 BadRequestException (javax.ws.rs.BadRequestException)1