Example usage for com.amazonaws.services.s3.model S3VersionSummary isDeleteMarker

List of usage examples for com.amazonaws.services.s3.model S3VersionSummary isDeleteMarker

Introduction

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

Prototype

boolean isDeleteMarker

To view the source code for com.amazonaws.services.s3.model S3VersionSummary isDeleteMarker.

Click Source Link

Document

True if this object represents a delete marker

Usage

From source file:com.emc.ecs.sync.util.AwsS3Util.java

License:Open Source License

public static ListIterator<S3ObjectVersion> listVersions(SyncPlugin parentPlugin, AmazonS3 s3, String bucket,
        String key, String relativePath) {
    List<S3ObjectVersion> versions = new ArrayList<>();

    VersionListing listing = null;/*from   w ww.ja va2 s.  c om*/
    do {
        if (listing == null)
            listing = s3.listVersions(bucket, key, null, null, "/", null);
        else
            listing = s3.listNextBatchOfVersions(listing);

        for (S3VersionSummary summary : listing.getVersionSummaries()) {

            if (summary.getKey().equals(key)) {
                versions.add(new S3ObjectVersion(parentPlugin, s3, bucket, key, summary.getVersionId(),
                        summary.isLatest(), summary.isDeleteMarker(), summary.getLastModified(),
                        summary.getETag(), relativePath, summary.getSize()));
            }
        }
    } while (listing.isTruncated());

    // sort chronologically
    Collections.sort(versions, new VersionComparator());
    return versions.listIterator();
}

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 {//from ww w . j  a va2s  .c o m
        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 void tagVersions(final S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto,
        final S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto,
        final List<S3VersionSummary> s3VersionSummaries, final Tag tag) {
    // Eliminate delete markers from the list of version summaries to be tagged.
    List<S3VersionSummary> s3VersionSummariesWithoutDeleteMarkers = null;
    if (CollectionUtils.isNotEmpty(s3VersionSummaries)) {
        s3VersionSummariesWithoutDeleteMarkers = s3VersionSummaries.stream()
                .filter(s3VersionSummary -> !s3VersionSummary.isDeleteMarker()).collect(Collectors.toList());
    }/*from w ww  . j a v a2s .  com*/

    LOGGER.info(
            "Tagging versions in S3... s3BucketName=\"{}\" s3KeyPrefix=\"{}\" s3VersionCount={} s3ObjectTagKey=\"{}\" s3ObjectTagValue=\"{}\" "
                    + "Excluding from tagging S3 delete markers... s3DeleteMarkerCount={}",
            s3FileTransferRequestParamsDto.getS3BucketName(), s3FileTransferRequestParamsDto.getS3KeyPrefix(),
            CollectionUtils.size(s3VersionSummariesWithoutDeleteMarkers), tag.getKey(), tag.getValue(),
            CollectionUtils.size(s3VersionSummaries)
                    - CollectionUtils.size(s3VersionSummariesWithoutDeleteMarkers));

    if (CollectionUtils.isNotEmpty(s3VersionSummariesWithoutDeleteMarkers)) {
        // Tag S3 versions.
        tagVersionsHelper(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto,
                s3VersionSummariesWithoutDeleteMarkers, tag);

        // Log a list of S3 versions that got tagged.
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Successfully tagged versions in S3 bucket. "
                    + "s3BucketName=\"{}\" s3KeyPrefix=\"{}\" s3VersionCount={} s3ObjectTagKey=\"{}\" s3ObjectTagValue=\"{}\"",
                    s3FileTransferRequestParamsDto.getS3BucketName(),
                    s3FileTransferRequestParamsDto.getS3KeyPrefix(),
                    s3VersionSummariesWithoutDeleteMarkers.size(), tag.getKey(), tag.getValue());

            for (S3VersionSummary s3VersionSummary : s3VersionSummariesWithoutDeleteMarkers) {
                LOGGER.info("s3Key=\"{}\" s3VersionId=\"{}\"", s3VersionSummary.getKey(),
                        s3VersionSummary.getVersionId());
            }
        }
    }
}