Search in sources :

Example 1 with AmazonS3

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

the class S3Endpoint method createS3Client.

/**
     * Provide the possibility to override this method for an mock implementation
     */
AmazonS3 createS3Client() {
    AmazonS3Client client = null;
    ClientConfiguration clientConfiguration = null;
    boolean isClientConfigFound = false;
    if (configuration.hasProxyConfiguration()) {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost(configuration.getProxyHost());
        clientConfiguration.setProxyPort(configuration.getProxyPort());
        isClientConfigFound = true;
    }
    if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
        if (isClientConfigFound) {
            client = new AmazonS3Client(credentials, clientConfiguration);
        } else {
            client = new AmazonS3Client(credentials);
        }
    } else {
        if (isClientConfigFound) {
            client = new AmazonS3Client();
        } else {
            client = new AmazonS3Client(clientConfiguration);
        }
    }
    S3ClientOptions clientOptions = S3ClientOptions.builder().setPathStyleAccess(configuration.isPathStyleAccess()).build();
    client.setS3ClientOptions(clientOptions);
    return client;
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) S3ClientOptions(com.amazonaws.services.s3.S3ClientOptions) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with AmazonS3

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

the class S3Producer method copyObject.

private void copyObject(AmazonS3 s3Client, Exchange exchange) {
    String bucketNameDestination;
    String destinationKey;
    String sourceKey;
    String bucketName;
    String versionId;
    bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
    if (ObjectHelper.isEmpty(bucketName)) {
        bucketName = getConfiguration().getBucketName();
    }
    sourceKey = exchange.getIn().getHeader(S3Constants.KEY, String.class);
    destinationKey = exchange.getIn().getHeader(S3Constants.DESTINATION_KEY, String.class);
    bucketNameDestination = exchange.getIn().getHeader(S3Constants.BUCKET_DESTINATION_NAME, String.class);
    versionId = exchange.getIn().getHeader(S3Constants.VERSION_ID, String.class);
    if (ObjectHelper.isEmpty(bucketName)) {
        throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(bucketNameDestination)) {
        throw new IllegalArgumentException("Bucket Name Destination must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(sourceKey)) {
        throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(destinationKey)) {
        throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
    }
    CopyObjectRequest copyObjectRequest;
    if (ObjectHelper.isEmpty(versionId)) {
        copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, bucketNameDestination, destinationKey);
    } else {
        copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination, destinationKey);
    }
    CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);
    Message message = getMessageForResponse(exchange);
    message.setHeader(S3Constants.E_TAG, copyObjectResult.getETag());
    if (copyObjectResult.getVersionId() != null) {
        message.setHeader(S3Constants.VERSION_ID, copyObjectResult.getVersionId());
    }
}
Also used : CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) Message(org.apache.camel.Message) CopyObjectResult(com.amazonaws.services.s3.model.CopyObjectResult)

Example 3 with AmazonS3

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

the class ITestS3AConfiguration method testDefaultUserAgent.

@Test
public void testDefaultUserAgent() throws Exception {
    conf = new Configuration();
    fs = S3ATestUtils.createTestFileSystem(conf);
    assertNotNull(fs);
    AmazonS3 s3 = fs.getAmazonS3Client();
    assertNotNull(s3);
    ClientConfiguration awsConf = getField(s3, ClientConfiguration.class, "clientConfiguration");
    assertEquals("Hadoop " + VersionInfo.getVersion(), awsConf.getUserAgentPrefix());
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(com.amazonaws.ClientConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Example 4 with AmazonS3

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

the class ITestS3AConfiguration method testCustomUserAgent.

@Test
public void testCustomUserAgent() throws Exception {
    conf = new Configuration();
    conf.set(Constants.USER_AGENT_PREFIX, "MyApp");
    fs = S3ATestUtils.createTestFileSystem(conf);
    assertNotNull(fs);
    AmazonS3 s3 = fs.getAmazonS3Client();
    assertNotNull(s3);
    ClientConfiguration awsConf = getField(s3, ClientConfiguration.class, "clientConfiguration");
    assertEquals("MyApp, Hadoop " + VersionInfo.getVersion(), awsConf.getUserAgentPrefix());
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(com.amazonaws.ClientConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Example 5 with AmazonS3

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

the class MockS3ClientFactory method createS3Client.

@Override
public AmazonS3 createS3Client(URI name, URI uri) {
    String bucket = name.getHost();
    AmazonS3 s3 = mock(AmazonS3.class);
    when(s3.doesBucketExist(bucket)).thenReturn(true);
    return s3;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)50 AmazonServiceException (com.amazonaws.AmazonServiceException)15 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)9 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)9 Bucket (com.amazonaws.services.s3.model.Bucket)6 ClientConfiguration (com.amazonaws.ClientConfiguration)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)4 Configuration (org.apache.hadoop.conf.Configuration)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)3 S3Object (com.amazonaws.services.s3.model.S3Object)3 AmazonClientException (com.amazonaws.AmazonClientException)2 BucketWebsiteConfiguration (com.amazonaws.services.s3.model.BucketWebsiteConfiguration)2 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)2 EmailAddressGrantee (com.amazonaws.services.s3.model.EmailAddressGrantee)2 Grant (com.amazonaws.services.s3.model.Grant)2