From 8e86bbe72dbccd64561209d8cb643d519e82207a Mon Sep 17 00:00:00 2001 From: Anushri Date: Fri, 27 Mar 2015 09:28:39 -0400 Subject: [PATCH] YARN-3189 --- .../hadoop/yarn/client/cli/ApplicationCLI.java | 20 ++++++- .../apache/hadoop/yarn/client/cli/TestYarnCLI.java | 61 ++++++++++++++++++---- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java index dd4a949..53a16fc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java @@ -109,14 +109,14 @@ public int run(String[] args) throws Exception { appTypeOpt.setValueSeparator(','); appTypeOpt.setArgs(Option.UNLIMITED_VALUES); appTypeOpt.setArgName("Types"); - opts.addOption(appTypeOpt); + // opts.addOption(appTypeOpt); Option appStateOpt = new Option(APP_STATE_CMD, true, "Works with -list " + "to filter applications based on input comma-separated list of " + "application states. " + getAllValidApplicationStates()); appStateOpt.setValueSeparator(','); appStateOpt.setArgs(Option.UNLIMITED_VALUES); appStateOpt.setArgName("States"); - opts.addOption(appStateOpt); + // opts.addOption(appStateOpt); opts.getOption(KILL_CMD).setArgName("Application ID"); opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID"); opts.getOption(QUEUE_CMD).setArgName("Queue Name"); @@ -166,6 +166,22 @@ public int run(String[] args) throws Exception { } return exitCode; } else if (cliParser.hasOption(LIST_CMD)) { + Options listOpts = new Options(); + Option appTypeOpt = new Option(APP_TYPE_CMD, true, "Works with -list to " + + "filter applications based on " + + "input comma-separated list of application types."); + appTypeOpt.setValueSeparator(','); + appTypeOpt.setArgs(Option.UNLIMITED_VALUES); + appTypeOpt.setArgName("Types"); + listOpts.addOption(appTypeOpt); + Option appStateOpt = new Option(APP_STATE_CMD, true, "Works with -list " + + "to filter applications based on input comma-separated list of " + + "application states. " + getAllValidApplicationStates()); + appStateOpt.setValueSeparator(','); + appStateOpt.setArgs(Option.UNLIMITED_VALUES); + appStateOpt.setArgName("States"); + opts.addOption(HELP_CMD, false, "Displays help for all commands."); + listOpts.addOption(appStateOpt); if (args[0].equalsIgnoreCase(APPLICATION)) { allAppStates = false; Set appTypes = new HashSet(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index 4b60c52..f3c0beb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -739,6 +739,31 @@ public void testAppsHelpCommand() throws Exception { } @Test (timeout = 10000) + public void testAppsListHelpCommand() throws Exception { + ApplicationCLI cli = createAndGetAppCLI(); + ApplicationCLI spyCli = spy(cli); + int result = spyCli.run(new String[] { "application", "-list", "-help" }); + Assert.assertTrue(result == 0); + verify(spyCli).printUsage(any(String.class), any(Options.class)); + Assert.assertEquals(createApplicationListCLIHelpMessage(), + sysOutStream.toString()); + + sysOutStream.reset(); + result = cli.run( + new String[] {"application", "-list", "-appStates","FINISHED", "args" }); + verify(spyCli).printUsage(any(String.class), any(Options.class)); + Assert.assertEquals(createApplicationListCLIHelpMessage(), + sysOutStream.toString()); + + sysOutStream.reset(); + result = cli.run( + new String[] { "application", "-list", "-appTypes","mapred", "args" }); + verify(spyCli).printUsage(any(String.class), any(Options.class)); + Assert.assertEquals(createApplicationListCLIHelpMessage(), + sysOutStream.toString()); + } + + @Test (timeout = 10000) public void testAppAttemptsHelpCommand() throws Exception { ApplicationCLI cli = createAndGetAppCLI(); ApplicationCLI spyCli = spy(cli); @@ -1452,15 +1477,15 @@ private String createApplicationCLIHelpMessage() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); pw.println("usage: application"); - pw.println(" -appStates Works with -list to filter applications"); - pw.println(" based on input comma-separated list of"); - pw.println(" application states. The valid application"); - pw.println(" state can be one of the following:"); - pw.println(" ALL,NEW,NEW_SAVING,SUBMITTED,ACCEPTED,RUN"); - pw.println(" NING,FINISHED,FAILED,KILLED"); - pw.println(" -appTypes Works with -list to filter applications"); - pw.println(" based on input comma-separated list of"); - pw.println(" application types."); +// pw.println(" -appStates Works with -list to filter applications"); +// pw.println(" based on input comma-separated list of"); +// pw.println(" application states. The valid application"); +// pw.println(" state can be one of the following:"); +// pw.println(" ALL,NEW,NEW_SAVING,SUBMITTED,ACCEPTED,RUN"); +// pw.println(" NING,FINISHED,FAILED,KILLED"); +// pw.println(" -appTypes Works with -list to filter applications"); +// pw.println(" based on input comma-separated list of"); +// pw.println(" application types."); pw.println(" -help Displays help for all commands."); pw.println(" -kill Kills the application."); pw.println(" -list List applications. Supports optional use"); @@ -1479,6 +1504,24 @@ private String createApplicationCLIHelpMessage() throws IOException { return appsHelpStr; } + private String createApplicationListCLIHelpMessage() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintWriter pw = new PrintWriter(baos); + pw.println("usage: application -list"); + pw.println(" -appStates Works with -list to filter applications"); + pw.println(" based on input comma-separated list of"); + pw.println(" application states. The valid application"); + pw.println(" state can be one of the following:"); + pw.println(" ALL,NEW,NEW_SAVING,SUBMITTED,ACCEPTED,RUN"); + pw.println(" NING,FINISHED,FAILED,KILLED"); + pw.println(" -appTypes Works with -list to filter applications"); + pw.println(" based on input comma-separated list of"); + pw.println(" application types."); + pw.close(); + String appsHelpStr = baos.toString("UTF-8"); + return appsHelpStr; + } + private String createApplicationAttemptCLIHelpMessage() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); -- 1.8.4.msysgit.0