Example usage for com.amazonaws.services.elasticbeanstalk.model UpdateConfigurationTemplateRequest UpdateConfigurationTemplateRequest

List of usage examples for com.amazonaws.services.elasticbeanstalk.model UpdateConfigurationTemplateRequest UpdateConfigurationTemplateRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticbeanstalk.model UpdateConfigurationTemplateRequest UpdateConfigurationTemplateRequest.

Prototype

public UpdateConfigurationTemplateRequest() 

Source Link

Document

Default constructor for UpdateConfigurationTemplateRequest object.

Usage

From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateConfigurationTemplateTask.java

License:Apache License

@TaskAction
public void createTemplate() {
    // to enable conventionMappings feature
    String appName = getAppName();

    AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class);
    AWSElasticBeanstalk eb = ext.getClient();

    configurationTemplates.forEach(config -> {
        String templateName = config.getName();
        String templateDesc = config.getDesc();
        String solutionStackName = config.getSolutionStackName() != null ? config.getSolutionStackName()
                : getDefaultSolutionStackName();
        boolean deleteTemplateIfExists = config.isRecreate();

        try {//from w ww. jav a  2s . com
            List<ConfigurationOptionSetting> optionSettings = loadConfigurationOptions(
                    config.getOptionSettings());
            List<ApplicationDescription> existingApps = eb
                    .describeApplications(new DescribeApplicationsRequest().withApplicationNames(appName))
                    .getApplications();
            if (existingApps.isEmpty()) {
                throw new IllegalArgumentException("App with name '" + appName + "' does not exist");
            }

            if (existingApps.get(0).getConfigurationTemplates().contains(templateName)) {
                if (deleteTemplateIfExists) {
                    eb.deleteConfigurationTemplate(new DeleteConfigurationTemplateRequest()
                            .withApplicationName(appName).withTemplateName(templateName));
                    getLogger().info("configuration template {} @ {} deleted", templateName, appName);
                } else {
                    eb.updateConfigurationTemplate(new UpdateConfigurationTemplateRequest()
                            .withApplicationName(appName).withTemplateName(templateName)
                            .withDescription(templateDesc).withOptionSettings(optionSettings));
                    getLogger().info("configuration template {} @ {} updated", templateName, appName);
                    return;
                }
            }

            eb.createConfigurationTemplate(new CreateConfigurationTemplateRequest().withApplicationName(appName)
                    .withTemplateName(templateName).withDescription(templateDesc)
                    .withSolutionStackName(solutionStackName).withOptionSettings(optionSettings));
            getLogger().info("configuration template {} @ {} created", templateName, appName);
        } catch (IOException e) {
            getLogger().error("IOException", e);
        }
    });
}