Search in sources :

Example 16 with ProvisionedThroughput

use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput 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)

Example 17 with ProvisionedThroughput

use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project amos-ss17-alexa by c-i-ber.

the class DynamoDbMapper method createTable.

/**
 * creates a new table by a pojo class
 *
 * @param cl class which will be mapped to the new table
 */
public void createTable(Class cl) throws InterruptedException {
    CreateTableRequest tableRequest = mapper.generateCreateTableRequest(cl);
    tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
    Table table = dynamoDB.createTable(tableRequest);
    table.waitForActive();
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest)

Example 18 with ProvisionedThroughput

use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project wildfly-camel by wildfly-extras.

the class DynamoDBUtils method createTable.

public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException {
    CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName).withKeySchema(new KeySchemaElement("Id", KeyType.HASH)).withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N)).withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)).withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES));
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.createTable(tableReq);
    return table.waitForActive();
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) StreamSpecification(com.amazonaws.services.dynamodbv2.model.StreamSpecification) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 19 with ProvisionedThroughput

use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project tutorials by eugenp.

the class ProductInfoRepositoryIntegrationTest method setup.

@Before
public void setup() {
    try {
        repository = new ProductInfoRepository();
        repository.setMapper(dynamoDBMapper);
        CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
        tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
        amazonDynamoDB.createTable(tableRequest);
    } catch (ResourceInUseException e) {
    // Do nothing, table already created
    }
    // TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
    dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
Also used : ProductInfoRepository(com.baeldung.dynamodb.repository.ProductInfoRepository) ProductInfo(com.baeldung.dynamodb.entity.ProductInfo) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) Before(org.junit.Before)

Example 20 with ProvisionedThroughput

use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project spring-integration-aws by spring-projects.

the class DynamoDbMetaDataStore method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    try {
        this.table.describe();
        this.createTableLatch.countDown();
        return;
    } catch (ResourceNotFoundException e) {
        if (logger.isInfoEnabled()) {
            logger.info("No table '" + this.table.getTableName() + "'. Creating one...");
        }
    }
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(this.table.getTableName()).withKeySchema(new KeySchemaElement(KEY, KeyType.HASH)).withAttributeDefinitions(new AttributeDefinition(KEY, ScalarAttributeType.S)).withProvisionedThroughput(new ProvisionedThroughput(this.readCapacity, this.writeCapacity));
    this.dynamoDB.createTableAsync(createTableRequest, new AsyncHandler<CreateTableRequest, CreateTableResult>() {

        @Override
        public void onError(Exception e) {
            logger.error("Cannot create DynamoDb table: " + DynamoDbMetaDataStore.this.table.getTableName(), e);
            DynamoDbMetaDataStore.this.createTableLatch.countDown();
        }

        @Override
        public void onSuccess(CreateTableRequest request, CreateTableResult createTableResult) {
            Waiter<DescribeTableRequest> waiter = DynamoDbMetaDataStore.this.dynamoDB.waiters().tableExists();
            WaiterParameters<DescribeTableRequest> waiterParameters = new WaiterParameters<>(new DescribeTableRequest(DynamoDbMetaDataStore.this.table.getTableName())).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(DynamoDbMetaDataStore.this.createTableRetries), new FixedDelayStrategy(DynamoDbMetaDataStore.this.createTableDelay)));
            waiter.runAsync(waiterParameters, new WaiterHandler<DescribeTableRequest>() {

                @Override
                public void onWaitSuccess(DescribeTableRequest request) {
                    DynamoDbMetaDataStore.this.createTableLatch.countDown();
                    DynamoDbMetaDataStore.this.table.describe();
                }

                @Override
                public void onWaitFailure(Exception e) {
                    logger.error("Cannot describe DynamoDb table: " + DynamoDbMetaDataStore.this.table.getTableName(), e);
                    DynamoDbMetaDataStore.this.createTableLatch.countDown();
                }
            });
        }
    });
}
Also used : MaxAttemptsRetryStrategy(com.amazonaws.waiters.MaxAttemptsRetryStrategy) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) WaiterParameters(com.amazonaws.waiters.WaiterParameters) PollingStrategy(com.amazonaws.waiters.PollingStrategy) FixedDelayStrategy(com.amazonaws.waiters.FixedDelayStrategy) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) Waiter(com.amazonaws.waiters.Waiter) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) CreateTableResult(com.amazonaws.services.dynamodbv2.model.CreateTableResult)

Aggregations

ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)30 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)25 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)23 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)23 ArrayList (java.util.ArrayList)14 Table (com.amazonaws.services.dynamodbv2.document.Table)11 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)7 AmazonServiceException (com.amazonaws.AmazonServiceException)5 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)5 Projection (com.amazonaws.services.dynamodbv2.model.Projection)5 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)5 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)3 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)3 GlobalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndex)3 LocalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex)3 StreamSpecification (com.amazonaws.services.dynamodbv2.model.StreamSpecification)3 AmazonClientException (com.amazonaws.AmazonClientException)2 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)2 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)2 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)2