Java Code Examples for com.amazonaws.services.s3.AmazonS3#listMultipartUploads()

The following examples show how to use com.amazonaws.services.s3.AmazonS3#listMultipartUploads() . 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: S3Backuper.java    From cassandra-backup with Apache License 2.0 5 votes vote down vote up
private void cleanupMultipartUploads() {
    final AmazonS3 s3Client = transferManager.getAmazonS3Client();

    final Instant yesterdayInstant = ZonedDateTime.now().minusDays(1).toInstant();

    logger.info("Cleaning up multipart uploads older than {}.", yesterdayInstant);

    final ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(request.storageLocation.bucket)
        .withPrefix(request.storageLocation.clusterId + "/" + request.storageLocation.datacenterId);

    while (true) {
        final MultipartUploadListing multipartUploadListing = s3Client.listMultipartUploads(listMultipartUploadsRequest);

        multipartUploadListing.getMultipartUploads().stream()
            .filter(u -> u.getInitiated().toInstant().isBefore(yesterdayInstant))
            .forEach(u -> {
                logger.info("Aborting multi-part upload for key \"{}\" initiated on {}", u.getKey(), u.getInitiated().toInstant());

                try {
                    s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(request.storageLocation.bucket, u.getKey(), u.getUploadId()));

                } catch (final AmazonClientException e) {
                    logger.error("Failed to abort multipart upload for key \"{}\".", u.getKey(), e);
                }
            });

        if (!multipartUploadListing.isTruncated()) {
            break;
        }

        listMultipartUploadsRequest
            .withKeyMarker(multipartUploadListing.getKeyMarker())
            .withUploadIdMarker(multipartUploadListing.getUploadIdMarker());
    }
}
 
Example 2
Source File: S3OperationsImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest, AmazonS3 s3Client)
{
    return s3Client.listMultipartUploads(listMultipartUploadsRequest);
}