Search in sources :

Example 1 with BucketReplicationProgress

use of com.aliyun.oss.model.BucketReplicationProgress in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetBucketReplicationProgress.

/**
 * Unmarshall get bucket replication response body to replication progress.
 */
public static BucketReplicationProgress parseGetBucketReplicationProgress(InputStream responseBody) throws ResponseParseException {
    try {
        BucketReplicationProgress progress = new BucketReplicationProgress();
        Element root = getXmlRootElement(responseBody);
        Element ruleElem = root.getChild("Rule");
        progress.setReplicationRuleID(ruleElem.getChildText("ID"));
        Element destination = ruleElem.getChild("Destination");
        progress.setTargetBucketName(destination.getChildText("Bucket"));
        progress.setTargetBucketLocation(destination.getChildText("Location"));
        progress.setReplicationStatus(ReplicationStatus.parse(ruleElem.getChildText("Status")));
        if (ruleElem.getChildText("HistoricalObjectReplication").equals("enabled")) {
            progress.setEnableHistoricalObjectReplication(true);
        } else {
            progress.setEnableHistoricalObjectReplication(false);
        }
        Element progressElem = ruleElem.getChild("Progress");
        if (progressElem != null) {
            if (progressElem.getChild("HistoricalObject") != null) {
                progress.setHistoricalObjectProgress(Float.parseFloat(progressElem.getChildText("HistoricalObject")));
            }
            progress.setNewObjectProgress(DateUtil.parseIso8601Date(progressElem.getChildText("NewObject")));
        }
        return progress;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) BucketReplicationProgress(com.aliyun.oss.model.BucketReplicationProgress) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 2 with BucketReplicationProgress

use of com.aliyun.oss.model.BucketReplicationProgress in project aliyun-oss-java-sdk by aliyun.

the class BucketReplicationTest method testNormalAddBucketReplicationWithRuleID.

@Test
public void testNormalAddBucketReplicationWithRuleID() throws ParseException {
    final String bucketName = "test-bucket-replication-ruleid-3";
    final String repRuleID = "~`!@#$%^&*()-_+=|\\[]{}<>:;\"',./?";
    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(bucketName, 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));
        ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, repRuleID));
    } catch (OSSException e) {
        Assert.fail(e.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : BucketReplicationProgress(com.aliyun.oss.model.BucketReplicationProgress) AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) ReplicationRule(com.aliyun.oss.model.ReplicationRule) Test(org.junit.Test)

Example 3 with BucketReplicationProgress

use of com.aliyun.oss.model.BucketReplicationProgress in project aliyun-oss-java-sdk by aliyun.

the class BucketReplicationTest method testNormalGetBucketReplicationProgress.

@Test
public void testNormalGetBucketReplicationProgress() throws ParseException {
    final String bucketName = "test-bucket-get-replication-progress";
    final String repRuleID = "test-replication-progress-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.getReplicationRuleID(), repRuleID);
        Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
        Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
        Assert.assertEquals(r0.isEnableHistoricalObjectReplication(), true);
        Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Starting);
        BucketReplicationProgress process = ossClient.getBucketReplicationProgress(bucketName, 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.isEnableHistoricalObjectReplication(), true);
        Assert.assertEquals(process.getHistoricalObjectProgress(), Float.valueOf(0));
        Assert.assertEquals(process.getNewObjectProgress(), null);
        ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, repRuleID));
    } catch (OSSException e) {
        Assert.fail(e.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : BucketReplicationProgress(com.aliyun.oss.model.BucketReplicationProgress) AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) ReplicationRule(com.aliyun.oss.model.ReplicationRule) Test(org.junit.Test)

Example 4 with BucketReplicationProgress

use of com.aliyun.oss.model.BucketReplicationProgress 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);
    }
}
Also used : BucketReplicationProgress(com.aliyun.oss.model.BucketReplicationProgress) AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) GetBucketReplicationProgressRequest(com.aliyun.oss.model.GetBucketReplicationProgressRequest) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) ReplicationRule(com.aliyun.oss.model.ReplicationRule) Test(org.junit.Test)

Example 5 with BucketReplicationProgress

use of com.aliyun.oss.model.BucketReplicationProgress 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);
    }
}
Also used : BucketReplicationProgress(com.aliyun.oss.model.BucketReplicationProgress) AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) ReplicationRule(com.aliyun.oss.model.ReplicationRule) Test(org.junit.Test)

Aggregations

BucketReplicationProgress (com.aliyun.oss.model.BucketReplicationProgress)5 OSSException (com.aliyun.oss.OSSException)4 AddBucketReplicationRequest (com.aliyun.oss.model.AddBucketReplicationRequest)4 DeleteBucketReplicationRequest (com.aliyun.oss.model.DeleteBucketReplicationRequest)4 ReplicationRule (com.aliyun.oss.model.ReplicationRule)4 Test (org.junit.Test)4 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 GetBucketReplicationProgressRequest (com.aliyun.oss.model.GetBucketReplicationProgressRequest)1 ParseException (java.text.ParseException)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1