Search in sources :

Example 6 with SetBucketVersioningConfigurationRequest

use of com.qcloud.cos.model.SetBucketVersioningConfigurationRequest 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 7 with SetBucketVersioningConfigurationRequest

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

the class PutGetLifeCycleConfigTest method testPutGetDelLifeCycleForBucketWithVersions.

@Ignore
public void testPutGetDelLifeCycleForBucketWithVersions() {
    if (!judgeUserInfoValid()) {
        return;
    }
    BucketVersioningConfiguration bucketVersionConfig = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
    SetBucketVersioningConfigurationRequest setBucketVersionReq = new SetBucketVersioningConfigurationRequest(bucket, bucketVersionConfig);
    cosclient.setBucketVersioningConfiguration(setBucketVersionReq);
    List<Rule> rules = new ArrayList<>();
    Rule standardIaRule = new Rule();
    standardIaRule.setId("standard_ia transition for version");
    standardIaRule.setFilter(new LifecycleFilter(new LifecyclePrefixPredicate("standard_ia/")));
    List<Transition> standardIaTransitions = new ArrayList<>();
    Transition standardTransition = new Transition();
    standardTransition.setDays(20);
    standardTransition.setStorageClass(StorageClass.Standard_IA.toString());
    standardIaTransitions.add(standardTransition);
    standardIaRule.setTransitions(standardIaTransitions);
    standardIaRule.setStatus(BucketLifecycleConfiguration.DISABLED);
    standardIaRule.setNoncurrentVersionExpirationInDays(360);
    List<NoncurrentVersionTransition> noncurrentVersionTransitions = new ArrayList<>();
    NoncurrentVersionTransition noncurrentVersionTransition = new NoncurrentVersionTransition();
    noncurrentVersionTransition.setDays(30);
    noncurrentVersionTransition.setStorageClass(StorageClass.Standard_IA);
    standardIaRule.setNoncurrentVersionTransitions(noncurrentVersionTransitions);
    standardIaRule.setExpirationInDays(120);
    rules.add(standardIaRule);
    testPutGetDelRules(rules);
    bucketVersionConfig.setStatus(BucketVersioningConfiguration.SUSPENDED);
    SetBucketVersioningConfigurationRequest closeBucketVersionReq = new SetBucketVersioningConfigurationRequest(bucket, bucketVersionConfig);
    cosclient.setBucketVersioningConfiguration(closeBucketVersionReq);
}
Also used : NoncurrentVersionTransition(com.qcloud.cos.model.BucketLifecycleConfiguration.NoncurrentVersionTransition) LifecycleFilter(com.qcloud.cos.model.lifecycle.LifecycleFilter) LifecyclePrefixPredicate(com.qcloud.cos.model.lifecycle.LifecyclePrefixPredicate) SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) ArrayList(java.util.ArrayList) Transition(com.qcloud.cos.model.BucketLifecycleConfiguration.Transition) NoncurrentVersionTransition(com.qcloud.cos.model.BucketLifecycleConfiguration.NoncurrentVersionTransition) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Rule(com.qcloud.cos.model.BucketLifecycleConfiguration.Rule) Ignore(org.junit.Ignore)

Example 8 with SetBucketVersioningConfigurationRequest

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

the class BucketVersioningTest method testBucketVersioningEnabled.

@Test
public void testBucketVersioningEnabled() {
    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());
    }
    BucketVersioningConfiguration bucketVersioningRet = cosclient.getBucketVersioningConfiguration(bucket);
    assertEquals(BucketVersioningConfiguration.ENABLED, bucketVersioningRet.getStatus());
}
Also used : SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Test(org.junit.Test)

Example 9 with SetBucketVersioningConfigurationRequest

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

the class BucketVersioningTest method testBucketVersioningSuspended.

@Test
public void testBucketVersioningSuspended() {
    if (!judgeUserInfoValid()) {
        return;
    }
    BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED);
    cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
    try {
        Thread.sleep(5000L);
    } catch (InterruptedException e) {
        fail(e.toString());
    }
    BucketVersioningConfiguration bucketVersioningRet = cosclient.getBucketVersioningConfiguration(bucket);
    assertEquals(BucketVersioningConfiguration.SUSPENDED, bucketVersioningRet.getStatus());
}
Also used : SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Test(org.junit.Test)

Aggregations

BucketVersioningConfiguration (com.qcloud.cos.model.BucketVersioningConfiguration)9 SetBucketVersioningConfigurationRequest (com.qcloud.cos.model.SetBucketVersioningConfigurationRequest)9 Test (org.junit.Test)7 File (java.io.File)3 ArrayList (java.util.ArrayList)3 COSVersionSummary (com.qcloud.cos.model.COSVersionSummary)2 DeleteObjectsRequest (com.qcloud.cos.model.DeleteObjectsRequest)2 KeyVersion (com.qcloud.cos.model.DeleteObjectsRequest.KeyVersion)2 DeleteObjectsResult (com.qcloud.cos.model.DeleteObjectsResult)2 ListVersionsRequest (com.qcloud.cos.model.ListVersionsRequest)2 PutObjectResult (com.qcloud.cos.model.PutObjectResult)2 VersionListing (com.qcloud.cos.model.VersionListing)2 COSClient (com.qcloud.cos.COSClient)1 ClientConfig (com.qcloud.cos.ClientConfig)1 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)1 COSCredentials (com.qcloud.cos.auth.COSCredentials)1 CosClientException (com.qcloud.cos.exception.CosClientException)1 CosServiceException (com.qcloud.cos.exception.CosServiceException)1 MultiObjectDeleteException (com.qcloud.cos.exception.MultiObjectDeleteException)1 NoncurrentVersionTransition (com.qcloud.cos.model.BucketLifecycleConfiguration.NoncurrentVersionTransition)1