Search in sources :

Example 26 with S3ObjectSummary

use of com.amazonaws.services.s3.model.S3ObjectSummary in project XRTB by benmfaul.

the class Configuration method processDirectory.

public void processDirectory(AmazonS3Client s3, ObjectListing listing, String bucket) throws Exception {
    for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
        long size = objectSummary.getSize();
        System.out.println("*** Processing S3 " + objectSummary.getKey() + ", size = " + size);
        S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));
        String bucketName = object.getBucketName();
        String keyName = object.getKey();
        if (keyName.contains("Darren")) {
            System.out.println("HERE");
        }
        GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucketName, keyName);
        GetObjectTaggingResult result = s3.getObjectTagging(request);
        List<Tag> tags = result.getTagSet();
        String type = null;
        String name = null;
        if (tags.isEmpty()) {
            System.err.println("Error: " + keyName + " has no tags");
        } else {
            for (Tag tag : tags) {
                String key = tag.getKey();
                String value = tag.getValue();
                if (key.equals("type")) {
                    type = value;
                }
                if (key.equals("name")) {
                    name = value;
                }
            }
            if (name == null)
                throw new Exception("Error: " + keyName + " is missing a name tag");
            if (name.contains(" "))
                throw new Exception("Error: " + keyName + " has a name attribute with a space in it");
            if (type == null)
                throw new Exception("Error: " + keyName + " has no type tag");
            if (!name.startsWith("$"))
                name = "$" + name;
            readData(type, name, object, size);
        }
    }
}
Also used : GetObjectTaggingRequest(com.amazonaws.services.s3.model.GetObjectTaggingRequest) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) S3Object(com.amazonaws.services.s3.model.S3Object) GeoTag(com.xrtb.geo.GeoTag) Tag(com.amazonaws.services.s3.model.Tag) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) GetObjectTaggingResult(com.amazonaws.services.s3.model.GetObjectTaggingResult)

Example 27 with S3ObjectSummary

use of com.amazonaws.services.s3.model.S3ObjectSummary in project aws-doc-sdk-examples by awsdocs.

