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());
}
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;
}
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());
}
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());
}
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());
}
Aggregations