Search in sources :

Example 6 with ListObjectsRequest

use of com.amazonaws.services.s3.model.ListObjectsRequest in project hadoop by apache.

the class S3AFileSystem method createListObjectsRequest.

/**
   * Create a {@code ListObjectsRequest} request against this bucket,
   * with the maximum keys returned in a query set by {@link #maxKeys}.
   * @param key key for request
   * @param delimiter any delimiter
   * @return the request
   */
private ListObjectsRequest createListObjectsRequest(String key, String delimiter) {
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucket);
    request.setMaxKeys(maxKeys);
    request.setPrefix(key);
    if (delimiter != null) {
        request.setDelimiter(delimiter);
    }
    return request;
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest)

Example 7 with ListObjectsRequest

use of com.amazonaws.services.s3.model.ListObjectsRequest in project jackrabbit-oak by apache.

the class S3Backend method deleteAllMetadataRecords.

public void deleteAllMetadataRecords(String prefix) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(addMetaKeyPrefix(prefix));
        ObjectListing metaList = s3service.listObjects(listObjectsRequest);
        List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
        for (S3ObjectSummary s3ObjSumm : metaList.getObjectSummaries()) {
            deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey()));
        }
        if (deleteList.size() > 0) {
            DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
            delObjsReq.setKeys(deleteList);
            DeleteObjectsResult dobjs = s3service.deleteObjects(delObjsReq);
        }
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
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) DeleteObjectsResult(com.amazonaws.services.s3.model.DeleteObjectsResult) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest)

Example 8 with ListObjectsRequest

use of com.amazonaws.services.s3.model.ListObjectsRequest in project jackrabbit-oak by apache.

the class S3Backend method deleteAllMetadataRecords.

@Override
public void deleteAllMetadataRecords(String prefix) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(addMetaKeyPrefix(prefix));
        ObjectListing metaList = s3service.listObjects(listObjectsRequest);
        List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
        for (S3ObjectSummary s3ObjSumm : metaList.getObjectSummaries()) {
            deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey()));
        }
        if (deleteList.size() > 0) {
            DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
            delObjsReq.setKeys(deleteList);
            s3service.deleteObjects(delObjsReq);
        }
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
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) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest)

Example 9 with ListObjectsRequest

use of com.amazonaws.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);
}
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 10 with ListObjectsRequest

use of com.amazonaws.services.s3.model.ListObjectsRequest in project exhibitor by soabase.

the class S3PseudoLock method getFileNames.

@Override
protected List<String> getFileNames(String lockPrefix) throws Exception {
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucket);
    request.setPrefix(lockPrefix);
    ObjectListing objectListing = client.listObjects(request);
    return Lists.transform(objectListing.getObjectSummaries(), new Function<S3ObjectSummary, String>() {

        @Override
        public String apply(S3ObjectSummary summary) {
            return summary.getKey();
        }
    });
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Aggregations

ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)21 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)20 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)15 ArrayList (java.util.ArrayList)11 Path (org.apache.hadoop.fs.Path)5 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)4 IOException (java.io.IOException)4 AmazonClientException (com.amazonaws.AmazonClientException)3 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 FileNotFoundException (java.io.FileNotFoundException)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)3 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DataRecord (org.apache.jackrabbit.core.data.DataRecord)2 AerospikeHandler (com.aerospike.redisson.AerospikeHandler)1 RedissonClient (com.aerospike.redisson.RedissonClient)1