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:org.apache.jackrabbit.oak.blob.cloud.aws.s3.Utils.java

License:Apache License

private static ClientConfiguration getClientConfiguration(Properties prop) {
    int connectionTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_CONN_TIMEOUT));
    int socketTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_SOCK_TIMEOUT));
    int maxConnections = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_CONNS));
    int maxErrorRetry = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_ERR_RETRY));

    String protocol = prop.getProperty(S3Constants.S3_CONN_PROTOCOL);
    String proxyHost = prop.getProperty(S3Constants.PROXY_HOST);
    String proxyPort = prop.getProperty(S3Constants.PROXY_PORT);

    ClientConfiguration cc = new ClientConfiguration();

    if (protocol != null && protocol.equalsIgnoreCase("http")) {
        cc.setProtocol(Protocol.HTTP);//from w  w w.  j ava 2 s . c o m
    }

    if (proxyHost != null && !proxyHost.isEmpty()) {
        cc.setProxyHost(proxyHost);
    }

    if (proxyPort != null && !proxyPort.isEmpty()) {
        cc.setProxyPort(Integer.parseInt(proxyPort));
    }

    cc.setConnectionTimeout(connectionTimeOut);
    cc.setSocketTimeout(socketTimeOut);
    cc.setMaxConnections(maxConnections);
    cc.setMaxErrorRetry(maxErrorRetry);
    return cc;
}

From source file:org.apache.nifi.processors.aws.AbstractAWSProcessor.java

License:Apache License

protected ClientConfiguration createConfiguration(final ProcessContext context) {
    final ClientConfiguration config = new ClientConfiguration();
    config.setMaxConnections(context.getMaxConcurrentTasks());
    config.setMaxErrorRetry(0);/*from w  ww.j  ava2  s.com*/
    config.setUserAgent(DEFAULT_USER_AGENT);
    // If this is changed to be a property, ensure other uses are also changed
    config.setProtocol(DEFAULT_PROTOCOL);
    final int commsTimeout = context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
    config.setConnectionTimeout(commsTimeout);
    config.setSocketTimeout(commsTimeout);

    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE)
            .asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.NONE);
        // NIFI-3788: Changed hostnameVerifier from null to DHV (BrowserCompatibleHostnameVerifier is deprecated)
        SdkTLSSocketFactory sdkTLSSocketFactory = new SdkTLSSocketFactory(sslContext,
                new DefaultHostnameVerifier());
        config.getApacheHttpClientConfig().setSslSocketFactory(sdkTLSSocketFactory);
    }

    if (context.getProperty(PROXY_HOST).isSet()) {
        String proxyHost = context.getProperty(PROXY_HOST).evaluateAttributeExpressions().getValue();
        config.setProxyHost(proxyHost);
        Integer proxyPort = context.getProperty(PROXY_HOST_PORT).evaluateAttributeExpressions().asInteger();
        config.setProxyPort(proxyPort);
    }

    return config;
}

From source file:org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AssumeRoleCredentialsStrategy.java

License:Apache License

@Override
public AWSCredentialsProvider getDerivedCredentialsProvider(Map<PropertyDescriptor, String> properties,
        AWSCredentialsProvider primaryCredentialsProvider) {
    final String assumeRoleArn = properties.get(ASSUME_ROLE_ARN);
    final String assumeRoleName = properties.get(ASSUME_ROLE_NAME);
    String rawMaxSessionTime = properties.get(MAX_SESSION_TIME);
    rawMaxSessionTime = (rawMaxSessionTime != null) ? rawMaxSessionTime : MAX_SESSION_TIME.getDefaultValue();
    final Integer maxSessionTime = Integer.parseInt(rawMaxSessionTime.trim());
    final String assumeRoleExternalId = properties.get(ASSUME_ROLE_EXTERNAL_ID);
    STSAssumeRoleSessionCredentialsProvider.Builder builder;
    ClientConfiguration config = new ClientConfiguration();

    // If proxy variables are set, then create Client Configuration with those values
    if (proxyVariablesValidForAssumeRole(properties)) {
        final String assumeRoleProxyHost = properties.get(ASSUME_ROLE_PROXY_HOST);
        final Integer assumeRoleProxyPort = Integer.parseInt(properties.get(ASSUME_ROLE_PROXY_PORT));
        config.withProxyHost(assumeRoleProxyHost);
        config.withProxyPort(assumeRoleProxyPort);
    }/*from www .  j a  v  a  2  s.c om*/

    AWSSecurityTokenService securityTokenService = new AWSSecurityTokenServiceClient(primaryCredentialsProvider,
            config);
    builder = new STSAssumeRoleSessionCredentialsProvider.Builder(assumeRoleArn, assumeRoleName)
            .withStsClient(securityTokenService).withRoleSessionDurationSeconds(maxSessionTime);

    if (assumeRoleExternalId != null && !assumeRoleExternalId.isEmpty()) {
        builder = builder.withExternalId(assumeRoleExternalId);
    }

    final AWSCredentialsProvider credsProvider = builder.build();

    return credsProvider;
}

