Search in sources :

Example 1 with GcsStorageClass

use of bio.terra.cli.serialization.userfacing.input.GcsStorageClass in project terra-cli by DataBiosphere.

the class GcsBucketControlled method updateMultipleProperties.

@Test
@DisplayName("update a controlled bucket, specifying multiple properties, except for lifecycle")
void updateMultipleProperties() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create gcs-bucket --name=$name --description=$description
    // --bucket-name=$bucketName`
    String name = "updateMultipleProperties";
    String description = "updateDescription";
    String bucketName = UUID.randomUUID().toString();
    TestCommand.runCommandExpectSuccess("resource", "create", "gcs-bucket", "--name=" + name, "--description=" + description, "--bucket-name=" + bucketName);
    // update the name, description, and storage class
    // `terra resources update gcs-bucket --name=$newName --new-name=$newName
    // --description=$newDescription --storage=$newStorage`
    String newName = "updateMultipleProperties_NEW";
    String newDescription = "updateDescription_NEW";
    GcsStorageClass newStorage = GcsStorageClass.NEARLINE;
    UFGcsBucket updateBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "update", "gcs-bucket", "--name=" + name, "--new-name=" + newName, "--description=" + newDescription, "--storage=" + newStorage);
    assertEquals(newName, updateBucket.name);
    assertEquals(newDescription, updateBucket.description);
    // `terra resources describe --name=$newName`
    UFGcsBucket describeBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "describe", "--name=" + newName);
    assertEquals(newDescription, describeBucket.description);
    // check the storage class from GCS directly
    Bucket bucketOnCloud = ExternalGCSBuckets.getStorageClient(workspaceCreator.getCredentialsWithCloudPlatformScope()).get(bucketName);
    assertNotNull(bucketOnCloud, "looking up bucket via GCS API succeeded");
    assertEquals(newStorage.toString(), bucketOnCloud.getStorageClass().toString(), "bucket storage class matches update input");
}
Also used : GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) Bucket(com.google.cloud.storage.Bucket) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with GcsStorageClass

use of bio.terra.cli.serialization.userfacing.input.GcsStorageClass in project terra-cli by DataBiosphere.

the class GcsBucketControlled method createWithAllOptionsExceptLifecycle.

@Test
@DisplayName("create a controlled bucket, specifying all options except lifecycle")
void createWithAllOptionsExceptLifecycle() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create gcs-bucket --name=$name --bucket-name=$bucketName --access=$access
    // --cloning=$cloning --description=$description --location=$location --storage=$storage
    // --format=json`
    String name = "createWithAllOptionsExceptLifecycle";
    String bucketName = UUID.randomUUID().toString();
    AccessScope access = AccessScope.PRIVATE_ACCESS;
    CloningInstructionsEnum cloning = CloningInstructionsEnum.REFERENCE;
    String description = "\"create with all options except lifecycle\"";
    String location = "US";
    GcsStorageClass storage = GcsStorageClass.NEARLINE;
    UFGcsBucket createdBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "create", "gcs-bucket", "--name=" + name, "--bucket-name=" + bucketName, "--access=" + access, "--cloning=" + cloning, "--description=" + description, "--location=" + location, "--storage=" + storage);
    // check that the properties match
    assertEquals(name, createdBucket.name, "create output matches name");
    assertEquals(bucketName, createdBucket.bucketName, "create output matches bucket name");
    assertEquals(access, createdBucket.accessScope, "create output matches access");
    assertEquals(cloning, createdBucket.cloningInstructions, "create output matches cloning");
    assertEquals(description, createdBucket.description, "create output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), createdBucket.privateUserName.toLowerCase(), "create output matches private user name");
    Bucket createdBucketOnCloud = ExternalGCSBuckets.getStorageClient(workspaceCreator.getCredentialsWithCloudPlatformScope()).get(bucketName);
    assertNotNull(createdBucketOnCloud, "looking up bucket via GCS API succeeded");
    assertEquals(location, createdBucketOnCloud.getLocation(), "bucket location matches create input");
    assertEquals(storage.toString(), createdBucketOnCloud.getStorageClass().toString(), "bucket storage class matches create input");
    // `terra resources describe --name=$name --format=json`
    UFGcsBucket describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "describe", "--name=" + name);
    // check that the properties match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(bucketName, describeResource.bucketName, "describe resource output matches bucket name");
    assertEquals(access, describeResource.accessScope, "describe output matches access");
    assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
    assertEquals(description, describeResource.description, "describe output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), describeResource.privateUserName.toLowerCase(), "describe output matches private user name");
    // `terra resources delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : CloningInstructionsEnum(bio.terra.workspace.model.CloningInstructionsEnum) GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) Bucket(com.google.cloud.storage.Bucket) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) AccessScope(bio.terra.workspace.model.AccessScope) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with GcsStorageClass

use of bio.terra.cli.serialization.userfacing.input.GcsStorageClass in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method fromCLIObject.

/**
 * This method converts this CLI-defined POJO class into a list of WSM client library-defined
 * request objects.
 *
 * @return list of lifecycle rules in the format expected by the WSM client library
 */
private static List<GcpGcsBucketLifecycleRule> fromCLIObject(GcsBucketLifecycle lifecycle) {
    List<GcpGcsBucketLifecycleRule> wsmLifecycleRules = new ArrayList<>();
    for (GcsBucketLifecycle.Rule rule : lifecycle.rule) {
        GcpGcsBucketLifecycleRuleAction action = new GcpGcsBucketLifecycleRuleAction().type(rule.action.type.toWSMEnum());
        if (rule.action.storageClass != null) {
            action.storageClass(rule.action.storageClass.toWSMEnum());
        }
        GcpGcsBucketLifecycleRuleCondition condition = new GcpGcsBucketLifecycleRuleCondition().age(rule.condition.age).createdBefore(dateAtMidnightAndUTC(rule.condition.createdBefore)).customTimeBefore(dateAtMidnightAndUTC(rule.condition.customTimeBefore)).daysSinceCustomTime(rule.condition.daysSinceCustomTime).daysSinceNoncurrentTime(rule.condition.daysSinceNoncurrentTime).live(rule.condition.isLive).matchesStorageClass(rule.condition.matchesStorageClass.stream().map(GcsStorageClass::toWSMEnum).collect(Collectors.toList())).noncurrentTimeBefore(dateAtMidnightAndUTC(rule.condition.noncurrentTimeBefore)).numNewerVersions(rule.condition.numNewerVersions);
        GcpGcsBucketLifecycleRule lifecycleRuleRequestObject = new GcpGcsBucketLifecycleRule().action(action).condition(condition);
        wsmLifecycleRules.add(lifecycleRuleRequestObject);
    }
    return wsmLifecycleRules;
}
Also used : GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) GcpGcsBucketLifecycleRuleCondition(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleCondition) GcpGcsBucketLifecycleRuleAction(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleAction) GcpGcsBucketLifecycleRule(bio.terra.workspace.model.GcpGcsBucketLifecycleRule) ArrayList(java.util.ArrayList) GcsBucketLifecycle(bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle)

