• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Java SDK)
  4. Lifecycle Management
  5. Viewing Lifecycle Rules

Viewing Lifecycle Rules

You can call ObsClient.getBucketLifecycleConfiguration to view lifecycle rules of a bucket. Sample code is as follows:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

LifecycleConfiguration config = obsClient.getBucketLifecycleConfiguration("bucketname");

for (Rule rule : config.getRules())
{
    System.out.println(rule.getId());
    System.out.println(rule.getPrefix());
 for(Transition transition : rule.getTransitions()){
        System.out.println(transition.getDays());
        System.out.println(transition.getStorageClass());
    }
    System.out.println(rule.getExpiration() != null ? rule.getExpiration().getDays() : "");
    for(NoncurrentVersionTransition noncurrentVersionTransition : rule.getNoncurrentVersionTransitions()){
        System.out.println(noncurrentVersionTransition.getDays());
        System.out.println(noncurrentVersionTransition.getStorageClass());
    }
    System.out.println(rule.getNoncurrentVersionExpiration() != null ? rule.getNoncurrentVersionExpiration().getDays() : "");
}

// Close obsClient.
obsClient.close();