use of software.amazon.awssdk.services.s3.model.ListObjectsRequest 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 software.amazon.awssdk.services.s3.model.ListObjectsRequest 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 software.amazon.awssdk.services.s3.model.ListObjectsRequest 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 software.amazon.awssdk.services.s3.model.ListObjectsRequest in project ats-framework by Axway.
the class S3Operations method listBucket.
/**
* @param folderPrefix
* @param searchString what pattern to be matched. If null it means all, i.e. ".*"
* @param recursive
*
* @return
* @throws S3OperationException in case of an error from server
*/
private List<S3ObjectInfo> listBucket(String folderPrefix, String searchString, boolean recursive) {
List<S3ObjectInfo> allListElements = new ArrayList<S3ObjectInfo>();
// Alternative but not documented in S3 API: getClient().listObjectsV2(bucket, "prefix")
ListObjectsRequest request = new ListObjectsRequest(bucketName, folderPrefix, null, recursive ? null : "/", null);
try {
ObjectListing objectListing = s3Client.listObjects(request);
int i = 0;
if (searchString == null) {
// any string
searchString = ".*";
}
Pattern searchStringPattern = Pattern.compile(searchString);
while (true) {
for (Iterator<?> iterator = objectListing.getObjectSummaries().iterator(); iterator.hasNext(); ) {
S3ObjectSummary objectSummary = (S3ObjectSummary) iterator.next();
if (LOG.isTraceEnabled()) {
LOG.trace("listObjects(" + (++i) + "): " + objectSummary.toString());
}
String[] fileTokens = objectSummary.getKey().split("/");
String s3Object = fileTokens[fileTokens.length - 1];
Matcher matcher = searchStringPattern.matcher(s3Object);
if (matcher.find()) {
allListElements.add(new S3ObjectInfo(objectSummary));
}
}
// more objectListing retrieve?
if (objectListing.isTruncated()) {
objectListing = s3Client.listNextBatchOfObjects(objectListing);
} else {
break;
}
}
} catch (AmazonClientException e) {
throw new S3OperationException(e);
}
return allListElements;
}
use of software.amazon.awssdk.services.s3.model.ListObjectsRequest in project gradle by gradle.
the class S3Client method listDirectChildren.
public List<String> listDirectChildren(URI parent) {
S3RegionalResource s3RegionalResource = new S3RegionalResource(parent);
String bucketName = s3RegionalResource.getBucketName();
String s3BucketKey = s3RegionalResource.getKey();
configureClient(s3RegionalResource);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(s3BucketKey).withMaxKeys(1000).withDelimiter("/");
ObjectListing objectListing = amazonS3Client.listObjects(listObjectsRequest);
ImmutableList.Builder<String> builder = ImmutableList.builder();
builder.addAll(resourceResolver.resolveResourceNames(objectListing));
while (objectListing.isTruncated()) {
objectListing = amazonS3Client.listNextBatchOfObjects(objectListing);
builder.addAll(resourceResolver.resolveResourceNames(objectListing));
}
return builder.build();
}
Aggregations