Search in sources :

Example 1 with DescribeStackEventsResult

use of com.amazonaws.services.cloudformation.model.DescribeStackEventsResult in project pipeline-aws-plugin by jenkinsci.

the class EventPrinter method waitAndPrintEvents.

private void waitAndPrintEvents(String stack, long pollIntervalMillis, BasicFuture<AmazonWebServiceRequest> waitResult) throws ExecutionException {
    Date startDate = new Date();
    String lastEventId = null;
    this.printLine();
    this.printStackName(stack);
    this.printLine();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    if (pollIntervalMillis > 0) {
        while (!waitResult.isDone()) {
            try {
                DescribeStackEventsResult result = this.client.describeStackEvents(new DescribeStackEventsRequest().withStackName(stack));
                List<StackEvent> stackEvents = new ArrayList<>();
                for (StackEvent event : result.getStackEvents()) {
                    if (event.getEventId().equals(lastEventId) || event.getTimestamp().before(startDate)) {
                        break;
                    }
                    stackEvents.add(event);
                }
                if (!stackEvents.isEmpty()) {
                    Collections.reverse(stackEvents);
                    for (StackEvent event : stackEvents) {
                        this.printEvent(sdf, event);
                        this.printLine();
                    }
                    lastEventId = stackEvents.get(stackEvents.size() - 1).getEventId();
                }
            } catch (AmazonCloudFormationException e) {
            // suppress and continue
            }
            try {
                Thread.sleep(pollIntervalMillis);
            } catch (InterruptedException e) {
            // suppress and continue
            }
        }
    }
    try {
        waitResult.get();
    } catch (InterruptedException e) {
        this.listener.getLogger().format("Failed to wait for CFN action to complete: %s", e.getMessage());
    }
}
Also used : DescribeStackEventsResult(com.amazonaws.services.cloudformation.model.DescribeStackEventsResult) StackEvent(com.amazonaws.services.cloudformation.model.StackEvent) ArrayList(java.util.ArrayList) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException) SimpleDateFormat(java.text.SimpleDateFormat) DescribeStackEventsRequest(com.amazonaws.services.cloudformation.model.DescribeStackEventsRequest) Date(java.util.Date)

Aggregations

AmazonCloudFormationException (com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)1 DescribeStackEventsRequest (com.amazonaws.services.cloudformation.model.DescribeStackEventsRequest)1 DescribeStackEventsResult (com.amazonaws.services.cloudformation.model.DescribeStackEventsResult)1 StackEvent (com.amazonaws.services.cloudformation.model.StackEvent)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1