Search in sources :

Example 1 with Property

use of org.apache.whirr.ClusterSpec.Property in project whirr by apache.

the class AbstractClusterCommand method getClusterSpec.

/**
 * Load the cluster spec by parsing the command line option set
 */
protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationException {
    Configuration optionsConfig = new PropertiesConfiguration();
    for (Map.Entry<Property, OptionSpec<?>> entry : optionSpecs.entrySet()) {
        Property property = entry.getKey();
        OptionSpec<?> option = entry.getValue();
        Object value;
        if (property.hasMultipleArguments()) {
            value = optionSet.valuesOf(option);
        } else {
            value = optionSet.valueOf(option);
        }
        if (value == null && property.getType().equals(Boolean.class) && optionSet.has(property.getSimpleName())) {
            value = Boolean.TRUE.toString();
        }
        if (value != null) {
            optionsConfig.setProperty(property.getConfigName(), value);
        }
    }
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(optionsConfig);
    if (optionSet.has(configOption)) {
        Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption));
        config.addConfiguration(defaults);
    }
    ClusterSpec clusterSpec = new ClusterSpec(config);
    for (Property required : EnumSet.of(CLUSTER_NAME, PROVIDER, IDENTITY, CREDENTIAL, INSTANCE_TEMPLATES, PRIVATE_KEY_FILE)) {
        if (clusterSpec.getConfiguration().getString(required.getConfigName()) == null) {
            throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName()));
        }
    }
    return clusterSpec;
}
Also used : OptionSpec(joptsimple.OptionSpec) ArgumentAcceptingOptionSpec(joptsimple.ArgumentAcceptingOptionSpec) Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ClusterSpec(org.apache.whirr.ClusterSpec) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Map(java.util.Map) Property(org.apache.whirr.ClusterSpec.Property)

Aggregations

Map (java.util.Map)1 ArgumentAcceptingOptionSpec (joptsimple.ArgumentAcceptingOptionSpec)1 OptionSpec (joptsimple.OptionSpec)1 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)1 Configuration (org.apache.commons.configuration.Configuration)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 ClusterSpec (org.apache.whirr.ClusterSpec)1 Property (org.apache.whirr.ClusterSpec.Property)1