use of bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket 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.generated.model.ApiCreatedControlledGcpGcsBucket 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();
}
use of bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket in project terra-workspace-manager by DataBiosphere.
the class AwaitCloneGcsBucketResourceFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
// wait for the flight
try {
final FlightState subflightState = context.getStairway().waitForFlight(subflightId, FLIGHT_POLL_SECONDS, FLIGHT_POLL_CYCLES);
final FlightStatus subflightStatus = subflightState.getFlightStatus();
final WsmCloneResourceResult cloneResult = WorkspaceCloneUtils.flightStatusToCloneResult(subflightStatus, resource);
final var cloneDetails = new WsmResourceCloneDetails();
cloneDetails.setResult(cloneResult);
final FlightMap resultMap = FlightUtils.getResultMapRequired(subflightState);
final var clonedBucket = resultMap.get(JobMapKeys.RESPONSE.getKeyName(), ApiClonedControlledGcpGcsBucket.class);
cloneDetails.setStewardshipType(StewardshipType.CONTROLLED);
cloneDetails.setResourceType(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
cloneDetails.setCloningInstructions(resource.getCloningInstructions());
cloneDetails.setSourceResourceId(resource.getResourceId());
cloneDetails.setDestinationResourceId(Optional.ofNullable(clonedBucket).map(ApiClonedControlledGcpGcsBucket::getBucket).map(ApiCreatedControlledGcpGcsBucket::getResourceId).orElse(null));
cloneDetails.setErrorMessage(FlightUtils.getFlightErrorMessage(subflightState));
cloneDetails.setName(resource.getName());
cloneDetails.setDescription(resource.getDescription());
// add to the map
final var resourceIdToResult = Optional.ofNullable(context.getWorkingMap().get(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, new TypeReference<Map<UUID, WsmResourceCloneDetails>>() {
})).orElseGet(HashMap::new);
resourceIdToResult.put(resource.getResourceId(), cloneDetails);
context.getWorkingMap().put(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, resourceIdToResult);
} catch (DatabaseOperationException | FlightWaitTimedOutException e) {
// Retry for database issues or expired wait loop
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT);
return StepResult.getStepResultSuccess();
}
Aggregations