Example usage for com.amazonaws ClientConfiguration ClientConfiguration

List of usage examples for com.amazonaws ClientConfiguration ClientConfiguration

Introduction

In this page you can find the example usage for com.amazonaws ClientConfiguration ClientConfiguration.

Prototype

public ClientConfiguration() 

Source Link

Usage

From source file:com.digitalpebble.stormcrawler.aws.s3.AbstractS3CacheBolt.java

License:Apache License

/** Returns an S3 client given the configuration **/
public static AmazonS3Client getS3Client(Map conf) {
    AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();
    AWSCredentials credentials = provider.getCredentials();
    ClientConfiguration config = new ClientConfiguration();

    AmazonS3Client client = new AmazonS3Client(credentials, config);

    String regionName = ConfUtils.getString(conf, REGION);
    if (StringUtils.isNotBlank(regionName)) {
        client.setRegion(RegionUtils.getRegion(regionName));
    }/*from  w  w  w  . ja  va 2s  .  co m*/

    String endpoint = ConfUtils.getString(conf, ENDPOINT);
    if (StringUtils.isNotBlank(endpoint)) {
        client.setEndpoint(endpoint);
    }
    return client;
}

From source file:com.dxc.temp.SimpleProducerConsumer.java

License:Open Source License

public static void main(String[] args) throws InterruptedException {
    int argIndex = 0;

    final String accessKey = args[argIndex++];
    final String secretKey = args[argIndex++];
    final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    final String endpoint = args[argIndex++];
    final String queueName = args[argIndex++];
    final int producerCount = Integer.parseInt(args[argIndex++]);
    final int consumerCount = Integer.parseInt(args[argIndex++]);
    final int batchSize = Integer.parseInt(args[argIndex++]);
    final int messageSizeByte = Integer.parseInt(args[argIndex++]);
    final int runTimeMinutes = Integer.parseInt(args[argIndex++]);

    // configure the SQS client with enough connections for all producer and
    // consumer threads
    AmazonSQS sqsClient = new AmazonSQSClient(credentials,
            new ClientConfiguration().withMaxConnections(producerCount + consumerCount));
    sqsClient.setEndpoint(endpoint);//from w w  w .  ja va  2s.c  o  m
    String queueUrl = sqsClient.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl();

    // the flag to stop producer, consumer, and monitor threads
    AtomicBoolean stop = new AtomicBoolean(false);

    // start the producers
    final AtomicInteger producedCount = new AtomicInteger();
    Thread[] producers = new Thread[producerCount];
    for (int i = 0; i < producerCount; i++) {
        if (batchSize == 1)
            producers[i] = new Producer(sqsClient, queueUrl, messageSizeByte, producedCount, stop);
        else
            producers[i] = new BatchProducer(sqsClient, queueUrl, batchSize, messageSizeByte, producedCount,
                    stop);
        producers[i].start();
    }

    // start the consumers
    final AtomicInteger consumedCount = new AtomicInteger();
    Thread[] consumers = new Thread[consumerCount];
    for (int i = 0; i < consumerCount; i++) {
        if (batchSize == 1)
            consumers[i] = new Consumer(sqsClient, queueUrl, consumedCount, stop);
        else
            consumers[i] = new BatchConsumer(sqsClient, queueUrl, batchSize, consumedCount, stop);
        consumers[i].start();
    }

    // start the monitor (thread)
    Thread monitor = new Monitor(producedCount, consumedCount, stop);
    monitor.start();

    // wait for the specified amount of time then stop
    Thread.sleep(TimeUnit.MINUTES.toMillis(Math.min(runTimeMinutes, MAX_RUNTIME_MINUTES)));
    stop.set(true);

    // join all threads
    for (int i = 0; i < producerCount; i++)
        producers[i].join();

    for (int i = 0; i < consumerCount; i++)
        consumers[i].join();

    monitor.interrupt();
    monitor.join();
}

From source file:com.easarrive.aws.plugins.common.service.impl.SimpleProducerConsumer.java