the class ListObjects method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of a bucket to list!\n" + "\n" + "Ex: ListObjects <bucket-name>\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucket_name = args[0];
    System.out.format("Objects in S3 bucket %s:\n", bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    ObjectListing ol = s3.listObjects(bucket_name);
    List<S3ObjectSummary> objects = ol.getObjectSummaries();
    for (S3ObjectSummary os : objects) {
        System.out.println("* " + os.getKey());
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 28 with S3ObjectSummary

use of com.amazonaws.services.s3.model.S3ObjectSummary in project aws-doc-sdk-examples by awsdocs.

the class DeleteBucket method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket\n" + "\n" + "Ex: DeleteBucket <bucketname>\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucket_name = args[0];
    System.out.println("Deleting S3 bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        System.out.println(" - removing objects from bucket");
        ObjectListing object_listing = s3.listObjects(bucket_name);
        while (true) {
            for (Iterator<?> iterator = object_listing.getObjectSummaries().iterator(); iterator.hasNext(); ) {
                S3ObjectSummary summary = (S3ObjectSummary) iterator.next();
                s3.deleteObject(bucket_name, summary.getKey());
            }
            // more object_listing to retrieve?
            if (object_listing.isTruncated()) {
                object_listing = s3.listNextBatchOfObjects(object_listing);
            } else {
                break;
            }
        }
        ;
        System.out.println(" - removing versions from bucket");
        VersionListing version_listing = s3.listVersions(new ListVersionsRequest().withBucketName(bucket_name));
        while (true) {
            for (Iterator<?> iterator = version_listing.getVersionSummaries().iterator(); iterator.hasNext(); ) {
                S3VersionSummary vs = (S3VersionSummary) iterator.next();
                s3.deleteVersion(bucket_name, vs.getKey(), vs.getVersionId());
            }
            if (version_listing.isTruncated()) {
                version_listing = s3.listNextBatchOfVersions(version_listing);
            } else {
                break;
            }
        }
        System.out.println(" OK, bucket ready to delete!");
        s3.deleteBucket(bucket_name);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) VersionListing(com.amazonaws.services.s3.model.VersionListing) S3VersionSummary(com.amazonaws.services.s3.model.S3VersionSummary) AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ListVersionsRequest(com.amazonaws.services.s3.model.ListVersionsRequest)

Example 29 with S3ObjectSummary

use of com.amazonaws.services.s3.model.S3ObjectSummary in project zeppelin by apache.

the class S3NotebookRepo method remove.

@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
    String key = user + "/" + "notebook" + "/" + noteId;
    final ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(key);
    try {
        ObjectListing objects = s3client.listObjects(listObjectsRequest);
        do {
            for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
                s3client.deleteObject(bucketName, objectSummary.getKey());
            }
            objects = s3client.listNextBatchOfObjects(objects);
        } while (objects.isTruncated());
    } catch (AmazonClientException ace) {
        throw new IOException("Unable to remove note in S3: " + ace, 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 30 with S3ObjectSummary

use of com.amazonaws.services.s3.model.S3ObjectSummary in project YCSB by brianfrankcooper.

the class S3Client method scanFromStorage.

/**
  * Perform an emulation of a database scan operation on a S3 bucket.
  *
  * @param bucket
  *            The name of the bucket
  * @param startkey
  *            The file key of the first file to read.
  * @param recordcount
  *            The number of files to read
  * @param fields
  *            The list of fields to read, or null for all of them
  * @param result
  *            A Vector of HashMaps, where each HashMap is a set field/value
  *            pairs for one file
  *
  */
protected Status scanFromStorage(String bucket, String startkey, int recordcount, Vector<HashMap<String, ByteIterator>> result, SSECustomerKey ssecLocal) {
    int counter = 0;
    ObjectListing listing = s3Client.listObjects(bucket);
    List<S3ObjectSummary> summaries = listing.getObjectSummaries();
    List<String> keyList = new ArrayList();
    int startkeyNumber = 0;
    int numberOfIteration = 0;
    // getting the list of files in the bucket
    while (listing.isTruncated()) {
        listing = s3Client.listNextBatchOfObjects(listing);
        summaries.addAll(listing.getObjectSummaries());
    }
    for (S3ObjectSummary summary : summaries) {
        String summaryKey = summary.getKey();
        keyList.add(summaryKey);
    }
    // Sorting the list of files in Alphabetical order
    // sorting the list
    Collections.sort(keyList);
    // Getting the position of the startingfile for the scan
    for (String key : keyList) {
        if (key.equals(startkey)) {
            startkeyNumber = counter;
        } else {
            counter = counter + 1;
        }
    }
    // if not using the total number of Files
    if (recordcount < keyList.size()) {
        numberOfIteration = recordcount;
    } else {
        numberOfIteration = keyList.size();
    }
    // of the Files or Till the recordcount number
    for (int i = startkeyNumber; i < numberOfIteration; i++) {
        HashMap<String, ByteIterator> resultTemp = new HashMap<String, ByteIterator>();
        readFromStorage(bucket, keyList.get(i), resultTemp, ssecLocal);
        result.add(resultTemp);
    }
    return Status.OK;
}
Also used : ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Aggregations

S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)46 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)37 ArrayList (java.util.ArrayList)19 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)14 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)13 AmazonS3 (com.amazonaws.services.s3.AmazonS3)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)8 AmazonClientException (com.amazonaws.AmazonClientException)7 DeleteObjectsResult (com.amazonaws.services.s3.model.DeleteObjectsResult)6 Properties (java.util.Properties)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 Path (org.apache.hadoop.fs.Path)5 IOException (java.io.IOException)4 Test (org.junit.Test)4 S3Object (com.amazonaws.services.s3.model.S3Object)3 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3