use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.
the class LaunchCreateReferenceResourceFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
if (CloningInstructions.COPY_REFERENCE != resource.getCloningInstructions()) {
// Nothing to do -- don't launch flight
return StepResult.getStepResultSuccess();
}
FlightUtils.validateRequiredEntries(context.getInputParameters(), ControlledResourceKeys.DESTINATION_WORKSPACE_ID, JobMapKeys.AUTH_USER_INFO.getKeyName());
final var destinationWorkspaceId = context.getInputParameters().get(ControlledResourceKeys.DESTINATION_WORKSPACE_ID, UUID.class);
final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
final String description = String.format("Clone of Referenced Resource %s", resource.getResourceId());
final ReferencedResource destinationResource = WorkspaceCloneUtils.buildDestinationReferencedResource(resource, destinationWorkspaceId, null, description);
// put the destination resource in the map, because it's not communicated
// from the flight as the response (and we need the workspace ID)
context.getWorkingMap().put(ControlledResourceKeys.DESTINATION_REFERENCED_RESOURCE, destinationResource);
final FlightMap subflightInputParameters = new FlightMap();
subflightInputParameters.put(ResourceKeys.RESOURCE, destinationResource);
subflightInputParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
subflightInputParameters.put(WorkspaceFlightMapKeys.ResourceKeys.RESOURCE_TYPE, resource.getResourceType().name());
try {
context.getStairway().submit(subflightId, CreateReferenceResourceFlight.class, subflightInputParameters);
} catch (DatabaseOperationException | StairwayExecutionException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
} catch (DuplicateFlightIdException unused) {
// already submitted the flight - treat as success
return StepResult.getStepResultSuccess();
}
FlightUtils.validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.DESTINATION_REFERENCED_RESOURCE);
return StepResult.getStepResultSuccess();
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.
the class ValidateReferenceStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
FlightMap inputMap = flightContext.getInputParameters();
ReferencedResource referencedResource = inputMap.get(ResourceKeys.RESOURCE, ReferencedResource.class);
AuthenticatedUserRequest userRequest = inputMap.get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
if (!referencedResource.checkAccess(beanBag, userRequest)) {
throw new InvalidReferenceException(String.format("Referenced resource %s was not found or you do not have access. Verify that your reference was correctly defined and that you have access.", referencedResource.getResourceId()));
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedResourceServiceTest method updateDataRepoReferenceTarget_updateSnapshotIdAndInstanceName.
@Test
void updateDataRepoReferenceTarget_updateSnapshotIdAndInstanceName() {
referenceResource = ReferenceResourceFixtures.makeDataRepoSnapshotResource(workspaceId);
referenceResourceService.createReferenceResource(referenceResource, USER_REQUEST);
UUID resourceId = referenceResource.getResourceId();
ReferencedDataRepoSnapshotResource originalResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, USER_REQUEST).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
String originalName = referenceResource.getName();
String originalDescription = referenceResource.getDescription();
String newSnapshotId = "new_snapshot_id";
String newInstanceName = "new_instance_name";
ReferencedResource updatedResource = originalResource.toBuilder().snapshotId(newSnapshotId).instanceName(newInstanceName).build();
referenceResourceService.updateReferenceResource(workspaceId, referenceResource.getResourceId(), null, null, updatedResource, USER_REQUEST);
ReferencedDataRepoSnapshotResource result = referenceResourceService.getReferenceResource(workspaceId, resourceId, USER_REQUEST).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
assertEquals(originalName, result.getName());
assertEquals(originalDescription, result.getDescription());
assertEquals(newInstanceName, result.getInstanceName());
assertEquals(newSnapshotId, result.getSnapshotId());
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedResourceServiceTest method updateDataRepoReferenceTarget_updateSnapshotIdOnly.
@Test
void updateDataRepoReferenceTarget_updateSnapshotIdOnly() {
referenceResource = ReferenceResourceFixtures.makeDataRepoSnapshotResource(workspaceId);
referenceResourceService.createReferenceResource(referenceResource, USER_REQUEST);
UUID resourceId = referenceResource.getResourceId();
ReferencedDataRepoSnapshotResource originalResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, USER_REQUEST).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
String originalName = referenceResource.getName();
String originalDescription = referenceResource.getDescription();
String originalInstanceName = originalResource.getInstanceName();
String newSnapshotId = "new_snapshot_id";
ReferencedResource updatedResource = originalResource.toBuilder().snapshotId(newSnapshotId).build();
referenceResourceService.updateReferenceResource(workspaceId, referenceResource.getResourceId(), null, null, updatedResource, USER_REQUEST);
ReferencedDataRepoSnapshotResource result = referenceResourceService.getReferenceResource(workspaceId, resourceId, USER_REQUEST).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
assertEquals(originalName, result.getName());
assertEquals(originalDescription, result.getDescription());
assertEquals(originalInstanceName, result.getInstanceName());
assertEquals(newSnapshotId, result.getSnapshotId());
}
use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.
the class ReferencedGcpResourceController method cloneGitRepoReference.
public ResponseEntity<ApiCloneReferencedGitRepoResourceResult> cloneGitRepoReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, userRequest);
final CloningInstructions effectiveCloningInstructions = Optional.ofNullable(body.getCloningInstructions()).map(CloningInstructions::fromApiModel).orElse(sourceReferencedResource.getCloningInstructions());
if (CloningInstructions.COPY_REFERENCE != effectiveCloningInstructions) {
// Nothing to clone here
final var emptyResult = new ApiCloneReferencedGitRepoResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
return new ResponseEntity<>(emptyResult, HttpStatus.OK);
}
// Clone the reference
final ReferencedGitRepoResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), userRequest).castByEnum(WsmResourceType.REFERENCED_ANY_GIT_REPO);
// Build the correct response type
ApiCloneReferencedGitRepoResourceResult result = new ApiCloneReferencedGitRepoResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
return new ResponseEntity<>(result, HttpStatus.OK);
}
Aggregations