Search in sources :

Example 1 with JobControl

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

the class ControlledGcsBucketLifecycle method testCloneBucket.

private void testCloneBucket(GcpGcsBucketResource sourceBucket, TestUserSpecification cloningUser, ControlledGcpResourceApi resourceApi) throws Exception {
    final String destinationBucketName = "clone-" + UUID.randomUUID().toString();
    // clone the bucket
    final String clonedBucketDescription = "A cloned bucket";
    final CloneControlledGcpGcsBucketRequest cloneRequest = new CloneControlledGcpGcsBucketRequest().bucketName(destinationBucketName).destinationWorkspaceId(getDestinationWorkspaceId()).name(sourceBucket.getMetadata().getName()).description(clonedBucketDescription).location(// use same as src
    null).cloningInstructions(CloningInstructionsEnum.RESOURCE).jobControl(new JobControl().id(UUID.randomUUID().toString()));
    logger.info("Cloning bucket\n\tname: {}\n\tresource ID: {}\n\tworkspace: {}\n\t" + "projectID: {}\ninto destination bucket\n\tname: {}\n\tworkspace: {}\n\tprojectID: {}", sourceBucket.getMetadata().getName(), sourceBucket.getMetadata().getResourceId(), sourceBucket.getMetadata().getWorkspaceId(), getSourceProjectId(), destinationBucketName, getDestinationWorkspaceId(), getDestinationProjectId());
    CloneControlledGcpGcsBucketResult cloneResult = resourceApi.cloneGcsBucket(cloneRequest, sourceBucket.getMetadata().getWorkspaceId(), sourceBucket.getMetadata().getResourceId());
    cloneResult = ClientTestUtils.pollWhileRunning(cloneResult, () -> resourceApi.getCloneGcsBucketResult(cloneRequest.getDestinationWorkspaceId(), cloneRequest.getJobControl().getId()), CloneControlledGcpGcsBucketResult::getJobReport, Duration.ofSeconds(5));
    ClientTestUtils.assertJobSuccess("cloned bucket", cloneResult.getJobReport(), cloneResult.getErrorReport());
    final ClonedControlledGcpGcsBucket clonedBucket = cloneResult.getBucket();
    assertEquals(getWorkspaceId(), clonedBucket.getSourceWorkspaceId());
    assertEquals(sourceBucket.getMetadata().getResourceId(), clonedBucket.getSourceResourceId());
    final CreatedControlledGcpGcsBucket createdBucket = clonedBucket.getBucket();
    final GcpGcsBucketResource clonedResource = createdBucket.getGcpBucket();
    assertEquals(destinationBucketName, clonedResource.getAttributes().getBucketName());
    final ResourceMetadata clonedResourceMetadata = clonedResource.getMetadata();
    assertEquals(getDestinationWorkspaceId(), clonedResourceMetadata.getWorkspaceId());
    assertEquals(sourceBucket.getMetadata().getName(), clonedResourceMetadata.getName());
    assertEquals(clonedBucketDescription, clonedResourceMetadata.getDescription());
    final ResourceMetadata sourceMetadata = sourceBucket.getMetadata();
    assertEquals(CloningInstructionsEnum.NOTHING, clonedResourceMetadata.getCloningInstructions());
    assertEquals(sourceMetadata.getCloudPlatform(), clonedResourceMetadata.getCloudPlatform());
    assertEquals(ResourceType.GCS_BUCKET, clonedResourceMetadata.getResourceType());
    assertEquals(StewardshipType.CONTROLLED, clonedResourceMetadata.getStewardshipType());
    assertEquals(sourceMetadata.getControlledResourceMetadata().getAccessScope(), clonedResourceMetadata.getControlledResourceMetadata().getAccessScope());
    assertEquals(sourceMetadata.getControlledResourceMetadata().getManagedBy(), clonedResourceMetadata.getControlledResourceMetadata().getManagedBy());
    assertEquals(sourceMetadata.getControlledResourceMetadata().getPrivateResourceUser(), clonedResourceMetadata.getControlledResourceMetadata().getPrivateResourceUser());
    assertEquals(CloudPlatform.GCP, clonedResourceMetadata.getCloudPlatform());
    final Storage destinationProjectStorageClient = ClientTestUtils.getGcpStorageClient(cloningUser, getDestinationProjectId());
    final Bucket destinationGcsBucket = destinationProjectStorageClient.get(destinationBucketName);
    // Location, storage class, and lifecycle rules should match values from createBucketAttempt
    assertEquals(StorageClass.STANDARD, destinationGcsBucket.getStorageClass());
    assertEquals(BUCKET_LOCATION, // default since not specified
    destinationGcsBucket.getLocation());
    assertEquals(2, destinationGcsBucket.getLifecycleRules().size());
    verifyClonedLifecycleRules(destinationGcsBucket);
    assertEquals(CloningInstructionsEnum.RESOURCE, clonedBucket.getEffectiveCloningInstructions());
    // test retrieving file from destination bucket
    Storage cloningUserStorageClient = ClientTestUtils.getGcpStorageClient(cloningUser, getDestinationProjectId());
    BlobId blobId = BlobId.of(destinationBucketName, GCS_BLOB_NAME);
    assertNotNull(blobId);
    final Blob retrievedFile = cloningUserStorageClient.get(blobId);
    assertNotNull(retrievedFile);
    assertEquals(blobId.getName(), retrievedFile.getBlobId().getName());
}
Also used : GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) Blob(com.google.cloud.storage.Blob) CloneControlledGcpGcsBucketResult(bio.terra.workspace.model.CloneControlledGcpGcsBucketResult) Storage(com.google.cloud.storage.Storage) Bucket(com.google.cloud.storage.Bucket) CreatedControlledGcpGcsBucket(bio.terra.workspace.model.CreatedControlledGcpGcsBucket) ClonedControlledGcpGcsBucket(bio.terra.workspace.model.ClonedControlledGcpGcsBucket) CloneControlledGcpGcsBucketRequest(bio.terra.workspace.model.CloneControlledGcpGcsBucketRequest) JobControl(bio.terra.workspace.model.JobControl) ClonedControlledGcpGcsBucket(bio.terra.workspace.model.ClonedControlledGcpGcsBucket) ResourceMetadata(bio.terra.workspace.model.ResourceMetadata) BlobId(com.google.cloud.storage.BlobId) CreatedControlledGcpGcsBucket(bio.terra.workspace.model.CreatedControlledGcpGcsBucket)

