Example usage for com.amazonaws.services.cloudformation.model Stack getOutputs

List of usage examples for com.amazonaws.services.cloudformation.model Stack getOutputs

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation.model Stack getOutputs.

Prototype


public java.util.List<Output> getOutputs() 

Source Link

Document

A list of output structures.

Usage

From source file:com.carrotgarden.maven.aws.cfn.CloudFormCreateStack.java

License:BSD License

/**
 * {@inheritDoc}//from  w  ww  . java  2 s. c om
 */
@Override
public void execute() throws MojoFailureException {

    try {

        getLog().info("stack create init [" + stackName() + "]");

        final Properties stackInputProps = Util.propsLoad(getLog(), stackPropertiesInputFile);

        final Map<String, String> pluginProps = mergePluginProps(stackInputProps, stackInputParams);

        final Map<String, String> stackTemplateParams = loadTemplateParameters(stackTemplateFile, pluginProps);

        final CarrotCloudForm formation = newCloudFormation(stackTemplateFile, stackTemplateParams);

        formation.logParamList();

        final Stack stack = formation.stackCreate();

        final StackStatus status = StackStatus.fromValue(stack.getStackStatus());

        switch (status) {
        case CREATE_COMPLETE:
            break;
        default:
            throw new IllegalStateException("stack create failed");
        }

        //

        getLog().info("stack create stack=\n" + stack);

        getLog().info("stack create output:");

        final List<Output> outputList = stack.getOutputs();

        final Properties outputProps = new Properties();

        for (final Output output : outputList) {

            final String key = output.getOutputKey();
            final String value = output.getOutputValue();

            outputProps.put(key, value);

            getLog().info("\t" + key + "=" + value);

        }

        if (stackIsInjectOutputProperties) {

            project().getProperties().putAll(outputProps);

            getLog().info("stack create output is injected in project.properties]");

        }

        if (stackIsPersistOutputProperties) {

            Util.propsSave(getLog(), outputProps, stackPropertiesOutputFile);

            getLog().info("stack create output is persisted to : " + stackPropertiesOutputFile);

        }

        //

        getLog().info("stack create done [" + stackName() + "]");

    } catch (final Exception e) {

        throw new MojoFailureException("bada-boom", e);

    }

}

From source file:com.deploymentio.cfnstacker.CloudFormationClient.java

License:Apache License

/**
* Prints the output variables for the given stack
* 
* @param stack the stack//  w  w w  . j a v a2s . c o m
*/
public void printStackOutputs(Stack stack) {
    for (Output outputs : stack.getOutputs()) {
        logger.info("Output Variable: Key=" + outputs.getOutputKey() + " Value=" + outputs.getOutputValue());
    }
}

From source file:com.github.kaklakariada.aws.sam.service.CloudformationService.java

License:Open Source License

