Java 类com.amazonaws.services.cloudformation.model.DescribeStacksResult 实例源码

项目:cerberus-lifecycle-cli    文件:CloudFormationService.java   
/**
 * Returns the current status of the named stack.
 *
 * @param stackId Stack ID.
 * @return Stack status data.
 */
@Nullable
public StackStatus getStackStatus(final String stackId) {
    final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId);

    try {
        final DescribeStacksResult result = cloudFormationClient.describeStacks(request);

        if (result.getStacks().size() > 0) {
            final String status = result.getStacks().get(0).getStackStatus();

            if (StringUtils.isNotBlank(status)) {
                return StackStatus.fromValue(status);
            }
        }
    } catch (final AmazonServiceException ase) {
        // Stack doesn't exist, just return with no status
        if (ase.getStatusCode() != 400) {
            throw ase;
        }
    }

    return null;
}
项目:cerberus-lifecycle-cli    文件:CloudFormationService.java   
/**
 * Since there doesn't appear to be a first class way through the SDK at this time to get a CF export. We can
 * iterate through the stacks for a given output key and return the value.
 * @param outputKey The exported CF variable to search and retrieve the value of.
 * @return The value for the export if found
 */
public Optional<String> searchStacksForOutput(String outputKey) {
    DescribeStacksResult describeStacksResult = null;
    do {
        DescribeStacksRequest request = new DescribeStacksRequest();
        if (describeStacksResult != null && describeStacksResult.getNextToken() != null) {
            request.withNextToken(describeStacksResult.getNextToken());
        }
        describeStacksResult = cloudFormationClient.describeStacks();
        for (Stack stack : describeStacksResult.getStacks()) {
            for (Output output : stack.getOutputs()) {
                if (StringUtils.equals(output.getOutputKey(), outputKey)) {
                    return Optional.of(output.getOutputValue());
                }
            }
        }

    } while (describeStacksResult.getNextToken() != null);

    return Optional.empty();
}
项目:spring-cloud-aws    文件:StackResourceUserTagsFactoryBeanTest.java   
@Test
public void getObject_stackWithTagsDefined_createTagsMap() throws Exception {
    //Arrange
    AmazonCloudFormation cloudFormation = mock(AmazonCloudFormation.class);
    StackNameProvider stackNameProvider = mock(StackNameProvider.class);

    when(stackNameProvider.getStackName()).thenReturn("testStack");
    when(cloudFormation.describeStacks(new DescribeStacksRequest().withStackName("testStack"))).
            thenReturn(new DescribeStacksResult().withStacks(new Stack().withTags(
                    new Tag().withKey("key1").withValue("value1"),
                    new Tag().withKey("key2").withValue("value2")
            )));


    StackResourceUserTagsFactoryBean factoryBean = new StackResourceUserTagsFactoryBean(cloudFormation, stackNameProvider);

    //Act
    factoryBean.afterPropertiesSet();
    Map<String, String> factoryBeanObject = factoryBean.getObject();

    //Assert
    assertEquals("value1", factoryBeanObject.get("key1"));
    assertEquals("value2", factoryBeanObject.get("key2"));
}
项目:spring-cloud-aws    文件:StackConfigurationBeanDefinitionParserTest.java   
@Test
public void parseInternal_stackConfigurationWithExternallyConfiguredCloudFormationClient_returnsConfiguredStackWithExternallyConfiguredClient() throws Exception {
    //Arrange
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-withCustomCloudFormationClient.xml", getClass()));

    AmazonCloudFormation amazonCloudFormationMock = beanFactory.getBean(AmazonCloudFormation.class);
    when(amazonCloudFormationMock.listStackResources(new ListStackResourcesRequest().withStackName("test"))).
            thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
    when(amazonCloudFormationMock.describeStacks(new DescribeStacksRequest().withStackName("test"))).
            thenReturn(new DescribeStacksResult().withStacks(new Stack()));


    //Act
    StackResourceRegistry stackResourceRegistry = beanFactory.getBean(StackResourceRegistry.class);

    //Assert
    assertNotNull(stackResourceRegistry);
    assertFalse(beanFactory.containsBeanDefinition(getBeanName(AmazonCloudFormationClient.class.getName())));
    verify(amazonCloudFormationMock, times(1)).listStackResources(new ListStackResourcesRequest().withStackName("test"));
    beanFactory.getBean("customStackTags");
    verify(amazonCloudFormationMock, times(1)).describeStacks(new DescribeStacksRequest().withStackName("test"));
}
项目:cerberus-lifecycle-cli    文件:CloudFormationService.java   
/**
 * Returns the current status of the named stack.
 *
 * @param stackId Stack name.
 * @return Stack outputs data.
 */
public Map<String, String> getStackParameters(final String stackId) {
    final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId);
    final DescribeStacksResult result = cloudFormationClient.describeStacks(request);
    final Map<String, String> parameters = Maps.newHashMap();

    if (result.getStacks().size() > 0) {
        parameters.putAll(result.getStacks().get(0).getParameters().stream().collect(
                Collectors.toMap(Parameter::getParameterKey, Parameter::getParameterValue)));

    }

    return parameters;
}
项目:cerberus-lifecycle-cli    文件:CloudFormationService.java   
/**
 * Returns the current status of the named stack.
 *
 * @param stackId Stack name.
 * @return Stack outputs data.
 */
