SchedConfCLI extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Options opts = new Options(); opts.addOption("add", ADD_QUEUES_OPTION, true, "Add queues with configurations"); opts.addOption("remove", REMOVE_QUEUES_OPTION, true, "Remove queues"); opts.addOption("update", UPDATE_QUEUES_OPTION, true, "Update queue configurations"); opts.addOption("global", GLOBAL_OPTIONS, true, "Update global scheduler configurations"); opts.addOption("h", HELP_CMD, false, "Displays help for all commands."); int exitCode = -1; CommandLine parsedCli = null; try { parsedCli = new GnuParser().parse(opts, args); } catch (MissingArgumentException ex) { System.err.println("Missing argument for options"); printUsage(); return exitCode; } if (parsedCli.hasOption(HELP_CMD)) { printUsage(); return 0; } boolean hasOption = false; SchedConfUpdateInfo updateInfo = new SchedConfUpdateInfo(); try { if (parsedCli.hasOption(ADD_QUEUES_OPTION)) { hasOption = true; addQueues(parsedCli.getOptionValue(ADD_QUEUES_OPTION), updateInfo); } if (parsedCli.hasOption(REMOVE_QUEUES_OPTION)) { hasOption = true; removeQueues(parsedCli.getOptionValue(REMOVE_QUEUES_OPTION), updateInfo); } if (parsedCli.hasOption(UPDATE_QUEUES_OPTION)) { hasOption = true; updateQueues(parsedCli.getOptionValue(UPDATE_QUEUES_OPTION), updateInfo); } if (parsedCli.hasOption(GLOBAL_OPTIONS)) { hasOption = true; globalUpdates(parsedCli.getOptionValue(GLOBAL_OPTIONS), updateInfo); } } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); return -1; } if (!hasOption) { System.err.println("Invalid Command Usage: "); printUsage(); return -1; } Client webServiceClient = Client.create(); WebResource webResource = webServiceClient .resource(WebAppUtils.getRMWebAppURLWithScheme(getConf())); ClientResponse response = null; try { response = webResource.path("ws").path("v1").path("cluster") .path("scheduler-conf").accept(MediaType.APPLICATION_JSON) .entity(YarnWebServiceUtils.toJson(updateInfo, SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON) .put(ClientResponse.class); if (response != null) { if (response.getStatus() == Status.OK.getStatusCode()) { System.out.println("Configuration changed successfully."); return 0; } else { System.err.println("Configuration change unsuccessful: " + response.getEntity(String.class)); } } else { System.err.println("Configuration change unsuccessful: null response"); } return -1; } finally { if (response != null) { response.close(); } webServiceClient.destroy(); } } SchedConfCLI(); static void main(String[] args); @Override int run(String[] args);  }
@Test(timeout = 10000) public void testInvalidConf() throws Exception { int exitCode = cli.run(new String[] {"-add", "root.a:=confVal"}); assertTrue("Should return an error code", exitCode != 0); assertTrue(sysErrStream.toString().contains("Specify configuration key " + "value as confKey=confVal.")); exitCode = cli.run(new String[] {"-update", "root.a:=confVal"}); assertTrue("Should return an error code", exitCode != 0); assertTrue(sysErrStream.toString().contains("Specify configuration key " + "value as confKey=confVal.")); exitCode = cli.run(new String[] {"-add", "root.a:confKey=confVal=conf"}); assertTrue("Should return an error code", exitCode != 0); assertTrue(sysErrStream.toString().contains("Specify configuration key " + "value as confKey=confVal.")); exitCode = cli.run(new String[] {"-update", "root.a:confKey=confVal=c"}); assertTrue("Should return an error code", exitCode != 0); assertTrue(sysErrStream.toString().contains("Specify configuration key " + "value as confKey=confVal.")); }