From source file:org.apache.samza.system.kinesis.KinesisConfig.java

License:Apache License

/**
 * @param system name of the system//from w w w  . j a v  a2s .com
 * @return {@link ClientConfiguration} which has options controlling how the client connects to kinesis
 *         (eg: proxy settings, retry counts, etc)
 */
ClientConfiguration getAWSClientConfig(String system) {
    ClientConfiguration awsClientConfig = new ClientConfiguration();
    setAwsClientConfigs(subset(String.format(CONFIG_AWS_CLIENT_CONFIG, system)), awsClientConfig);
    awsClientConfig.getApacheHttpClientConfig().setSslSocketFactory(getSSLSocketFactory(system));
    return awsClientConfig;
}

From source file:org.apache.storm.kinesis.spout.test.KinesisSpoutTopology.java

License:Apache License

public static void main(String args[])
        throws InvalidTopologyException, AuthorizationException, AlreadyAliveException {
    String topologyName = args[0];
    RecordToTupleMapper recordToTupleMapper = new TestRecordToTupleMapper();
    KinesisConnectionInfo kinesisConnectionInfo = new KinesisConnectionInfo(new CredentialsProviderChain(),
            new ClientConfiguration(), Regions.US_WEST_2, 1000);
    ZkInfo zkInfo = new ZkInfo("localhost:2181", "/kinesisOffsets", 20000, 15000, 10000L, 3, 2000);
    KinesisConfig kinesisConfig = new KinesisConfig(args[1], ShardIteratorType.TRIM_HORIZON,
            recordToTupleMapper, new Date(), new ExponentialBackoffRetrier(), zkInfo, kinesisConnectionInfo,
            10000L);/*  w  ww .ja  v  a 2  s  .c  o  m*/
    KinesisSpout kinesisSpout = new KinesisSpout(kinesisConfig);
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout("spout", kinesisSpout, 3);
    topologyBuilder.setBolt("bolt", new KinesisBoltTest(), 1).shuffleGrouping("spout");
    Config topologyConfig = new Config();
    topologyConfig.setDebug(true);
    topologyConfig.setNumWorkers(3);
    StormSubmitter.submitTopology(topologyName, topologyConfig, topologyBuilder.createTopology());
}

From source file:org.apache.storm.s3.output.UploaderFactory.java

License:Apache License

public static Uploader buildUploader(Map conf) {
    Protocol protocol = Protocol.HTTPS;// w ww .  j a  v a 2  s .com
    String proxy = null;
    int proxyPort = 0;
    if (conf.containsKey(S3_PROTOCOL)) {
        protocol = Protocol.valueOf((String) conf.get(S3_PROTOCOL));
    }
    if (conf.containsKey(S3_PROXY)) {
        proxy = (String) conf.get(S3_PROXY);
    }
    if (conf.containsKey(S3_PROXY_PORT)) {
        proxyPort = ((Long) conf.get(S3_PROXY_PORT)).intValue();
    }
    AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();
    AWSCredentials credentials = provider.getCredentials();
    ClientConfiguration config = new ClientConfiguration().withProtocol(protocol);
    if (proxy != null) {
        config.withProxyHost(proxy);
    }
    if (proxyPort != 0) {
        config.withProxyPort(proxyPort);
    }
    AmazonS3 client = new AmazonS3Client(credentials, config);
    if (conf.containsKey(S3_ENDPOINT)) {
        client.setEndpoint((String) conf.get(S3_ENDPOINT));
    }
    return getUploader(conf, client);
}

From source file:org.apache.stratos.aws.extension.AWSHelper.java

License:Apache License

