use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.
the class ControlledGcsBucketResourceTest method testSerialization.
@Test
public void testSerialization() throws JsonProcessingException {
ControlledGcsBucketResource gcsBucketResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(null).build();
final ObjectMapper objectMapper = StairwayMapper.getObjectMapper();
final String serialized = objectMapper.writeValueAsString(gcsBucketResource);
final ControlledGcsBucketResource deserialized = objectMapper.readValue(serialized, ControlledGcsBucketResource.class);
assertThat(deserialized, equalTo(gcsBucketResource));
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.
the class ResourceDaoTest method listAndDeleteControlledResourceInContext.
@Test
public void listAndDeleteControlledResourceInContext() {
UUID workspaceId = createGcpWorkspace();
ControlledGcsBucketResource bucket = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceId).build();
ControlledBigQueryDatasetResource dataset = ControlledResourceFixtures.makeDefaultControlledBigQueryBuilder(workspaceId).build();
resourceDao.createControlledResource(bucket);
resourceDao.createControlledResource(dataset);
List<ControlledResource> gcpList = resourceDao.listControlledResources(workspaceId, CloudPlatform.GCP);
List<ControlledResource> azureList = resourceDao.listControlledResources(workspaceId, CloudPlatform.AZURE);
List<ControlledResource> allCloudList = resourceDao.listControlledResources(workspaceId, null);
assertTrue(azureList.isEmpty());
assertThat(gcpList, containsInAnyOrder(bucket, dataset));
assertThat(allCloudList, containsInAnyOrder(bucket, dataset));
assertTrue(resourceDao.deleteAllControlledResources(workspaceId, CloudPlatform.GCP));
assertFalse(resourceDao.deleteAllControlledResources(workspaceId, CloudPlatform.AZURE));
List<ControlledResource> listAfterDeletion = resourceDao.listControlledResources(workspaceId, CloudPlatform.GCP);
assertTrue(listAfterDeletion.isEmpty());
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.
the class ResourceDaoTest method duplicateControlledBucketNameRejected.
@Test
public void duplicateControlledBucketNameRejected() {
final String clashingBucketName = "not-a-pail";
final UUID workspaceId1 = createGcpWorkspace();
final ControlledGcsBucketResource initialResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceId1).bucketName(clashingBucketName).build();
resourceDao.createControlledResource(initialResource);
final UUID workspaceId2 = createGcpWorkspace();
final ControlledGcsBucketResource duplicatingResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceId2).bucketName(clashingBucketName).build();
assertThrows(DuplicateResourceException.class, () -> resourceDao.createControlledResource(duplicatingResource));
// clean up
resourceDao.deleteResource(initialResource.getWorkspaceId(), initialResource.getResourceId());
resourceDao.deleteResource(duplicatingResource.getWorkspaceId(), duplicatingResource.getResourceId());
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.
the class ControlledGcpResourceApiController method createBucket.
@Override
public ResponseEntity<ApiCreatedControlledGcpGcsBucket> createBucket(UUID workspaceId, @Valid ApiCreateControlledGcpGcsBucketRequestBody body) {
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
ControlledGcsBucketResource resource = ControlledGcsBucketResource.builder().bucketName(body.getGcsBucket().getName()).common(commonFields).build();
final ControlledGcsBucketResource createdBucket = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getGcsBucket()).castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
var response = new ApiCreatedControlledGcpGcsBucket().resourceId(createdBucket.getResourceId()).gcpBucket(createdBucket.toApiResource());
return new ResponseEntity<>(response, HttpStatus.OK);
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource in project terra-workspace-manager by DataBiosphere.
the class CopyGcsBucketDefinitionStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
final FlightMap inputParameters = flightContext.getInputParameters();
final FlightMap workingMap = flightContext.getWorkingMap();
final CloningInstructions cloningInstructions = Optional.ofNullable(inputParameters.get(ControlledResourceKeys.CLONING_INSTRUCTIONS, CloningInstructions.class)).orElse(sourceBucket.getCloningInstructions());
// future steps need the resolved cloning instructions
workingMap.put(ControlledResourceKeys.CLONING_INSTRUCTIONS, cloningInstructions);
if (CloningInstructions.COPY_NOTHING.equals(cloningInstructions)) {
final ApiClonedControlledGcpGcsBucket noOpResult = new ApiClonedControlledGcpGcsBucket().effectiveCloningInstructions(cloningInstructions.toApiModel()).bucket(null).sourceWorkspaceId(sourceBucket.getWorkspaceId()).sourceResourceId(sourceBucket.getResourceId());
FlightUtils.setResponse(flightContext, noOpResult, HttpStatus.OK);
return StepResult.getStepResultSuccess();
}
// todo: handle COPY_REFERENCE PF-811, PF-812
final String resourceName = FlightUtils.getInputParameterOrWorkingValue(flightContext, ResourceKeys.RESOURCE_NAME, ResourceKeys.PREVIOUS_RESOURCE_NAME, String.class);
final String description = FlightUtils.getInputParameterOrWorkingValue(flightContext, ResourceKeys.RESOURCE_DESCRIPTION, ResourceKeys.PREVIOUS_RESOURCE_DESCRIPTION, String.class);
final String bucketName = Optional.ofNullable(inputParameters.get(ControlledResourceKeys.DESTINATION_BUCKET_NAME, String.class)).orElseGet(this::randomBucketName);
final PrivateResourceState privateResourceState = sourceBucket.getAccessScope() == AccessScopeType.ACCESS_SCOPE_PRIVATE ? PrivateResourceState.INITIALIZING : PrivateResourceState.NOT_APPLICABLE;
// Store effective bucket name for destination
workingMap.put(ControlledResourceKeys.DESTINATION_BUCKET_NAME, bucketName);
final UUID destinationWorkspaceId = inputParameters.get(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, UUID.class);
// bucket resource for create flight
ControlledResourceFields commonFields = ControlledResourceFields.builder().workspaceId(destinationWorkspaceId).resourceId(// random ID for new resource
UUID.randomUUID()).name(resourceName).description(description).cloningInstructions(sourceBucket.getCloningInstructions()).assignedUser(sourceBucket.getAssignedUser().orElse(null)).accessScope(sourceBucket.getAccessScope()).managedBy(sourceBucket.getManagedBy()).applicationId(sourceBucket.getApplicationId()).privateResourceState(privateResourceState).build();
ControlledGcsBucketResource destinationBucketResource = ControlledGcsBucketResource.builder().bucketName(bucketName).common(commonFields).build();
final ApiGcpGcsBucketCreationParameters destinationCreationParameters = getDestinationCreationParameters(inputParameters, workingMap);
final ControlledResourceIamRole iamRole = IamRoleUtils.getIamRoleForAccessScope(sourceBucket.getAccessScope());
// Launch a CreateControlledResourcesFlight to make the destination bucket
final ControlledGcsBucketResource clonedBucket = controlledResourceService.createControlledResourceSync(destinationBucketResource, iamRole, userRequest, destinationCreationParameters).castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
workingMap.put(ControlledResourceKeys.CLONED_RESOURCE_DEFINITION, clonedBucket);
final ApiCreatedControlledGcpGcsBucket apiCreatedBucket = new ApiCreatedControlledGcpGcsBucket().gcpBucket(clonedBucket.toApiResource()).resourceId(destinationBucketResource.getResourceId());
final ApiClonedControlledGcpGcsBucket apiBucketResult = new ApiClonedControlledGcpGcsBucket().effectiveCloningInstructions(cloningInstructions.toApiModel()).bucket(apiCreatedBucket).sourceWorkspaceId(sourceBucket.getWorkspaceId()).sourceResourceId(sourceBucket.getResourceId());
workingMap.put(ControlledResourceKeys.CLONE_DEFINITION_RESULT, apiBucketResult);
if (cloningInstructions.equals(CloningInstructions.COPY_DEFINITION)) {
FlightUtils.setResponse(flightContext, apiBucketResult, HttpStatus.OK);
}
return StepResult.getStepResultSuccess();
}
Aggregations