Search in sources :

Example 61 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project hazelcast by hazelcast.

the class AwsConfig method buildClient.

public AmazonKinesisAsync buildClient() {
    AmazonKinesisAsyncClientBuilder builder = AmazonKinesisAsyncClientBuilder.standard();
    if (endpoint == null) {
        if (region != null) {
            builder.setRegion(region);
        }
    } else {
        builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region));
    }
    builder.withCredentials(accessKey == null ? new DefaultAWSCredentialsProviderChain() : new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
    builder.withClientConfiguration(new ClientConfiguration());
    return builder.build();
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonKinesisAsyncClientBuilder(com.amazonaws.services.kinesis.AmazonKinesisAsyncClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 62 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project YCSB by brianfrankcooper.

the class DynamoDBClient method init.

@Override
public void init() throws DBException {
    String debug = getProperties().getProperty("dynamodb.debug", null);
    if (null != debug && "true".equalsIgnoreCase(debug)) {
        LOGGER.setLevel(Level.DEBUG);
    }
    String configuredEndpoint = getProperties().getProperty("dynamodb.endpoint", null);
    String credentialsFile = getProperties().getProperty("dynamodb.awsCredentialsFile", null);
    String primaryKey = getProperties().getProperty("dynamodb.primaryKey", null);
    String primaryKeyTypeString = getProperties().getProperty("dynamodb.primaryKeyType", null);
    String consistentReads = getProperties().getProperty("dynamodb.consistentReads", null);
    String connectMax = getProperties().getProperty("dynamodb.connectMax", null);
    String configuredRegion = getProperties().getProperty("dynamodb.region", null);
    if (null != connectMax) {
        this.maxConnects = Integer.parseInt(connectMax);
    }
    if (null != consistentReads && "true".equalsIgnoreCase(consistentReads)) {
        this.consistentRead = true;
    }
    if (null != configuredEndpoint) {
        this.endpoint = configuredEndpoint;
    }
    if (null == primaryKey || primaryKey.length() < 1) {
        throw new DBException("Missing primary key attribute name, cannot continue");
    }
    if (null != primaryKeyTypeString) {
        try {
            this.primaryKeyType = PrimaryKeyType.valueOf(primaryKeyTypeString.trim().toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new DBException("Invalid primary key mode specified: " + primaryKeyTypeString + ". Expecting HASH or HASH_AND_RANGE.");
        }
    }
    if (this.primaryKeyType == PrimaryKeyType.HASH_AND_RANGE) {
        // When the primary key type is HASH_AND_RANGE, keys used by YCSB
        // are range keys so we can benchmark performance of individual hash
        // partitions. In this case, the user must specify the hash key's name
        // and optionally can designate a value for the hash key.
        String configuredHashKeyName = getProperties().getProperty("dynamodb.hashKeyName", null);
        if (null == configuredHashKeyName || configuredHashKeyName.isEmpty()) {
            throw new DBException("Must specify a non-empty hash key name when the primary key type is HASH_AND_RANGE.");
        }
        this.hashKeyName = configuredHashKeyName;
        this.hashKeyValue = getProperties().getProperty("dynamodb.hashKeyValue", DEFAULT_HASH_KEY_VALUE);
    }
    if (null != configuredRegion && configuredRegion.length() > 0) {
        region = configuredRegion;
    }
    try {
        AmazonDynamoDBClientBuilder dynamoDBBuilder = AmazonDynamoDBClientBuilder.standard();
        dynamoDBBuilder = null == endpoint ? dynamoDBBuilder.withRegion(this.region) : dynamoDBBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(this.endpoint, this.region));
        dynamoDB = dynamoDBBuilder.withClientConfiguration(new ClientConfiguration().withTcpKeepAlive(true).withMaxConnections(this.maxConnects)).withCredentials(new AWSStaticCredentialsProvider(new PropertiesCredentials(new File(credentialsFile)))).build();
        primaryKeyName = primaryKey;
        LOGGER.info("dynamodb connection created with " + this.endpoint);
    } catch (Exception e1) {
        LOGGER.error("DynamoDBClient.init(): Could not initialize DynamoDB client.", e1);
    }
}
Also used : AmazonDynamoDBClientBuilder(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) File(java.io.File) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 63 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project YCSB by brianfrankcooper.

the class S3Client method init.

/**
 * Initialize any state for the storage.
 * Called once per S3 instance; If the client is not null it is re-used.
 */
@Override
public void init() throws DBException {
    final int count = INIT_COUNT.incrementAndGet();
    synchronized (S3Client.class) {
        Properties propsCL = getProperties();
        int recordcount = Integer.parseInt(propsCL.getProperty("recordcount"));
        int operationcount = Integer.parseInt(propsCL.getProperty("operationcount"));
        int numberOfOperations = 0;
        if (recordcount > 0) {
            if (recordcount > operationcount) {
                numberOfOperations = recordcount;
            } else {
                numberOfOperations = operationcount;
            }
        } else {
            numberOfOperations = operationcount;
        }
        if (count <= numberOfOperations) {
            String accessKeyId = null;
            String secretKey = null;
            String endPoint = null;
            String region = null;
            String maxErrorRetry = null;
            String maxConnections = null;
            String protocol = null;
            BasicAWSCredentials s3Credentials;
            ClientConfiguration clientConfig;
            if (s3Client != null) {
                System.out.println("Reusing the same client");
                return;
            }
            try {
                InputStream propFile = S3Client.class.getClassLoader().getResourceAsStream("s3.properties");
                Properties props = new Properties(System.getProperties());
                props.load(propFile);
                accessKeyId = props.getProperty("s3.accessKeyId");
                if (accessKeyId == null) {
                    accessKeyId = propsCL.getProperty("s3.accessKeyId");
                }
                System.out.println(accessKeyId);
                secretKey = props.getProperty("s3.secretKey");
                if (secretKey == null) {
                    secretKey = propsCL.getProperty("s3.secretKey");
                }
                System.out.println(secretKey);
                endPoint = props.getProperty("s3.endPoint");
                if (endPoint == null) {
                    endPoint = propsCL.getProperty("s3.endPoint", "s3.amazonaws.com");
                }
                System.out.println(endPoint);
                region = props.getProperty("s3.region");
                if (region == null) {
                    region = propsCL.getProperty("s3.region", "us-east-1");
                }
                System.out.println(region);
                maxErrorRetry = props.getProperty("s3.maxErrorRetry");
                if (maxErrorRetry == null) {
                    maxErrorRetry = propsCL.getProperty("s3.maxErrorRetry", "15");
                }
                maxConnections = props.getProperty("s3.maxConnections");
                if (maxConnections == null) {
                    maxConnections = propsCL.getProperty("s3.maxConnections");
                }
                protocol = props.getProperty("s3.protocol");
                if (protocol == null) {
                    protocol = propsCL.getProperty("s3.protocol", "HTTPS");
                }
                sse = props.getProperty("s3.sse");
                if (sse == null) {
                    sse = propsCL.getProperty("s3.sse", "false");
                }
                String ssec = props.getProperty("s3.ssec");
                if (ssec == null) {
                    ssec = propsCL.getProperty("s3.ssec", null);
                } else {
                    ssecKey = new SSECustomerKey(ssec);
                }
            } catch (Exception e) {
                System.err.println("The file properties doesn't exist " + e.toString());
                e.printStackTrace();
            }
            try {
                System.out.println("Inizializing the S3 connection");
                s3Credentials = new BasicAWSCredentials(accessKeyId, secretKey);
                clientConfig = new ClientConfiguration();
                clientConfig.setMaxErrorRetry(Integer.parseInt(maxErrorRetry));
                if (protocol.equals("HTTP")) {
                    clientConfig.setProtocol(Protocol.HTTP);
                } else {
                    clientConfig.setProtocol(Protocol.HTTPS);
                }
                if (maxConnections != null) {
                    clientConfig.setMaxConnections(Integer.parseInt(maxConnections));
                }
                s3Client = new AmazonS3Client(s3Credentials, clientConfig);
                s3Client.setRegion(Region.getRegion(Regions.fromName(region)));
                s3Client.setEndpoint(endPoint);
                System.out.println("Connection successfully initialized");
            } catch (Exception e) {
                System.err.println("Could not connect to S3 storage: " + e.toString());
                e.printStackTrace();
                throw new DBException(e);
            }
        } else {
            System.err.println("The number of threads must be less or equal than the operations");
            throw new DBException(new Error("The number of threads must be less or equal than the operations"));
        }
    }
}
Also used : DBException(site.ycsb.DBException) SSECustomerKey(com.amazonaws.services.s3.model.SSECustomerKey) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Properties(java.util.Properties) ClientConfiguration(com.amazonaws.ClientConfiguration) DBException(site.ycsb.DBException)

Example 64 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project exhibitor by soabase.

the class PropertyBasedS3ClientConfig method getAWSClientConfig.

@Override
public ClientConfiguration getAWSClientConfig() {
    ClientConfiguration awsClientConfig = new ClientConfiguration();
    awsClientConfig.setProxyHost(proxyHost);
    awsClientConfig.setProxyPort(proxyPort);
    if (proxyUsername != null) {
        awsClientConfig.setProxyUsername(proxyUsername);
    }
    if (proxyPassword != null) {
        awsClientConfig.setProxyPassword(proxyPassword);
    }
    return awsClientConfig;
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 65 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project SimianArmy by Netflix.

the class AWSClient method sdbClient.

/**
 * Amazon SimpleDB client.
 *
 * @return the Amazon SimpleDB client
 */
public AmazonSimpleDB sdbClient() {
    AmazonSimpleDB client;
    ClientConfiguration cc = awsClientConfig;
    if (cc == null) {
        cc = new ClientConfiguration();
        cc.setMaxErrorRetry(SIMPLE_DB_MAX_RETRY);
    }
    if (awsCredentialsProvider == null) {
        client = new AmazonSimpleDBClient(cc);
    } else {
        client = new AmazonSimpleDBClient(awsCredentialsProvider, cc);
    }
    // http://docs.amazonwebservices.com/general/latest/gr/rande.html#sdb_region
    if (region == null || region.equals("us-east-1")) {
        client.setEndpoint("sdb.amazonaws.com");
    } else {
        client.setEndpoint("sdb." + region + ".amazonaws.com");
    }
    return client;
}
Also used : AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) ClientConfiguration(com.amazonaws.ClientConfiguration)

Aggregations

ClientConfiguration (com.amazonaws.ClientConfiguration)134 Test (org.junit.Test)35 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)29 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)17 AWSCredentials (com.amazonaws.auth.AWSCredentials)14 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)13 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)13 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)10 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)8 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)7 EnvVars (hudson.EnvVars)7 File (java.io.File)7 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)6 Configuration (org.apache.hadoop.conf.Configuration)6 AmazonClientException (com.amazonaws.AmazonClientException)5 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)5 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)5 URI (java.net.URI)5 Properties (java.util.Properties)5 Test (org.testng.annotations.Test)5