Example usage for com.amazonaws.services.s3.model BucketLifecycleConfiguration getRules

List of usage examples for com.amazonaws.services.s3.model BucketLifecycleConfiguration getRules

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model BucketLifecycleConfiguration getRules.

Prototype

public List<Rule> getRules() 

Source Link

Document

Returns the list of rules that comprise this configuration.

Usage

From source file:c3.ops.priam.aws.S3FileSystem.java

License:Apache License

/**
 * Note: Current limitation allows only 100 object expiration rules to be
 * set. Removes the rule is set to 0.//from   w w w.  j  a  v  a  2  s.c om
 */
@Override
public void cleanup() {
    AmazonS3 s3Client = getS3Client();
    String clusterPath = pathProvider.get().clusterPrefix("");
    BucketLifecycleConfiguration lifeConfig = s3Client
            .getBucketLifecycleConfiguration(config.getBackupPrefix());
    if (lifeConfig == null) {
        lifeConfig = new BucketLifecycleConfiguration();
        List<Rule> rules = Lists.newArrayList();
        lifeConfig.setRules(rules);
    }
    List<Rule> rules = lifeConfig.getRules();
    if (updateLifecycleRule(rules, clusterPath)) {
        if (rules.size() > 0) {
            lifeConfig.setRules(rules);
            s3Client.setBucketLifecycleConfiguration(config.getBackupPrefix(), lifeConfig);
        } else
            s3Client.deleteBucketLifecycleConfiguration(config.getBackupPrefix());
    }
}

From source file:com.eucalyptus.imaging.manifest.DownloadManifestFactory.java

License:Open Source License

private static boolean checkManifestsBucket(EucaS3Client s3Client) {
    try {/*  w  ww . ja  va 2s  .  c  o  m*/
        //Since we're using the eucalyptus admin, which has access to all buckets, check the bucket owner explicitly
        AccessControlList acl = s3Client.getBucketAcl(DOWNLOAD_MANIFEST_BUCKET_NAME);
        if (!acl.getOwner().getId().equals(getDownloadManifestS3User().getAccount().getCanonicalId())) {
            //Bucket exists, but is owned by another account
            LOG.warn("Found existence of download manifest bucket: " + DOWNLOAD_MANIFEST_BUCKET_NAME
                    + " but it is owned by another account: " + acl.getOwner().getId() + ", "
                    + acl.getOwner().getDisplayName());
            return false;
        }

        BucketLifecycleConfiguration config = s3Client
                .getBucketLifecycleConfiguration(DOWNLOAD_MANIFEST_BUCKET_NAME);

        return (config.getRules() != null && config.getRules().size() == 1
                && config.getRules().get(0).getExpirationInDays() == 1
                && "enabled".equalsIgnoreCase(config.getRules().get(0).getStatus())
                && DOWNLOAD_MANIFEST_PREFIX.equals(config.getRules().get(0).getPrefix()));
    } catch (AmazonServiceException e) {
        //Expected possible path if doesn't exist.
        return false;
    } catch (Exception e) {
        LOG.warn("Unexpected error checking for download manifest bucket", e);
        return false;
    }
}