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