License:Open Source License

public static void main(String[] args) throws InterruptedException {
    final AWSCredentials credentials = new BasicAWSCredentials("AKIAIDPJMKK4UHLE3OVA",
            "A+cn+TT3tUs6xbto5k1IKkWwPLBq995aOkqKxZNY");

    final String endpoint = "sqs.us-west-2.amazonaws.com";
    final String queueName = "image";
    final int producerCount = 10;
    final int consumerCount = 3;
    final int batchSize = 3;
    final int messageSizeByte = 10000;
    final int runTimeMinutes = 100;

    // configure the SQS client with enough connections for all producer and
    // consumer threads
    AmazonSQS sqsClient = new AmazonSQSClient(credentials,
            new ClientConfiguration().withMaxConnections(producerCount + consumerCount));
    sqsClient.setEndpoint(endpoint);/*from   www.  ja  v  a  2  s  .  c  om*/
    String queueUrl = sqsClient.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl();

    // the flag to stop producer, consumer, and monitor threads
    AtomicBoolean stop = new AtomicBoolean(false);

    // start the producers
    final AtomicInteger producedCount = new AtomicInteger();
    Thread[] producers = new Thread[producerCount];
    for (int i = 0; i < producerCount; i++) {
        producers[i] = new BatchProducer(sqsClient, queueUrl, batchSize, messageSizeByte, producedCount, stop);
        producers[i].start();
    }

    // start the consumers
    final AtomicInteger consumedCount = new AtomicInteger();
    Thread[] consumers = new Thread[consumerCount];
    for (int i = 0; i < consumerCount; i++) {
        consumers[i] = new BatchConsumer(sqsClient, queueUrl, batchSize, consumedCount, stop);
        consumers[i].start();
    }

    // start the monitor (thread)
    Thread monitor = new Monitor(producedCount, consumedCount, stop);
    monitor.start();

    // wait for the specified amount of time then stop
    Thread.sleep(TimeUnit.MINUTES.toMillis(Math.min(runTimeMinutes, MAX_RUNTIME_MINUTES)));
    stop.set(true);

    // join all threads
    for (int i = 0; i < producerCount; i++)
        producers[i].join();

    for (int i = 0; i < consumerCount; i++)
        consumers[i].join();

    monitor.interrupt();
    monitor.join();
}

From source file:com.emc.ecs.sync.source.S3Source.java

License:Open Source License

@Override
public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) {
    Assert.hasText(accessKey, "accessKey is required");
    Assert.hasText(secretKey, "secretKey is required");
    Assert.hasText(bucketName, "bucketName is required");
    Assert.isTrue(bucketName.matches("[A-Za-z0-9._-]+"), bucketName + " is not a valid bucket name");

    AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
    ClientConfiguration config = new ClientConfiguration();

    if (protocol != null)
        config.setProtocol(Protocol.valueOf(protocol.toUpperCase()));

    if (legacySignatures)
        config.setSignerOverride("S3SignerType");

    if (socketTimeoutMs >= 0)
        config.setSocketTimeout(socketTimeoutMs);

    s3 = new AmazonS3Client(creds, config);

    if (endpoint != null)
        s3.setEndpoint(endpoint);// ww w.j ava2s .c  o  m

    // TODO: generalize uri translation
    AwsS3Util.S3Uri s3Uri = new AwsS3Util.S3Uri();
    s3Uri.protocol = protocol;
    s3Uri.endpoint = endpoint;
    s3Uri.accessKey = accessKey;
    s3Uri.secretKey = secretKey;
    s3Uri.rootKey = rootKey;
    if (sourceUri == null)
        sourceUri = s3Uri.toUri();

    if (disableVHosts) {
        log.info(
                "The use of virtual hosted buckets on the s3 source has been DISABLED.  Path style buckets will be used.");
        S3ClientOptions opts = new S3ClientOptions();
        opts.setPathStyleAccess(true);
        s3.setS3ClientOptions(opts);
    }

    if (!s3.doesBucketExist(bucketName)) {
        throw new ConfigurationException("The bucket " + bucketName + " does not exist.");
    }

    if (rootKey == null)
        rootKey = ""; // make sure rootKey isn't null

    // for version support. TODO: genericize version support
    if (target instanceof S3Target) {
        s3Target = (S3Target) target;
        if (s3Target.isIncludeVersions()) {
            BucketVersioningConfiguration versioningConfig = s3.getBucketVersioningConfiguration(bucketName);
            List<String> versionedStates = Arrays.asList(BucketVersioningConfiguration.ENABLED,
                    BucketVersioningConfiguration.SUSPENDED);
            versioningEnabled = versionedStates.contains(versioningConfig.getStatus());
        }
    }
}