Example 4 with GcsStorageClass

use of bio.terra.cli.serialization.userfacing.input.GcsStorageClass in project terra-cli by DataBiosphere.

the class GcsBucketControlled method updateIndividualProperties.

@Test
@DisplayName("update a controlled bucket, one property at a time, except for lifecycle")
void updateIndividualProperties() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create gcs-bucket --name=$name --description=$description
    // --bucket-name=$bucketName`
    String name = "updateIndividualProperties";
    String description = "updateDescription";
    String bucketName = UUID.randomUUID().toString();
    TestCommand.runCommandExpectSuccess("resource", "create", "gcs-bucket", "--name=" + name, "--description=" + description, "--bucket-name=" + bucketName);
    // update just the name
    // `terra resources update gcs-bucket --name=$name --new-name=$newName`
    String newName = "updateIndividualProperties_NEW";
    UFGcsBucket updateBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "update", "gcs-bucket", "--name=" + name, "--new-name=" + newName);
    assertEquals(newName, updateBucket.name);
    assertEquals(description, updateBucket.description);
    // `terra resources describe --name=$newName`
    UFGcsBucket describeBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "describe", "--name=" + newName);
    assertEquals(description, describeBucket.description);
    // update just the description
    // `terra resources update gcs-bucket --name=$newName --description=$newDescription`
    String newDescription = "updateDescription_NEW";
    updateBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "update", "gcs-bucket", "--name=" + newName, "--description=" + newDescription);
    assertEquals(newName, updateBucket.name);
    assertEquals(newDescription, updateBucket.description);
    // `terra resources describe --name=$newName`
    describeBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "describe", "--name=" + newName);
    assertEquals(newDescription, describeBucket.description);
    // update just the storage class
    // `terra resources update gcs-bucket --name=$newName --storageClass
    GcsStorageClass newStorage = GcsStorageClass.ARCHIVE;
    TestCommand.runCommandExpectSuccess("resource", "update", "gcs-bucket", "--name=" + newName, "--storage=" + newStorage);
    // check the updated storage class from GCS directly
    Bucket bucketOnCloud = ExternalGCSBuckets.getStorageClient(workspaceCreator.getCredentialsWithCloudPlatformScope()).get(bucketName);
    assertNotNull(bucketOnCloud, "looking up bucket via GCS API succeeded");
    assertEquals(newStorage.toString(), bucketOnCloud.getStorageClass().toString(), "bucket storage class matches update input");
}
Also used : GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) Bucket(com.google.cloud.storage.Bucket) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

GcsStorageClass (bio.terra.cli.serialization.userfacing.input.GcsStorageClass)4 UFGcsBucket (bio.terra.cli.serialization.userfacing.resource.UFGcsBucket)3 Bucket (com.google.cloud.storage.Bucket)3 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 GcsBucketLifecycle (bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle)1 AccessScope (bio.terra.workspace.model.AccessScope)1 CloningInstructionsEnum (bio.terra.workspace.model.CloningInstructionsEnum)1 GcpGcsBucketLifecycle (bio.terra.workspace.model.GcpGcsBucketLifecycle)1 GcpGcsBucketLifecycleRule (bio.terra.workspace.model.GcpGcsBucketLifecycleRule)1 GcpGcsBucketLifecycleRuleAction (bio.terra.workspace.model.GcpGcsBucketLifecycleRuleAction)1 GcpGcsBucketLifecycleRuleCondition (bio.terra.workspace.model.GcpGcsBucketLifecycleRuleCondition)1 ArrayList (java.util.ArrayList)1