Search in sources :

Example 1 with ReplicationRule

use of com.qcloud.cos.model.ReplicationRule in project cos-java-sdk-v5 by tencentyun.

the class BucketReplicationTest method setGetDelBucketReplicationTest.

@Test
public void setGetDelBucketReplicationTest() {
    if (!judgeUserInfoValid()) {
        return;
    }
    BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
    cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
    try {
        Thread.sleep(5000L);
    } catch (InterruptedException e) {
        fail(e.toString());
    }
    ReplicationRule replicationRule = new ReplicationRule();
    String prefix = "copy1_folder/";
    replicationRule.setPrefix(prefix);
    replicationRule.setStatus(ReplicationRuleStatus.Enabled);
    ReplicationDestinationConfig replicationDestinationConfig = new ReplicationDestinationConfig();
    String bucketQCS = "qcs:id/0:cos:ap-chengdu:appid/1251668577:chengwus3cd";
    replicationDestinationConfig.setBucketQCS(bucketQCS);
    replicationDestinationConfig.setStorageClass(StorageClass.Standard);
    replicationRule.setDestinationConfig(replicationDestinationConfig);
    BucketReplicationConfiguration bucketReplicationConfiguration = new BucketReplicationConfiguration();
    String ruleName = "qcs::cam::uin/123456789:uin/987654543";
    bucketReplicationConfiguration.setRoleName(ruleName);
    String ruleId = "cctest1";
    replicationRule.setID(ruleId);
    bucketReplicationConfiguration.addRule(replicationRule);
    cosclient.setBucketReplicationConfiguration(bucket, bucketReplicationConfiguration);
    // replication设置后, 立刻获取会需要一段时间
    try {
        Thread.sleep(5000L);
    } catch (InterruptedException e) {
        fail(e.toString());
    }
    BucketReplicationConfiguration replicaConfigGet = cosclient.getBucketReplicationConfiguration(bucket);
    assertEquals(ruleName, replicaConfigGet.getRoleName());
    assertEquals(1, replicaConfigGet.getRules().size());
    ReplicationRule replicationRule2 = replicaConfigGet.getRules().get(0);
    assertEquals(bucketQCS, replicationRule2.getDestinationConfig().getBucketQCS());
    assertEquals(StorageClass.Standard.toString(), replicationRule2.getDestinationConfig().getStorageClass());
    assertEquals(ReplicationRuleStatus.Enabled.toString(), replicationRule2.getStatus());
    assertEquals(prefix, replicationRule2.getPrefix());
    cosclient.deleteBucketReplicationConfiguration(bucket);
}
Also used : ReplicationDestinationConfig(com.qcloud.cos.model.ReplicationDestinationConfig) BucketReplicationConfiguration(com.qcloud.cos.model.BucketReplicationConfiguration) SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) ReplicationRule(com.qcloud.cos.model.ReplicationRule) Test(org.junit.Test)

Example 2 with ReplicationRule

use of com.qcloud.cos.model.ReplicationRule in project cos-java-sdk-v5 by tencentyun.

the class BucketReplicationDemo method putBucketReplication.

public static void putBucketReplication() {
    BucketReplicationConfiguration bucketReplicationConfiguration = new BucketReplicationConfiguration();
    bucketReplicationConfiguration.setRoleName("qcs::cam::uin/1000000001:uin/1000000001");
    ReplicationRule replicationRule = new ReplicationRule();
    replicationRule.setID("test");
    replicationRule.setStatus(ReplicationRuleStatus.Disabled);
    replicationRule.setPrefix("testReplication");
    ReplicationDestinationConfig replicationDestinationConfig = new ReplicationDestinationConfig();
    replicationDestinationConfig.setBucketQCS("qcs::cos:ap-shanghai::examplebucket-cp-1251668577");
    replicationRule.setDestinationConfig(replicationDestinationConfig);
    bucketReplicationConfiguration.addRule(replicationRule);
    ReplicationRule replicationRule2 = new ReplicationRule();
    replicationRule2.setID("test2");
    replicationRule2.setStatus(ReplicationRuleStatus.Disabled);
    replicationRule2.setPrefix("test2Replication");
    ReplicationDestinationConfig replicationDestinationConfig2 = new ReplicationDestinationConfig();
    replicationDestinationConfig2.setBucketQCS("qcs::cos:ap-shanghai::examplebucket-cp-1251668577");
    replicationRule2.setDestinationConfig(replicationDestinationConfig2);
    bucketReplicationConfiguration.addRule(replicationRule2);
    ReplicationRule replicationRule3 = new ReplicationRule();
    replicationRule3.setID("test3");
    replicationRule3.setStatus(ReplicationRuleStatus.Disabled);
    replicationRule3.setPrefix("test3Replication");
    ReplicationDestinationConfig replicationDestinationConfig3 = new ReplicationDestinationConfig();
    replicationDestinationConfig3.setBucketQCS("qcs::cos:ap-shanghai::examplebucket-cp-1251668577");
    replicationRule2.setDestinationConfig(replicationDestinationConfig3);
    bucketReplicationConfiguration.addRule(replicationRule3);
    bucketReplicationConfiguration.removeRule(replicationRule3);
    cosClient.setBucketReplicationConfiguration(bucketName, bucketReplicationConfiguration);
}
Also used : BucketReplicationConfiguration(com.qcloud.cos.model.BucketReplicationConfiguration) ReplicationDestinationConfig(com.qcloud.cos.model.ReplicationDestinationConfig) ReplicationRule(com.qcloud.cos.model.ReplicationRule)

Aggregations

BucketReplicationConfiguration (com.qcloud.cos.model.BucketReplicationConfiguration)2 ReplicationDestinationConfig (com.qcloud.cos.model.ReplicationDestinationConfig)2 ReplicationRule (com.qcloud.cos.model.ReplicationRule)2 BucketVersioningConfiguration (com.qcloud.cos.model.BucketVersioningConfiguration)1 SetBucketVersioningConfigurationRequest (com.qcloud.cos.model.SetBucketVersioningConfigurationRequest)1 Test (org.junit.Test)1