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