Example usage for com.amazonaws.services.cloudformation AmazonCloudFormationAsyncClient getTemplate

List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormationAsyncClient getTemplate

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation AmazonCloudFormationAsyncClient getTemplate.

Prototype

GetTemplateResult getTemplate(GetTemplateRequest getTemplateRequest);

Source Link

Document

Returns the template body for a specified stack.

Usage

From source file:com.mweagle.tereus.commands.pipelines.UpdatePipeline.java

License:Open Source License

protected void publishGlobals(ScriptEngine engine) {
    super.publishGlobals(engine);

    // Publish a function that accepts a stack target name, defined by the patch
    // file, that represents the target.  We'll push all this
    Function<String, String> fnStackInfo = (stackName) -> {
        // Get the information...
        final GetTemplateRequest templateRequest = new GetTemplateRequest().withStackName(stackName);
        final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient(
                super.getAwsCredentials());
        awsClient.setRegion(super.getRegion());
        final GetTemplateResult stackTemplateResult = awsClient.getTemplate(templateRequest);

        // Get the stack info and return it
        final DescribeStacksRequest describeRequest = new DescribeStacksRequest().withStackName(stackName);
        final DescribeStacksResult describeResult = awsClient.describeStacks(describeRequest);

        // And finally the tags and parameters
        final Stack stackInfo = !describeResult.getStacks().isEmpty() ? describeResult.getStacks().get(0)
                : null;/* w  w w  . j  a  v  a 2  s  .c  o m*/
        final Map<String, Object> tags = (stackInfo != null)
                ? stackInfo.getTags().stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue))
                : Collections.emptyMap();

        final Map<String, Object> params = (stackInfo != null)
                ? stackInfo.getParameters().stream()
                        .collect(Collectors.toMap(Parameter::getParameterKey, Parameter::getParameterValue))
                : Collections.emptyMap();

        HashMap<String, Object> results = new HashMap<>();
        results.put("tags", tags);
        results.put("params", params);
        results.put("stack", stackInfo);
        results.put("template", stackTemplateResult.getTemplateBody().toString());
        Gson gson = new Gson();
        return gson.toJson(results);
    };
    engine.put("TargetStackInfoImpl", fnStackInfo);

    Supplier<String> fnArgs = () -> {
        HashMap<String, Map<String, Object>> args = new HashMap<>();
        args.put("arguments", this.arguments);
        Gson gson = new Gson();
        return gson.toJson(args);
    };
    engine.put("ArgumentsImpl", fnArgs);
}