Search in sources :

Example 1 with WaiterHandler

use of com.amazonaws.waiters.WaiterHandler in project pipeline-aws-plugin by jenkinsci.

the class EventPrinter method waitAndPrintStackEvents.

public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, long pollIntervalMillis) throws ExecutionException {
    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
    waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)), new WaiterHandler() {

        @Override
        public void onWaitSuccess(AmazonWebServiceRequest request) {
            waitResult.completed(request);
        }

        @Override
        public void onWaitFailure(Exception e) {
            waitResult.failed(e);
        }
    });
    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) BasicFuture(org.apache.http.concurrent.BasicFuture) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) ExecutionException(java.util.concurrent.ExecutionException) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)

Example 2 with WaiterHandler

use of com.amazonaws.waiters.WaiterHandler in project pipeline-aws-plugin by jenkinsci.

the class EventPrinter method waitAndPrintChangeSetEvents.

public void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter, long pollIntervalMillis) throws ExecutionException {
    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
    waiter.runAsync(new WaiterParameters<>(new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)), new WaiterHandler() {

        @Override
        public void onWaitSuccess(AmazonWebServiceRequest request) {
            waitResult.completed(request);
        }

        @Override
        public void onWaitFailure(Exception e) {
            waitResult.failed(e);
        }
    });
    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
Also used : BasicFuture(org.apache.http.concurrent.BasicFuture) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) ExecutionException(java.util.concurrent.ExecutionException) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)

Example 3 with WaiterHandler

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

WaiterHandler (com.amazonaws.waiters.WaiterHandler)3 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)2 AmazonCloudFormationException (com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 BasicFuture (org.apache.http.concurrent.BasicFuture)2 DescribeChangeSetRequest (com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)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 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)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 FixedDelayStrategy (com.amazonaws.waiters.FixedDelayStrategy)1 MaxAttemptsRetryStrategy (com.amazonaws.waiters.MaxAttemptsRetryStrategy)1 PollingStrategy (com.amazonaws.waiters.PollingStrategy)1 Waiter (com.amazonaws.waiters.Waiter)1 WaiterParameters (com.amazonaws.waiters.WaiterParameters)1