Search in sources :

Example 1 with StackEvent

use of com.amazonaws.services.cloudformation.model.StackEvent 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)

Example 2 with StackEvent

use of com.amazonaws.services.cloudformation.model.StackEvent in project cloudbreak by hortonworks.

the class AbstractAwsStackStatusCheckerTask method doCall.

@Override
protected Boolean doCall() {
    LOGGER.info("Checking if AWS CloudFormation stack '{}' reached status '{}'", cloudFormationStackName, successStatus);
    try {
        com.amazonaws.services.cloudformation.model.Stack cfStack = cfClient.describeStacks(describeStacksRequest).getStacks().get(0);
        List<StackEvent> stackEvents = cfClient.describeStackEvents(stackEventsRequest).getStackEvents();
        return doCheck(cfStack, stackEvents);
    } catch (AmazonServiceException e) {
        return handleError(e);
    }
}
Also used : StackEvent(com.amazonaws.services.cloudformation.model.StackEvent) AmazonServiceException(com.amazonaws.AmazonServiceException) Stack(com.amazonaws.services.cloudformation.model.Stack)

Aggregations

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