Example usage for com.amazonaws.services.s3.transfer TransferManager appendSingleObjectUserAgent

List of usage examples for com.amazonaws.services.s3.transfer TransferManager appendSingleObjectUserAgent

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.transfer TransferManager appendSingleObjectUserAgent.

Prototype

public static <X extends AmazonWebServiceRequest> X appendSingleObjectUserAgent(X request) 

Source Link

Usage

From source file:org.finra.dm.dao.impl.S3DaoImpl.java

License:Apache License

/**
 * {@inheritDoc}//from w  ww  . j a  v a  2s. co m
 */
@Override
public int abortMultipartUploads(S3FileTransferRequestParamsDto params, Date thresholdDate) {
    AmazonS3Client s3Client = null;
    int abortedMultipartUploadsCount = 0;

    try {
        // Create an Amazon S3 client.
        s3Client = getAmazonS3(params);

        // List upload markers. Null implies initial list request.
        String uploadIdMarker = null;
        String keyMarker = null;

        boolean truncated;
        do {
            // Create the list multipart request, optionally using the last markers.
            ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(params.getS3BucketName());
            request.setUploadIdMarker(uploadIdMarker);
            request.setKeyMarker(keyMarker);

            // Request the multipart upload listing.
            MultipartUploadListing uploadListing = s3Operations
                    .listMultipartUploads(TransferManager.appendSingleObjectUserAgent(request), s3Client);

            for (MultipartUpload upload : uploadListing.getMultipartUploads()) {
                if (upload.getInitiated().compareTo(thresholdDate) < 0) {
                    // Abort the upload.
                    s3Operations.abortMultipartUpload(
                            TransferManager.appendSingleObjectUserAgent(new AbortMultipartUploadRequest(
                                    params.getS3BucketName(), upload.getKey(), upload.getUploadId())),
                            s3Client);

                    // Log the information about the aborted multipart upload.
                    LOGGER.info(String.format(
                            "Aborted S3 multipart upload for \"%s\" object key initiated at [%s] in \"%s\" S3 bucket.",
                            upload.getKey(), upload.getInitiated(), params.getS3BucketName()));

                    // Increment the counter.
                    abortedMultipartUploadsCount++;
                }
            }

            // Determine whether there are more uploads to list.
            truncated = uploadListing.isTruncated();
            if (truncated) {
                // Record the list markers.
                uploadIdMarker = uploadListing.getUploadIdMarker();
                keyMarker = uploadListing.getKeyMarker();
            }
        } while (truncated);
    } finally {
        // Shutdown the Amazon S3 client instance to release resources.
        if (s3Client != null) {
            s3Client.shutdown();
        }
    }

    return abortedMultipartUploadsCount;
}

From source file:org.finra.herd.dao.impl.S3DaoImpl.java

License:Apache License

@Override
public int abortMultipartUploads(S3FileTransferRequestParamsDto params, Date thresholdDate) {
    // Create an Amazon S3 client.
    AmazonS3Client s3Client = getAmazonS3(params);
    int abortedMultipartUploadsCount = 0;

    try {//w w w  . j av  a 2s. c o  m
        // List upload markers. Null implies initial list request.
        String uploadIdMarker = null;
        String keyMarker = null;

        boolean truncated;
        do {
            // Create the list multipart request, optionally using the last markers.
            ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(params.getS3BucketName());
            request.setUploadIdMarker(uploadIdMarker);
            request.setKeyMarker(keyMarker);

            // Request the multipart upload listing.
            MultipartUploadListing uploadListing = s3Operations
                    .listMultipartUploads(TransferManager.appendSingleObjectUserAgent(request), s3Client);

            for (MultipartUpload upload : uploadListing.getMultipartUploads()) {
                if (upload.getInitiated().compareTo(thresholdDate) < 0) {
                    // Abort the upload.
                    s3Operations.abortMultipartUpload(
                            TransferManager.appendSingleObjectUserAgent(new AbortMultipartUploadRequest(
                                    params.getS3BucketName(), upload.getKey(), upload.getUploadId())),
                            s3Client);

                    // Log the information about the aborted multipart upload.
                    LOGGER.info(
                            "Aborted S3 multipart upload. s3Key=\"{}\" s3BucketName=\"{}\" s3MultipartUploadInitiatedDate=\"{}\"",
                            upload.getKey(), params.getS3BucketName(), upload.getInitiated());

                    // Increment the counter.
                    abortedMultipartUploadsCount++;
                }
            }

            // Determine whether there are more uploads to list.
            truncated = uploadListing.isTruncated();
            if (truncated) {
                // Record the list markers.
                uploadIdMarker = uploadListing.getNextUploadIdMarker();
                keyMarker = uploadListing.getNextKeyMarker();
            }
        } while (truncated);
    } finally {
        // Shutdown the Amazon S3 client instance to release resources.
        s3Client.shutdown();
    }

    return abortedMultipartUploadsCount;
}