Skip to content

Commit 78f2b43

Browse files
liyanzhang505huiguangjun
authored andcommitted
Add data redundancy type configuration to create bucket request.
1 parent e1aa322 commit 78f2b43

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,19 @@ public static final class CreateBucketRequestMarshaller implements RequestMarsha
198198
@Override
199199
public FixedLengthInputStream marshall(CreateBucketRequest request) {
200200
StringBuffer xmlBody = new StringBuffer();
201-
if (request.getLocationConstraint() != null || request.getStorageClass() != null) {
201+
if (request.getLocationConstraint() != null
202+
|| request.getStorageClass() != null
203+
|| request.getDataRedundancyType() != null) {
202204
xmlBody.append("<CreateBucketConfiguration>");
203205
if (request.getLocationConstraint() != null) {
204206
xmlBody.append("<LocationConstraint>" + request.getLocationConstraint() + "</LocationConstraint>");
205207
}
206208
if (request.getStorageClass() != null) {
207209
xmlBody.append("<StorageClass>" + request.getStorageClass().toString() + "</StorageClass>");
208210
}
211+
if (request.getDataRedundancyType() != null) {
212+
xmlBody.append("<DataRedundancyType>" + request.getDataRedundancyType().toString() + "</DataRedundancyType>");
213+
}
209214
xmlBody.append("</CreateBucketConfiguration>");
210215
}
211216
return stringMarshaller.marshall(xmlBody.toString());

src/main/java/com/aliyun/oss/model/CreateBucketRequest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class CreateBucketRequest extends GenericRequest {
2424
private String locationConstraint;
2525
private CannedAccessControlList cannedACL;
2626
private StorageClass storageClass;
27+
private DataRedundancyType dataRedundancyType;
2728

2829
public CreateBucketRequest(String bucketName) {
2930
super(bucketName);
@@ -86,4 +87,34 @@ public CreateBucketRequest withStorageType(StorageClass storageClass) {
8687
setStorageClass(storageClass);
8788
return this;
8889
}
90+
91+
/**
92+
* Sets the bucket's data redundancy type.
93+
* If the storage class has not been specified, the creating opreation maybe failed.
94+
*
95+
* @param dataRedundancyType
96+
* The Bucketdata redundancy type.
97+
*/
98+
public void setDataRedundancyType(DataRedundancyType dataRedundancyType) {
99+
this.dataRedundancyType = dataRedundancyType;
100+
}
101+
102+
/**
103+
* Creates the instance with data redundancy type.
104+
* If the storage class has not been specified, the creating opreation maybe failed.
105+
*
106+
* @param dataRedundancyType
107+
* The Bucketdata redundancy type.
108+
*/
109+
public CreateBucketRequest withDataRedundancyType(DataRedundancyType dataRedundancyType) {
110+
setDataRedundancyType(dataRedundancyType);
111+
return this;
112+
}
113+
114+
/**
115+
* Gets the bucket's data redundancy type.
116+
*/
117+
public DataRedundancyType getDataRedundancyType() {
118+
return dataRedundancyType;
119+
}
89120
}

src/test/java/com/aliyun/oss/integrationtests/CreateBucketTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
import com.aliyun.oss.OSSException;
4141
import com.aliyun.oss.model.AccessControlList;
4242
import com.aliyun.oss.model.Bucket;
43+
import com.aliyun.oss.model.BucketInfo;
4344
import com.aliyun.oss.model.BucketList;
4445
import com.aliyun.oss.model.CannedAccessControlList;
4546
import com.aliyun.oss.model.CreateBucketRequest;
47+
import com.aliyun.oss.model.DataRedundancyType;
4648
import com.aliyun.oss.model.Grant;
4749
import com.aliyun.oss.model.GroupGrantee;
4850
import com.aliyun.oss.model.Permission;
@@ -435,5 +437,35 @@ public void testPutWithStorageTypeCompatibility() {
435437
ossClient.deleteBucket(bucketName);
436438
}
437439
}
438-
440+
441+
@Test
442+
public void testPutWithDataRedundancyType() {
443+
final String bucketName = super.bucketName + "-with-data-redundancy-type";
444+
445+
try {
446+
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName)
447+
.withDataRedundancyType(DataRedundancyType.LRS).withStorageType(StorageClass.Standard);
448+
ossClient.createBucket(createBucketRequest);
449+
Thread.sleep(2000);
450+
BucketInfo bucketInfo = ossClient.getBucketInfo(bucketName);
451+
Assert.assertEquals(DataRedundancyType.LRS, bucketInfo.getDataRedundancyType());
452+
} catch (Exception e) {
453+
Assert.fail(e.getMessage());
454+
} finally {
455+
ossClient.deleteBucket(bucketName);
456+
}
457+
458+
try {
459+
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName)
460+
.withDataRedundancyType(DataRedundancyType.ZRS).withStorageType(StorageClass.Standard);
461+
ossClient.createBucket(createBucketRequest);
462+
Thread.sleep(2000);
463+
BucketInfo bucketInfo = ossClient.getBucketInfo(bucketName);
464+
Assert.assertEquals(DataRedundancyType.ZRS, bucketInfo.getDataRedundancyType());
465+
} catch (Exception e) {
466+
Assert.fail(e.getMessage());
467+
} finally {
468+
ossClient.deleteBucket(bucketName);
469+
}
470+
}
439471
}

0 commit comments

Comments
 (0)