Example usage for com.amazonaws.services.elasticbeanstalk.model ConfigurationOptionDescription getName

List of usage examples for com.amazonaws.services.elasticbeanstalk.model ConfigurationOptionDescription getName

Introduction

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

Prototype


public String getName() 

Source Link

Document

The name of the configuration option.

Usage

From source file:br.com.ingenieux.mojo.beanstalk.env.DumpEnvironmentSettings.java

License:Apache License

protected Object executeInternal() throws Exception {
    DescribeConfigurationOptionsResult configOptions = getService()
            .describeConfigurationOptions(new DescribeConfigurationOptionsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    for (ConfigurationOptionDescription o : configOptions.getOptions()) {
        String key = String.format("beanstalk.env.%s.%s", o.getNamespace().replace(":", "."), o.getName());

        for (Map.Entry<String, ConfigurationOptionSetting> entry : COMMON_PARAMETERS.entrySet()) {
            ConfigurationOptionSetting cos = entry.getValue();

            if (cos.getNamespace().equals(o.getNamespace()) && cos.getOptionName().equals(o.getName())) {
                key = entry.getKey();/*  w  ww.j ava2 s .  c  o m*/
                break;
            }
        }

        defaultSettings.put(key, o);
    }

    DescribeConfigurationSettingsResult configurationSettings = getService()
            .describeConfigurationSettings(new DescribeConfigurationSettingsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    Properties newProperties = new Properties();

    if (configurationSettings.getConfigurationSettings().isEmpty()) {
        throw new IllegalStateException("No Configuration Settings received");
    }

    ConfigurationSettingsDescription configSettings = configurationSettings.getConfigurationSettings().get(0);

    Map<String, ConfigurationOptionSetting> keyMap = new LinkedHashMap<String, ConfigurationOptionSetting>();

    for (ConfigurationOptionSetting d : configSettings.getOptionSettings()) {
        String key = String.format("beanstalk.env.%s.%s", d.getNamespace().replaceAll(":", "."),
                d.getOptionName());
        String defaultValue = "";
        String outputKey = key;

        keyMap.put(key, d);

        for (Map.Entry<String, ConfigurationOptionSetting> cosEntry : COMMON_PARAMETERS.entrySet()) {
            ConfigurationOptionSetting v = cosEntry.getValue();

            boolean match = v.getNamespace().equals(d.getNamespace())
                    && v.getOptionName().equals(d.getOptionName());

            if (match) {
                outputKey = cosEntry.getKey();
                break;
            }
        }

        if (defaultSettings.containsKey(outputKey)) {
            defaultValue = StringUtils.defaultString(defaultSettings.get(outputKey).getDefaultValue());
        }

        String value = d.getValue();

        if (null == value || StringUtils.isBlank("" + value)) {
            continue;
        }

        if (!defaultValue.equals(value)) {
            if (!value.contains(curEnv.getEnvironmentId())) {
                getLog().info("Adding property " + key);

                if (changedOnly) {
                    String curValue = project.getProperties().getProperty(outputKey);

                    if (!value.equals(curValue)) {
                        newProperties.put(outputKey, value);
                    }
                } else {
                    newProperties.put(outputKey, value);
                }
            } else {
                getLog().info("Ignoring property " + outputKey + "(value=" + value
                        + ") due to containing references to the environment id");
            }

        } else {
            getLog().debug("Ignoring property " + key + " (defaulted)");
        }
    }

    if ("properties".equals(this.outputFileFormat)) {
        String comment = "elastic beanstalk environment properties for " + curEnv.getEnvironmentName();
        if (null != outputFile) {
            newProperties.store(new FileOutputStream(outputFile), comment);
        } else {
            newProperties.store(System.out, comment);
        }
    } else if ("yaml".equals(this.outputFileFormat)) {
        PrintStream printStream = System.out;

        if (null != outputFile) {
            printStream = new PrintStream(outputFile);
        }

        printStream.println("option_settings:");

        for (Map.Entry<Object, Object> e : newProperties.entrySet()) {
            ConfigurationOptionSetting c = keyMap.get("" + e.getKey());
            String value = "" + e.getValue();

            printStream.println("  - namespace: " + c.getNamespace());
            printStream.println("    option_name: " + c.getOptionName());
            printStream.println("    value: " + value);
        }

        printStream.close();
    }

    return null;
}