Search in sources :

Example 6 with ReferencedResource

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();
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) StairwayExecutionException(bio.terra.stairway.exception.StairwayExecutionException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) DuplicateFlightIdException(bio.terra.stairway.exception.DuplicateFlightIdException)

Example 7 with ReferencedResource

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();
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) FlightMap(bio.terra.stairway.FlightMap) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) InvalidReferenceException(bio.terra.workspace.service.resource.referenced.exception.InvalidReferenceException)

Example 8 with ReferencedResource

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());
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) UUID(java.util.UUID) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 9 with ReferencedResource

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());
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) UUID(java.util.UUID) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 10 with ReferencedResource

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);
}
Also used : ApiCloneReferencedGitRepoResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGitRepoResourceResult) ReferencedGitRepoResource(bio.terra.workspace.service.resource.referenced.cloud.any.gitrepo.ReferencedGitRepoResource) ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ResponseEntity(org.springframework.http.ResponseEntity) CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Aggregations

ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)11 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)7 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ReferencedDataRepoSnapshotResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)4 Test (org.junit.jupiter.api.Test)3 FlightMap (bio.terra.stairway.FlightMap)2 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)2 UUID (java.util.UUID)2 StepResult (bio.terra.stairway.StepResult)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1 DuplicateFlightIdException (bio.terra.stairway.exception.DuplicateFlightIdException)1 StairwayExecutionException (bio.terra.stairway.exception.StairwayExecutionException)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 ApiCloneReferencedGcpBigQueryDataTableResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDataTableResourceResult)1 ApiCloneReferencedGcpBigQueryDatasetResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDatasetResourceResult)1 ApiCloneReferencedGcpDataRepoSnapshotResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult)1 ApiCloneReferencedGcpGcsBucketResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsBucketResourceResult)1 ApiCloneReferencedGcpGcsObjectResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsObjectResourceResult)1 ApiCloneReferencedGitRepoResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGitRepoResourceResult)1