use of bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleCondition in project terra-workspace-manager by DataBiosphere.
the class GcsApiConversionsTest method testLifecycleConditionConversions.
@Test
public void testLifecycleConditionConversions() {
LifecycleCondition googleLifecycleCondition1 = toGcsApi(WSM_LIFECYCLE_RULE_CONDITION_1);
assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getAge(), googleLifecycleCondition1.getAge());
assertEquals(toGoogleDateTimeDateOnly(WSM_LIFECYCLE_RULE_CONDITION_1.getCreatedBefore()), googleLifecycleCondition1.getCreatedBefore());
ApiGcpGcsBucketLifecycleRuleCondition roundTrippedCondition = toWsmApi(googleLifecycleCondition1);
// We can't compare the round-tripped condition with the original for equality, because the
// conversion
// to Google DateTime with dateOnly=true is lossy.
assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getAge(), roundTrippedCondition.getAge());
assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getDaysSinceCustomTime(), roundTrippedCondition.getDaysSinceCustomTime());
assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getDaysSinceNoncurrentTime(), roundTrippedCondition.getDaysSinceNoncurrentTime());
assertThat(WSM_LIFECYCLE_RULE_CONDITION_1.getMatchesStorageClass(), containsInAnyOrder(roundTrippedCondition.getMatchesStorageClass().toArray()));
assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getCustomTimeBefore(), roundTrippedCondition.getCustomTimeBefore());
assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getNumNewerVersions(), roundTrippedCondition.getNumNewerVersions());
ApiGcpGcsBucketLifecycleRuleCondition wsmCondition = toWsmApi(GCS_LIFECYCLE_CONDITION_1);
assertEquals(42, wsmCondition.getAge());
assertNull(wsmCondition.getMatchesStorageClass());
assertFalse(wsmCondition.isLive());
assertEquals(2, wsmCondition.getNumNewerVersions());
}
use of bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleCondition in project terra-workspace-manager by DataBiosphere.
the class WorkspaceServiceTest method cloneGcpWorkspace.
@Test
public void cloneGcpWorkspace() {
// Create a workspace
final Workspace sourceWorkspace = defaultRequestBuilder(UUID.randomUUID()).userFacingId("source-user-facing-id").displayName("Source Workspace").description("The original workspace.").spendProfileId(new SpendProfileId(SPEND_PROFILE_ID)).build();
final UUID sourceWorkspaceId = workspaceService.createWorkspace(sourceWorkspace, USER_REQUEST);
// create a cloud context
final String createCloudContextJobId = UUID.randomUUID().toString();
workspaceService.createGcpCloudContext(sourceWorkspaceId, createCloudContextJobId, USER_REQUEST);
jobService.waitForJob(createCloudContextJobId);
assertNull(jobService.retrieveJobResult(createCloudContextJobId, Object.class, USER_REQUEST).getException());
// add a bucket resource
final ControlledGcsBucketResource bucketResource = ControlledGcsBucketResource.builder().bucketName("terra-test-" + UUID.randomUUID().toString().toLowerCase()).common(ControlledResourceFields.builder().name("bucket_1").description("Just a plain bucket.").cloningInstructions(CloningInstructions.COPY_RESOURCE).resourceId(UUID.randomUUID()).workspaceUuid(sourceWorkspaceId).managedBy(ManagedByType.MANAGED_BY_USER).privateResourceState(PrivateResourceState.INITIALIZING).accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE).applicationId(null).iamRole(ControlledResourceIamRole.OWNER).assignedUser(USER_REQUEST.getEmail()).build()).build();
final ApiGcpGcsBucketCreationParameters creationParameters = new ApiGcpGcsBucketCreationParameters().name("foo").defaultStorageClass(ApiGcpGcsBucketDefaultStorageClass.NEARLINE).lifecycle(new ApiGcpGcsBucketLifecycle().addRulesItem(new ApiGcpGcsBucketLifecycleRule().condition(new ApiGcpGcsBucketLifecycleRuleCondition().age(90)).action(new ApiGcpGcsBucketLifecycleRuleAction().type(ApiGcpGcsBucketLifecycleRuleActionType.SET_STORAGE_CLASS).storageClass(ApiGcpGcsBucketDefaultStorageClass.STANDARD))));
final ControlledResource createdResource = controlledResourceService.createControlledResourceSync(bucketResource, ControlledResourceIamRole.OWNER, USER_REQUEST, creationParameters);
final ControlledGcsBucketResource createdBucketResource = createdResource.castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
final Workspace destinationWorkspace = defaultRequestBuilder(UUID.randomUUID()).userFacingId("dest-user-facing-id").displayName("Destination Workspace").description("Copied from source").spendProfileId(new SpendProfileId(SPEND_PROFILE_ID)).build();
final String destinationLocation = "us-east1";
final String cloneJobId = workspaceService.cloneWorkspace(sourceWorkspaceId, USER_REQUEST, destinationLocation, destinationWorkspace);
jobService.waitForJob(cloneJobId);
final JobResultOrException<ApiClonedWorkspace> cloneResultOrException = jobService.retrieveJobResult(cloneJobId, ApiClonedWorkspace.class, USER_REQUEST);
assertNull(cloneResultOrException.getException());
final ApiClonedWorkspace cloneResult = cloneResultOrException.getResult();
assertEquals(destinationWorkspace.getWorkspaceId(), cloneResult.getDestinationWorkspaceId());
assertThat(cloneResult.getResources(), hasSize(1));
final ApiResourceCloneDetails bucketCloneDetails = cloneResult.getResources().get(0);
assertEquals(ApiCloneResourceResult.SUCCEEDED, bucketCloneDetails.getResult());
assertNull(bucketCloneDetails.getErrorMessage());
assertEquals(ApiResourceType.GCS_BUCKET, bucketCloneDetails.getResourceType());
assertEquals(createdBucketResource.getResourceId(), bucketCloneDetails.getSourceResourceId());
// destination WS should exist
final Workspace retrievedDestinationWorkspace = workspaceService.getWorkspace(destinationWorkspace.getWorkspaceId(), USER_REQUEST);
assertEquals("Destination Workspace", retrievedDestinationWorkspace.getDisplayName().orElseThrow());
assertEquals("Copied from source", retrievedDestinationWorkspace.getDescription().orElseThrow());
assertEquals(WorkspaceStage.MC_WORKSPACE, retrievedDestinationWorkspace.getWorkspaceStage());
// Destination Workspace should have a GCP context
assertNotNull(gcpCloudContextService.getGcpCloudContext(destinationWorkspace.getWorkspaceId()).orElseThrow());
// clean up
workspaceService.deleteWorkspace(sourceWorkspaceId, USER_REQUEST);
workspaceService.deleteWorkspace(destinationWorkspace.getWorkspaceId(), USER_REQUEST);
}
Aggregations