From source file:com.emc.ecs.sync.target.S3Target.java

License:Open Source License

@Override
public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) {
    Assert.hasText(accessKey, "accessKey is required");
    Assert.hasText(secretKey, "secretKey is required");
    Assert.hasText(bucketName, "bucketName is required");
    Assert.isTrue(bucketName.matches("[A-Za-z0-9._-]+"), bucketName + " is not a valid bucket name");

    AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
    ClientConfiguration config = new ClientConfiguration();

    if (protocol != null)
        config.setProtocol(Protocol.valueOf(protocol.toUpperCase()));

    if (legacySignatures)
        config.setSignerOverride("S3SignerType");

    if (socketTimeoutMs >= 0)
        config.setSocketTimeout(socketTimeoutMs);

    s3 = new AmazonS3Client(creds, config);

    if (endpoint != null)
        s3.setEndpoint(endpoint);/*  w ww.  j a  v  a 2  s. co  m*/

    // TODO: generalize uri translation
    AwsS3Util.S3Uri s3Uri = new AwsS3Util.S3Uri();
    s3Uri.protocol = protocol;
    s3Uri.endpoint = endpoint;
    s3Uri.accessKey = accessKey;
    s3Uri.secretKey = secretKey;
    s3Uri.rootKey = rootKey;
    if (targetUri == null)
        targetUri = s3Uri.toUri();

    if (disableVHosts) {
        log.info(
                "The use of virtual hosted buckets on the s3 source has been DISABLED.  Path style buckets will be used.");
        S3ClientOptions opts = new S3ClientOptions();
        opts.setPathStyleAccess(true);
        s3.setS3ClientOptions(opts);
    }

    // for version support. TODO: genericize version support
    if (source instanceof S3Source) {
        s3Source = (S3Source) source;
        if (!s3Source.isVersioningEnabled())
            includeVersions = false; // don't include versions if source versioning is off
    } else if (includeVersions) {
        throw new ConfigurationException(
                "Object versions are currently only supported with the S3 source & target plugins.");
    }

    if (!s3.doesBucketExist(bucketName)) {
        if (createBucket) {
            s3.createBucket(bucketName);
            if (includeVersions)
                s3.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucketName,
                        new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED)));
        } else {
            throw new ConfigurationException("The bucket " + bucketName + " does not exist.");
        }
    }

    if (rootKey == null)
        rootKey = ""; // make sure rootKey isn't null

    if (includeVersions) {
        String status = s3.getBucketVersioningConfiguration(bucketName).getStatus();
        if (BucketVersioningConfiguration.OFF.equals(status))
            throw new ConfigurationException("The specified bucket does not have versioning enabled.");
    }

    if (mpuThresholdMB > AwsS3Util.MAX_PUT_SIZE_MB) {
        log.warn("{}MB is above the maximum PUT size of {}MB. the maximum will be used instead", mpuThresholdMB,
                AwsS3Util.MAX_PUT_SIZE_MB);
        mpuThresholdMB = AwsS3Util.MAX_PUT_SIZE_MB;
    }
    if (mpuPartSizeMB < AwsS3Util.MIN_PART_SIZE_MB) {
        log.warn("{}MB is below the minimum MPU part size of {}MB. the minimum will be used instead",
                mpuPartSizeMB, AwsS3Util.MIN_PART_SIZE_MB);
        mpuPartSizeMB = AwsS3Util.MIN_PART_SIZE_MB;
    }
}

