ConfigCommands implements CommandMarker { @CliCommand(value = "configuration set", help = "Sets the desired configuration") public String setConfig(@CliOption(key = "type", mandatory = true, help = "Type of the configuration") ConfigType configType, @CliOption(key = "url", help = "URL of the config") String url, @CliOption(key = "file", help = "File of the config") File file) throws IOException { Configuration configuration = new Configuration(false); if (file == null) { configuration.addResource(new URL(url)); } else { configuration.addResource(new FileInputStream(file)); } Map<String, String> config = new HashMap<String, String>(); Iterator<Map.Entry<String, String>> iterator = configuration.iterator(); while (iterator.hasNext()) { Map.Entry<String, String> entry = iterator.next(); config.put(entry.getKey(), entry.getValue()); } client.modifyConfiguration(configType.getName(), config); return "Restart is required!\n" + renderSingleMap(config, "KEY", "VALUE"); } @Autowired  ConfigCommands(AmbariClient client, AmbariContext context); @CliAvailabilityIndicator("configuration show") boolean isConfigShowCommandAvailable(); @CliCommand(value = "configuration show", help = "Prints the desired configuration") String showConfig(@CliOption(key = "type", mandatory = true, help = "Type of the configuration") ConfigType configType); @CliAvailabilityIndicator("configuration set") boolean isConfigSetCommandAvailable(); @CliCommand(value = "configuration set", help = "Sets the desired configuration") String setConfig(@CliOption(key = "type", mandatory = true, help = "Type of the configuration") ConfigType configType,
    @CliOption(key = "url", help = "URL of the config") String url,
    @CliOption(key = "file", help = "File of the config") File file); @CliAvailabilityIndicator("configuration modify") boolean isConfigModifyCommandAvailable(); @CliCommand(value = "configuration modify", help = "Modify the desired configuration") String modifyConfig(@CliOption(key = "type", mandatory = true, help = "Type of the configuration") ConfigType configType,
    @CliOption(key = "key", mandatory = true, help = "Key of the config") String key,
    @CliOption(key = "value", mandatory = true, help = "Value of the config") String value); @CliAvailabilityIndicator("configuration download") boolean isConfigDownloadCommandAvailable(); @CliCommand(value = "configuration download", help = "Downloads the desired configuration") String downloadConfig(@CliOption(key = "type", mandatory = true, help = "Type of the configuration") ConfigType configType);  }
@Test public void testSetConfigForFile() throws IOException { ConfigType configType = mock(ConfigType.class); File file = new File("src/test/resources/core-site.xml"); when(configType.getName()).thenReturn(CORE_SITE); configCommands.setConfig(configType, "", file); Map<String, String> config = new HashMap<String, String>(); config.put("fs.trash.interval", "350"); config.put("ipc.client.connection.maxidletime", "30000"); verify(client).modifyConfiguration(CORE_SITE, config); }