Search in sources :

Example 21 with S3Object

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

the class MockAmazonS3 method getObject.

@Override
public S3Object getObject(GetObjectRequest getObjectRequest) throws AmazonClientException {
    if (getObjectHttpCode != SC_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode);
        exception.setStatusCode(getObjectHttpCode);
        throw exception;
    }
    return null;
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 22 with S3Object

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

the class S3ConfigurationSource method poll.

@Override
public PollResult poll(boolean initial, Object checkPoint) throws IOException, AmazonServiceException {
    GetObjectRequest s3request = new GetObjectRequest(bucketName, key);
    InputStream is = null;
    try {
        S3Object result = client.getObject(s3request);
        is = result.getObjectContent();
        Map<String, Object> resultMap = inputStreamToMap(is);
        return PollResult.createFull(resultMap);
    } finally {
        if (is != null)
            is.close();
    }
}
Also used : InputStream(java.io.InputStream) S3Object(com.amazonaws.services.s3.model.S3Object) S3Object(com.amazonaws.services.s3.model.S3Object) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 23 with S3Object

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

the class S3ClientImpl method getObject.

@Override
public S3Object getObject(String bucket, String key) throws Exception {
    RefCountedClient holder = client.get();
    AmazonS3Client amazonS3Client = holder.useClient();
    try {
        return amazonS3Client.getObject(bucket, key);
    } finally {
        holder.release();
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client)

Example 24 with S3Object

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

the class S3ConfigProvider method loadConfig.

@Override
public LoadedInstanceConfig loadConfig() throws Exception {
    Date lastModified;
    Properties properties = new Properties();
    S3Object object = getConfigObject();
    if (object != null) {
        try {
            lastModified = object.getObjectMetadata().getLastModified();
            properties.load(object.getObjectContent());
        } finally {
            CloseableUtils.closeQuietly(object.getObjectContent());
        }
    } else {
        lastModified = new Date(0L);
    }
    PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
    return new LoadedInstanceConfig(config, lastModified.getTime());
}
Also used : PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) S3Object(com.amazonaws.services.s3.model.S3Object) Properties(java.util.Properties) Date(java.util.Date) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Example 25 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)30 InputStream (java.io.InputStream)13 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)10 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AmazonS3 (com.amazonaws.services.s3.AmazonS3)7 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)7 IOException (java.io.IOException)6 SignedDomain (com.yahoo.athenz.zms.SignedDomain)5 FileInputStream (java.io.FileInputStream)5 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 DomainData (com.yahoo.athenz.zms.DomainData)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Test (org.testng.annotations.Test)4 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)3 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)3 Date (java.util.Date)3 Exchange (org.apache.camel.Exchange)3 DecryptRequest (com.amazonaws.services.kms.model.DecryptRequest)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2