Search in sources :

Example 91 with S3ObjectSummary

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;
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) NoteInfo(org.apache.zeppelin.notebook.NoteInfo) HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

Example 92 with S3ObjectSummary

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);
    }
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

Example 93 with S3ObjectSummary

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);
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) ArrayList(java.util.ArrayList) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 94 with S3ObjectSummary

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);
}
Also used : S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 95 with S3ObjectSummary

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;
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Aggregations

S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)196 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)106 ArrayList (java.util.ArrayList)64 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)61 Test (org.junit.Test)50 Date (java.util.Date)29 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)27 ListObjectsV2Result (com.amazonaws.services.s3.model.ListObjectsV2Result)25 Test (org.testng.annotations.Test)25 AmazonS3 (com.amazonaws.services.s3.AmazonS3)23 S3Object (com.amazonaws.services.s3.model.S3Object)19 AmazonClientException (com.amazonaws.AmazonClientException)18 IOException (java.io.IOException)17 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)16 AmazonServiceException (com.amazonaws.AmazonServiceException)14 ListObjectsV2Request (com.amazonaws.services.s3.model.ListObjectsV2Request)14 File (java.io.File)13 HashMap (java.util.HashMap)13 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)13 StorageFile (org.finra.herd.model.api.xml.StorageFile)13