com.amazonaws.services.cloudformation.model.Output Java Examples
The following examples show how to use
com.amazonaws.services.cloudformation.model.Output.
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: CloudFormationClient.java From herd-mdl with Apache License 2.0 | 6 votes |
/** * Get outputs for the wrapper stack and all nested stacks * * @return Outputs for stack {@link #stackName} */ public Map<String, String> getStackOutput() throws Exception { String rootStackId = getStackInfo().stackId(); LOGGER.info("rootStackId = " + rootStackId); Map<String, String> outputs = new HashMap<>(); outputs.put("rootStackId", rootStackId); DescribeStacksResult describeStacksResult = amazonCloudFormation.describeStacks(); for (Stack currentStack : describeStacksResult.getStacks()) { // Get the output details for the running stacks that got created // go through both root and nested stacks if (currentStack.getStackStatus().equals(StackStatus.CREATE_COMPLETE.toString()) && (rootStackId.equals(currentStack.getRootId()) || rootStackId.equals(currentStack.getStackId()))) { for (Output output : currentStack.getOutputs()) { LOGGER.info(output.getOutputKey() + " = " + output.getOutputValue()); outputs.put(output.getOutputKey(), output.getOutputValue()); } } } return outputs; }
Example #2
Source File: AWSProvider.java From testgrid with Apache License 2.0 | 6 votes |
private static Properties getCloudformationOutputs(AmazonCloudFormation cloudFormation, CreateStackResult stack) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.setStackName(stack.getStackId()); final DescribeStacksResult describeStacksResult = cloudFormation .describeStacks(describeStacksRequest); Properties outputProps = new Properties(); for (Stack st : describeStacksResult.getStacks()) { StringBuilder outputsStr = new StringBuilder("Infrastructure/Deployment outputs {\n"); for (Output output : st.getOutputs()) { outputProps.setProperty(output.getOutputKey(), output.getOutputValue()); outputsStr.append(output.getOutputKey()).append("=").append(output.getOutputValue()).append("\n"); } //Log cfn outputs logger.info(outputsStr.toString() + "\n}"); } return outputProps; }
Example #3
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void executeChangeSetWithChanges() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest() .withStackName("foo") .withChangeSetName("bar") )).thenReturn(new DescribeChangeSetResult() .withChanges(new Change()) ); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("CREATE_COMPLETE").withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); Map<String, String> outputs = stack.executeChangeSet("bar", PollConfiguration.DEFAULT); Mockito.verify(client).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class)); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #4
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void noExecuteChangeSetIfNoChanges() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest() .withStackName("foo") .withChangeSetName("bar") )).thenReturn(new DescribeChangeSetResult()); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); Map<String, String> outputs = stack.executeChangeSet("bar", PollConfiguration.DEFAULT); Mockito.verify(client, Mockito.never()).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "false"); }
Example #5
Source File: CloudFormationStack.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
public Map<String, String> describeOutputs() { DescribeStacksResult result = this.client.describeStacks(new DescribeStacksRequest().withStackName(this.stack)); Stack cfnStack = result.getStacks().get(0); Map<String, String> map = new HashMap<>(); for (Output output : cfnStack.getOutputs()) { map.put(output.getOutputKey(), output.getOutputValue()); } return map; }
Example #6
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void describeStack() { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); Assertions.assertThat(stack.describeOutputs()).isEqualTo(Collections.singletonMap( "bar", "baz" )); }
Example #7
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void updateStack() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10); Map<String, String> outputs = stack.update("templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig); ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class); Mockito.verify(client).updateStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest() .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withRoleARN("myarn") .withRollbackConfiguration(rollbackConfig) ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #8
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void updateStackWithTemplateUrl() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10); Map<String, String> outputs = stack.update(null, "bar", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig); ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class); Mockito.verify(client).updateStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest() .withStackName("foo") .withTemplateURL("bar") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withRoleARN("myarn") .withRollbackConfiguration(rollbackConfig) ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #9
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void updateStackWithPreviousTemplate() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10); Map<String, String> outputs = stack.update(null, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig); ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class); Mockito.verify(client).updateStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest() .withStackName("foo") .withUsePreviousTemplate(true) .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withRoleARN("myarn") .withRollbackConfiguration(rollbackConfig) ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #10
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void createStack() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); Map<String, String> outputs = stack.create("templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", OnFailure.DO_NOTHING.toString(), null); ArgumentCaptor<CreateStackRequest> captor = ArgumentCaptor.forClass(CreateStackRequest.class); Mockito.verify(client).createStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateStackRequest() .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withTimeoutInMinutes((int) PollConfiguration.DEFAULT.getTimeout().toMinutes()) .withOnFailure(OnFailure.DO_NOTHING) .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #11
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void createStackWithTemplateUrl() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); PollConfiguration pollConfiguration = PollConfiguration.builder() .timeout(Duration.ofMinutes(3)) .pollInterval(Duration.ofSeconds(17)) .build(); Map<String, String> outputs = stack.create(null, "bar", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), pollConfiguration, "myarn", OnFailure.DO_NOTHING.toString(), true); ArgumentCaptor<CreateStackRequest> captor = ArgumentCaptor.forClass(CreateStackRequest.class); Mockito.verify(client).createStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateStackRequest() .withStackName("foo") .withEnableTerminationProtection(true) .withTemplateURL("bar") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withTimeoutInMinutes(3) .withOnFailure(OnFailure.DO_NOTHING) .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(pollConfiguration)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #12
Source File: TestStackInstanceIdService.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
private static String getOutputValue(Stack stack, String outputKey) { for (Output output : stack.getOutputs()) { if (output.getOutputKey().equals(outputKey)) { return output.getOutputValue(); } } throw new IllegalStateException("No output '" + outputKey + "' defined in stack '" + stack.getStackName() + "'"); }
Example #13
Source File: CloudFormationStackUtil.java From cloudbreak with Apache License 2.0 | 5 votes |
public Map<String, String> getOutputs(String cFStackName, AmazonCloudFormationRetryClient client) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); String outputNotFound = String.format("Couldn't get Cloudformation stack's('%s') output", cFStackName); List<Output> cfStackOutputs = client.describeStacks(describeStacksRequest).getStacks() .stream().findFirst().orElseThrow(getCloudConnectorExceptionSupplier(outputNotFound)).getOutputs(); return cfStackOutputs.stream().collect(Collectors.toMap(Output::getOutputKey, Output::getOutputValue)); }
Example #14
Source File: AwsLaunchTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private DescribeStacksResult getDescribeStacksResult() { return new DescribeStacksResult().withStacks( new Stack().withOutputs( new Output().withOutputKey("CreatedVpc").withOutputValue("vpc-id"), new Output().withOutputKey("CreatedSubnet").withOutputValue("subnet-id"), new Output().withOutputKey("EIPAllocationIDmaster1").withOutputValue("eipalloc-id") )); }
Example #15
Source File: CloudFormationClient.java From herd-mdl with Apache License 2.0 | 4 votes |
public List<Output> outputs() { return stack.getOutputs(); }