Search in sources :

Example 1 with FixedDelayStrategy

use of com.amazonaws.waiters.FixedDelayStrategy 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)

Example 2 with FixedDelayStrategy

use of com.amazonaws.waiters.FixedDelayStrategy in project spring-integration-aws by spring-projects.

the class DynamoDbMetadataStoreTests method setup.

@BeforeClass
public static void setup() throws Exception {
    AmazonDynamoDBAsync dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB();
    try {
        dynamoDB.deleteTableAsync(TEST_TABLE);
        Waiter<DescribeTableRequest> waiter = dynamoDB.waiters().tableNotExists();
        waiter.run(new WaiterParameters<>(new DescribeTableRequest(TEST_TABLE)).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(1))));
    } catch (Exception e) {
    }
    store = new DynamoDbMetaDataStore(dynamoDB, TEST_TABLE);
    store.afterPropertiesSet();
}
Also used : PollingStrategy(com.amazonaws.waiters.PollingStrategy) AmazonDynamoDBAsync(com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync) MaxAttemptsRetryStrategy(com.amazonaws.waiters.MaxAttemptsRetryStrategy) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) FixedDelayStrategy(com.amazonaws.waiters.FixedDelayStrategy) WaiterParameters(com.amazonaws.waiters.WaiterParameters) BeforeClass(org.junit.BeforeClass)

Aggregations

DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)2 FixedDelayStrategy (com.amazonaws.waiters.FixedDelayStrategy)2 MaxAttemptsRetryStrategy (com.amazonaws.waiters.MaxAttemptsRetryStrategy)2 PollingStrategy (com.amazonaws.waiters.PollingStrategy)2 WaiterParameters (com.amazonaws.waiters.WaiterParameters)2 AmazonDynamoDBAsync (com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync)1 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)1 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)1 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)1 Waiter (com.amazonaws.waiters.Waiter)1 WaiterHandler (com.amazonaws.waiters.WaiterHandler)1 BeforeClass (org.junit.BeforeClass)1