Search in sources :

Example 1 with ApiGcpGcsBucketLifecycleRule

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

the class GcsApiConversionsTest method testLifecycleRuleConversions.

@Test
public void testLifecycleRuleConversions() {
    final ApiGcpGcsBucketLifecycleRule wsmRule1 = toWsmApi(GCS_LIFECYCLE_RULE_1);
    assertEquals(ApiGcpGcsBucketLifecycleRuleActionType.DELETE, wsmRule1.getAction().getType());
    assertNull(wsmRule1.getAction().getStorageClass());
    assertEquals(42, wsmRule1.getCondition().getAge());
    assertFalse(wsmRule1.getCondition().isLive());
    assertEquals(2, wsmRule1.getCondition().getNumNewerVersions());
    // not empty list
    assertNull(wsmRule1.getCondition().getMatchesStorageClass());
    final LifecycleRule gcsRule1 = toGcsApi(wsmRule1);
    // Direct equality comparison with LifecycleAction and LifecycleCondition
    // types doesn't work for some reason. Hence, comparing fields.
    assertEquals(GCS_LIFECYCLE_RULE_1.getAction().getActionType(), gcsRule1.getAction().getActionType());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getAge(), gcsRule1.getCondition().getAge());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getCreatedBefore(), gcsRule1.getCondition().getCreatedBefore());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getMatchesStorageClass(), gcsRule1.getCondition().getMatchesStorageClass());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getNumberOfNewerVersions(), gcsRule1.getCondition().getNumberOfNewerVersions());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getIsLive(), gcsRule1.getCondition().getIsLive());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getDaysSinceNoncurrentTime(), gcsRule1.getCondition().getDaysSinceNoncurrentTime());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getNoncurrentTimeBefore(), gcsRule1.getCondition().getNoncurrentTimeBefore());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getCustomTimeBefore(), gcsRule1.getCondition().getCustomTimeBefore());
    assertEquals(GCS_LIFECYCLE_RULE_1.getCondition().getDaysSinceCustomTime(), gcsRule1.getCondition().getDaysSinceCustomTime());
}
Also used : ApiGcpGcsBucketLifecycleRule(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) ApiGcpGcsBucketLifecycleRule(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with ApiGcpGcsBucketLifecycleRule

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

the class GcsApiConversionsTest method testToUpdateParameters.

@Test
public void testToUpdateParameters() {
    final ApiGcpGcsBucketUpdateParameters updateParameters1 = toUpdateParameters(GCS_BUCKET_INFO_1);
    assertEquals(ApiGcpGcsBucketDefaultStorageClass.STANDARD, updateParameters1.getDefaultStorageClass());
    final ApiGcpGcsBucketLifecycle wsmLifecycle = updateParameters1.getLifecycle();
    assertThat(wsmLifecycle.getRules(), hasSize(2));
    final ApiGcpGcsBucketLifecycleRule rule1 = wsmLifecycle.getRules().get(0);
    assertEquals(ApiGcpGcsBucketLifecycleRuleActionType.DELETE, rule1.getAction().getType());
    assertNull(rule1.getAction().getStorageClass());
    final ApiGcpGcsBucketLifecycleRule rule2 = wsmLifecycle.getRules().get(1);
    assertEquals(ApiGcpGcsBucketLifecycleRuleActionType.SET_STORAGE_CLASS, rule2.getAction().getType());
    assertEquals(ApiGcpGcsBucketDefaultStorageClass.STANDARD, rule2.getAction().getStorageClass());
}
Also used : ApiGcpGcsBucketLifecycleRule(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule) ApiGcpGcsBucketLifecycle(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycle) ApiGcpGcsBucketUpdateParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with ApiGcpGcsBucketLifecycleRule

use of bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule 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);
}
Also used : ApiResourceCloneDetails(bio.terra.workspace.generated.model.ApiResourceCloneDetails) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) ApiGcpGcsBucketLifecycleRule(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule) ApiGcpGcsBucketLifecycleRuleCondition(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleCondition) ApiGcpGcsBucketLifecycleRuleAction(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleAction) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) ApiGcpGcsBucketLifecycle(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycle) UUID(java.util.UUID) ApiGcpGcsBucketCreationParameters(bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Aggregations

ApiGcpGcsBucketLifecycleRule (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule)3 Test (org.junit.jupiter.api.Test)3 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)2 ApiGcpGcsBucketLifecycle (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycle)2 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)1 ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)1 ApiGcpGcsBucketLifecycleRuleAction (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleAction)1 ApiGcpGcsBucketLifecycleRuleCondition (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleCondition)1 ApiGcpGcsBucketUpdateParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketUpdateParameters)1 ApiResourceCloneDetails (bio.terra.workspace.generated.model.ApiResourceCloneDetails)1 ControlledGcsBucketResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)1 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)1 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)1 Workspace (bio.terra.workspace.service.workspace.model.Workspace)1 LifecycleRule (com.google.cloud.storage.BucketInfo.LifecycleRule)1 UUID (java.util.UUID)1