Skip to content

Commit 026a0e0

Browse files
committed
Support Cloud and CloudLocation for data replication overcloud.
1 parent 7e1c994 commit 026a0e0

File tree

7 files changed

+367
-1
lines changed

7 files changed

+367
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,13 @@ public FixedLengthInputStream marshall(AddBucketReplicationRequest request) {
563563
xmlBody.append("<ID>" + escapeKey(request.getReplicationRuleID()) + "</ID>");
564564
xmlBody.append("<Destination>");
565565
xmlBody.append("<Bucket>" + request.getTargetBucketName() + "</Bucket>");
566-
xmlBody.append("<Location>" + request.getTargetBucketLocation() + "</Location>");
566+
if (request.getTargetBucketLocation() != null) {
567+
xmlBody.append("<Location>" + request.getTargetBucketLocation() + "</Location>");
568+
} else if (request.getTargetCloud() != null && request.getTargetCloudLocation() != null) {
569+
xmlBody.append("<Cloud>" + request.getTargetCloud() + "</Cloud>");
570+
xmlBody.append("<CloudLocation>" + request.getTargetCloudLocation() + "</CloudLocation>");
571+
}
572+
567573
xmlBody.append("</Destination>");
568574
if (request.isEnableHistoricalObjectReplication()) {
569575
xmlBody.append("<HistoricalObjectReplication>" + "enabled" + "</HistoricalObjectReplication>");

src/main/java/com/aliyun/oss/internal/ResponseParsers.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,9 @@ public static List<ReplicationRule> parseGetBucketReplication(InputStream respon
20592059
repRule.setTargetBucketName(destination.getChildText("Bucket"));
20602060
repRule.setTargetBucketLocation(destination.getChildText("Location"));
20612061

2062+
repRule.setTargetCloud(destination.getChildText("Cloud"));
2063+
repRule.setTargetCloudLocation(destination.getChildText("CloudLocation"));
2064+
20622065
repRule.setReplicationStatus(ReplicationStatus.parse(ruleElem.getChildText("Status")));
20632066

20642067
if (ruleElem.getChildText("HistoricalObjectReplication").equals("enabled")) {
@@ -2112,6 +2115,8 @@ public static BucketReplicationProgress parseGetBucketReplicationProgress(InputS
21122115
Element destination = ruleElem.getChild("Destination");
21132116
progress.setTargetBucketName(destination.getChildText("Bucket"));
21142117
progress.setTargetBucketLocation(destination.getChildText("Location"));
2118+
progress.setTargetCloud(destination.getChildText("Cloud"));
2119+
progress.setTargetCloudLocation(destination.getChildText("CloudLocation"));
21152120

21162121
progress.setReplicationStatus(ReplicationStatus.parse(ruleElem.getChildText("Status")));
21172122

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ public void setTargetBucketLocation(String targetBucketLocation) {
102102
this.targetBucketLocation = targetBucketLocation;
103103
}
104104

105+
public String getTargetCloud()
106+
{
107+
return this.targetCloud;
108+
}
109+
110+
public void setTargetCloud(String targetCloud)
111+
{
112+
this.targetCloud = targetCloud;
113+
}
114+
115+
public String getTargetCloudLocation()
116+
{
117+
return this.targetCloudLocation;
118+
}
119+
120+
public void setTargetCloudLocation( String targetCloudLocation)
121+
{
122+
this.targetCloudLocation = targetCloudLocation;
123+
}
124+
105125
public boolean isEnableHistoricalObjectReplication() {
106126
return enableHistoricalObjectReplication;
107127
}
@@ -135,6 +155,8 @@ public void setReplicationActionList(List<ReplicationAction> replicationActionLi
135155
private String replicationRuleID = "";
136156
private String targetBucketName;
137157
private String targetBucketLocation;
158+
private String targetCloud;
159+
private String targetCloudLocation;
138160
private boolean enableHistoricalObjectReplication = true;
139161
private List<String> objectPrefixList = new ArrayList<String>();
140162
private List<ReplicationAction> replicationActionList = new ArrayList<ReplicationAction>();

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ public void setTargetBucketLocation(String targetBucketLocation) {
6464
this.targetBucketLocation = targetBucketLocation;
6565
}
6666

67+
public String getTargetCloud(){
68+
return this.targetCloud;
69+
}
70+
71+
public void setTargetCloud(String targetCloud){
72+
this.targetCloud = targetCloud;
73+
}
74+
75+
public String getTargetCloudLocation(){
76+
return this.targetCloudLocation;
77+
}
78+
79+
public void setTargetCloudLocation(String targetCloudLocation){
80+
this.targetCloudLocation = targetCloudLocation;
81+
}
82+
6783
public boolean isEnableHistoricalObjectReplication() {
6884
return enableHistoricalObjectReplication;
6985
}
@@ -92,6 +108,8 @@ public void setNewObjectProgress(Date newObjectProgress) {
92108
private ReplicationStatus replicationStatus;
93109
private String targetBucketName;
94110
private String targetBucketLocation;
111+
private String targetCloud;
112+
private String targetCloudLocation;
95113
private boolean enableHistoricalObjectReplication;
96114

97115
private float historicalObjectProgress;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ public void setTargetBucketLocation(String targetBucketLocation) {
6161
this.targetBucketLocation = targetBucketLocation;
6262
}
6363

64+
public String getTargetCloud(){
65+
return this.targetCloud;
66+
}
67+
public void setTargetCloud(String targetCloud){
68+
this.targetCloud = targetCloud;
69+
}
70+
public String getTargetCloudLocation(){
71+
return this.targetCloudLocation;
72+
}
73+
public void setTargetCloudLocation(String targetCloudLocation){
74+
this.targetCloudLocation = targetCloudLocation;
75+
}
76+
6477
public boolean isEnableHistoricalObjectReplication() {
6578
return enableHistoricalObjectReplication;
6679
}
@@ -95,6 +108,8 @@ public void setReplicationActionList(List<ReplicationAction> replicationActionLi
95108
private ReplicationStatus replicationStatus;
96109
private String targetBucketName;
97110
private String targetBucketLocation;
111+
private String targetCloud;
112+
private String targetCloudLocation;
98113
private boolean enableHistoricalObjectReplication;
99114
private List<String> objectPrefixList;
100115
private List<ReplicationAction> replicationActionList;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.aliyun.oss.common.parser;
2+
3+
/**
4+
* Created by zhoufeng.chen on 2018/1/10.
5+
*/
6+
7+
import com.aliyun.oss.common.comm.io.FixedLengthInputStream;
8+
import com.aliyun.oss.model.AddBucketReplicationRequest;
9+
import junit.framework.Assert;
10+
import org.jdom.Document;
11+
import org.jdom.Element;
12+
import org.jdom.JDOMException;
13+
import org.jdom.input.SAXBuilder;
14+
import org.junit.Test;
15+
16+
import java.io.IOException;
17+
18+
import static com.aliyun.oss.common.parser.RequestMarshallers.addBucketReplicationRequestMarshaller;
19+
20+
public class RequestMarshallersTest {
21+
@Test
22+
public void testAddBucketReplicationRequestMarshallerWithCloudLocation()
23+
{
24+
String bucketName = "alicloud-bucket";
25+
String targetBucketName = "alicloud-targetBucketName";
26+
String targetCloud = "testTargetCloud";
27+
String targetCloudLocation = "testTargetCloudLocation";
28+
AddBucketReplicationRequest addBucketReplicationRequest = new AddBucketReplicationRequest(bucketName);
29+
addBucketReplicationRequest.setTargetBucketName(targetBucketName);
30+
addBucketReplicationRequest.setTargetCloud(targetCloud);
31+
addBucketReplicationRequest.setTargetCloudLocation(targetCloudLocation);
32+
33+
FixedLengthInputStream is = addBucketReplicationRequestMarshaller.marshall(addBucketReplicationRequest);
34+
35+
SAXBuilder builder = new SAXBuilder();
36+
Document doc = null;
37+
try {
38+
doc = builder.build(is);
39+
} catch (JDOMException e) {
40+
e.printStackTrace();
41+
} catch (IOException e) {
42+
e.printStackTrace();
43+
}
44+
Element root = doc.getRootElement();
45+
Element ruleElems = root.getChild("Rule");
46+
Element destination = ruleElems.getChild("Destination");
47+
String aTargetBucketName = destination.getChildText("Bucket");
48+
String aTargetLocation = destination.getChildText("Location");
49+
String aTargetCloud = destination.getChildText("Cloud");
50+
String aTargetCloudLocation = destination.getChildText("CloudLocation");
51+
52+
Assert.assertEquals(targetBucketName, aTargetBucketName);
53+
Assert.assertNull(aTargetLocation);
54+
Assert.assertEquals(targetCloud, aTargetCloud);
55+
Assert.assertEquals(targetCloudLocation, aTargetCloudLocation);
56+
57+
}
58+
59+
@Test
60+
public void testAddBucketReplicationRequestMarshallerWithoutCloudLocation()
61+
{
62+
String bucketName = "alicloud-bucket";
63+
String targetBucketName = "alicloud-targetBucketName";
64+
String targetBucketLocation = "alicloud-targetBucketLocation";
65+
String targetCloud = "testTargetCloud";
66+
String targetCloudLocation = "testTargetCloudLocation";
67+
AddBucketReplicationRequest addBucketReplicationRequest = new AddBucketReplicationRequest(bucketName);
68+
addBucketReplicationRequest.setTargetBucketName(targetBucketName);
69+
addBucketReplicationRequest.setTargetBucketLocation(targetBucketLocation);
70+
addBucketReplicationRequest.setTargetCloud(targetCloud);
71+
addBucketReplicationRequest.setTargetCloudLocation(targetCloudLocation);
72+
73+
FixedLengthInputStream is = addBucketReplicationRequestMarshaller.marshall(addBucketReplicationRequest);
74+
75+
SAXBuilder builder = new SAXBuilder();
76+
Document doc = null;
77+
try {
78+
doc = builder.build(is);
79+
} catch (JDOMException e) {
80+
e.printStackTrace();
81+
} catch (IOException e) {
82+
e.printStackTrace();
83+
}
84+
Element root = doc.getRootElement();
85+
Element ruleElems = root.getChild("Rule");
86+
Element destination = ruleElems.getChild("Destination");
87+
String aTargetBucketName = destination.getChildText("Bucket");
88+
String aTargetLocation = destination.getChildText("Location");
89+
String aTargetCloud = destination.getChildText("Cloud");
90+
String aTargetCloudLocation = destination.getChildText("CloudLocation");
91+
92+
Assert.assertEquals(targetBucketName, aTargetBucketName);
93+
Assert.assertEquals(targetBucketLocation, aTargetLocation);
94+
Assert.assertNull(aTargetCloud);
95+
Assert.assertNull(aTargetCloudLocation);
96+
}
97+
}

0 commit comments

Comments
 (0)