/** * A convenient blocking call that can be used, typically during table * deletion, to wait for the table to become deleted. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. */ public void waitForDelete() throws InterruptedException { Waiter waiter = client.waiters().tableNotExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); } catch (Exception exception) { throw new IllegalArgumentException("Table " + tableName + " is not deleted.", exception); } }
@SuppressWarnings("unchecked") public static void createBucket(AmazonS3Client client, String bucketName) throws Exception { client.createBucket(bucketName); HeadBucketRequest request = new HeadBucketRequest(bucketName); Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists(); Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
@SuppressWarnings("unchecked") public static void createBucket(AmazonS3Client client, String bucketName) throws Exception { client.createBucket(bucketName); HeadBucketRequest request = new HeadBucketRequest(bucketName); Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists(); Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
/** * A convenient blocking call that can be used, typically during table * creation, to wait for the table to become active. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. * * @return the table description when the table has become active * * @throws IllegalArgumentException if the table is being deleted * @throws ResourceNotFoundException if the table doesn't exist */ public TableDescription waitForActive() throws InterruptedException { Waiter waiter = client.waiters().tableExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); return describe(); } catch (Exception exception) { // The additional describe call is to return ResourceNotFoundException if the table doesn't exist. // This is to preserve backwards compatibility. describe(); throw new IllegalArgumentException("Table " + tableName + " did not transition into ACTIVE state.", exception); } }
public static void createStream(AmazonKinesisClient client, String streamName) throws Exception { client.createStream(streamName, 1); Waiter<DescribeStreamRequest> waiter = client.waiters().streamExists(); DescribeStreamRequest request = new DescribeStreamRequest().withStreamName(streamName); Assert.assertNotNull("Cannot obtain stream description", request); Future<Void> future = waiter.runAsync(new WaiterParameters<DescribeStreamRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
@Test public void delete_whenTableAlreadyExists_deletesTable() { DeleteDynamoDBTable deleteDynamoDBTable = new DeleteDynamoDBTable(dynamoDB, "asdf", "asdf"); //setup when(dynamoDB.deleteTable("asdf")).thenReturn(new DeleteTableResult()); when(dynamoDB.waiters()).thenReturn(waiters); when(waiters.tableNotExists()).thenReturn(tableNotExists); doNothing().when(tableNotExists).run(any()); when(dynamoDB.describeTable("asdf")).thenThrow(new ResourceNotFoundException("")); //test deleteDynamoDBTable.delete(); //verify verify(dynamoDB).deleteTable("asdf"); verify(tableNotExists).run(any()); }
public static void createStream(AmazonKinesisClient client, String streamName) throws Exception { client.createStream(streamName, 1); Waiter<DescribeStreamRequest> waiter = client.waiters().streamExists(); DescribeStreamRequest request = new DescribeStreamRequest().withStreamName(streamName); Assert.assertNotNull("Cannot obtain stream description", request); Future<Void> future = waiter.runAsync(new WaiterParameters<DescribeStreamRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
@Override protected Void run() throws Exception { TaskListener listener = this.getContext().get(TaskListener.class); AmazonCloudFront client = AWSClientFactory.create(AmazonCloudFrontClientBuilder.standard(), this.getContext()); String distribution = this.step.getDistribution(); String[] paths = this.step.getPaths(); boolean waitForCompletion = this.step.getWaitForCompletion(); listener.getLogger().format("Invalidating paths %s in distribution %s%n", Arrays.toString(paths), distribution); Paths invalidationPaths = new Paths().withItems(paths).withQuantity(paths.length); InvalidationBatch batch = new InvalidationBatch(invalidationPaths, Long.toString(System.currentTimeMillis())); String invalidationId = client.createInvalidation(new CreateInvalidationRequest(distribution, batch)).getInvalidation().getId(); listener.getLogger().format("Invalidation %s enqueued%n", invalidationId); if (waitForCompletion) { listener.getLogger().format("Waiting for invalidation %s to be completed...%n", invalidationId); client.waiters().invalidationCompleted().run(new WaiterParameters<GetInvalidationRequest>(new GetInvalidationRequest(distribution, invalidationId))); listener.getLogger().format("Invalidation %s completed%n", invalidationId); } return null; }
void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, PollConfiguration pollConfiguration) throws ExecutionException { final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null); waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)).withPollingStrategy(this.pollingStrategy(pollConfiguration)), new WaiterHandler() { @Override public void onWaitSuccess(AmazonWebServiceRequest request) { waitResult.completed(request); } @Override public void onWaitFailure(Exception e) { waitResult.failed(e); } }); this.waitAndPrintEvents(stack, pollConfiguration, waitResult); }
@Test public void delete_whenTableNotExistsWaiterThrows_deletesTableAndThrows() { DeleteDynamoDBTable deleteDynamoDBTable = new DeleteDynamoDBTable(dynamoDB, "asdf", "asdf"); //setup when(dynamoDB.deleteTable("asdf")).thenReturn(new DeleteTableResult()); when(dynamoDB.waiters()).thenReturn(waiters); when(waiters.tableNotExists()).thenReturn(tableNotExists); doThrow(new IllegalArgumentException()).when(tableNotExists).run(any()); when(dynamoDB.describeTable("asdf")).thenThrow(new ResourceNotFoundException("")); //test try { deleteDynamoDBTable.delete(); fail(); } catch(IllegalStateException e) { //verify exception assertTrue(e.getCause() instanceof IllegalArgumentException); } verify(dynamoDB).deleteTable("asdf"); verify(tableNotExists).run(any()); }
void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter, PollConfiguration pollConfiguration) throws ExecutionException { final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null); waiter.runAsync(new WaiterParameters<>(new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)).withPollingStrategy(this.pollingStrategy(pollConfiguration)), new WaiterHandler() { @Override public void onWaitSuccess(AmazonWebServiceRequest request) { waitResult.completed(request); } @Override public void onWaitFailure(Exception e) { waitResult.failed(e); } }); this.waitAndPrintEvents(stack, pollConfiguration, waitResult); }
/** * A convenient blocking call that can be used, typically during table * deletion, to wait for the table to become deleted. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. */ public void waitForDelete() throws InterruptedException { Waiter waiter = client.waiters().tableNotExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); } catch (Exception exception) { throw new IllegalArgumentException("Table " + tableName + " is not deleted.", exception); } }
@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) { updateTimeToLiveIfAny(); 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(); } }); }
elbClient_.waiters().loadBalancersDeleted().run(new WaiterParameters<DescribeLoadBalancersRequest>( new DescribeLoadBalancersRequest() .withLoadBalancerArns(loadBalancer.getLoadBalancerArn())
@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) { updateTimeToLiveIfAny(); 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(); } }); }
/** * A convenient blocking call that can be used, typically during table * creation, to wait for the table to become active. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. * * @return the table description when the table has become active * * @throws IllegalArgumentException if the table is being deleted * @throws ResourceNotFoundException if the table doesn't exist */ public TableDescription waitForActive() throws InterruptedException { Waiter waiter = client.waiters().tableExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); return describe(); } catch (Exception exception) { // The additional describe call is to return ResourceNotFoundException if the table doesn't exist. // This is to preserve backwards compatibility. describe(); throw new IllegalArgumentException("Table " + tableName + " did not transition into ACTIVE state.", exception); } }
AmazonCloudFormationWaiters(stackdestroy).stackDeleteComplete(); try { describeStacksRequestWaiter.run(new WaiterParameters<>(new DescribeStacksRequest() .withStackName(stackName))); } catch (WaiterUnrecoverableException e) {
@BeforeClass public static void init() { dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB(); try { dynamoDB.deleteTableAsync(DynamoDbLockRegistry.DEFAULT_TABLE_NAME); Waiter<DescribeTableRequest> waiter = dynamoDB.waiters() .tableNotExists(); waiter.run(new WaiterParameters<>(new DescribeTableRequest(DynamoDbLockRegistry.DEFAULT_TABLE_NAME)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(1)))); } catch (Exception e) { } }
@BeforeClass public static void setup() { AmazonDynamoDBAsync dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB(); try { dynamoDB.deleteTableAsync(DynamoDbLockRegistry.DEFAULT_TABLE_NAME); Waiter<DescribeTableRequest> waiter = dynamoDB.waiters() .tableNotExists(); waiter.run(new WaiterParameters<>(new DescribeTableRequest(DynamoDbLockRegistry.DEFAULT_TABLE_NAME)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(1)))); } catch (Exception e) { } }
@BeforeClass public static void setup() { 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.setTimeToLive(10); // Dynalite doesn't support TTL store.afterPropertiesSet(); }