public AWSHelper() throws LoadBalancerExtensionException {
    // Read values for awsAccessKey, awsSecretKey etc. from config file

    String awsPropertiesFile = System.getProperty(Constants.AWS_PROPERTIES_FILE);

    Properties properties = new Properties();

    InputStream inputStream = null;

    try {/* w  w w . ja  v a2 s. c o  m*/
        inputStream = new FileInputStream(awsPropertiesFile);

        properties.load(inputStream);

        this.awsAccessKey = properties.getProperty(Constants.AWS_ACCESS_KEY);
        this.awsSecretKey = properties.getProperty(Constants.AWS_SECRET_KEY);

        if (this.awsAccessKey.isEmpty() || this.awsSecretKey.isEmpty()) {
            throw new LoadBalancerExtensionException("Invalid AWS credentials.");
        }

        this.lbPrefix = properties.getProperty(Constants.LB_PREFIX);

        if (this.lbPrefix.isEmpty() || this.lbPrefix.length() > Constants.LOAD_BALANCER_PREFIX_MAX_LENGTH) {
            throw new LoadBalancerExtensionException("Invalid load balancer prefix.");
        }

        lbSequence = new AtomicInteger(1);

        this.lbSecurityGroupName = properties.getProperty(Constants.LOAD_BALANCER_SECURITY_GROUP_NAME);

        lbSecurityGroupId = properties.getProperty(Constants.LOAD_BALANCER_SECURITY_GROUP_ID);

        if ((lbSecurityGroupId == null || lbSecurityGroupId.isEmpty()) && (this.lbSecurityGroupName.isEmpty()
                || this.lbSecurityGroupName.length() > Constants.SECURITY_GROUP_NAME_MAX_LENGTH)) {
            throw new LoadBalancerExtensionException(
                    "Either security group name or security " + "group id is required");
        }

        //            if (this.lbSecurityGroupName.isEmpty() || this.lbSecurityGroupName.length() >
        //                    Constants.SECURITY_GROUP_NAME_MAX_LENGTH) {
        //                throw new LoadBalancerExtensionException("Invalid load balancer security group name.");
        //            }

        // Read the SSL certificate Id. This is mandatory if only we are using HTTPS as the front end protocol.
        // http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/using-elb-listenerconfig-quickref.html
        this.sslCertificateId = properties.getProperty(Constants.LOAD_BALANCER_SSL_CERTIFICATE_ID).trim();

        // Cookie name for application level stickiness
        this.appStickySessionCookie = properties.getProperty(Constants.APP_STICKY_SESSION_COOKIE_NAME).trim();

        this.allowedCidrIpForLBSecurityGroup = properties.getProperty(Constants.ALLOWED_CIDR_IP_KEY);

        if (this.allowedCidrIpForLBSecurityGroup.isEmpty()) {
            throw new LoadBalancerExtensionException("Invalid allowed CIDR IP.");
        }

        String allowedProtocols = properties.getProperty(Constants.ALLOWED_PROTOCOLS);

        if (allowedProtocols.isEmpty()) {
            throw new LoadBalancerExtensionException("Please specify at least one Internet protocol.");
        }

        String[] protocols = allowedProtocols.split(",");

        this.allowedProtocolsForLBSecurityGroup = new ArrayList<String>();

        for (String protocol : protocols) {
            this.allowedProtocolsForLBSecurityGroup.add(protocol);
        }

        String interval = properties.getProperty(Constants.STATISTICS_INTERVAL);

        if (interval == null || interval.isEmpty()) {
            this.statisticsInterval = Constants.STATISTICS_INTERVAL_MULTIPLE_OF;
        } else {
            try {
                this.statisticsInterval = Integer.parseInt(interval);

                if (this.statisticsInterval % Constants.STATISTICS_INTERVAL_MULTIPLE_OF != 0) {
                    this.statisticsInterval = Constants.STATISTICS_INTERVAL_MULTIPLE_OF;
                }
            } catch (NumberFormatException e) {
                log.warn("Invalid statistics interval. Setting it to 15.");
                this.statisticsInterval = 15;
            }
        }

        this.lbSecurityGroupDescription = Constants.LOAD_BALANCER_SECURITY_GROUP_DESCRIPTION;

        String commaSeparatedInitialZones = properties.getProperty(Constants.INITIAL_AVAILABILITY_ZONES);
        if (commaSeparatedInitialZones != null && !commaSeparatedInitialZones.isEmpty()) {
            initialZones.addAll(Arrays.asList(commaSeparatedInitialZones.trim().split("\\s*," + "\\s*")));
        }

        String commaSeparatedSubnetIds = properties.getProperty(Constants.SUBNET_IDS);
        if (commaSeparatedSubnetIds != null && !commaSeparatedSubnetIds.isEmpty()) {
            subnetIds.addAll(Arrays.asList(commaSeparatedSubnetIds.trim().split("\\s*," + "\\s*")));
        }

        String commaSeparatedVPCIds = properties.getProperty(Constants.VPC_IDS);
        if (commaSeparatedVPCIds != null && !commaSeparatedVPCIds.isEmpty()) {
            vpcIds.addAll(Arrays.asList(commaSeparatedVPCIds.trim().split("\\s*," + "\\s*")));
        }

        lbScheme = properties.getProperty(Constants.LB_SCHEME);

        regionToSecurityGroupIdMap = new ConcurrentHashMap<String, String>();

        awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
        clientConfiguration = new ClientConfiguration();

        elbClient = new AmazonElasticLoadBalancingClient(awsCredentials, clientConfiguration);

        ec2Client = new AmazonEC2Client(awsCredentials, clientConfiguration);

        cloudWatchClient = new AmazonCloudWatchClient(awsCredentials, clientConfiguration);

    } catch (IOException e) {
        log.error("Error reading aws configuration file.");
        throw new LoadBalancerExtensionException("Error reading aws configuration file.", e);
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            log.warn("Failed to close input stream to aws configuration file.");
        }
    }
}