public Map<String, String> getStackOutputs(final String stackId) {
    final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId);
    final DescribeStacksResult result = cloudFormationClient.describeStacks(request);
    final Map<String, String> outputs = Maps.newHashMap();

    if (result.getStacks().size() > 0) {
        outputs.putAll(result.getStacks().get(0).getOutputs().stream().collect(
                Collectors.toMap(Output::getOutputKey, Output::getOutputValue)));

    }

    return outputs;
}
项目:cloud-configurator    文件:CmdlineApp.java   
private void listExistingApplications(CommandLine cmd, String region) {
  logger.debug("list environments for region: {}", region);

  DescribeStacksResult dst = null;
  if (cmd.hasOption("e")) {
    dst = provider.describeStacks(cmd.getOptionValue("e"));
  } else {
    dst = provider.describeStacks(null);
  }

  logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  logger.info("active applications: {}", dst);
  logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
}
项目:spring-cloud-aws    文件:StackResourceUserTagsFactoryBean.java   
@Override
protected Map<String, String> createInstance() throws Exception {
    LinkedHashMap<String, String> userTags = new LinkedHashMap<>();
    DescribeStacksResult stacksResult = this.amazonCloudFormation.describeStacks(new DescribeStacksRequest().withStackName(this.stackNameProvider.getStackName()));
    for (Stack stack : stacksResult.getStacks()) {
        for (Tag tag : stack.getTags()) {
            userTags.put(tag.getKey(), tag.getValue());
        }
    }
    return userTags;
}
项目:spring-cloud-aws    文件:TestStackEnvironment.java   
private DescribeStackResourcesResult getStackResources(String stackName) throws InterruptedException, IOException {
    try {
        DescribeStacksResult describeStacksResult = this.amazonCloudFormationClient.describeStacks(new DescribeStacksRequest().withStackName(stackName));
        for (Stack stack : describeStacksResult.getStacks()) {
            if (isAvailable(stack)) {
                return this.amazonCloudFormationClient.describeStackResources(new DescribeStackResourcesRequest().withStackName(stack.getStackName()));
            }
            if (isError(stack)) {
                if (this.stackCreatedByThisInstance) {
                    throw new IllegalArgumentException("Could not create stack");
                }
                this.amazonCloudFormationClient.deleteStack(new DeleteStackRequest().withStackName(stack.getStackName()));
                return getStackResources(stackName);
            }
            if (isInProgress(stack)) {
                //noinspection BusyWait
                Thread.sleep(5000L);
                return getStackResources(stackName);
            }
        }
    } catch (AmazonClientException e) {
        String templateBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource(TEMPLATE_PATH).getInputStream()));
        this.amazonCloudFormationClient.createStack(new CreateStackRequest().withTemplateBody(templateBody).withOnFailure(OnFailure.DELETE).
                withStackName(stackName).withTags(new Tag().withKey("tag1").withValue("value1")).
                withParameters(new Parameter().withParameterKey("RdsPassword").withParameterValue(this.rdsPassword)));
        this.stackCreatedByThisInstance = true;
    }

    return getStackResources(stackName);
}
项目:spring-cloud-aws    文件:TestStackInstanceIdService.java   
private static Stack getStack(DescribeStacksResult describeStacksResult, String stackName) {
    for (Stack stack : describeStacksResult.getStacks()) {
        if (stack.getStackName().equals(stackName)) {
            return stack;
        }
    }

    throw new IllegalStateException("No stack found with name '" + stackName + "' (available stacks: " + allStackNames(describeStacksResult) + ")");
}
项目:spring-cloud-aws    文件:TestStackInstanceIdService.java   
@Override
public String getInstanceId() {
    DescribeStacksResult describeStacksResult = this.amazonCloudFormationClient.describeStacks(new DescribeStacksRequest());
    Stack stack = getStack(describeStacksResult, this.stackName);

    return getOutputValue(stack, this.outputKey);
}
项目:cfnassist    文件:DeletesStacks.java   
private List<String> fetchCurrentStacks() {
    List<String> current = new LinkedList<>();

    DescribeStacksResult result = cfnClient.describeStacks();
    for(Stack stack : result.getStacks()) {
        current.add(stack.getStackName());
    }
    return current;
}
项目:aws-sam-gradle    文件:CloudformationService.java   
private List<Stack> describeStack(String stackName) {
    final DescribeStacksResult result = cloudFormation
            .describeStacks(new DescribeStacksRequest().withStackName(stackName));
    return result.getStacks();
}
项目:jwrapper-maven-plugin    文件:CarrotCloudForm.java   
public Stack findStack() throws Exception {

        final DescribeStacksRequest request = new DescribeStacksRequest();

        final DescribeStacksResult result = amazonClient
                .describeStacks(request);

        for (final Stack stack : result.getStacks()) {
            if (name.equals(stack.getStackName())) {
                return stack;
            }
        }

        return null;

    }
项目:cloud-configurator    文件:Provider.java   
DescribeStacksResult describeStacks(String environment);