Search in sources :

Example 1 with CloneWorkspaceRequest

use of bio.terra.workspace.model.CloneWorkspaceRequest in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method cloneWorkspace.

/**
 * Call the Workspace Manager POST "/api/workspaces/v1/{workspaceId}/clone" endpoint to clone a
 * workspace.
 *
 * @param workspaceId - workspace ID to clone
 * @param displayName - optional name of new cloned workspace
 * @param description - optional description for new workspace
 * @return object with information about the clone job success and destination workspace
 */
public CloneWorkspaceResult cloneWorkspace(UUID workspaceId, @Nullable String displayName, @Nullable String description) {
    var request = new CloneWorkspaceRequest().spendProfile(Context.getServer().getWsmDefaultSpendProfile()).displayName(displayName).description(description).location(null);
    WorkspaceApi workspaceApi = new WorkspaceApi(apiClient);
    CloneWorkspaceResult initialResult = callWithRetries(() -> workspaceApi.cloneWorkspace(request, workspaceId), "Error cloning workspace");
    logger.debug("clone workspace initial result: {}", initialResult);
    // poll until the workspace clone completes.
    // TODO PF-745: return immediately and give some interface for checking on the job status
    // and retrieving the result.
    CloneWorkspaceResult cloneWorkspaceResult = handleClientExceptions(() -> HttpUtils.pollWithRetries(() -> workspaceApi.getCloneWorkspaceResult(workspaceId, initialResult.getJobReport().getId()), (result) -> isDone(result.getJobReport()), WorkspaceManagerService::isRetryable, CLONE_WORKSPACE_MAXIMUM_RETRIES, CLONE_WORKSPACE_RETRY_INTERVAL), "Error in cloning workspace.");
    logger.debug("clone workspace polling result: {}", cloneWorkspaceResult);
    throwIfJobNotCompleted(cloneWorkspaceResult.getJobReport(), cloneWorkspaceResult.getErrorReport());
    return cloneWorkspaceResult;
}
Also used : Context(bio.terra.cli.businessobject.Context) JobControl(bio.terra.workspace.model.JobControl) GcpGcsBucketAttributes(bio.terra.workspace.model.GcpGcsBucketAttributes) StatusEnum(bio.terra.workspace.model.JobReport.StatusEnum) WorkspaceDescriptionList(bio.terra.workspace.model.WorkspaceDescriptionList) ErrorReport(bio.terra.workspace.model.ErrorReport) GcpBigQueryDataTableAttributes(bio.terra.workspace.model.GcpBigQueryDataTableAttributes) Duration(java.time.Duration) ZoneOffset(java.time.ZoneOffset) UpdateReferencedBqDatasetParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqDatasetParams) GcpAiNotebookInstanceVmImage(bio.terra.workspace.model.GcpAiNotebookInstanceVmImage) GcpAiNotebookInstanceAcceleratorConfig(bio.terra.workspace.model.GcpAiNotebookInstanceAcceleratorConfig) CreateGcsBucketParams(bio.terra.cli.serialization.userfacing.input.CreateGcsBucketParams) ControlledResourceCommonFields(bio.terra.workspace.model.ControlledResourceCommonFields) UpdateControlledGcpBigQueryDatasetRequestBody(bio.terra.workspace.model.UpdateControlledGcpBigQueryDatasetRequestBody) ApiClient(bio.terra.workspace.client.ApiClient) GcpGcsBucketLifecycleRuleAction(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleAction) UpdateGcsBucketObjectReferenceRequestBody(bio.terra.workspace.model.UpdateGcsBucketObjectReferenceRequestBody) CreatedControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult) GitRepoResource(bio.terra.workspace.model.GitRepoResource) IamRole(bio.terra.workspace.model.IamRole) UpdateBigQueryDatasetReferenceRequestBody(bio.terra.workspace.model.UpdateBigQueryDatasetReferenceRequestBody) GcsBucketLifecycle(bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle) GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) UpdateReferencedBqTableParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqTableParams) GcpBigQueryDatasetCreationParameters(bio.terra.workspace.model.GcpBigQueryDatasetCreationParameters) HttpStatusCodes(com.google.api.client.http.HttpStatusCodes) CreateGcpGcsBucketReferenceRequestBody(bio.terra.workspace.model.CreateGcpGcsBucketReferenceRequestBody) GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) AddBqTableParams(bio.terra.cli.serialization.userfacing.input.AddBqTableParams) ReferenceResourceCommonFields(bio.terra.workspace.model.ReferenceResourceCommonFields) UpdateBigQueryDataTableReferenceRequestBody(bio.terra.workspace.model.UpdateBigQueryDataTableReferenceRequestBody) CreateControlledGcpAiNotebookInstanceRequestBody(bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody) GcpBigQueryDataTableResource(bio.terra.workspace.model.GcpBigQueryDataTableResource) UpdateWorkspaceRequestBody(bio.terra.workspace.model.UpdateWorkspaceRequestBody) DeleteControlledGcpGcsBucketRequest(bio.terra.workspace.model.DeleteControlledGcpGcsBucketRequest) ArrayList(java.util.ArrayList) CreateWorkspaceRequestBody(bio.terra.workspace.model.CreateWorkspaceRequestBody) GcpAiNotebookInstanceContainerImage(bio.terra.workspace.model.GcpAiNotebookInstanceContainerImage) GcpGcsBucketCreationParameters(bio.terra.workspace.model.GcpGcsBucketCreationParameters) GcpGcsObjectAttributes(bio.terra.workspace.model.GcpGcsObjectAttributes) WorkspaceApi(bio.terra.workspace.api.WorkspaceApi) WorkspaceStageModel(bio.terra.workspace.model.WorkspaceStageModel) Nullable(javax.annotation.Nullable) DeleteControlledGcpAiNotebookInstanceRequest(bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceRequest) CreateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.CreateControlledGcpGcsBucketRequestBody) ApiException(bio.terra.workspace.client.ApiException) CloneWorkspaceResult(bio.terra.workspace.model.CloneWorkspaceResult) GcpGcsObjectResource(bio.terra.workspace.model.GcpGcsObjectResource) DeleteControlledGcpGcsBucketResult(bio.terra.workspace.model.DeleteControlledGcpGcsBucketResult) GcpAiNotebookInstanceCreationParameters(bio.terra.workspace.model.GcpAiNotebookInstanceCreationParameters) GrantRoleRequestBody(bio.terra.workspace.model.GrantRoleRequestBody) ResourceApi(bio.terra.workspace.api.ResourceApi) CreateGcpNotebookParams(bio.terra.cli.serialization.userfacing.input.CreateGcpNotebookParams) GcpBigQueryDatasetAttributes(bio.terra.workspace.model.GcpBigQueryDatasetAttributes) AccessScope(bio.terra.workspace.model.AccessScope) UpdateGitRepoReferenceRequestBody(bio.terra.workspace.model.UpdateGitRepoReferenceRequestBody) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) GcpGcsBucketLifecycleRule(bio.terra.workspace.model.GcpGcsBucketLifecycleRule) LoggerFactory(org.slf4j.LoggerFactory) WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) HttpStatus(org.apache.http.HttpStatus) ControlledResourceIamRole(bio.terra.workspace.model.ControlledResourceIamRole) UpdateControlledBqDatasetParams(bio.terra.cli.serialization.userfacing.input.UpdateControlledBqDatasetParams) CreateCloudContextResult(bio.terra.workspace.model.CreateCloudContextResult) GcpBigQueryDatasetResource(bio.terra.workspace.model.GcpBigQueryDatasetResource) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle) UpdateReferencedGcsObjectParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsObjectParams) DeleteControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceResult) LocalTime(java.time.LocalTime) GcpGcsBucketLifecycleRuleCondition(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleCondition) AddGcsObjectParams(bio.terra.cli.serialization.userfacing.input.AddGcsObjectParams) Predicate(java.util.function.Predicate) UpdateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.UpdateControlledGcpGcsBucketRequestBody) GcpBigQueryDatasetUpdateParameters(bio.terra.workspace.model.GcpBigQueryDatasetUpdateParameters) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PrivateResourceUser(bio.terra.workspace.model.PrivateResourceUser) CreateCloudContextRequest(bio.terra.workspace.model.CreateCloudContextRequest) AddGitRepoParams(bio.terra.cli.serialization.userfacing.input.AddGitRepoParams) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) UpdateReferencedGitRepoParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGitRepoParams) SystemException(bio.terra.cli.exception.SystemException) CreateGcpBigQueryDataTableReferenceRequestBody(bio.terra.workspace.model.CreateGcpBigQueryDataTableReferenceRequestBody) GcpAiNotebookInstanceResource(bio.terra.workspace.model.GcpAiNotebookInstanceResource) UpdateControlledGcsBucketParams(bio.terra.cli.serialization.userfacing.input.UpdateControlledGcsBucketParams) RoleBindingList(bio.terra.workspace.model.RoleBindingList) ManagedBy(bio.terra.workspace.model.ManagedBy) PrivateResourceIamRoles(bio.terra.workspace.model.PrivateResourceIamRoles) ResourceList(bio.terra.workspace.model.ResourceList) JacksonMapper(bio.terra.cli.utils.JacksonMapper) CreateControlledGcpBigQueryDatasetRequestBody(bio.terra.workspace.model.CreateControlledGcpBigQueryDatasetRequestBody) GcpGcsBucketUpdateParameters(bio.terra.workspace.model.GcpGcsBucketUpdateParameters) HttpUtils(bio.terra.cli.service.utils.HttpUtils) JobReport(bio.terra.workspace.model.JobReport) CreateGcpGcsObjectReferenceRequestBody(bio.terra.workspace.model.CreateGcpGcsObjectReferenceRequestBody) CreateGcpBigQueryDatasetReferenceRequestBody(bio.terra.workspace.model.CreateGcpBigQueryDatasetReferenceRequestBody) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) UpdateGcsBucketReferenceRequestBody(bio.terra.workspace.model.UpdateGcsBucketReferenceRequestBody) UpdateReferencedGcsBucketParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsBucketParams) CloudPlatform(bio.terra.workspace.model.CloudPlatform) Logger(org.slf4j.Logger) UserActionableException(bio.terra.cli.exception.UserActionableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UnauthenticatedApi(bio.terra.workspace.api.UnauthenticatedApi) CreateBqDatasetParams(bio.terra.cli.serialization.userfacing.input.CreateBqDatasetParams) Server(bio.terra.cli.businessobject.Server) CreateGitRepoReferenceRequestBody(bio.terra.workspace.model.CreateGitRepoReferenceRequestBody) SystemVersion(bio.terra.workspace.model.SystemVersion) ResourceDescription(bio.terra.workspace.model.ResourceDescription) CreateResourceParams(bio.terra.cli.serialization.userfacing.input.CreateResourceParams) CloneWorkspaceRequest(bio.terra.workspace.model.CloneWorkspaceRequest) GitRepoAttributes(bio.terra.workspace.model.GitRepoAttributes) AccessToken(com.google.auth.oauth2.AccessToken) CloneWorkspaceResult(bio.terra.workspace.model.CloneWorkspaceResult) CloneWorkspaceRequest(bio.terra.workspace.model.CloneWorkspaceRequest) WorkspaceApi(bio.terra.workspace.api.WorkspaceApi)

Example 2 with CloneWorkspaceRequest

use of bio.terra.workspace.model.CloneWorkspaceRequest in project terra-workspace-manager by DataBiosphere.

the class CloneWorkspace method doUserJourney.

@Override
protected void doUserJourney(TestUserSpecification sourceOwnerUser, WorkspaceApi sourceOwnerWorkspaceApi) throws Exception {
    // As reader user, clone the workspace
    // Get a new workspace API for the reader
    cloningUserWorkspaceApi = ClientTestUtils.getWorkspaceClient(cloningUser, server);
    final CloneWorkspaceRequest cloneWorkspaceRequest = new CloneWorkspaceRequest().displayName("Cloned Workspace").description("A clone of workspace " + getWorkspaceId().toString()).spendProfile(// TODO- use a different one if available
    getSpendProfileId()).location("us-central1");
    CloneWorkspaceResult cloneResult = cloningUserWorkspaceApi.cloneWorkspace(cloneWorkspaceRequest, getWorkspaceId());
    final String jobId = cloneResult.getJobReport().getId();
    cloneResult = ClientTestUtils.pollWhileRunning(cloneResult, () -> cloningUserWorkspaceApi.getCloneWorkspaceResult(getWorkspaceId(), jobId), CloneWorkspaceResult::getJobReport, Duration.ofSeconds(10));
    logger.info("Clone result: {}", cloneResult);
    ClientTestUtils.assertJobSuccess("Clone Workspace", cloneResult.getJobReport(), cloneResult.getErrorReport());
    assertNull(cloneResult.getErrorReport());
    assertNotNull(cloneResult.getWorkspace());
    assertThat(cloneResult.getWorkspace().getResources(), hasSize(EXPECTED_NUM_CLONED_RESOURCES));
    assertEquals(getWorkspaceId(), cloneResult.getWorkspace().getSourceWorkspaceId());
    destinationWorkspaceId = cloneResult.getWorkspace().getDestinationWorkspaceId();
    assertNotNull(destinationWorkspaceId);
    // Verify shared GCS bucket succeeds and is populated
    final ResourceCloneDetails sharedBucketCloneDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> sharedSourceBucket.getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(sharedBucketCloneDetails.toString());
    assertEquals(CloneResourceResult.SUCCEEDED, sharedBucketCloneDetails.getResult());
    assertEquals(CloningInstructionsEnum.RESOURCE, sharedBucketCloneDetails.getCloningInstructions());
    assertEquals(ResourceType.GCS_BUCKET, sharedBucketCloneDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, sharedBucketCloneDetails.getStewardshipType());
    assertNotNull(sharedBucketCloneDetails.getDestinationResourceId());
    assertNull(sharedBucketCloneDetails.getErrorMessage());
    assertEquals(sharedSourceBucket.getGcpBucket().getMetadata().getName(), sharedBucketCloneDetails.getName());
    assertEquals(sharedSourceBucket.getGcpBucket().getMetadata().getDescription(), sharedBucketCloneDetails.getDescription());
    // We need to get the destination bucket name and project ID
    final WorkspaceDescription destinationWorkspace = cloningUserWorkspaceApi.getWorkspace(destinationWorkspaceId);
    final String destinationProjectId = destinationWorkspace.getGcpContext().getProjectId();
    final var clonedSharedBucket = cloningUserResourceApi.getBucket(destinationWorkspaceId, sharedBucketCloneDetails.getDestinationResourceId());
    GcsBucketObjectUtils.retrieveBucketFile(clonedSharedBucket.getAttributes().getBucketName(), destinationProjectId, cloningUser);
    // Verify clone of private bucket fails
    final ResourceCloneDetails privateBucketCloneDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> privateSourceBucket.getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(privateBucketCloneDetails.toString());
    assertEquals(CloneResourceResult.FAILED, privateBucketCloneDetails.getResult());
    assertEquals(CloningInstructionsEnum.RESOURCE, privateBucketCloneDetails.getCloningInstructions());
    assertEquals(ResourceType.GCS_BUCKET, privateBucketCloneDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, privateBucketCloneDetails.getStewardshipType());
    assertNull(privateBucketCloneDetails.getDestinationResourceId());
    assertNotNull(privateBucketCloneDetails.getErrorMessage());
    assertEquals(privateSourceBucket.getGcpBucket().getMetadata().getName(), privateBucketCloneDetails.getName());
    assertEquals(privateSourceBucket.getGcpBucket().getMetadata().getDescription(), privateBucketCloneDetails.getDescription());
    // Verify COPY_NOTHING bucket was skipped
    final ResourceCloneDetails copyNothingBucketCloneDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> sharedCopyNothingSourceBucket.getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(copyNothingBucketCloneDetails.toString());
    assertEquals(CloneResourceResult.SKIPPED, copyNothingBucketCloneDetails.getResult());
    assertEquals(CloningInstructionsEnum.NOTHING, copyNothingBucketCloneDetails.getCloningInstructions());
    assertEquals(ResourceType.GCS_BUCKET, copyNothingBucketCloneDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, copyNothingBucketCloneDetails.getStewardshipType());
    assertNull(copyNothingBucketCloneDetails.getDestinationResourceId());
    assertNull(copyNothingBucketCloneDetails.getErrorMessage());
    assertEquals(sharedCopyNothingSourceBucket.getGcpBucket().getMetadata().getName(), copyNothingBucketCloneDetails.getName());
    assertEquals(sharedCopyNothingSourceBucket.getGcpBucket().getMetadata().getDescription(), copyNothingBucketCloneDetails.getDescription());
    // verify COPY_DEFINITION bucket exists but is empty
    final ResourceCloneDetails copyDefinitionBucketDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> copyDefinitionSourceBucket.getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(copyDefinitionBucketDetails.toString());
    assertEquals(CloneResourceResult.SUCCEEDED, copyDefinitionBucketDetails.getResult());
    assertEquals(CloningInstructionsEnum.DEFINITION, copyDefinitionBucketDetails.getCloningInstructions());
    assertEquals(ResourceType.GCS_BUCKET, copyDefinitionBucketDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, copyDefinitionBucketDetails.getStewardshipType());
    assertNotNull(copyDefinitionBucketDetails.getDestinationResourceId());
    final GcpGcsBucketResource clonedCopyDefinitionBucket = cloningUserResourceApi.getBucket(destinationWorkspaceId, copyDefinitionBucketDetails.getDestinationResourceId());
    assertEmptyBucket(clonedCopyDefinitionBucket.getAttributes().getBucketName(), destinationProjectId);
    assertEquals(copyDefinitionSourceBucket.getGcpBucket().getMetadata().getName(), copyDefinitionBucketDetails.getName());
    assertEquals(copyDefinitionSourceBucket.getGcpBucket().getMetadata().getDescription(), copyDefinitionBucketDetails.getDescription());
    // verify COPY_DEFINITION dataset exists but has no tables
    final ResourceCloneDetails copyDefinitionDatasetDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> copyDefinitionDataset.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(copyDefinitionDatasetDetails.toString());
    assertEquals(CloneResourceResult.SUCCEEDED, copyDefinitionDatasetDetails.getResult());
    assertEquals(CloningInstructionsEnum.DEFINITION, copyDefinitionDatasetDetails.getCloningInstructions());
    assertEquals(ResourceType.BIG_QUERY_DATASET, copyDefinitionDatasetDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, copyDefinitionDatasetDetails.getStewardshipType());
    assertNotNull(copyDefinitionDatasetDetails.getDestinationResourceId());
    assertNull(copyDefinitionDatasetDetails.getErrorMessage());
    assertEquals(copyDefinitionDataset.getMetadata().getName(), copyDefinitionDatasetDetails.getName());
    assertEquals(copyDefinitionDataset.getMetadata().getDescription(), copyDefinitionDatasetDetails.getDescription());
    final BigQuery bigQueryClient = ClientTestUtils.getGcpBigQueryClient(cloningUser, destinationProjectId);
    assertDatasetHasNoTables(destinationProjectId, bigQueryClient, copyDefinitionDatasetResourceName);
    // verify clone resource dataset succeeded and has rows and tables
    final ResourceCloneDetails copyResourceDatasetDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> copyResourceDataset.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(copyResourceDatasetDetails.toString());
    assertEquals(CloneResourceResult.SUCCEEDED, copyResourceDatasetDetails.getResult());
    assertEquals(CloningInstructionsEnum.RESOURCE, copyResourceDatasetDetails.getCloningInstructions());
    assertEquals(ResourceType.BIG_QUERY_DATASET, copyResourceDatasetDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, copyResourceDatasetDetails.getStewardshipType());
    assertNotNull(copyResourceDatasetDetails.getDestinationResourceId());
    assertNull(copyResourceDatasetDetails.getErrorMessage());
    // Use cloned result table to avoid Domain Restricted Sharing conflicts created by temporary
    // result table IAM.
    TableId resultTableId = TableId.of(destinationProjectId, copyResourceDatasetResourceName, BQ_RESULT_TABLE_NAME);
    final QueryJobConfiguration employeeQueryJobConfiguration = QueryJobConfiguration.newBuilder("SELECT * FROM `" + destinationProjectId + "." + copyResourceDatasetResourceName + ".employee`;").setDestinationTable(resultTableId).setWriteDisposition(WriteDisposition.WRITE_TRUNCATE).build();
    final TableResult employeeTableResult = bigQueryClient.query(employeeQueryJobConfiguration);
    final long numEmployees = StreamSupport.stream(employeeTableResult.getValues().spliterator(), false).count();
    assertThat(numEmployees, is(greaterThanOrEqualTo(2L)));
    // verify private dataset clone failed
    final ResourceCloneDetails privateDatasetDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> privateDataset.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(privateDatasetDetails.toString());
    assertEquals(CloneResourceResult.FAILED, privateDatasetDetails.getResult());
    assertEquals(CloningInstructionsEnum.RESOURCE, privateDatasetDetails.getCloningInstructions());
    assertEquals(ResourceType.BIG_QUERY_DATASET, privateDatasetDetails.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, privateDatasetDetails.getStewardshipType());
    assertNull(privateDatasetDetails.getDestinationResourceId());
    assertNotNull(privateDatasetDetails.getErrorMessage());
    final ResourceCloneDetails bucketReferenceDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> sourceBucketReference.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(bucketReferenceDetails.toString());
    assertEquals(CloneResourceResult.SUCCEEDED, bucketReferenceDetails.getResult());
    assertEquals(CloningInstructionsEnum.REFERENCE, bucketReferenceDetails.getCloningInstructions());
    assertEquals(ResourceType.GCS_BUCKET, bucketReferenceDetails.getResourceType());
    assertEquals(StewardshipType.REFERENCED, bucketReferenceDetails.getStewardshipType());
    assertNotNull(bucketReferenceDetails.getDestinationResourceId());
    assertNull(bucketReferenceDetails.getErrorMessage());
    final ResourceCloneDetails bucketFileReferenceDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> sourceBucketFileReference.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    logger.info(bucketFileReferenceDetails.toString());
    assertEquals(CloneResourceResult.SUCCEEDED, bucketFileReferenceDetails.getResult());
    assertEquals(CloningInstructionsEnum.REFERENCE, bucketFileReferenceDetails.getCloningInstructions());
    assertEquals(ResourceType.GCS_OBJECT, bucketFileReferenceDetails.getResourceType());
    assertEquals(StewardshipType.REFERENCED, bucketFileReferenceDetails.getStewardshipType());
    assertNotNull(bucketFileReferenceDetails.getDestinationResourceId());
    assertNull(bucketFileReferenceDetails.getErrorMessage());
    final ResourceCloneDetails datasetReferenceDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> sourceDatasetReference.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    assertEquals(CloneResourceResult.SKIPPED, datasetReferenceDetails.getResult());
    assertEquals(CloningInstructionsEnum.NOTHING, datasetReferenceDetails.getCloningInstructions());
    assertEquals(ResourceType.BIG_QUERY_DATASET, datasetReferenceDetails.getResourceType());
    assertEquals(StewardshipType.REFERENCED, datasetReferenceDetails.getStewardshipType());
    assertNull(datasetReferenceDetails.getDestinationResourceId());
    assertNull(datasetReferenceDetails.getErrorMessage());
    final ResourceCloneDetails dataTableReferenceDetails = getOrFail(cloneResult.getWorkspace().getResources().stream().filter(r -> sourceDataTableReference.getMetadata().getResourceId().equals(r.getSourceResourceId())).findFirst());
    assertEquals(CloneResourceResult.SKIPPED, dataTableReferenceDetails.getResult());
    assertEquals(CloningInstructionsEnum.NOTHING, dataTableReferenceDetails.getCloningInstructions());
    assertEquals(ResourceType.BIG_QUERY_DATA_TABLE, dataTableReferenceDetails.getResourceType());
    assertEquals(StewardshipType.REFERENCED, dataTableReferenceDetails.getStewardshipType());
    assertNull(dataTableReferenceDetails.getDestinationResourceId());
    assertNull(dataTableReferenceDetails.getErrorMessage());
}
Also used : TableId(com.google.cloud.bigquery.TableId) CloneWorkspaceResult(bio.terra.workspace.model.CloneWorkspaceResult) WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) CloneWorkspaceRequest(bio.terra.workspace.model.CloneWorkspaceRequest) BigQuery(com.google.cloud.bigquery.BigQuery) TableResult(com.google.cloud.bigquery.TableResult) ResourceCloneDetails(bio.terra.workspace.model.ResourceCloneDetails) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration)

