From 7e6a280b22725cffabe61d8f6b570e404fbd3c77 Mon Sep 17 00:00:00 2001 From: abhinav Date: Tue, 9 Jul 2019 18:03:36 +0530 Subject: [PATCH 1/5] locationType field is added in Bucket --- .../java/com/google/cloud/storage/Bucket.java | 6 ++++ .../com/google/cloud/storage/BucketInfo.java | 30 +++++++++++++++++++ .../google/cloud/storage/BucketInfoTest.java | 5 ++++ .../com/google/cloud/storage/BucketTest.java | 5 ++++ 4 files changed, 46 insertions(+) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java index 30f9ce61f1fc..cbe94c631f5f 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java @@ -661,6 +661,12 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) { return this; } + @Override + public Builder setLocationType(String locationType) { + infoBuilder.setLocationType(locationType); + return this; + } + @Override public Bucket build() { return new Bucket(storage, infoBuilder); diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index c8d1d07a274b..82eab0540077 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -96,6 +96,7 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo) private final Boolean retentionPolicyIsLocked; private final Long retentionPeriod; private final IamConfiguration iamConfiguration; + private final String locationType; /** * The Bucket's IAM Configuration. @@ -848,6 +849,8 @@ public abstract static class Builder { abstract Builder setMetageneration(Long metageneration); + abstract Builder setLocationType(String location); + /** * Sets the bucket's Cross-Origin Resource Sharing (CORS) configuration. * @@ -938,6 +941,7 @@ static final class BuilderImpl extends Builder { private Boolean retentionPolicyIsLocked; private Long retentionPeriod; private IamConfiguration iamConfiguration; + private String locationType; BuilderImpl(String name) { this.name = name; @@ -969,6 +973,7 @@ static final class BuilderImpl extends Builder { retentionPolicyIsLocked = bucketInfo.retentionPolicyIsLocked; retentionPeriod = bucketInfo.retentionPeriod; iamConfiguration = bucketInfo.iamConfiguration; + locationType = bucketInfo.locationType; } @Override @@ -1127,6 +1132,12 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) { return this; } + @Override + public Builder setLocationType(String locationType) { + this.locationType = locationType; + return this; + } + @Override public BucketInfo build() { checkNotNull(name); @@ -1160,6 +1171,7 @@ public BucketInfo build() { retentionPolicyIsLocked = builder.retentionPolicyIsLocked; retentionPeriod = builder.retentionPeriod; iamConfiguration = builder.iamConfiguration; + locationType = builder.locationType; } /** Returns the service-generated id for the bucket. */ @@ -1283,6 +1295,16 @@ public String getLocation() { return location; } + /** + * Returns the bucket's locationType. Data for blobs in the bucket resides in physical storage + * within this region. + * + * @see Bucket locationType + */ + public String getLocationType() { + return locationType; + } + /** * Returns the bucket's storage class. This defines how blobs in the bucket are stored and * determines the SLA and the cost of storage. @@ -1442,6 +1464,9 @@ com.google.api.services.storage.model.Bucket toPb() { if (location != null) { bucketPb.setLocation(location); } + if (locationType != null) { + bucketPb.setLocationType(locationType); + } if (storageClass != null) { bucketPb.setStorageClass(storageClass.toString()); } @@ -1666,6 +1691,11 @@ public DeleteRule apply(Rule rule) { } } Bucket.IamConfiguration iamConfiguration = bucketPb.getIamConfiguration(); + + if (bucketPb.getLocationType() != null) { + builder.setLocationType(bucketPb.getLocationType()); + } + if (iamConfiguration != null) { builder.setIamConfiguration(IamConfiguration.fromPb(iamConfiguration)); } diff --git a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java index 919afeb0adea..857da2b4ba9f 100644 --- a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java +++ b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java @@ -83,6 +83,9 @@ public class BucketInfoTest { private static final Long RETENTION_EFFECTIVE_TIME = 10L; private static final Long RETENTION_PERIOD = 10L; private static final Boolean RETENTION_POLICY_IS_LOCKED = false; + private static final List LOCATION_TYPES = + ImmutableList.of("multi-region", "region", "dual-region"); + private static final String LOCATION_TYPE = "multi-region"; private static final BucketInfo BUCKET_INFO = BucketInfo.newBuilder("b") .setAcl(ACL) @@ -100,6 +103,7 @@ public class BucketInfoTest { .setIamConfiguration(IAM_CONFIGURATION) .setNotFoundPage(NOT_FOUND_PAGE) .setLocation(LOCATION) + .setLocationType(LOCATION_TYPE) .setStorageClass(STORAGE_CLASS) .setVersioningEnabled(VERSIONING_ENABLED) .setLabels(BUCKET_LABELS) @@ -159,6 +163,7 @@ public void testBuilder() { assertEquals(RETENTION_EFFECTIVE_TIME, BUCKET_INFO.getRetentionEffectiveTime()); assertEquals(RETENTION_PERIOD, BUCKET_INFO.getRetentionPeriod()); assertEquals(RETENTION_POLICY_IS_LOCKED, BUCKET_INFO.retentionPolicyIsLocked()); + assertTrue(LOCATION_TYPES.contains(BUCKET_INFO.getLocationType())); } @Test diff --git a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java index 6bbc67b4adfa..9923c6107f24 100644 --- a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java +++ b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java @@ -92,6 +92,9 @@ public class BucketTest { private static final Long RETENTION_EFFECTIVE_TIME = 10L; private static final Long RETENTION_PERIOD = 10L; private static final Boolean RETENTION_POLICY_IS_LOCKED = false; + private static final List LOCATION_TYPES = + ImmutableList.of("multi-region", "region", "dual-region"); + private static final String LOCATION_TYPE = "multi-region"; private static final BucketInfo FULL_BUCKET_INFO = BucketInfo.newBuilder("b") .setAcl(ACLS) @@ -786,6 +789,7 @@ public void testBuilder() { .setIndexPage(INDEX_PAGE) .setNotFoundPage(NOT_FOUND_PAGE) .setLocation(LOCATION) + .setLocationType(LOCATION_TYPE) .setStorageClass(STORAGE_CLASS) .setVersioningEnabled(VERSIONING_ENABLED) .setLabels(BUCKET_LABELS) @@ -821,5 +825,6 @@ public void testBuilder() { assertEquals(RETENTION_PERIOD, bucket.getRetentionPeriod()); assertEquals(RETENTION_POLICY_IS_LOCKED, bucket.retentionPolicyIsLocked()); assertEquals(storage.getOptions(), bucket.getStorage().getOptions()); + assertTrue(LOCATION_TYPES.contains(LOCATION_TYPE)); } } From 1e2254791f44acaae397acec06483b590379c686 Mon Sep 17 00:00:00 2001 From: abhinav Date: Tue, 9 Jul 2019 18:18:23 +0530 Subject: [PATCH 2/5] method comment changes --- .../src/main/java/com/google/cloud/storage/BucketInfo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index 82eab0540077..080f4ae06ade 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -1296,8 +1296,7 @@ public String getLocation() { } /** - * Returns the bucket's locationType. Data for blobs in the bucket resides in physical storage - * within this region. + * Returns the bucket's locationType. * * @see Bucket locationType */ From 6ee931821945ef6fd0fcee8ec63259d733262414 Mon Sep 17 00:00:00 2001 From: abhinav Date: Tue, 9 Jul 2019 20:11:56 +0530 Subject: [PATCH 3/5] method argument changes and IT test case added --- .../java/com/google/cloud/storage/BucketInfo.java | 4 ++-- .../com/google/cloud/storage/it/ITStorageTest.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index 080f4ae06ade..a65e3f38541f 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -849,7 +849,7 @@ public abstract static class Builder { abstract Builder setMetageneration(Long metageneration); - abstract Builder setLocationType(String location); + abstract Builder setLocationType(String locationType); /** * Sets the bucket's Cross-Origin Resource Sharing (CORS) configuration. @@ -1298,7 +1298,7 @@ public String getLocation() { /** * Returns the bucket's locationType. * - * @see Bucket locationType + * @see Bucket LocationType */ public String getLocationType() { return locationType; diff --git a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java index 8b2d627b23db..2f4789a6043d 100644 --- a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java +++ b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java @@ -156,6 +156,8 @@ public class ITStorageTest { private static final boolean IS_VPC_TEST = System.getenv("GOOGLE_CLOUD_TESTS_IN_VPCSC") != null && System.getenv("GOOGLE_CLOUD_TESTS_IN_VPCSC").equalsIgnoreCase("true"); + private static final List LOCATION_TYPES = + ImmutableList.of("multi-region", "region", "dual-region"); @BeforeClass public static void beforeClass() throws IOException { @@ -2584,4 +2586,13 @@ public void testUploadUsingSignedURL() throws Exception { assertEquals(bytesArrayToUpload.length, lengthOfDownLoadBytes); assertTrue(storage.delete(BUCKET, blobName)); } + + @Test + public void testbucketLocationType() { + Storage storage = StorageOptions.getDefaultInstance().getService(); + long bucketMetageneration = 42; + Bucket bucket = + storage.get(BUCKET, Storage.BucketGetOption.metagenerationNotMatch(bucketMetageneration)); + assertTrue(LOCATION_TYPES.contains(bucket.getLocationType())); + } } From 5ebd475f549c974ad29316147e66677ef34f3fcf Mon Sep 17 00:00:00 2001 From: abhinav Date: Wed, 10 Jul 2019 15:40:32 +0530 Subject: [PATCH 4/5] change in integration test case testBucketLocationType --- .../cloud/storage/it/ITStorageTest.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java index 2f4789a6043d..7c3c3e942c5a 100644 --- a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java +++ b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java @@ -2588,11 +2588,37 @@ public void testUploadUsingSignedURL() throws Exception { } @Test - public void testbucketLocationType() { - Storage storage = StorageOptions.getDefaultInstance().getService(); + public void testBucketLocationType() throws ExecutionException, InterruptedException { + String bucketName = RemoteStorageHelper.generateBucketName(); long bucketMetageneration = 42; + storage.create( + BucketInfo.newBuilder(bucketName) + .setLocation("us") + .setRetentionPeriod(RETENTION_PERIOD) + .build()); Bucket bucket = - storage.get(BUCKET, Storage.BucketGetOption.metagenerationNotMatch(bucketMetageneration)); + storage.get( + bucketName, Storage.BucketGetOption.metagenerationNotMatch(bucketMetageneration)); assertTrue(LOCATION_TYPES.contains(bucket.getLocationType())); + + Bucket bucket1 = + storage.lockRetentionPolicy(bucket, Storage.BucketTargetOption.metagenerationMatch()); + assertTrue(LOCATION_TYPES.contains(bucket1.getLocationType())); + + Bucket updatedBucket = + storage.update( + BucketInfo.newBuilder(bucketName) + .setLocation("asia") + .setRetentionPeriod(RETENTION_PERIOD) + .build()); + assertTrue(LOCATION_TYPES.contains(updatedBucket.getLocationType())); + + Iterator bucketIterator = + storage.list(Storage.BucketListOption.prefix(bucketName)).iterateAll().iterator(); + while (bucketIterator.hasNext()) { + Bucket remoteBucket = bucketIterator.next(); + assertTrue(LOCATION_TYPES.contains(remoteBucket.getLocationType())); + } + RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS); } } From 50c2d2128e31d2e8fe8f49552d0f3b44dca3aed0 Mon Sep 17 00:00:00 2001 From: abhinav Date: Mon, 15 Jul 2019 19:15:18 +0530 Subject: [PATCH 5/5] setLocationType method changes --- .../src/main/java/com/google/cloud/storage/Bucket.java | 2 +- .../src/main/java/com/google/cloud/storage/BucketInfo.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java index cbe94c631f5f..4ec54435aba6 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java @@ -662,7 +662,7 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) { } @Override - public Builder setLocationType(String locationType) { + Builder setLocationType(String locationType) { infoBuilder.setLocationType(locationType); return this; } diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index a65e3f38541f..73ba7dc121ac 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -1133,7 +1133,7 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) { } @Override - public Builder setLocationType(String locationType) { + Builder setLocationType(String locationType) { this.locationType = locationType; return this; }