use of com.aliyun.oss.model.ReplicationRule in project aliyun-oss-java-sdk by aliyun.
the class BucketReplicationTest method testNormalDeleteBucketReplicationWithRuleID.
@Test
public void testNormalDeleteBucketReplicationWithRuleID() throws ParseException {
final String bucketName = "test-bucket-delete-replication-ruleid";
final String repRuleID = "test-replication-ruleid";
try {
ossClient.createBucket(bucketName);
AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
request.setReplicationRuleID(repRuleID);
request.setTargetBucketName(targetBucketName);
request.setTargetBucketLocation(targetBucketLoc);
ossClient.addBucketReplication(request);
List<ReplicationRule> rules = ossClient.getBucketReplication(bucketName);
Assert.assertEquals(rules.size(), 1);
ReplicationRule r0 = rules.get(0);
Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Starting);
ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName).withReplicationRuleID(repRuleID));
rules = ossClient.getBucketReplication(bucketName);
Assert.assertEquals(rules.size(), 1);
r0 = rules.get(0);
Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Closing);
} catch (OSSException e) {
Assert.fail(e.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.ReplicationRule in project aliyun-oss-java-sdk by aliyun.
the class BucketReplicationTest method testNormalGetBucketReplicationProgressWithDisableHistory.
@Test
public void testNormalGetBucketReplicationProgressWithDisableHistory() throws ParseException {
final String bucketName = "test-bucket-replication-progress-disable-history";
final String repRuleID = "test-replication-ruleid";
try {
ossClient.createBucket(bucketName);
AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
request.setReplicationRuleID(repRuleID);
request.setTargetBucketName(targetBucketName);
request.setTargetBucketLocation(targetBucketLoc);
request.setEnableHistoricalObjectReplication(false);
ossClient.addBucketReplication(request);
List<ReplicationRule> rules = ossClient.getBucketReplication(bucketName);
Assert.assertEquals(rules.size(), 1);
ReplicationRule r0 = rules.get(0);
Assert.assertEquals(r0.getReplicationRuleID(), repRuleID);
Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
Assert.assertEquals(r0.isEnableHistoricalObjectReplication(), false);
Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Starting);
BucketReplicationProgress process = ossClient.getBucketReplicationProgress(new GetBucketReplicationProgressRequest(bucketName).withReplicationRuleID(repRuleID));
Assert.assertEquals(process.getReplicationRuleID(), repRuleID);
Assert.assertEquals(process.getTargetBucketName(), targetBucketName);
Assert.assertEquals(process.getTargetBucketLocation(), targetBucketLoc);
Assert.assertEquals(process.getReplicationStatus(), ReplicationStatus.Starting);
Assert.assertEquals(process.getHistoricalObjectProgress(), Float.valueOf(0));
Assert.assertEquals(process.isEnableHistoricalObjectReplication(), false);
Assert.assertEquals(process.getNewObjectProgress(), null);
// Assert.assertEquals(diffSecond(process.getNewObjectProgress(), now) < 5, true);
ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, repRuleID));
} catch (OSSException e) {
Assert.fail(e.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.ReplicationRule in project aliyun-oss-java-sdk by aliyun.
the class BucketReplicationTest method testNormalAddBucketReplication.
@Test
public void testNormalAddBucketReplication() throws ParseException {
final String bucketName = "test-bucket-set-replication";
final String ruleId = "bucket-replication-rule-id";
try {
ossClient.createBucket(bucketName);
AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
request.setReplicationRuleID(ruleId);
request.setTargetBucketName(targetBucketName);
request.setTargetBucketLocation(targetBucketLoc);
ossClient.addBucketReplication(request);
List<ReplicationRule> rules = ossClient.getBucketReplication(bucketName);
Assert.assertEquals(rules.size(), 1);
ReplicationRule r0 = rules.get(0);
Assert.assertEquals(r0.getReplicationRuleID(), ruleId);
Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Starting);
Assert.assertNull(r0.getObjectPrefixList());
Assert.assertEquals(r0.getReplicationActionList().size(), 1);
Assert.assertEquals(r0.getReplicationActionList().get(0), ReplicationAction.parse("ALL"));
BucketReplicationProgress progress = ossClient.getBucketReplicationProgress(bucketName, ruleId);
Assert.assertEquals(progress.getReplicationRuleID(), ruleId);
Assert.assertEquals(progress.getTargetBucketName(), targetBucketName);
Assert.assertEquals(progress.getTargetBucketLocation(), targetBucketLoc);
Assert.assertEquals(progress.getReplicationStatus(), ReplicationStatus.Starting);
Assert.assertEquals(progress.getHistoricalObjectProgress(), Float.valueOf(0));
Assert.assertEquals(progress.isEnableHistoricalObjectReplication(), true);
Assert.assertEquals(progress.getNewObjectProgress(), null);
ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, ruleId));
rules = ossClient.getBucketReplication(bucketName);
Assert.assertEquals(rules.size(), 1);
r0 = rules.get(0);
Assert.assertEquals(r0.getReplicationRuleID(), ruleId);
Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Closing);
List<String> locations = ossClient.getBucketReplicationLocation(bucketName);
Assert.assertEquals(locations.size() > 0, true);
} catch (OSSException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.ReplicationRule in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketReplication.
/**
* Unmarshall get bucket replication response body to replication result.
*/
@SuppressWarnings("unchecked")
public static List<ReplicationRule> parseGetBucketReplication(InputStream responseBody) throws ResponseParseException {
try {
List<ReplicationRule> repRules = new ArrayList<ReplicationRule>();
Element root = getXmlRootElement(responseBody);
List<Element> ruleElems = root.getChildren("Rule");
for (Element ruleElem : ruleElems) {
ReplicationRule repRule = new ReplicationRule();
repRule.setReplicationRuleID(ruleElem.getChildText("ID"));
Element destination = ruleElem.getChild("Destination");
repRule.setTargetBucketName(destination.getChildText("Bucket"));
repRule.setTargetBucketLocation(destination.getChildText("Location"));
repRule.setReplicationStatus(ReplicationStatus.parse(ruleElem.getChildText("Status")));
if (ruleElem.getChildText("HistoricalObjectReplication").equals("enabled")) {
repRule.setEnableHistoricalObjectReplication(true);
} else {
repRule.setEnableHistoricalObjectReplication(false);
}
if (ruleElem.getChild("PrefixSet") != null) {
List<String> objectPrefixes = new ArrayList<String>();
List<Element> prefixElems = ruleElem.getChild("PrefixSet").getChildren("Prefix");
for (Element prefixElem : prefixElems) {
objectPrefixes.add(prefixElem.getText());
}
repRule.setObjectPrefixList(objectPrefixes);
}
if (ruleElem.getChild("Action") != null) {
String[] actionStrs = ruleElem.getChildText("Action").split(",");
List<ReplicationAction> repActions = new ArrayList<ReplicationAction>();
for (String actionStr : actionStrs) {
repActions.add(ReplicationAction.parse(actionStr));
}
repRule.setReplicationActionList(repActions);
}
repRules.add(repRule);
}
return repRules;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations