Search in sources :

Example 1 with UFGcsBucket

use of bio.terra.cli.serialization.userfacing.resource.UFGcsBucket in project terra-cli by DataBiosphere.

the class GcsBucket method execute.

/**
 * Update a bucket in the workspace.
 */
@Override
protected void execute() {
    workspaceOption.overrideIfSpecified();
    // all update parameters are optional, but make sure at least one is specified
    if (!resourceUpdateOptions.isDefined() && !storageClassOption.isDefined() && !lifecycleOptions.isDefined() && newBucketName.getNewBucketName() == null) {
        throw new UserActionableException("Specify at least one property to update.");
    }
    // get the resource and make sure it's the right type
    bio.terra.cli.businessobject.resource.GcsBucket resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.GCS_BUCKET);
    if (resource.getStewardshipType().equals(StewardshipType.REFERENCED)) {
        // some options only apply to controlled resources
        if (storageClassOption.isDefined() || lifecycleOptions.isDefined()) {
            throw new UserActionableException("Storage and lifecycle options can only be updated for controlled resources.");
        }
        UpdateReferencedGcsBucketParams.Builder gcsBucketParams = new UpdateReferencedGcsBucketParams.Builder().resourceParams(resourceUpdateOptions.populateMetadataFields().build()).bucketName(newBucketName.getNewBucketName());
        resource.updateReferenced(gcsBucketParams.build());
    } else {
        resource.updateControlled(new UpdateControlledGcsBucketParams.Builder().resourceFields(resourceUpdateOptions.populateMetadataFields().build()).defaultStorageClass(storageClassOption.storageClass).lifecycle(lifecycleOptions.buildLifecycleObject()).build());
    }
    formatOption.printReturnValue(new UFGcsBucket(resource), GcsBucket::printText);
}
Also used : UpdateReferencedGcsBucketParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsBucketParams) UserActionableException(bio.terra.cli.exception.UserActionableException) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) UpdateControlledGcsBucketParams(bio.terra.cli.serialization.userfacing.input.UpdateControlledGcsBucketParams) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Example 2 with UFGcsBucket

use of bio.terra.cli.serialization.userfacing.resource.UFGcsBucket in project terra-cli by DataBiosphere.

the class GcsBucketReferenced method listDescribeReflectAdd.

@Test
@DisplayName("list and describe reflect adding a new referenced bucket")
void listDescribeReflectAdd() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource add-ref gcs-bucket --name=$name --bucket-name=$bucketName --format=json`
    String name = "listDescribeReflectAdd";
    UFGcsBucket addedBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "add-ref", "gcs-bucket", "--name=" + name, "--bucket-name=" + externalSharedBucket.getName());
    // check that the name and bucket name match
    assertEquals(name, addedBucket.name, "add ref output matches name");
    assertEquals(externalSharedBucket.getName(), addedBucket.bucketName, "add ref output matches bucket name");
    // check that the bucket is in the list
    UFGcsBucket matchedResource = listOneBucketResourceWithName(name);
    assertEquals(name, matchedResource.name, "list output matches name");
    assertEquals(externalSharedBucket.getName(), matchedResource.bucketName, "list output matches bucket name");
    // `terra resource describe --name=$name --format=json`
    UFGcsBucket describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "describe", "--name=" + name);
    // check that the name and bucket name match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(externalSharedBucket.getName(), describeResource.bucketName, "describe resource output matches bucket name");
    assertEquals(externalSharedBucket.getLocation(), describeResource.location, "describe resource location matches bucket location");
    assertEquals(0, describeResource.numObjects, "describe resource numObjects is zero");
    // `terra resource delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with UFGcsBucket

use of bio.terra.cli.serialization.userfacing.resource.UFGcsBucket in project terra-cli by DataBiosphere.

the class GcsBucketReferenced method addWithAllOptions.

@Test
@DisplayName("add a referenced bucket, specifying all options")
void addWithAllOptions() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources add-ref gcs-bucket --name=$name --bucket-name=$bucketName --cloning=$cloning
    // --description=$description --format=json`
    String name = "addWithAllOptionsExceptLifecycle";
    CloningInstructionsEnum cloning = CloningInstructionsEnum.REFERENCE;
    String description = "add with all options except lifecycle";
    UFGcsBucket addedBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "add-ref", "gcs-bucket", "--name=" + name, "--bucket-name=" + externalSharedBucket.getName(), "--cloning=" + cloning, "--description=" + description);
    // check that the properties match
    assertEquals(name, addedBucket.name, "add ref output matches name");
    assertEquals(externalSharedBucket.getName(), addedBucket.bucketName, "add ref output matches bucket name");
    assertEquals(cloning, addedBucket.cloningInstructions, "add ref output matches cloning");
    assertEquals(description, addedBucket.description, "add ref output matches description");
    // `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(externalSharedBucket.getName(), describeResource.bucketName, "describe resource output matches bucket name");
    assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
    assertEquals(description, describeResource.description, "describe output matches description");
    // `terra resources delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : CloningInstructionsEnum(bio.terra.workspace.model.CloningInstructionsEnum) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with UFGcsBucket

use of bio.terra.cli.serialization.userfacing.resource.UFGcsBucket 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 5 with UFGcsBucket

use of bio.terra.cli.serialization.userfacing.resource.UFGcsBucket 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)

Aggregations

UFGcsBucket (bio.terra.cli.serialization.userfacing.resource.UFGcsBucket)19 Test (org.junit.jupiter.api.Test)16 DisplayName (org.junit.jupiter.api.DisplayName)15 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)3 GcsStorageClass (bio.terra.cli.serialization.userfacing.input.GcsStorageClass)3 UFBqDataset (bio.terra.cli.serialization.userfacing.resource.UFBqDataset)3 Bucket (com.google.cloud.storage.Bucket)3 CreateGcsBucketParams (bio.terra.cli.serialization.userfacing.input.CreateGcsBucketParams)2 CreateResourceParams (bio.terra.cli.serialization.userfacing.input.CreateResourceParams)2 CloningInstructionsEnum (bio.terra.workspace.model.CloningInstructionsEnum)2 UserActionableException (bio.terra.cli.exception.UserActionableException)1 UFClonedResource (bio.terra.cli.serialization.userfacing.UFClonedResource)1 UFClonedWorkspace (bio.terra.cli.serialization.userfacing.UFClonedWorkspace)1 UFResource (bio.terra.cli.serialization.userfacing.UFResource)1 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)1 UpdateControlledGcsBucketParams (bio.terra.cli.serialization.userfacing.input.UpdateControlledGcsBucketParams)1 UpdateReferencedGcsBucketParams (bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsBucketParams)1 UFGitRepo (bio.terra.cli.serialization.userfacing.resource.UFGitRepo)1 AccessScope (bio.terra.workspace.model.AccessScope)1 TestUser (harness.TestUser)1