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

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

Introduction

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

Prototype

public BucketLifecycleConfiguration withRules(Rule... rules) 

Source Link

Document

Convenience array style method for BucketLifecycleConfiguration#withRules(List)

Usage

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

License:Open Source License

/**
 * Creates system owned bucket to store download manifest files
 * @throws EucalyptusCloudException/*w  w  w. jav  a2 s .  co  m*/
 */
public static void createManifestsBucket(@Nonnull EucaS3Client s3Client) throws EucalyptusCloudException {
    if (checkManifestsBucket(s3Client))
        return;

    Bucket manifestBucket;
    try {
        manifestBucket = s3Client.createBucket(DOWNLOAD_MANIFEST_BUCKET_NAME);
    } catch (Exception e) {
        LOG.error("Error creating manifest bucket " + DOWNLOAD_MANIFEST_BUCKET_NAME, e);
        throw new EucalyptusCloudException("Failed to create bucket " + DOWNLOAD_MANIFEST_BUCKET_NAME, e);
    }

    try {
        BucketLifecycleConfiguration lc = new BucketLifecycleConfiguration();
        BucketLifecycleConfiguration.Rule expireRule = new BucketLifecycleConfiguration.Rule();
        expireRule.setId("Manifest Expiration Rule");
        expireRule.setPrefix(DOWNLOAD_MANIFEST_PREFIX);
        expireRule.setStatus("Enabled");
        expireRule.setExpirationInDays(1);
        lc = lc.withRules(expireRule);
        s3Client.setBucketLifecycleConfiguration(manifestBucket.getName(), lc);
    } catch (Exception e) {
        throw new EucalyptusCloudException(
                "Failed to set bucket lifecycle on bucket " + DOWNLOAD_MANIFEST_BUCKET_NAME, e);
    }
    LOG.debug("Created bucket for download-manifests " + DOWNLOAD_MANIFEST_BUCKET_NAME);
}