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

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

Introduction

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

Prototype

public String getNextKeyMarker() 

Source Link

Document

Returns the next key marker that should be used in the next request to get the next page of results.

Usage

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public ListMultipartUploadsResponseType listMultipartUploads(ListMultipartUploadsType request)
        throws S3Exception {
    ListMultipartUploadsResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    String bucketName = request.getBucket();
    ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(bucketName);
    listMultipartUploadsRequest.setMaxUploads(request.getMaxUploads());
    listMultipartUploadsRequest.setKeyMarker(request.getKeyMarker());
    listMultipartUploadsRequest.setDelimiter(request.getDelimiter());
    listMultipartUploadsRequest.setPrefix(request.getPrefix());
    listMultipartUploadsRequest.setUploadIdMarker(request.getUploadIdMarker());
    try {// w  w w . ja v  a 2  s .c o m
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();

        MultipartUploadListing listing = s3Client.listMultipartUploads(listMultipartUploadsRequest);
        reply.setBucket(listing.getBucketName());
        reply.setKeyMarker(listing.getKeyMarker());
        reply.setUploadIdMarker(listing.getUploadIdMarker());
        reply.setNextKeyMarker(listing.getNextKeyMarker());
        reply.setNextUploadIdMarker(listing.getNextUploadIdMarker());
        reply.setMaxUploads(listing.getMaxUploads());
        reply.setIsTruncated(listing.isTruncated());
        reply.setPrefix(listing.getPrefix());
        reply.setDelimiter(listing.getDelimiter());

        List<String> commonPrefixes = listing.getCommonPrefixes();
        List<MultipartUpload> multipartUploads = listing.getMultipartUploads();

        List<com.eucalyptus.storage.msgs.s3.Upload> uploads = reply.getUploads();
        List<CommonPrefixesEntry> prefixes = reply.getCommonPrefixes();

        for (MultipartUpload multipartUpload : multipartUploads) {
            uploads.add(new com.eucalyptus.storage.msgs.s3.Upload(multipartUpload.getKey(),
                    multipartUpload.getUploadId(),
                    new Initiator(multipartUpload.getInitiator().getId(),
                            multipartUpload.getInitiator().getDisplayName()),
                    new CanonicalUser(multipartUpload.getOwner().getId(),
                            multipartUpload.getOwner().getDisplayName()),
                    multipartUpload.getStorageClass(), multipartUpload.getInitiated()));
        }
        for (String commonPrefix : commonPrefixes) {
            prefixes.add(new CommonPrefixesEntry(commonPrefix));
        }
        return reply;
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
}

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 {//from   w  w  w.j  a v  a  2  s .  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;
}