From source file:com.emc.vipr.s3.sample.AWSS3Factory.java

License:Open Source License

public static AmazonS3 getS3Client() {
    BasicAWSCredentials creds = new BasicAWSCredentials(S3_ACCESS_KEY_ID, S3_SECRET_KEY);

    ClientConfiguration cc = new ClientConfiguration();
    //cc.setProxyHost("localhost");
    //cc.setProxyPort(8888);

    // Force use of v2 Signer.
    cc.setSignerOverride("S3SignerType");

    AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
            .withClientConfiguration(cc).withPathStyleAccessEnabled(true) // Path-style bucket naming is highly recommended
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(S3_ENDPOINT, null)).build();

    return client;
}

From source file:com.emc.vipr.services.s3.S3ClientFactory.java

License:Open Source License

private static void checkProxyConfig(AmazonS3Client client, Properties props) {
    String proxyHost = props.getProperty(ViprConfig.PROP_PROXY_HOST);
    if (proxyHost != null && !proxyHost.isEmpty()) {
        int proxyPort = Integer.parseInt(props.getProperty(ViprConfig.PROP_PROXY_PORT));
        ClientConfiguration config = new ClientConfiguration();
        config.setProxyHost(proxyHost);//from  w w  w . j ava  2 s  . com
        config.setProxyPort(proxyPort);
        client.setConfiguration(config);
    }
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

/**
 * Constructs a new ViPR S3 client using the specified endpoint, AWS credentials to
 * access the EMC ViPR S3 protocol./*from  w  ww.j a v a  2 s . co m*/
 *
 * @param endpoint
 *            The ViPR S3 endpoint (i.e. "https://vipr-data.emc.com:9021")
 * @param awsCredentials
 *            The AWS credentials to use when making requests
 *            with this client.
 *
 * @see AmazonS3Client#AmazonS3Client()
 * @see AmazonS3Client#AmazonS3Client(AWSCredentials)
 */
public ViPRS3Client(String endpoint, AWSCredentials awsCredentials) {
    this(endpoint, new StaticCredentialsProvider(awsCredentials), new ClientConfiguration());
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

/**
 * Constructs a new ViPR S3 client using the specified endpoint, AWS credentials
 * provider to access the EMC ViPR S3 protocol.
 *
 * @param endpoint// w  ww  .  java 2s  . c o m
 *            The ViPR S3 endpoint (i.e. "https://vipr-data.emc.com:9021")
 * @param credentialsProvider
 *            The AWS credentials provider which will provide credentials
 *            to authenticate requests.
 * @see AmazonS3Client#AmazonS3Client(AWSCredentialsProvider)
 */
public ViPRS3Client(String endpoint, AWSCredentialsProvider credentialsProvider) {
    this(endpoint, credentialsProvider, new ClientConfiguration());
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

/**
 * Constructs a new ViPR S3 client using the specified endpoint, AWS credentials and
 * client configuration to access the EMC ViPR S3 protocol.
 *
 * @param endpoint//from  w w  w.  j  a v  a  2s  .  co  m
 *            The ViPR S3 endpoint (i.e. "https://vipr-data.emc.com:9021")
 * @param credentialsProvider
 *            The AWS credentials provider which will provide credentials
 *            to authenticate requests.
 * @param clientConfiguration
 *            The client configuration options controlling how this client
 *            connects (e.g. proxy settings, retry counts, etc).
 */
public ViPRS3Client(String endpoint, AWSCredentialsProvider credentialsProvider,
        ClientConfiguration clientConfiguration) {
    super(credentialsProvider, clientConfiguration == null ? new ClientConfiguration() : clientConfiguration);
    setEndpoint(endpoint);
}