Example usage for com.amazonaws.services.s3.model VersionListing getNextVersionIdMarker

List of usage examples for com.amazonaws.services.s3.model VersionListing getNextVersionIdMarker

Introduction

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

Prototype

public String getNextVersionIdMarker() 

Source Link

Document

Gets the version ID marker to use in the next listVersions request in order to obtain the next page of results.

Usage

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

License:Open Source License

@Override
public ListVersionsResponseType listVersions(ListVersionsType request) throws S3Exception {
    ListVersionsResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    try {// w  w w.j  a  v  a  2 s .c om
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        ListVersionsRequest listVersionsRequest = new ListVersionsRequest(request.getBucket(),
                request.getPrefix(), request.getKeyMarker(), request.getVersionIdMarker(),
                request.getDelimiter(), Integer.parseInt(request.getMaxKeys()));
        VersionListing result = s3Client.listVersions(listVersionsRequest);

        CanonicalUser owner;
        try {
            owner = AclUtils.buildCanonicalUser(requestUser.getAccount());
        } catch (AuthException e) {
            LOG.error("Error getting request user's account during bucket version listing", e);
            owner = null;
            throw new AccountProblemException("Account for user " + requestUser.getUserId());
        }

        //Populate result to euca
        reply.setBucket(request.getBucket());
        reply.setMaxKeys(result.getMaxKeys());
        reply.setDelimiter(result.getDelimiter());
        reply.setNextKeyMarker(result.getNextKeyMarker());
        reply.setNextVersionIdMarker(result.getNextVersionIdMarker());
        reply.setIsTruncated(result.isTruncated());
        reply.setVersionIdMarker(result.getVersionIdMarker());
        reply.setKeyMarker(result.getKeyMarker());

        if (result.getCommonPrefixes() != null && result.getCommonPrefixes().size() > 0) {
            reply.setCommonPrefixesList(new ArrayList<CommonPrefixesEntry>());

            for (String s : result.getCommonPrefixes()) {
                reply.getCommonPrefixesList().add(new CommonPrefixesEntry(s));
            }
        }

        ArrayList<KeyEntry> versions = new ArrayList<>();
        VersionEntry v;
        DeleteMarkerEntry d;
        for (S3VersionSummary summary : result.getVersionSummaries()) {
            if (!summary.isDeleteMarker()) {
                v = new VersionEntry();
                v.setKey(summary.getKey());
                v.setVersionId(summary.getVersionId());
                v.setLastModified(DateFormatter.dateToHeaderFormattedString(summary.getLastModified()));
                v.setEtag(summary.getETag());
                v.setIsLatest(summary.isLatest());
                v.setOwner(owner);
                v.setSize(summary.getSize());
                versions.add(v);
            } else {
                d = new DeleteMarkerEntry();
                d.setIsLatest(summary.isLatest());
                d.setKey(summary.getKey());
                d.setLastModified(DateFormatter.dateToHeaderFormattedString(summary.getLastModified()));
                d.setOwner(owner);
                d.setVersionId(summary.getVersionId());
                versions.add(d);
            }
        }
        //Again, this is wrong, should be a single listing
        reply.setKeyEntries(versions);
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }

    return reply;
}

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

License:Apache License

@Override
public List<S3VersionSummary> listVersions(final S3FileTransferRequestParamsDto params) {
    Assert.isTrue(!isRootKeyPrefix(params.getS3KeyPrefix()),
            "Listing of S3 versions from root directory is not allowed.");

    AmazonS3Client s3Client = getAmazonS3(params);
    List<S3VersionSummary> s3VersionSummaries = new ArrayList<>();

    try {//from  w w w. jav  a2  s  .  com
        ListVersionsRequest listVersionsRequest = new ListVersionsRequest()
                .withBucketName(params.getS3BucketName()).withPrefix(params.getS3KeyPrefix());
        VersionListing versionListing;

        do {
            versionListing = s3Operations.listVersions(listVersionsRequest, s3Client);
            s3VersionSummaries.addAll(versionListing.getVersionSummaries());
            listVersionsRequest.setKeyMarker(versionListing.getNextKeyMarker());
            listVersionsRequest.setVersionIdMarker(versionListing.getNextVersionIdMarker());
        } while (versionListing.isTruncated());
    } catch (AmazonS3Exception amazonS3Exception) {
        if (S3Operations.ERROR_CODE_NO_SUCH_BUCKET.equals(amazonS3Exception.getErrorCode())) {
            throw new IllegalArgumentException(
                    "The specified bucket '" + params.getS3BucketName() + "' does not exist.",
                    amazonS3Exception);
        }
        throw new IllegalStateException("Error accessing S3", amazonS3Exception);
    } catch (AmazonClientException e) {
        throw new IllegalStateException(
                String.format("Failed to list S3 versions with prefix \"%s\" from bucket \"%s\". Reason: %s",
                        params.getS3KeyPrefix(), params.getS3BucketName(), e.getMessage()),
                e);
    } finally {
        // Shutdown the AmazonS3Client instance to release resources.
        s3Client.shutdown();
    }

    return s3VersionSummaries;
}