Search in sources :

Example 16 with S3Object

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

the class S3Client method getS3ObjectAndMetadata.

private Map.Entry<S3Object, ObjectMetadata> getS3ObjectAndMetadata(String bucket, String key, SSECustomerKey ssecLocal) {
    GetObjectRequest getObjectRequest;
    GetObjectMetadataRequest getObjectMetadataRequest;
    if (ssecLocal != null) {
        getObjectRequest = new GetObjectRequest(bucket, key).withSSECustomerKey(ssecLocal);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key).withSSECustomerKey(ssecLocal);
    } else {
        getObjectRequest = new GetObjectRequest(bucket, key);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key);
    }
    return new AbstractMap.SimpleEntry<>(s3Client.getObject(getObjectRequest), s3Client.getObjectMetadata(getObjectMetadataRequest));
}
Also used : GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 17 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project elasticsearch by elastic.

the class TestAmazonS3 method getObject.

@Override
public S3Object getObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException {
    if (shouldFail(bucketName, key, readFailureRate)) {
        logger.info("--> random read failure on getObject method: throwing an exception for [bucket={}, key={}]", bucketName, key);
        AmazonS3Exception ex = new AmazonS3Exception("Random S3 read exception");
        ex.setStatusCode(404);
        throw ex;
    } else {
        return super.getObject(bucketName, key);
    }
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 18 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project gradle by gradle.

the class S3ResourceConnector method getMetaData.

public ExternalResourceMetaData getMetaData(URI location, boolean revalidate) {
    LOGGER.debug("Attempting to get resource metadata: {}", location);
    S3Object s3Object = s3Client.getMetaData(location);
    if (s3Object == null) {
        return null;
    }
    try {
        ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
        return new DefaultExternalResourceMetaData(location, objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
        null);
    } finally {
        IoActions.closeQuietly(s3Object);
    }
}
Also used : S3Object(com.amazonaws.services.s3.model.S3Object) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DefaultExternalResourceMetaData(org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData)

Example 19 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project gradle by gradle.

the class S3Client method doGetS3Object.

private S3Object doGetS3Object(URI uri, boolean isLightWeight) {
    S3RegionalResource s3RegionalResource = new S3RegionalResource(uri);
    String bucketName = s3RegionalResource.getBucketName();
    String s3BucketKey = s3RegionalResource.getKey();
    configureClient(s3RegionalResource);
    GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, s3BucketKey);
    if (isLightWeight) {
        //Skip content download
        getObjectRequest.setRange(0, 0);
    }
    try {
        return amazonS3Client.getObject(getObjectRequest);
    } catch (AmazonServiceException e) {
        String errorCode = e.getErrorCode();
        if (null != errorCode && errorCode.equalsIgnoreCase("NoSuchKey")) {
            return null;
        }
        throw ResourceExceptions.getFailed(uri, e);
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 20 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project camel by apache.

the class S3Consumer method poll.

@Override
protected int poll() throws Exception {
    // must reset for each poll
    shutdownRunningTask = null;
    pendingExchanges = 0;
    String fileName = getConfiguration().getFileName();
    String bucketName = getConfiguration().getBucketName();
    Queue<Exchange> exchanges;
    if (fileName != null) {
        LOG.trace("Getting object in bucket [{}] with file name [{}]...", bucketName, fileName);
        S3Object s3Object = getAmazonS3Client().getObject(new GetObjectRequest(bucketName, fileName));
        exchanges = createExchanges(s3Object);
    } else {
        LOG.trace("Queueing objects in bucket [{}]...", bucketName);
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
        listObjectsRequest.setBucketName(bucketName);
        listObjectsRequest.setPrefix(getConfiguration().getPrefix());
        if (maxMessagesPerPoll > 0) {
            listObjectsRequest.setMaxKeys(maxMessagesPerPoll);
        }
        // if there was a marker from previous poll then use that to continue from where we left last time
        if (marker != null) {
            LOG.trace("Resuming from marker: {}", marker);
            listObjectsRequest.setMarker(marker);
        }
        ObjectListing listObjects = getAmazonS3Client().listObjects(listObjectsRequest);
        if (listObjects.isTruncated()) {
            marker = listObjects.getNextMarker();
            LOG.trace("Returned list is truncated, so setting next marker: {}", marker);
        } else {
            // no more data so clear marker
            marker = null;
        }
        if (LOG.isTraceEnabled()) {
            LOG.trace("Found {} objects in bucket [{}]...", listObjects.getObjectSummaries().size(), bucketName);
        }
        exchanges = createExchanges(listObjects.getObjectSummaries());
    }
    return processBatch(CastUtils.cast(exchanges));
}
Also used : Exchange(org.apache.camel.Exchange) ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3Object(com.amazonaws.services.s3.model.S3Object) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Aggregations

S3Object (com.amazonaws.services.s3.model.S3Object)22 InputStream (java.io.InputStream)8 AmazonServiceException (com.amazonaws.AmazonServiceException)7 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)7 AmazonS3 (com.amazonaws.services.s3.AmazonS3)6 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 IOException (java.io.IOException)4 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)3 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Exchange (org.apache.camel.Exchange)3 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)2 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)2 DBException (com.yahoo.ycsb.DBException)2 FileNotFoundException (java.io.FileNotFoundException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2