Search in sources :

Example 1 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project archaius by Netflix.

the class DynamoBackedConfigurationIntegrationTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    try {
        dbClient = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain().getCredentials());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.setProperty("com.netflix.config.dynamo.tableName", tableName);
    if (dbClient != null) {
        createTable(dbClient, tableName);
        addElements(dbClient, tableName);
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) BeforeClass(org.junit.BeforeClass)

Example 2 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient 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);
    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);
    }
    try {
        AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile));
        ClientConfiguration cconfig = new ClientConfiguration();
        cconfig.setMaxConnections(maxConnects);
        dynamoDB = new AmazonDynamoDBClient(credentials, cconfig);
        dynamoDB.setEndpoint(this.endpoint);
        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 : PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AWSCredentials(com.amazonaws.auth.AWSCredentials) File(java.io.File) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 3 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project camel by apache.

the class DdbEndpoint method createDdbClient.

AmazonDynamoDB createDdbClient() {
    AmazonDynamoDB client = null;
    ClientConfiguration clientConfiguration = null;
    boolean isClientConfigFound = false;
    if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
        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 AmazonDynamoDBClient(credentials, clientConfiguration);
        } else {
            client = new AmazonDynamoDBClient(credentials);
        }
    } else {
        if (isClientConfigFound) {
            client = new AmazonDynamoDBClient();
        } else {
            client = new AmazonDynamoDBClient(clientConfiguration);
        }
    }
    return client;
}
Also used : AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 4 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project cas by apereo.

the class DynamoDbCloudConfigBootstrapConfiguration method locate.

@Override
public PropertySource<?> locate(final Environment environment) {
    final AmazonDynamoDB amazonDynamoDBClient = getAmazonDynamoDbClient(environment);
    createSettingsTable(amazonDynamoDBClient, false);
    final ScanRequest scan = new ScanRequest(TABLE_NAME);
    LOGGER.debug("Scanning table with request [{}]", scan);
    final ScanResult result = amazonDynamoDBClient.scan(scan);
    LOGGER.debug("Scanned table with result [{}]", scan);
    final Properties props = new Properties();
    result.getItems().stream().map(DynamoDbCloudConfigBootstrapConfiguration::retrieveSetting).forEach(p -> props.put(p.getKey(), p.getValue()));
    return new PropertiesPropertySource(getClass().getSimpleName(), props);
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Properties(java.util.Properties)

Example 5 with AmazonDynamoDBClient

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient in project cas by apereo.

the class DynamoDbTicketRegistryFacilitator method createTicketTables.

/**
 * Create ticket tables.
 *
 * @param deleteTables the delete tables
 */
public void createTicketTables(final boolean deleteTables) {
    final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
    metadata.forEach(Unchecked.consumer(r -> {
        final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getColumnName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getColumnName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(r.getProperties().getStorageName());
        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    }));
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) PutItemResult(com.amazonaws.services.dynamodbv2.model.PutItemResult) Getter(lombok.Getter) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) KeyType(com.amazonaws.services.dynamodbv2.model.KeyType) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TicketCatalog(org.apereo.cas.ticket.TicketCatalog) Unchecked(org.jooq.lambda.Unchecked) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Collection(java.util.Collection) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Collectors(java.util.stream.Collectors) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) TableUtils(com.amazonaws.services.dynamodbv2.util.TableUtils) PutItemRequest(com.amazonaws.services.dynamodbv2.model.PutItemRequest) ScalarAttributeType(com.amazonaws.services.dynamodbv2.model.ScalarAttributeType) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) Slf4j(lombok.extern.slf4j.Slf4j) DynamoDbTicketRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties) AllArgsConstructor(lombok.AllArgsConstructor) Ticket(org.apereo.cas.ticket.Ticket) DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Aggregations

AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)14 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)5 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)5 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)5 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)4 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)4 BeforeClass (org.junit.BeforeClass)4 ClientConfiguration (com.amazonaws.ClientConfiguration)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)3 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)3 SneakyThrows (lombok.SneakyThrows)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)2 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)2 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)2 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)2