use of com.amazonaws.services.s3.model.ObjectListing in project crate by crate.
the class S3BlobContainer method delete.
@Override
public void delete() throws IOException {
try (AmazonS3Reference clientReference = blobStore.clientReference()) {
ObjectListing prevListing = null;
while (true) {
ObjectListing list;
if (prevListing != null) {
final ObjectListing finalPrevListing = prevListing;
list = clientReference.client().listNextBatchOfObjects(finalPrevListing);
} else {
final ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(blobStore.bucket());
listObjectsRequest.setPrefix(keyPath);
list = clientReference.client().listObjects(listObjectsRequest);
}
final List<String> blobsToDelete = list.getObjectSummaries().stream().map(S3ObjectSummary::getKey).collect(Collectors.toList());
if (list.isTruncated()) {
doDeleteBlobs(blobsToDelete, false);
prevListing = list;
} else {
final List<String> lastBlobsToDelete = new ArrayList<>(blobsToDelete);
lastBlobsToDelete.add(keyPath);
doDeleteBlobs(lastBlobsToDelete, false);
break;
}
}
} catch (final AmazonClientException e) {
throw new IOException("Exception when deleting blob container [" + keyPath + "]", e);
}
}
use of com.amazonaws.services.s3.model.ObjectListing in project zeppelin by apache.
the class S3NotebookRepo method list.
@Override
public Map<String, NoteInfo> list(AuthenticationInfo subject) throws IOException {
Map<String, NoteInfo> notesInfo = new HashMap<>();
try {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(user + "/" + "notebook");
ObjectListing objectListing;
do {
objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
if (objectSummary.getKey().endsWith(".zpln")) {
try {
NoteInfo info = getNoteInfo(objectSummary.getKey());
notesInfo.put(info.getId(), info);
} catch (IOException e) {
LOGGER.warn(e.getMessage());
}
}
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
} catch (AmazonClientException ace) {
throw new IOException("Fail to list objects in S3", ace);
}
return notesInfo;
}
use of com.amazonaws.services.s3.model.ObjectListing in project zeppelin by apache.
the class S3NotebookRepo method move.
@Override
public void move(String folderPath, String newFolderPath, AuthenticationInfo subject) throws IOException {
try {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(rootFolder + folderPath + "/");
ObjectListing objectListing;
do {
objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
if (objectSummary.getKey().endsWith(".zpln")) {
String noteId = getNoteId(objectSummary.getKey());
String notePath = getNotePath(rootFolder, objectSummary.getKey());
String newNotePath = newFolderPath + notePath.substring(folderPath.length());
move(noteId, notePath, newNotePath, subject);
}
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
} catch (AmazonClientException ace) {
throw new IOException("Fail to move folder: " + folderPath + " to " + newFolderPath + " in S3", ace);
}
}
use of com.amazonaws.services.s3.model.ObjectListing in project cloudstack by apache.
the class S3Utils method listDirectory.
public static List<S3ObjectSummary> listDirectory(final ClientOptions clientOptions, final String bucketName, final String directory) {
LOGGER.debug(format("Listing S3 directory %1$s in bucket %2$s", directory, bucketName));
List<S3ObjectSummary> objects = new ArrayList<>();
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.withBucketName(bucketName);
listObjectsRequest.withPrefix(directory);
ObjectListing ol = getAmazonS3Client(clientOptions).listObjects(listObjectsRequest);
if (ol.isTruncated()) {
do {
objects.addAll(ol.getObjectSummaries());
listObjectsRequest.setMarker(ol.getNextMarker());
ol = getAmazonS3Client(clientOptions).listObjects(listObjectsRequest);
} while (ol.isTruncated());
} else {
objects.addAll(ol.getObjectSummaries());
}
if (objects.isEmpty()) {
return emptyList();
}
return unmodifiableList(objects);
}
use of com.amazonaws.services.s3.model.ObjectListing in project alluxio by Alluxio.
the class S3AUnderFileSystem method getObjectListingChunkV1.
// Get next chunk of listing result.
private ObjectListing getObjectListingChunkV1(ListObjectsRequest request) throws IOException {
ObjectListing result;
try {
// Query S3 for the next batch of objects.
result = mClient.listObjects(request);
// Advance the request continuation token to the next set of objects.
request.setMarker(result.getNextMarker());
} catch (AmazonClientException e) {
throw new IOException(e);
}
return result;
}
Aggregations