com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Transition Java Examples

The following examples show how to use com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Transition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlResponsesSaxParser.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStartElement(
    String uri,
    String name,
    String qName,
    Attributes attrs) {

    if (in("LifecycleConfiguration")) {
        if (name.equals("Rule")) {
            currentRule = new Rule();
        }
    } else if (in("LifecycleConfiguration", "Rule")) {
        if (name.equals("Transition")) {
            currentTransition = new Transition();
        } else if (name.equals("NoncurrentVersionTransition")) {
            currentNcvTransition = new NoncurrentVersionTransition();
        } else if (name.equals("AbortIncompleteMultipartUpload")) {
            abortIncompleteMultipartUpload = new
                AbortIncompleteMultipartUpload();
        } else if (name.equals("Filter")) {
            currentFilter = new LifecycleFilter();
        }
    } else if (in("LifecycleConfiguration", "Rule", "Filter")) {
        if (name.equals("And")) {
            andOperandsList = new ArrayList<LifecycleFilterPredicate>();
        }
    }
}
 
Example #2
Source File: BucketTransitionGlacier.java    From cloudExplorer with GNU General Public License v3.0 4 votes vote down vote up
public void run() {
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration());
    if (endpoint.contains("amazonaws.com")) {
        String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket));
        if (aws_endpoint.contains("US")) {
            s3Client.setEndpoint("https://s3.amazonaws.com");
        } else if (aws_endpoint.contains("us-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("eu-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("ap-")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("sa-east-1")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else {
            s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com");
        }
    } else {
        s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());
        s3Client.setEndpoint(endpoint);
    }
    int converted_days = 0;
    if (!disabled) {
        converted_days = Integer.parseInt(days);
    }

    Transition transToArchive = new Transition()
            .withDays(converted_days)
            .withStorageClass(StorageClass.Glacier);

    BucketLifecycleConfiguration.Rule ruleArchiveAndExpire = null;
    if (!disabled) {
        ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule()
                .withPrefix(prefix)
                .withTransition(transToArchive)
                // .withExpirationInDays(converted_days + 1)
                .withStatus(BucketLifecycleConfiguration.ENABLED.toString());
    } else {
        ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule()
                .withPrefix(prefix)
                .withTransition(transToArchive)
                //.withExpirationInDays(100)
                .withStatus(BucketLifecycleConfiguration.DISABLED.toString());
    }
    List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>();
    rules.add(ruleArchiveAndExpire);

    try {
        BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration()
                .withRules(rules);
        s3Client.setBucketLifecycleConfiguration(bucket, configuration);
    } catch (Exception get) {
        mainFrame.jTextArea1.append("\n" + get.getMessage());
    }
    if (!disabled) {
        mainFrame.jTextArea1.append("\nSent request to set bucket life cycle to tier to Glacier after: " + converted_days + " day(s). Please observe for any errors.");
    } else {
        mainFrame.jTextArea1.append("\nSent request to disable the bucket life cycle. Please observe for any errors.");
    }
    calibrate();
}