Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) {
return this;
}

@Override
Builder setLocationType(String locationType) {
infoBuilder.setLocationType(locationType);
return this;
}

@Override
public Bucket build() {
return new Bucket(storage, infoBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -848,6 +849,8 @@ public abstract static class Builder {

abstract Builder setMetageneration(Long metageneration);

abstract Builder setLocationType(String locationType);

/**
* Sets the bucket's Cross-Origin Resource Sharing (CORS) configuration.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -969,6 +973,7 @@ static final class BuilderImpl extends Builder {
retentionPolicyIsLocked = bucketInfo.retentionPolicyIsLocked;
retentionPeriod = bucketInfo.retentionPeriod;
iamConfiguration = bucketInfo.iamConfiguration;
locationType = bucketInfo.locationType;
}

@Override
Expand Down Expand Up @@ -1127,6 +1132,12 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) {
return this;
}

@Override
Builder setLocationType(String locationType) {
this.locationType = locationType;
return this;
}

@Override
public BucketInfo build() {
checkNotNull(name);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -1283,6 +1295,15 @@ public String getLocation() {
return location;
}

/**
* Returns the bucket's locationType.
*
* @see <a href="https://cloud.google.com/storage/docs/bucket-locations">Bucket LocationType</a>
*/
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.
Expand Down Expand Up @@ -1442,6 +1463,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());
}
Expand Down Expand Up @@ -1666,6 +1690,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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> LOCATION_TYPES =
ImmutableList.of("multi-region", "region", "dual-region");

@BeforeClass
public static void beforeClass() throws IOException {
Expand Down Expand Up @@ -2584,4 +2586,39 @@ public void testUploadUsingSignedURL() throws Exception {
assertEquals(bytesArrayToUpload.length, lengthOfDownLoadBytes);
assertTrue(storage.delete(BUCKET, blobName));
}

@Test
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(
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<Bucket> 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);
}
}