Example 2 with JobControl

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

the class PrivateControlledGcsBucketLifecycle method deleteBucket.

private DeleteControlledGcpGcsBucketResult deleteBucket(ControlledGcpResourceApi resourceApi, UUID resourceId) throws Exception {
    String deleteJobId = UUID.randomUUID().toString();
    var deleteRequest = new DeleteControlledGcpGcsBucketRequest().jobControl(new JobControl().id(deleteJobId));
    logger.info("Deleting bucket resource id {} jobId {}", resourceId, deleteJobId);
    DeleteControlledGcpGcsBucketResult result = resourceApi.deleteBucket(deleteRequest, getWorkspaceId(), resourceId);
    while (ClientTestUtils.jobIsRunning(result.getJobReport())) {
        TimeUnit.SECONDS.sleep(DELETE_BUCKET_POLL_SECONDS);
        result = resourceApi.getDeleteBucketResult(getWorkspaceId(), deleteJobId);
    }
    return result;
}
Also used : DeleteControlledGcpGcsBucketRequest(bio.terra.workspace.model.DeleteControlledGcpGcsBucketRequest) DeleteControlledGcpGcsBucketResult(bio.terra.workspace.model.DeleteControlledGcpGcsBucketResult) JobControl(bio.terra.workspace.model.JobControl)

Example 3 with JobControl

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

the class Jobs method doUserJourney.

@Override
public void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
    JobsApi jobsApi = ClientTestUtils.getJobsClient(testUser, server);
    // The purpose of this test is to exercise the jobsApi so we
    // create a cloud context - something that will run async
    String contextJobId = UUID.randomUUID().toString();
    var createContext = new CreateCloudContextRequest().cloudPlatform(CloudPlatform.GCP).jobControl(new JobControl().id(contextJobId));
    logger.info("Creating GCP cloud context");
    CreateCloudContextResult contextResult = workspaceApi.createCloudContext(createContext, getWorkspaceId());
    JobReport jobReport = contextResult.getJobReport();
    while (ClientTestUtils.jobIsRunning(jobReport)) {
        TimeUnit.SECONDS.sleep(10);
        jobReport = jobsApi.retrieveJob(contextJobId);
    }
    logger.info("Create GCP context status is {}", jobReport.getStatus().toString());
}
Also used : JobsApi(bio.terra.workspace.api.JobsApi) CreateCloudContextResult(bio.terra.workspace.model.CreateCloudContextResult) JobControl(bio.terra.workspace.model.JobControl) CreateCloudContextRequest(bio.terra.workspace.model.CreateCloudContextRequest) JobReport(bio.terra.workspace.model.JobReport)

