Search in sources :

Example 11 with AmazonDynamoDBClient

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

the class DynamoDbCloudConfigBootstrapConfiguration method createSettingsTable.

@SneakyThrows
private static void createSettingsTable(final AmazonDynamoDB amazonDynamoDBClient, final boolean deleteTables) {
    final String name = ColumnNames.ID.getColumnName();
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(name, ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(name, KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)).withTableName(TABLE_NAME);
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        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) 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) SneakyThrows(lombok.SneakyThrows)

Example 12 with AmazonDynamoDBClient

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

the class AmazonDynamoDbClientFactory method createAmazonDynamoDb.

/**
 * Create amazon dynamo db instance.
 *
 * @param dynamoDbProperties the dynamo db properties
 * @return the amazon dynamo db
 */
@SneakyThrows
public AmazonDynamoDB createAmazonDynamoDb(final AbstractDynamoDbProperties dynamoDbProperties) {
    if (dynamoDbProperties.isLocalInstance()) {
        LOGGER.debug("Creating DynamoDb standard client with endpoint [{}] and region [{}]", dynamoDbProperties.getEndpoint(), dynamoDbProperties.getRegion());
        final AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(dynamoDbProperties.getEndpoint(), dynamoDbProperties.getRegion());
        return AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).build();
    }
    final AWSCredentialsProvider provider = ChainingAWSCredentialsProvider.getInstance(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey(), dynamoDbProperties.getCredentialsPropertiesFile());
    LOGGER.debug("Creating DynamoDb client configuration...");
    final ClientConfiguration cfg = new ClientConfiguration();
    cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
    cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
    cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
    cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
    cfg.setUseGzip(dynamoDbProperties.isUseGzip());
    cfg.setUseReaper(dynamoDbProperties.isUseReaper());
    cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
    cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
    cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
    cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
    cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
    if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
        LOGGER.debug("Creating DynamoDb client local address [{}]", dynamoDbProperties.getLocalAddress());
        cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
    }
    LOGGER.debug("Creating DynamoDb client instance...");
    final AmazonDynamoDBClient client = new AmazonDynamoDBClient(provider, cfg);
    if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
        LOGGER.debug("Setting DynamoDb client endpoint [{}]", dynamoDbProperties.getEndpoint());
        client.setEndpoint(dynamoDbProperties.getEndpoint());
    }
    if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
        LOGGER.debug("Setting DynamoDb client region [{}]", dynamoDbProperties.getRegion());
        client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
    }
    if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
        LOGGER.debug("Setting DynamoDb client region override [{}]", dynamoDbProperties.getRegionOverride());
        client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
    }
    if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
        client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
    }
    if (dynamoDbProperties.getTimeOffset() != 0) {
        client.setTimeOffset(dynamoDbProperties.getTimeOffset());
    }
    return client;
}
Also used : AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) ChainingAWSCredentialsProvider(org.apereo.cas.aws.ChainingAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClientConfiguration(com.amazonaws.ClientConfiguration) SneakyThrows(lombok.SneakyThrows)

Example 13 with AmazonDynamoDBClient

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

the class DynamoDbServiceRegistryFacilitator method createServicesTable.

/**
 * Create tables.
 *
 * @param deleteTables the delete tables
 */
@SneakyThrows
public void createServicesTable(final boolean deleteTables) {
    LOGGER.debug("Attempting to create DynamoDb services table");
    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(dynamoDbProperties.getTableName());
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        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) 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) SneakyThrows(lombok.SneakyThrows)

Example 14 with AmazonDynamoDBClient

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

the class AbstractDynamoDBProcessor method createClient.

/**
 * Create client using AWSCredentials
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AmazonDynamoDBClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().debug("Creating client with aws credentials");
    final AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials, config);
    return client;
}
Also used : AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)

Example 15 with AmazonDynamoDBClient

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

the class ITAbstractDynamoDBTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    FileInputStream fis = new FileInputStream(CREDENTIALS_FILE);
    final PropertiesCredentials credentials = new PropertiesCredentials(fis);
    amazonDynamoDBClient = new AmazonDynamoDBClient(credentials);
    dynamoDB = new DynamoDB(amazonDynamoDBClient);
    amazonDynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2));
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("hashS").withAttributeType("S"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("rangeS").withAttributeType("S"));
    ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashS").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeS").withKeyType(KeyType.RANGE));
    CreateTableRequest request = new CreateTableRequest().withTableName(stringHashStringRangeTableName).withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(6L));
    Table stringHashStringRangeTable = dynamoDB.createTable(request);
    stringHashStringRangeTable.waitForActive();
    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("rangeN").withAttributeType("N"));
    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeN").withKeyType(KeyType.RANGE));
    request = new CreateTableRequest().withTableName(numberHashNumberRangeTableName).withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(6L));
    Table numberHashNumberRangeTable = dynamoDB.createTable(request);
    numberHashNumberRangeTable.waitForActive();
    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));
    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));
    request = new CreateTableRequest().withTableName(numberHashOnlyTableName).withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(6L));
    Table numberHashOnlyTable = dynamoDB.createTable(request);
    numberHashOnlyTable.waitForActive();
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) ArrayList(java.util.ArrayList) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) FileInputStream(java.io.FileInputStream) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) BeforeClass(org.junit.BeforeClass)

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