Example usage for com.amazonaws.services.s3.model MultipartUploadListing setBucketName

List of usage examples for com.amazonaws.services.s3.model MultipartUploadListing setBucketName

Introduction

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

Prototype

public void setBucketName(String bucketName) 

Source Link

Document

Sets the name of the bucket containing the listed multipart uploads, as specified in the original request.

Usage

From source file:org.apache.nifi.processors.aws.s3.PutS3Object.java

License:Apache License

protected MultipartUploadListing getS3AgeoffListAndAgeoffLocalState(final ProcessContext context,
        final AmazonS3Client s3, final long now) {
    final long ageoff_interval = context.getProperty(MULTIPART_S3_AGEOFF_INTERVAL)
            .asTimePeriod(TimeUnit.MILLISECONDS);
    final String bucket = context.getProperty(BUCKET).evaluateAttributeExpressions().getValue();
    final Long maxAge = context.getProperty(MULTIPART_S3_MAX_AGE).asTimePeriod(TimeUnit.MILLISECONDS);
    final long ageCutoff = now - maxAge;

    final List<MultipartUpload> ageoffList = new ArrayList<>();
    if ((lastS3AgeOff.get() < now - ageoff_interval) && s3BucketLock.tryLock()) {
        try {//from w w w.ja v  a2s  . c  om

            ListMultipartUploadsRequest listRequest = new ListMultipartUploadsRequest(bucket);
            MultipartUploadListing listing = s3.listMultipartUploads(listRequest);
            for (MultipartUpload upload : listing.getMultipartUploads()) {
                long uploadTime = upload.getInitiated().getTime();
                if (uploadTime < ageCutoff) {
                    ageoffList.add(upload);
                }
            }

            // ageoff any local state
            ageoffLocalState(ageCutoff);
            lastS3AgeOff.set(System.currentTimeMillis());
        } catch (AmazonClientException e) {
            if (e instanceof AmazonS3Exception && ((AmazonS3Exception) e).getStatusCode() == 403
                    && ((AmazonS3Exception) e).getErrorCode().equals("AccessDenied")) {
                getLogger().warn("AccessDenied checking S3 Multipart Upload list for {}: {} "
                        + "** The configured user does not have the s3:ListBucketMultipartUploads permission "
                        + "for this bucket, S3 ageoff cannot occur without this permission.  Next ageoff check "
                        + "time is being advanced by interval to prevent checking on every upload **",
                        new Object[] { bucket, e.getMessage() });
                lastS3AgeOff.set(System.currentTimeMillis());
            } else {
                getLogger().error("Error checking S3 Multipart Upload list for {}: {}",
                        new Object[] { bucket, e.getMessage() });
            }
        } finally {
            s3BucketLock.unlock();
        }
    }
    MultipartUploadListing result = new MultipartUploadListing();
    result.setBucketName(bucket);
    result.setMultipartUploads(ageoffList);
    return result;
}