Search in sources :

Example 11 with ControlledGcsBucketResource

use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource 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 12 with ControlledGcsBucketResource

use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class ControlledResourceServiceTest method createDefaultSharedGcsBucket.

/**
 * Creates a user-shared controlled GCS bucket in the provided workspace, using the credentials of
 * the provided user. This uses the default bucket creation parameters from {@code
 * ControlledResourceFixtures}.
 */
private ControlledGcsBucketResource createDefaultSharedGcsBucket(Workspace workspace, UserAccessUtils.TestUser user) {
    ControlledGcsBucketResource originalResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspace.getWorkspaceId()).build();
    ControlledGcsBucketResource createdBucket = controlledResourceService.createControlledResourceSync(originalResource, null, user.getAuthenticatedRequest(), ControlledResourceFixtures.getGoogleBucketCreationParameters()).castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
    assertEquals(originalResource, createdBucket);
    return createdBucket;
}
Also used : ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)

Example 13 with ControlledGcsBucketResource

use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class FindResourcesToCloneStepTest method setup.

@BeforeEach
public void setup() {
    resource = new ControlledGcsBucketResource(UUID.randomUUID(), UUID.randomUUID(), "foo", "as in foobar", CloningInstructions.COPY_RESOURCE, null, PrivateResourceState.NOT_APPLICABLE, AccessScopeType.ACCESS_SCOPE_SHARED, ManagedByType.MANAGED_BY_USER, null, "bucket-with-hole-in-it-dear-liza");
    findResourcesToCloneStep = new FindResourcesToCloneStep(mockResourceDao);
    doReturn(mockStairway).when(mockFlightContext).getStairway();
    doReturn(FLIGHT_ID).when(mockStairway).createFlightId();
    final FlightMap inputParameters = new FlightMap();
    inputParameters.put(ControlledResourceKeys.SOURCE_WORKSPACE_ID, UUID.randomUUID());
    doReturn(inputParameters).when(mockFlightContext).getInputParameters();
    workingMap = new FlightMap();
    doReturn(workingMap).when(mockFlightContext).getWorkingMap();
}
Also used : FlightMap(bio.terra.stairway.FlightMap) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with ControlledGcsBucketResource

use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class StoreControlledResourceMetadataStepTest method testEntersInfo.

@Test
public void testEntersInfo() throws InterruptedException, RetryException {
    // Generate a fake workspace and cloud context so that the
    // database insert will pass FK constraints.
    UUID workspaceId = UUID.randomUUID();
    Workspace workspace = Workspace.builder().workspaceStage(WorkspaceStage.RAWLS_WORKSPACE).workspaceId(workspaceId).build();
    workspaceDao.createWorkspace(workspace);
    gcpCloudContextService.createGcpCloudContext(workspaceId, new GcpCloudContext("fake-project"), "flight-testentersinfo");
    StoreMetadataStep storeGoogleBucketMetadataStep = new StoreMetadataStep(resourceDao);
    // Stub the flight map as of this step
    ControlledGcsBucketResource bucketResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceId).build();
    final FlightMap inputFlightMap = new FlightMap();
    inputFlightMap.put(ResourceKeys.RESOURCE, bucketResource);
    inputFlightMap.makeImmutable();
    doReturn(inputFlightMap).when(mockFlightContext).getInputParameters();
    final StepResult result = storeGoogleBucketMetadataStep.doStep(mockFlightContext);
    assertThat(result, equalTo(StepResult.getStepResultSuccess()));
    WsmResource daoResource = resourceDao.getResource(bucketResource.getWorkspaceId(), bucketResource.getResourceId());
    assertThat(daoResource.getResourceType(), equalTo(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET));
    ControlledGcsBucketResource daoBucket = (ControlledGcsBucketResource) daoResource;
    assertThat(bucketResource, equalTo(daoBucket));
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) StoreMetadataStep(bio.terra.workspace.service.resource.controlled.flight.create.StoreMetadataStep) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 15 with ControlledGcsBucketResource

use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.

the class ControlledGcpResourceApiController method getBucket.

@Override
public ResponseEntity<ApiGcpGcsBucketResource> getBucket(UUID workspaceId, UUID resourceId) {
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ControlledGcsBucketResource resource = controlledResourceService.getControlledResource(workspaceId, resourceId, userRequest).castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
    return new ResponseEntity<>(resource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)

Aggregations

ControlledGcsBucketResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)19 Test (org.junit.jupiter.api.Test)13 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)8 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)8 UUID (java.util.UUID)6 StepStatus (bio.terra.stairway.StepStatus)5 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)5 HashMap (java.util.HashMap)5 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)4 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)4 ControlledResourceFields (bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)4 StorageCow (bio.terra.cloudres.google.storage.StorageCow)3 FlightMap (bio.terra.stairway.FlightMap)3 ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ApiCreatedControlledGcpGcsBucket (bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket)2 CreateGcsBucketStep (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.CreateGcsBucketStep)2 GcsBucketCloudSyncStep (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.GcsBucketCloudSyncStep)2 RetrieveGcsBucketCloudAttributesStep (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.RetrieveGcsBucketCloudAttributesStep)2 UpdateGcsBucketStep (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.UpdateGcsBucketStep)2