use of com.amazonaws.services.s3.model.S3ObjectSummary 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.S3ObjectSummary 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.S3ObjectSummary 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.S3ObjectSummary in project cloudstack by apache.
the class S3Utils method deleteDirectory.
public static void deleteDirectory(final ClientOptions clientOptions, final String bucketName, final String directoryName) {
LOGGER.debug(format("Deleting S3 Directory %1$s in bucket %2$s", directoryName, bucketName));
final List<S3ObjectSummary> objects = listDirectory(clientOptions, bucketName, directoryName);
for (final S3ObjectSummary object : objects) {
deleteObject(clientOptions, bucketName, object.getKey());
}
deleteObject(clientOptions, bucketName, directoryName);
}
use of com.amazonaws.services.s3.model.S3ObjectSummary in project cloudstack by apache.
the class NfsSecondaryStorageResource method s3ListVolume.
Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
String bucket = s3.getBucketName();
// List the objects in the source directory on S3
final List<S3ObjectSummary> objectSummaries = S3Utils.listDirectory(s3, bucket, VOLUME_ROOT_DIR);
if (objectSummaries == null) {
return null;
}
Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
for (S3ObjectSummary objectSummary : objectSummaries) {
String key = objectSummary.getKey();
// String installPath = StringUtils.substringBeforeLast(key,
// S3Utils.SEPARATOR);
Long id = determineS3VolumeIdFromKey(key);
// TODO: how to get volume template name
TemplateProp tInfo = new TemplateProp(id.toString(), key, objectSummary.getSize(), objectSummary.getSize(), true, false);
tmpltInfos.put(id, tInfo);
}
return tmpltInfos;
}
Aggregations