List of usage examples for com.amazonaws.services.s3.model ListVersionsRequest ListVersionsRequest
public ListVersionsRequest(String bucketName, String prefix, String keyMarker, String versionIdMarker,
String delimiter, Integer maxResults)
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 w w w . ja va 2s . 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:com.netflix.spinnaker.front50.model.S3StorageService.java
License:Apache License
@Override public <T extends Timestamped> Collection<T> listObjectVersions(ObjectType objectType, String objectKey, int maxResults) throws NotFoundException { try {//w w w . j a va2s . c o m VersionListing versionListing = amazonS3.listVersions(new ListVersionsRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), null, null, null, maxResults)); return versionListing.getVersionSummaries().stream().map(s3VersionSummary -> { try { S3Object s3Object = amazonS3.getObject(new GetObjectRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), s3VersionSummary.getVersionId())); T item = deserialize(s3Object, (Class<T>) objectType.clazz); item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime()); return item; } catch (IOException e) { throw new IllegalStateException(e); } }).collect(Collectors.toList()); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { throw new NotFoundException(String.format("No item found with id of %s", objectKey.toLowerCase())); } throw e; } }
From source file:com.netflix.spinnaker.front50.model.S3Support.java
License:Apache License
public Collection<T> allVersionsOf(String id, int limit) throws NotFoundException { try {/*from ww w .ja va2 s . c om*/ VersionListing versionListing = amazonS3 .listVersions(new ListVersionsRequest(bucket, buildS3Key(id), null, null, null, limit)); return versionListing.getVersionSummaries().stream().map(s3VersionSummary -> { try { S3Object s3Object = amazonS3.getObject( new GetObjectRequest(bucket, buildS3Key(id), s3VersionSummary.getVersionId())); T item = deserialize(s3Object); item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime()); return item; } catch (IOException e) { throw new IllegalStateException(e); } }).collect(Collectors.toList()); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { throw new NotFoundException(String.format("No item found with id of %s", id.toLowerCase())); } throw e; } }
From source file:org.mule.module.s3.S3Connector.java
License:Open Source License
/** * Lazily lists all object versions for a given bucket that has versioning * enabled. As S3 does not limit in any way the number of objects, such * listing can retrieve an arbitrary amount of object versions, and may need * to perform extra calls to the api while it is iterated. * * {@sample.xml ../../../doc/mule-module-s3.xml.sample * s3:list-object-versions}/* www . ja va 2 s .c om*/ * * @param bucketName * the target bucket's name * @param prefix * optional parameter restricting the response to keys which * begin with the specified prefix. You can use prefixes to * separate a bucket into different sets of keys in a way similar * to how a file system uses folders. * @param keyMarker * where in the sorted list of all versions in the specified * bucket to begin returning results. Results are always ordered * first lexicographically (i.e. alphabetically) and then from * most recent version to least recent version. If a keyMarker is * used without a versionIdMarker, results begin immediately * after that key's last version. When a keyMarker is used with a * versionIdMarker, results begin immediately after the version * with the specified key and version ID. * @param versionIdMarker * where in the sorted list of all versions in the specified * bucket to begin returning results. Results are always ordered * first lexicographically (i.e. alphabetically) and then from * most recent version to least recent version. A keyMarker must * be specified when specifying a versionIdMarker. Results begin * immediately after the version with the specified key and * version ID. * @param delimiter * causes keys that contain the same string between the prefix * and the first occurrence of the delimiter to be rolled up into * a single result element in the * {@link VersionListing#getCommonPrefixes()} list. These * rolled-up keys are not returned elsewhere in the response. The * most commonly used delimiter is "/", which simulates a * hierarchical organization similar to a file system directory * structure. * @param maxResults * the maximum number of results to include in the response. * @param encodingType * the encoding method to be applied on the response. An object * key can contain any Unicode character; however, XML 1.0 parser * cannot parse some characters, such as characters with an ASCII * value from 0 to 10. For characters that are not supported in * XML 1.0, you can add this parameter to request that Amazon S3 * encode the keys in the response. * @return An iterable */ @Processor public Iterable<S3VersionSummary> listObjectVersions(String bucketName, @Optional String prefix, @Optional String keyMarker, @Optional String versionIdMarker, @Optional String delimiter, @Optional Integer maxResults, @Default("NOT_ENCODED") EncodingType encodingType) { String sdkEncoding = null; if (encodingType != null) { sdkEncoding = encodingType.sdkValue(); } ListVersionsRequest request = new ListVersionsRequest(bucketName, prefix, keyMarker, versionIdMarker, delimiter, maxResults).withEncodingType(sdkEncoding); return client.listObjectVersions(request); }