/** * 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); } }
/** * 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); } }
@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; }
@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()); }
@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()); }
/** * 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); } }
elbClient_.waiters().loadBalancersDeleted().run(new WaiterParameters<DescribeLoadBalancersRequest>( new DescribeLoadBalancersRequest() .withLoadBalancerArns(loadBalancer.getLoadBalancerArn())
/** * 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(); }