@Test public void testOverrides() throws Exception { AbstractClusterCommand clusterCommand = new AbstractClusterCommand("name", "description", new ClusterControllerFactory()) { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { return 0; } }; Map<String, File> keys = KeyPair.generateTemporaryFiles(); OptionSet optionSet = clusterCommand.parser.parse("--quiet", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath() ); ClusterSpec clusterSpec = clusterCommand.getClusterSpec(optionSet); assertThat(optionSet.has("quiet"), is(true)); assertThat(clusterSpec.isQuiet(), is(true)); assertThat(clusterSpec.getServiceName(), is("overridden-test-service")); assertThat(clusterSpec.getClusterName(), is("test-cluster")); optionSet = clusterCommand.parser.parse("--quiet", "true", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath() ); clusterSpec = clusterCommand.getClusterSpec(optionSet); assertThat(optionSet.has("quiet"), is(true)); assertThat(clusterSpec.isQuiet(), is(true)); assertThat(clusterSpec.getServiceName(), is("overridden-test-service")); assertThat(clusterSpec.getClusterName(), is("test-cluster")); optionSet = clusterCommand.parser.parse("--quiet", "false", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath() ); clusterSpec = clusterCommand.getClusterSpec(optionSet); assertThat(optionSet.has("quiet"), is(true)); assertThat(clusterSpec.isQuiet(), is(false)); assertThat(clusterSpec.getServiceName(), is("overridden-test-service")); assertThat(clusterSpec.getClusterName(), is("test-cluster")); optionSet = clusterCommand.parser.parse("--quiet", "some-value", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath() ); clusterSpec = clusterCommand.getClusterSpec(optionSet); assertThat(optionSet.has("quiet"), is(true)); assertThat(clusterSpec.isQuiet(), is(false)); assertThat(clusterSpec.getServiceName(), is("overridden-test-service")); assertThat(clusterSpec.getClusterName(), is("test-cluster")); optionSet = clusterCommand.parser.parse( "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath() ); clusterSpec = clusterCommand.getClusterSpec(optionSet); assertThat(optionSet.has("quiet"), is(false)); assertThat(clusterSpec.isQuiet(), is(false)); assertThat(clusterSpec.getServiceName(), is("overridden-test-service")); assertThat(clusterSpec.getClusterName(), is("test-cluster")); }
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; }
AbstractClusterCommand extends Command { 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; } }
AbstractClusterCommand extends Command { 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; } AbstractClusterCommand(String name, String description, ClusterControllerFactory factory);  AbstractClusterCommand(String name, String description, ClusterControllerFactory factory,
        ClusterStateStoreFactory stateStoreFactory); }
AbstractClusterCommand extends Command { 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; } AbstractClusterCommand(String name, String description, ClusterControllerFactory factory);  AbstractClusterCommand(String name, String description, ClusterControllerFactory factory,
        ClusterStateStoreFactory stateStoreFactory); @Override void printUsage(PrintStream stream); }
AbstractClusterCommand extends Command { 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; } AbstractClusterCommand(String name, String description, ClusterControllerFactory factory);  AbstractClusterCommand(String name, String description, ClusterControllerFactory factory,
        ClusterStateStoreFactory stateStoreFactory); @Override void printUsage(PrintStream stream);  }