From source file:org.apache.streams.amazon.kinesis.KinesisPersistReader.java

License:Apache License

@Override
public void prepare(Object configurationObject) {
    // Connect to Kinesis
    synchronized (this) {
        // Create the credentials Object
        AWSCredentials credentials = new BasicAWSCredentials(config.getKey(), config.getSecretKey());

        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.valueOf(config.getProtocol().toString()));

        this.client = new AmazonKinesisClient(credentials, clientConfig);
        if (StringUtils.isNotEmpty(config.getRegion()))
            this.client.setRegion(Region.getRegion(Regions.fromName(config.getRegion())));
    }//from w ww.j  a v  a  2  s. c  om
    streamNames = this.config.getStreams();
    executor = Executors.newFixedThreadPool(streamNames.size());
}

From source file:org.apache.streams.amazon.kinesis.KinesisPersistWriter.java

License:Apache License

@Override
public void prepare(Object configurationObject) {
    // Connect to Kinesis
    synchronized (this) {
        // Create the credentials Object
        AWSCredentials credentials = new BasicAWSCredentials(config.getKey(), config.getSecretKey());

        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.valueOf(config.getProtocol().toString()));

        this.client = new AmazonKinesisClient(credentials, clientConfig);
        if (StringUtils.isNotEmpty(config.getRegion())) {
            this.client.setRegion(Region.getRegion(Regions.fromName(config.getRegion())));
        }/*  w ww. j a  v a  2 s .c o m*/
    }
    executor = Executors.newSingleThreadExecutor();

}

From source file:org.apache.streams.s3.S3PersistReader.java

License:Apache License

public void prepare(Object configurationObject) {
    // Connect to S3
    synchronized (this) {
        // Create the credentials Object
        AWSCredentials credentials = new BasicAWSCredentials(s3ReaderConfiguration.getKey(),
                s3ReaderConfiguration.getSecretKey());

        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.valueOf(s3ReaderConfiguration.getProtocol().toString()));

        // We do not want path style access
        S3ClientOptions clientOptions = new S3ClientOptions();
        clientOptions.setPathStyleAccess(false);

        this.amazonS3Client = new AmazonS3Client(credentials, clientConfig);
        if (!Strings.isNullOrEmpty(s3ReaderConfiguration.getRegion()))
            this.amazonS3Client
                    .setRegion(Region.getRegion(Regions.fromName(s3ReaderConfiguration.getRegion())));
        this.amazonS3Client.setS3ClientOptions(clientOptions);
    }//from w  ww . j a  v a 2  s. com

    final ListObjectsRequest request = new ListObjectsRequest()
            .withBucketName(this.s3ReaderConfiguration.getBucket())
            .withPrefix(s3ReaderConfiguration.getReaderPath()).withMaxKeys(500);

    ObjectListing listing = this.amazonS3Client.listObjects(request);

    this.files = new ArrayList<String>();

    /**
     * If you can list files that are in this path, then you must be dealing with a directory
     * if you cannot list files that are in this path, then you are most likely dealing with
     * a simple file.
     */
    boolean hasCommonPrefixes = listing.getCommonPrefixes().size() > 0 ? true : false;
    boolean hasObjectSummaries = listing.getObjectSummaries().size() > 0 ? true : false;

    if (hasCommonPrefixes || hasObjectSummaries) {
        // Handle the 'directory' use case
        do {
            if (hasCommonPrefixes) {
                for (String file : listing.getCommonPrefixes()) {
                    this.files.add(file);
                }
            } else {
                for (final S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
                    this.files.add(objectSummary.getKey());
                }
            }

            // get the next batch.
            listing = this.amazonS3Client.listNextBatchOfObjects(listing);
        } while (listing.isTruncated());
    } else {
        // handle the single file use-case
        this.files.add(s3ReaderConfiguration.getReaderPath());
    }

    if (this.files.size() <= 0)
        LOGGER.error("There are no files to read");

    this.persistQueue = Queues.synchronizedQueue(new LinkedBlockingQueue<StreamsDatum>(10000));
    this.executor = Executors.newSingleThreadExecutor();
}