use of com.netflix.spinnaker.front50.api.model.Timestamped in project front50 by spinnaker.
the class AzureStorageService method listObjectVersions.
@Override
public <T extends Timestamped> Collection<T> listObjectVersions(ObjectType objectType, String objectKey, int maxResults) throws NotFoundException {
Set<T> results = new HashSet<>();
String fullKey = buildKeyPath(objectType.group, objectKey, objectType.defaultMetadataFilename);
try {
ResultContinuation token = null;
EnumSet<BlobListingDetails> listDetails = EnumSet.of(BlobListingDetails.SNAPSHOTS);
do {
ResultSegment<ListBlobItem> result = getBlobContainer().listBlobsSegmented(fullKey, true, listDetails, NUM_OF_SNAPSHOT_LIMITATION, token, null, null);
token = result.getContinuationToken();
// By default, listBlobsSegmented with maxResult parameter will return oldest blob snapshots
// But here we want the latest blob snapshots, and storage sdk doesn't provide a way to get
// latest number of snapshots
// So fetch all and then do sort and filter work (SnapshotID == null means the latest one)
List<CloudBlockBlob> filteredResults = result.getResults().stream().map(item -> (CloudBlockBlob) item).sorted((a, b) -> {
if (a.getSnapshotID() == null)
return -1;
if (b.getSnapshotID() == null)
return 1;
return b.getSnapshotID().compareTo(a.getSnapshotID());
}).limit(maxResults).collect(Collectors.toList());
for (ListBlobItem item : filteredResults) {
CloudBlockBlob blob = (CloudBlockBlob) item;
T blobObject = deserialize(blob, (Class<T>) objectType.clazz);
blobObject.setLastModified(blob.getProperties().getLastModified().getTime());
results.add(blobObject);
}
} while (token != null);
} catch (StorageException se) {
logStorageException(se, fullKey);
} catch (Exception e) {
log.error("Error retrieving versions for {} object: {}", value("key", fullKey), value("exception", e.getMessage()));
}
return results;
}
use of com.netflix.spinnaker.front50.api.model.Timestamped in project front50 by spinnaker.
the class S3StorageService method listObjectVersions.
@Override
public <T extends Timestamped> Collection<T> listObjectVersions(ObjectType objectType, String objectKey, int maxResults) throws NotFoundException {
if (maxResults == 1) {
List<T> results = new ArrayList<>();
results.add(loadObject(objectType, objectKey));
return results;
}
try {
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;
}
}
Aggregations