Search in sources :

Example 6 with SetBucketLifecycleRequest

use of com.aliyun.oss.model.SetBucketLifecycleRequest in project feeyo-hlsserver by variflight.

the class OssUtil method updateExpirationDays.

/**
 * 更新生命周期
 */
public void updateExpirationDays(int days) {
    // 获取生命周期规则列表
    List<LifecycleRule> list = ossClient.getBucketLifecycle(bucketName);
    if (list.size() > 0) {
        LifecycleRule lifecycleRule = list.get(0);
        List<StorageTransition> storageTransitionList = lifecycleRule.getStorageTransition();
        if (storageTransitionList.size() > 0) {
            StorageTransition storageTransition = storageTransitionList.get(0);
            // 如果原转换到归档存储的时间 与设定时间不一样,则更新
            if (storageTransition.getExpirationDays() != days) {
                storageTransition.setExpirationDays(days);
                SetBucketLifecycleRequest setBucketLifecycleRequest = new SetBucketLifecycleRequest(bucketName);
                setBucketLifecycleRequest.setLifecycleRules(list);
                ossClient.setBucketLifecycle(setBucketLifecycleRequest);
                LOGGER.info("oss life cycle set expir : " + days + " days");
            }
        }
    }
}
Also used : SetBucketLifecycleRequest(com.aliyun.oss.model.SetBucketLifecycleRequest) StorageTransition(com.aliyun.oss.model.LifecycleRule.StorageTransition) LifecycleRule(com.aliyun.oss.model.LifecycleRule)

Aggregations

LifecycleRule (com.aliyun.oss.model.LifecycleRule)6 SetBucketLifecycleRequest (com.aliyun.oss.model.SetBucketLifecycleRequest)6 OSSException (com.aliyun.oss.OSSException)4 StorageTransition (com.aliyun.oss.model.LifecycleRule.StorageTransition)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 TestUtils.genRandomString (com.aliyun.oss.integrationtests.TestUtils.genRandomString)2 AbortMultipartUpload (com.aliyun.oss.model.LifecycleRule.AbortMultipartUpload)2 OSS (com.aliyun.oss.OSS)1 OSSClient (com.aliyun.oss.OSSClient)1 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)1 AccessControlList (com.aliyun.oss.model.AccessControlList)1 BucketLoggingResult (com.aliyun.oss.model.BucketLoggingResult)1 BucketReferer (com.aliyun.oss.model.BucketReferer)1 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)1 Grant (com.aliyun.oss.model.Grant)1 ObjectListing (com.aliyun.oss.model.ObjectListing)1 SetBucketCORSRequest (com.aliyun.oss.model.SetBucketCORSRequest)1 CORSRule (com.aliyun.oss.model.SetBucketCORSRequest.CORSRule)1 SetBucketLoggingRequest (com.aliyun.oss.model.SetBucketLoggingRequest)1