Aggregations

CloneWorkspaceRequest (bio.terra.workspace.model.CloneWorkspaceRequest)2 CloneWorkspaceResult (bio.terra.workspace.model.CloneWorkspaceResult)2 GcpGcsBucketResource (bio.terra.workspace.model.GcpGcsBucketResource)2 WorkspaceDescription (bio.terra.workspace.model.WorkspaceDescription)2 Context (bio.terra.cli.businessobject.Context)1 Server (bio.terra.cli.businessobject.Server)1 SystemException (bio.terra.cli.exception.SystemException)1 UserActionableException (bio.terra.cli.exception.UserActionableException)1 AddBqTableParams (bio.terra.cli.serialization.userfacing.input.AddBqTableParams)1 AddGcsObjectParams (bio.terra.cli.serialization.userfacing.input.AddGcsObjectParams)1 AddGitRepoParams (bio.terra.cli.serialization.userfacing.input.AddGitRepoParams)1 CreateBqDatasetParams (bio.terra.cli.serialization.userfacing.input.CreateBqDatasetParams)1 CreateGcpNotebookParams (bio.terra.cli.serialization.userfacing.input.CreateGcpNotebookParams)1 CreateGcsBucketParams (bio.terra.cli.serialization.userfacing.input.CreateGcsBucketParams)1 CreateResourceParams (bio.terra.cli.serialization.userfacing.input.CreateResourceParams)1 GcsBucketLifecycle (bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle)1 GcsStorageClass (bio.terra.cli.serialization.userfacing.input.GcsStorageClass)1 UpdateControlledBqDatasetParams (bio.terra.cli.serialization.userfacing.input.UpdateControlledBqDatasetParams)1 UpdateControlledGcsBucketParams (bio.terra.cli.serialization.userfacing.input.UpdateControlledGcsBucketParams)1 UpdateReferencedBqDatasetParams (bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqDatasetParams)1