public List<Output> getOutputParameters(String stackName) {
    final Stack stack = describeStack(stackName).stream().findFirst()
            .orElseThrow(() -> new DeploymentException("Stack not found"));
    return stack.getOutputs();
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.CfStackDetail.java

License:Open Source License

private void buildUI(DescribeStacksResult detail) {

    JTabbedPane tabs = new JTabbedPane();
    tabs.add("Stack", primaryScrollPane);

    final JTable outputCheckTable = new JTable(outputTableModel);
    JScrollPane healthCheckScrollPane = new JScrollPane(outputCheckTable);
    tabs.add("Output", healthCheckScrollPane);

    final JTable paramsTable = new JTable(parametersTableModel);
    JScrollPane listenersScrollPane = new JScrollPane(paramsTable);
    tabs.add("Parameters", listenersScrollPane);

    this.add(tabs, BorderLayout.CENTER);

    if (!detail.getStacks().isEmpty()) {

        List<Stack> stacks = detail.getStacks();
        Stack stack = stacks.get(0);

        if (stack.getCreationTime() != null) {
            primaryTableModel.addRow(new Object[] { "Created", getDateString(stack.getCreationTime()) });
        }/*from   w  w w.  ja va2s  .  co m*/
        if (stack.getDescription() != null) {
            primaryTableModel.addRow(new Object[] { "Description", stack.getDescription() });
        }
        if (stack.getDisableRollback() != null) {
            primaryTableModel.addRow(new Object[] { "Disable Rollback", stack.getDisableRollback() });
        }
        if (stack.getLastUpdatedTime() != null) {
            primaryTableModel
                    .addRow(new Object[] { "Last Updated", getDateString(stack.getLastUpdatedTime()) });
        }
        if (stack.getNotificationARNs() != null) {
            primaryTableModel.addRow(new Object[] { "Notification Arns", stack.getNotificationARNs() });
        }
        if (stack.getStackId() != null) {
            primaryTableModel.addRow(new Object[] { "Stacks Id", stack.getStackId() });
        }
        if (stack.getStackName() != null) {
            primaryTableModel.addRow(new Object[] { "Stacks Name", stack.getStackName() });
        }
        if (stack.getStackStatus() != null) {
            primaryTableModel.addRow(new Object[] { "Stacks Status", stack.getStackStatus() });
        }
        if (stack.getStackStatusReason() != null) {
            primaryTableModel.addRow(new Object[] { "Stacks Status Reason", stack.getStackStatusReason() });
        }
        if (stack.getTimeoutInMinutes() != null) {
            primaryTableModel.addRow(new Object[] { "Timeout (minutes)", stack.getTimeoutInMinutes() });
        }

        /**
         * Tags
         */
        List<Tag> tags = stack.getTags();
        for (Tag tag : tags) {
            tagsTableModel.addRow(new Object[] { tag.getKey(), tag.getValue() });
        }

        /**
         * Output
         */
        outputTableModel.addColumn("Description");
        outputTableModel.addColumn("Key");
        outputTableModel.addColumn("Value");

        List<Output> outputs = stack.getOutputs();
        for (Output output : outputs) {
            tagsTableModel.addRow(
                    new Object[] { output.getDescription(), output.getOutputKey(), output.getOutputValue() });
        }

        /**
         * Parameters
         */
        parametersTableModel.addColumn("Key");
        parametersTableModel.addColumn("Value");
        parametersTableModel.addColumn("User Previous Value");

        List<Parameter> parameters = stack.getParameters();
        for (Parameter parameter : parameters) {
            tagsTableModel.addRow(new Object[] { parameter.getParameterKey(), parameter.getParameterValue(),
                    parameter.getUsePreviousValue() });
        }
    }
}

From source file:com.netflix.spinnaker.clouddriver.aws.provider.agent.AmazonCloudFormationCachingAgent.java

License:Apache License

@Override
public CacheResult loadData(ProviderCache providerCache) {
    log.info("Describing items in {}", getAgentType());
    AmazonCloudFormation cloudformation = amazonClientProvider.getAmazonCloudFormation(account, region);

    Collection<CacheData> stackCacheData = new ArrayList<>();

    try {/*from   ww w  .j av  a  2  s  .com*/
        List<Stack> stacks = cloudformation.describeStacks().getStacks();

        for (Stack stack : stacks) {
            Map<String, Object> stackAttributes = new HashMap<>();
            stackAttributes.put("stackId", stack.getStackId());
            stackAttributes.put("tags",
                    stack.getTags().stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue)));
            stackAttributes.put("outputs", stack.getOutputs().stream()
                    .collect(Collectors.toMap(Output::getOutputKey, Output::getOutputValue)));
            stackAttributes.put("stackName", stack.getStackName());
            stackAttributes.put("region", region);
            stackAttributes.put("accountName", account.getName());
            stackAttributes.put("accountId", account.getAccountId());
            stackAttributes.put("stackStatus", stack.getStackStatus());
            stackAttributes.put("creationTime", stack.getCreationTime());

            if (stack.getStackStatus().equals("ROLLBACK_COMPLETE")) {
                DescribeStackEventsRequest request = new DescribeStackEventsRequest()
                        .withStackName(stack.getStackName());
                cloudformation.describeStackEvents(request).getStackEvents().stream()
                        .filter(e -> e.getResourceStatus().equals("CREATE_FAILED")).findFirst()
                        .map(StackEvent::getResourceStatusReason)
                        .map(statusReason -> stackAttributes.put("stackStatusReason", statusReason));
            }
            String stackCacheKey = Keys.getCloudFormationKey(stack.getStackId(), region, account.getName());
            Map<String, Collection<String>> relationships = new HashMap<>();
            relationships.put(STACKS.getNs(), Collections.singletonList(stackCacheKey));
            stackCacheData.add(new DefaultCacheData(stackCacheKey, stackAttributes, relationships));
        }
    } catch (AmazonCloudFormationException e) {
        log.error("Error retrieving stacks", e);
    }

    log.info("Caching {} items in {}", stackCacheData.size(), getAgentType());
    HashMap<String, Collection<CacheData>> result = new HashMap<>();
    result.put(STACKS.getNs(), stackCacheData);
    return new DefaultCacheResult(result);
}