Example 4 with JobControl

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

the class PrivateControlledAiNotebookInstanceLifecycle method createAControlledAiNotebookInstanceWithoutSpecifiedInstanceId_validInstanceIdIsGenerated.

private void createAControlledAiNotebookInstanceWithoutSpecifiedInstanceId_validInstanceIdIsGenerated(ControlledGcpResourceApi resourceUserApi) throws ApiException, InterruptedException {
    CreatedControlledGcpAiNotebookInstanceResult resourceWithNotebookInstanceIdNotSpecified = NotebookUtils.makeControlledNotebookUserPrivate(getWorkspaceId(), /*instanceId=*/
    null, /*location=*/
    null, resourceUserApi);
    assertNotNull(resourceWithNotebookInstanceIdNotSpecified.getAiNotebookInstance().getAttributes().getInstanceId());
    resourceUserApi.deleteAiNotebookInstance(new DeleteControlledGcpAiNotebookInstanceRequest().jobControl(new JobControl().id(UUID.randomUUID().toString())), getWorkspaceId(), resourceWithNotebookInstanceIdNotSpecified.getAiNotebookInstance().getMetadata().getResourceId());
}
Also used : CreatedControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult) DeleteControlledGcpAiNotebookInstanceRequest(bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceRequest) JobControl(bio.terra.workspace.model.JobControl)

Example 5 with JobControl

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

the class PrivateControlledAiNotebookInstanceLifecycle method createAControlledAiNotebookInstanceWithoutSpecifiedInstanceId_specifyLocation.

private void createAControlledAiNotebookInstanceWithoutSpecifiedInstanceId_specifyLocation(ControlledGcpResourceApi resourceUserApi) throws ApiException, InterruptedException {
    String location = "us-east1-b";
    CreatedControlledGcpAiNotebookInstanceResult resourceWithNotebookInstanceIdNotSpecified = NotebookUtils.makeControlledNotebookUserPrivate(getWorkspaceId(), /*instanceId=*/
    null, /*location=*/
    location, resourceUserApi);
    assertEquals(location, resourceWithNotebookInstanceIdNotSpecified.getAiNotebookInstance().getAttributes().getLocation());
    resourceUserApi.deleteAiNotebookInstance(new DeleteControlledGcpAiNotebookInstanceRequest().jobControl(new JobControl().id(UUID.randomUUID().toString())), getWorkspaceId(), resourceWithNotebookInstanceIdNotSpecified.getAiNotebookInstance().getMetadata().getResourceId());
}
Also used : CreatedControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult) DeleteControlledGcpAiNotebookInstanceRequest(bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceRequest) JobControl(bio.terra.workspace.model.JobControl)

Aggregations

JobControl (bio.terra.workspace.model.JobControl)15 DeleteControlledGcpAiNotebookInstanceRequest (bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceRequest)5 ControlledGcpResourceApi (bio.terra.workspace.api.ControlledGcpResourceApi)4 CreatedControlledGcpAiNotebookInstanceResult (bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult)4 CreateCloudContextRequest (bio.terra.workspace.model.CreateCloudContextRequest)3 CreateCloudContextResult (bio.terra.workspace.model.CreateCloudContextResult)3 DeleteControlledGcpGcsBucketRequest (bio.terra.workspace.model.DeleteControlledGcpGcsBucketRequest)3 DeleteControlledGcpGcsBucketResult (bio.terra.workspace.model.DeleteControlledGcpGcsBucketResult)3 CreateControlledGcpAiNotebookInstanceRequestBody (bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody)2 DeleteControlledGcpAiNotebookInstanceResult (bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceResult)2 ResourceMetadata (bio.terra.workspace.model.ResourceMetadata)2 UUID (java.util.UUID)2 UserActionableException (bio.terra.cli.exception.UserActionableException)1 JobsApi (bio.terra.workspace.api.JobsApi)1 ResourceApi (bio.terra.workspace.api.ResourceApi)1 WorkspaceApi (bio.terra.workspace.api.WorkspaceApi)1 ApiException (bio.terra.workspace.client.ApiException)1 CloneControlledGcpBigQueryDatasetRequest (bio.terra.workspace.model.CloneControlledGcpBigQueryDatasetRequest)1 CloneControlledGcpBigQueryDatasetResult (bio.terra.workspace.model.CloneControlledGcpBigQueryDatasetResult)1 CloneControlledGcpGcsBucketRequest (bio.terra.workspace.model.CloneControlledGcpGcsBucketRequest)1