com.amazonaws.services.cloudformation.model.DescribeStackEventsResult Java Examples
The following examples show how to use
com.amazonaws.services.cloudformation.model.DescribeStackEventsResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmazonWebServicesClientProxyTest.java From cloudformation-cli-java-plugin with Apache License 2.0 | 4 votes |
@Test public void testInjectCredentialsAndInvoke() { final LoggerProxy loggerProxy = mock(LoggerProxy.class); final Credentials credentials = new Credentials("accessKeyId", "secretAccessKey", "sessionToken"); final AmazonWebServicesClientProxy proxy = new AmazonWebServicesClientProxy(loggerProxy, credentials, () -> 1000L); final DescribeStackEventsRequest request = mock(DescribeStackEventsRequest.class); final DescribeStackEventsResult expectedResult = new DescribeStackEventsResult(); expectedResult.setStackEvents(Collections.emptyList()); final AmazonCloudFormation client = mock(AmazonCloudFormation.class); when(client.describeStackEvents(any(DescribeStackEventsRequest.class))).thenReturn(expectedResult); final DescribeStackEventsResult result = proxy.injectCredentialsAndInvoke(request, client::describeStackEvents); // ensure credentials are injected and then removed verify(request).setRequestCredentialsProvider(any(AWSStaticCredentialsProvider.class)); verify(request).setRequestCredentialsProvider(eq(null)); // ensure the return type matches assertThat(result).isEqualTo(expectedResult); }
Example #2
Source File: StackCreationWaiter.java From testgrid with Apache License 2.0 | 4 votes |
@Override public Boolean call() throws Exception { //Stack details DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); DescribeStacksResult describeStacksResult = cloudFormation.describeStacks(describeStacksRequest); final List<Stack> stacks = describeStacksResult.getStacks(); if (stacks.size() > 1 || stacks.isEmpty()) { String stackNames = stacks.stream().map(Stack::getStackName).collect(Collectors.joining(", ")); final String msg = "More than one stack found or stack list is empty for the stack name: " + stackName + ": " + stackNames; logger.error(msg); throw new IllegalStateException(msg); } Stack stack = stacks.get(0); StackStatus stackStatus = StackStatus.fromValue(stack.getStackStatus()); // Event details of the stack DescribeStackEventsRequest describeStackEventsRequest = new DescribeStackEventsRequest() .withStackName(stackName); DescribeStackEventsResult describeStackEventsResult = cloudFormation. describeStackEvents(describeStackEventsRequest); //Print a log of the current state of the resources StringBuilder stringBuilder = new StringBuilder(); final List<StackEvent> originalStackEvents = describeStackEventsResult.getStackEvents(); final List<StackEvent> newStackEvents = new ArrayList<>(originalStackEvents); newStackEvents.removeAll(prevStackEvents); ListIterator<StackEvent> li = newStackEvents.listIterator(newStackEvents.size()); while (li.hasPrevious()) { StackEvent stackEvent = li.previous(); stringBuilder.append(StringUtil.concatStrings( "Status: ", stackEvent.getResourceStatus(), ", ")); stringBuilder.append(StringUtil.concatStrings( "Resource Type: ", stackEvent.getResourceType(), ", ")); stringBuilder.append(StringUtil.concatStrings( "Logical ID: ", stackEvent.getLogicalResourceId(), ", ")); stringBuilder.append(StringUtil.concatStrings( "Status Reason: ", Optional.ofNullable(stackEvent.getResourceStatusReason()).orElse("-"))); stringBuilder.append("\n"); } logger.info(StringUtil.concatStrings("\n", stringBuilder.toString())); prevStackEvents = originalStackEvents; //Determine the steps to execute based on the status of the stack switch (stackStatus) { case CREATE_COMPLETE: return true; case CREATE_IN_PROGRESS: break; default: throw new TestGridInfrastructureException(StringUtil.concatStrings( "Stack creation transitioned to ", stackStatus.toString(), " state.")); } return false; }