Search in sources :

Example 1 with Transition

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

the class BucketConfigurationXmlFactory method addTransitions.

private void addTransitions(XmlWriter xml, List<Transition> transitions) {
    if (transitions == null || transitions.isEmpty()) {
        return;
    }
    for (Transition t : transitions) {
        if (t != null) {
            xml.start("Transition");
            if (t.getDate() != null) {
                xml.start("Date");
                xml.value(DateUtils.formatISO8601Date(t.getDate()));
                xml.end();
            }
            if (t.getDays() != -1) {
                xml.start("Days");
                xml.value(Integer.toString(t.getDays()));
                xml.end();
            }
            xml.start("StorageClass");
            xml.value(t.getStorageClass().toString());
            // <StorageClass>
            xml.end();
            // </Transition>
            xml.end();
        }
    }
}
Also used : Transition(com.qcloud.cos.model.BucketLifecycleConfiguration.Transition) NoncurrentVersionTransition(com.qcloud.cos.model.BucketLifecycleConfiguration.NoncurrentVersionTransition)

Example 2 with Transition

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

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

the class PutGetLifeCycleConfigTest method testPutGetDelLifeCycleForNormalBucket.

@Test
public void testPutGetDelLifeCycleForNormalBucket() {
    if (!judgeUserInfoValid()) {
        return;
    }
    List<Rule> rules = new ArrayList<>();
    // 30天后删除
    Rule deletePrefixRule = new Rule();
    deletePrefixRule.setId("delete prefix xxxy after 30 days");
    deletePrefixRule.setFilter(new LifecycleFilter(new LifecyclePrefixPredicate("delete_prefix/")));
    deletePrefixRule.setExpirationInDays(30);
    deletePrefixRule.setStatus(BucketLifecycleConfiguration.ENABLED);
    // 20天后沉降到低频,一年后删除
    Rule standardIaRule = new Rule();
    standardIaRule.setId("standard_ia transition");
    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.setExpirationInDays(120);
    rules.add(deletePrefixRule);
    rules.add(standardIaRule);
    testPutGetDelRules(rules);
}
Also used : LifecycleFilter(com.qcloud.cos.model.lifecycle.LifecycleFilter) LifecyclePrefixPredicate(com.qcloud.cos.model.lifecycle.LifecyclePrefixPredicate) ArrayList(java.util.ArrayList) Transition(com.qcloud.cos.model.BucketLifecycleConfiguration.Transition) NoncurrentVersionTransition(com.qcloud.cos.model.BucketLifecycleConfiguration.NoncurrentVersionTransition) Rule(com.qcloud.cos.model.BucketLifecycleConfiguration.Rule) Test(org.junit.Test)

Aggregations

NoncurrentVersionTransition (com.qcloud.cos.model.BucketLifecycleConfiguration.NoncurrentVersionTransition)3 Transition (com.qcloud.cos.model.BucketLifecycleConfiguration.Transition)3 Rule (com.qcloud.cos.model.BucketLifecycleConfiguration.Rule)2 LifecycleFilter (com.qcloud.cos.model.lifecycle.LifecycleFilter)2 LifecyclePrefixPredicate (com.qcloud.cos.model.lifecycle.LifecyclePrefixPredicate)2 ArrayList (java.util.ArrayList)2 BucketVersioningConfiguration (com.qcloud.cos.model.BucketVersioningConfiguration)1 SetBucketVersioningConfigurationRequest (com.qcloud.cos.model.SetBucketVersioningConfigurationRequest)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1