List of usage examples for com.amazonaws.services.cloudformation.model DescribeStackEventsRequest withNextToken
public DescribeStackEventsRequest withNextToken(String nextToken)
A string that identifies the next page of events that you want to retrieve.
From source file:br.com.ingenieux.mojo.cloudformation.cmd.WaitForStackCommand.java
License:Apache License
public void execute() throws Exception { Set<StackEvent> events = new TreeSet<>((o1, o2) -> { return o1.getEventId().compareTo(o2.getEventId()); });//from w ww. ja v a 2 s. c o m boolean done = false; Date timeoutsAt = new Date(System.currentTimeMillis() + 60000L * ctx.getTimeoutMins()); do { boolean timedOut = !timeoutsAt.after(new Date(System.currentTimeMillis())); if (timedOut) throw new IllegalStateException("Timed Out"); { final DescribeStackEventsRequest req = new DescribeStackEventsRequest() .withStackName(ctx.getStackId()); String nextToken = null; do { req.withNextToken(nextToken); Optional<DescribeStackEventsResult> stackEvents = getDescribeStackEventsResult(req); if (!stackEvents.isPresent()) { return; } else { for (StackEvent e : stackEvents.get().getStackEvents()) { if (!events.contains(e)) { ctx.getNotifier().info("" + e); events.add(e); } } } } while (null != nextToken); } { final DescribeStacksResult stacks = ctx.getClient() .describeStacks(new DescribeStacksRequest().withStackName(ctx.getStackId())); Optional<Stack> foundStack = stacks.getStacks().stream().filter( stack -> ctx.getStatusesToMatch().contains(StackStatus.fromValue(stack.getStackStatus()))) .findFirst(); done = foundStack.isPresent(); } if (!done) { Thread.sleep(15000); } } while (!done); }