From source file:com.tvarit.plugin.S3WarUploadEventToInvokeLambdaMaker.java

License:Open Source License

void make(AmazonS3Client amazonS3Client, String bucketName, Stack stack) {
    final List<Output> outputs = stack.getOutputs();
    final String lambdaFunctionArn = outputs.stream()
            .filter(output -> output.getOutputKey().equals("LambdaFunctionArn")).findFirst().get()
            .getOutputValue();/*w ww.  ja v  a 2 s  .co m*/
    final BucketNotificationConfiguration notificationConfiguration = new BucketNotificationConfiguration();
    final HashMap<String, NotificationConfiguration> configurations = new HashMap<>();
    final LambdaConfiguration lambdaConfiguration = new LambdaConfiguration(lambdaFunctionArn);
    final HashSet<String> events = new HashSet<>();
    events.add("s3:ObjectCreated:*");
    lambdaConfiguration.setEvents(events);
    final com.amazonaws.services.s3.model.Filter notificationFilter = new com.amazonaws.services.s3.model.Filter();
    final S3KeyFilter s3KeyFilter = new S3KeyFilter();
    notificationFilter.withS3KeyFilter(s3KeyFilter);
    s3KeyFilter.withFilterRules(new FilterRule().withName("suffix").withValue(".war"),
            new FilterRule().withName("prefix").withValue("deployables"));
    lambdaConfiguration.setFilter(notificationFilter);
    configurations.put("warUploaded", lambdaConfiguration);
    notificationConfiguration.setConfigurations(configurations);
    final SetBucketNotificationConfigurationRequest setBucketNotificationConfigurationRequest = new SetBucketNotificationConfigurationRequest(
            bucketName, notificationConfiguration);
    amazonS3Client.setBucketNotificationConfiguration(setBucketNotificationConfigurationRequest);

}

From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java

License:Apache License

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());
    }// w  ww . ja  v  a  2 s  .  c  o  m
    return map;
}

From source file:doug.iotdemo.common.AmazonUtils.java

License:Open Source License

public static String getStackOutput(String outputKey) {
    AmazonCloudFormation cf = new AmazonCloudFormationClient();
    DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackName);
    for (Stack stack : cf.describeStacks(request).getStacks()) {
        for (Output output : stack.getOutputs()) {
            if (outputKey.equals(output.getOutputKey())) {
                return output.getOutputValue();
            }//from  w  ww  .ja  v  a 2 s  .co  m
        }
    }
    return null;
}

From source file:io.konig.maven.CreateCloudFormationStackAction.java

License:Apache License

private List<Output> getOutputForRequest(String stackName, AmazonCloudFormation client)
        throws InterruptedException, StackCreationException {
    int tried = 0;
    String maxTime = System.getProperty("stackMaxTime");
    while (tried < (maxTime == null ? 1800 : Integer.parseInt(maxTime))) {
        DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
        describeStacksRequest.withStackName(stackName);
        Stack resultStack = client.describeStacks(describeStacksRequest).getStacks().get(0);
        StackStatus stackStatus = StackStatus.valueOf(resultStack.getStackStatus());
        if (("CREATE_COMPLETE").equals(stackStatus.toString())) {
            return resultStack.getOutputs();
        } else if (stackStatus.toString().endsWith("IN_PROGRESS")) {
            Thread.sleep(10000);/*from   w ww.  ja v  a  2  s .c  o m*/
        } else {
            DescribeStackEventsRequest describeStackEventsRequest = new DescribeStackEventsRequest();
            describeStackEventsRequest.withStackName(stackName);
            List<StackEvent> stackEvents = client.describeStackEvents(describeStackEventsRequest)
                    .getStackEvents();
            List<StackEvent> errorEvents = new ArrayList<StackEvent>();
            for (StackEvent stackEvent : stackEvents) {
                if (stackEvent.getResourceStatus().equals("CREATE_FAILED")) {
                    errorEvents.add(stackEvent);
                }
            }
            throw new StackCreationException(errorEvents.toString());
        }
        tried++;
    }
    throw new RuntimeException("stack creation/deletion timed out");
}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationWaitStackStatusTask.java

License:Apache License

private void printOutputs(Stack stack) {
    getLogger().info("==== Outputs ====");
    stack.getOutputs().stream().forEach(
            o -> getLogger().info("{} ({}) = {}", o.getOutputKey(), o.getDescription(), o.getOutputValue()));
}