Search in sources :

Example 86 with AmazonS3

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project components by Talend.

the class S3DatasetRuntime method listBuckets.

@Override
public Set<String> listBuckets() {
    AmazonS3 conn = S3Connection.createClient(properties.getDatastoreProperties());
    String region = properties.region.getValue().getValue();
    if (S3Region.OTHER.getValue().equals(region)) {
        region = properties.unknownRegion.getValue();
    }
    conn.setEndpoint(regionToEndpoint(region));
    LOG.debug("Start to find buckets in region {}", region);
    List<Bucket> buckets = conn.listBuckets();
    Set<String> bucketsName = new HashSet<>();
    for (Bucket bucket : buckets) {
        String bucketName = bucket.getName();
        try {
            String bucketLocation = conn.getBucketLocation(bucketName);
            String bucketRegion = locationToRegion(bucketLocation);
            LOG.debug("Bucket is {} and location is {}({})", bucketName, bucketLocation, bucketRegion);
            if (region.equals(bucketRegion)) {
                bucketsName.add(bucketName);
            }
        } catch (Exception e) {
            // Ignore any exception when calling getBucketLocation, try next
            LOG.debug("Exception when check bucket location: {}", e.getMessage());
        }
    }
    return bucketsName;
}
Also used : AmazonS3(com.talend.shaded.com.amazonaws.services.s3.AmazonS3) Bucket(com.talend.shaded.com.amazonaws.services.s3.model.Bucket) HashSet(java.util.HashSet)

Example 87 with AmazonS3

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project syndesis by syndesisio.

the class AWSS3VerifierExtension method verifyConnectivity.

// *********************************
// Connectivity validation
// *********************************
@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
protected Result verifyConnectivity(Map<String, Object> parameters) {
    ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
    try {
        S3Configuration configuration = setProperties(new S3Configuration(), parameters);
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
        AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).withRegion(Regions.valueOf(configuration.getRegion())).build();
        client.listBuckets();
    } catch (SdkClientException e) {
        ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()).detail("aws_s3_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()).detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);
        builder.error(errorBuilder.build());
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        builder.error(ResultErrorBuilder.withException(e).build());
    }
    return builder.build();
}
Also used : ResultBuilder(org.apache.camel.component.extension.verifier.ResultBuilder) AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) S3Configuration(org.apache.camel.component.aws.s3.S3Configuration) SdkClientException(com.amazonaws.SdkClientException) ResultErrorBuilder(org.apache.camel.component.extension.verifier.ResultErrorBuilder) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) SdkClientException(com.amazonaws.SdkClientException)

Example 88 with AmazonS3

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project qpp-conversion-tool by CMSgov.

the class QrdaApiAcceptance method getS3ObjectCount.

private long getS3ObjectCount() {
    AmazonS3 s3Client = AwsTestHelper.getS3Client();
    ObjectListing objectListing = s3Client.listObjects(TEST_S3_BUCKET_NAME);
    long objectCount = objectListing.getObjectSummaries().size();
    while (objectListing.isTruncated()) {
        objectListing = s3Client.listNextBatchOfObjects(objectListing);
        objectCount += objectListing.getObjectSummaries().size();
    }
    return objectCount;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectListing(com.amazonaws.services.s3.model.ObjectListing)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)85 AmazonServiceException (com.amazonaws.AmazonServiceException)16 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)13 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)13 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)12 File (java.io.File)11 Test (org.junit.Test)11 S3Object (com.amazonaws.services.s3.model.S3Object)10 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)7 Bucket (com.amazonaws.services.s3.model.Bucket)7 ArrayList (java.util.ArrayList)7 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)6 AmazonClientException (com.amazonaws.AmazonClientException)5 ClientConfiguration (com.amazonaws.ClientConfiguration)5 Regions (com.amazonaws.regions.Regions)4 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Configuration (org.apache.hadoop.conf.Configuration)4