diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java index a7b7d65..dbf0cd1 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java @@ -23,6 +23,7 @@ import java.text.DecimalFormat; import java.util.EnumSet; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -38,6 +39,8 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationReport; import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; +import org.apache.hadoop.yarn.api.records.QueueInfo; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.util.ConverterUtils; @@ -53,6 +56,14 @@ private static final String APP_TYPE_CMD = "appTypes"; private static final String APP_STATE_CMD ="appStates"; private static final String ALLSTATES_OPTION = "ALL"; + private static final String FINAL_STATUS_CMD ="finalStatus"; + private static final String USER_CMD ="user"; + private static final String QUEUE_CMD ="queue"; + private static final String STARTED_TIME_BEGIN_CMD ="startedTimeBegin"; + private static final String STARTED_TIME_END_CMD ="startedTimeEnd"; + private static final String FINISHED_TIME_BEGIN_CMD ="finishedTimeBegin"; + private static final String FINISHED_TIME_END_CMD ="finishedTimeEnd"; + private static final String LIMIT_CMD ="limit"; private boolean allAppStates; @@ -90,6 +101,42 @@ public int run(String[] args) throws Exception { appStateOpt.setArgs(Option.UNLIMITED_VALUES); appStateOpt.setArgName("States"); opts.addOption(appStateOpt); + Option finalStatusOpt = new Option(FINAL_STATUS_CMD, true, + "Works with -list to filter applications based on final " + + "application status. " + getAllValidFinalApplicationStatus()); + finalStatusOpt.setArgName("FinalStatus"); + opts.addOption(finalStatusOpt); + Option userOpt = new Option(USER_CMD, true, + "Works with -list to filter applications based on user " + + "name."); + userOpt.setArgName("UserName"); + opts.addOption(userOpt); + Option queueOpt = new Option(QUEUE_CMD, true, + "Works with -list to filter applications based on queue " + + "name."); + queueOpt.setArgName("QueueName"); + opts.addOption(queueOpt); + Option startedTimeBeginOpt = new Option(STARTED_TIME_BEGIN_CMD, true, + "Works with -list to filter applications based on started time."); + startedTimeBeginOpt.setArgName("StartedTime"); + opts.addOption(startedTimeBeginOpt); + Option startedTimeEndOpt = new Option(STARTED_TIME_END_CMD, true, + "Works with -list to filter applications based on started time."); + startedTimeEndOpt.setArgName("StartedTime"); + opts.addOption(startedTimeEndOpt); + Option finishedTimeBeginOpt = new Option(FINISHED_TIME_BEGIN_CMD, true, + "Works with -list to filter applications based on finished time."); + finishedTimeBeginOpt.setArgName("FinishedTime"); + opts.addOption(finishedTimeBeginOpt); + Option finishedTimeEndOpt = new Option(FINISHED_TIME_END_CMD, true, + "Works with -list to filter applications based on finished time."); + finishedTimeEndOpt.setArgName("FinishedTime"); + opts.addOption(finishedTimeEndOpt); + Option limitOpt = new Option(LIMIT_CMD, true, + "Total number of applications to be returned. Works with -list " + + "to filter applications."); + limitOpt.setArgName("Number"); + opts.addOption(limitOpt); opts.getOption(KILL_CMD).setArgName("Application ID"); opts.getOption(STATUS_CMD).setArgName("Application ID"); @@ -147,7 +194,105 @@ public int run(String[] args) throws Exception { } } } - listApplications(appTypes, appStates); + + String finalStatus = null; + if(cliParser.hasOption(FINAL_STATUS_CMD)) { + finalStatus = cliParser.getOptionValue(FINAL_STATUS_CMD); + if (finalStatus != null) { + try { + FinalApplicationStatus.valueOf(finalStatus.toUpperCase() + .trim()); + } catch (IllegalArgumentException ex) { + sysout.println("The final status " + finalStatus + + " is invalid."); + sysout.println(getAllValidFinalApplicationStatus()); + return exitCode; + } + } + } + + String user = null; + if(cliParser.hasOption(USER_CMD)) { + user = cliParser.getOptionValue(USER_CMD); + } + + String queue = null; + if(cliParser.hasOption(QUEUE_CMD)) { + queue = cliParser.getOptionValue(QUEUE_CMD); + QueueInfo info = client.getQueueInfo(queue); + if (info == null) { + sysout.println("The queue name " + queue + " is invalid."); + return exitCode; + } + } + + String startedBegin = null; + long sBegin = 0; + if(cliParser.hasOption(STARTED_TIME_BEGIN_CMD)) { + startedBegin = cliParser.getOptionValue(STARTED_TIME_BEGIN_CMD); + if (startedBegin != null && !startedBegin.isEmpty()) { + sBegin = Long.parseLong(startedBegin); + if (sBegin < 0) { + sysout.println("The started time must be greater than 0."); + return exitCode; + } + } + } + + String startedEnd = null; + long sEnd = Long.MAX_VALUE; + if(cliParser.hasOption(STARTED_TIME_END_CMD)) { + startedEnd = cliParser.getOptionValue(STARTED_TIME_END_CMD); + if (startedEnd != null && !startedEnd.isEmpty()) { + sEnd = Long.parseLong(startedEnd); + if (sEnd < 0) { + sysout.println("The started time must be greater than 0."); + return exitCode; + } + } + } + + String finishedBegin = null; + long fBegin = 0; + if(cliParser.hasOption(FINISHED_TIME_BEGIN_CMD)) { + finishedBegin = cliParser.getOptionValue(FINISHED_TIME_BEGIN_CMD); + if (finishedBegin != null && !finishedBegin.isEmpty()) { + fBegin = Long.parseLong(finishedBegin); + if (fBegin < 0) { + sysout.println("The finished time must be greater than 0."); + return exitCode; + } + } + } + + String finishedEnd = null; + long fEnd = Long.MAX_VALUE; + if(cliParser.hasOption(FINISHED_TIME_END_CMD)) { + finishedEnd = cliParser.getOptionValue(FINISHED_TIME_END_CMD); + if (finishedEnd != null && !finishedEnd.isEmpty()) { + fEnd = Long.parseLong(finishedEnd); + if (fEnd < 0) { + sysout.println("The finished time must be greater than 0."); + return exitCode; + } + } + } + + String count = null; + int countNum = Integer.MAX_VALUE; + if(cliParser.hasOption(LIMIT_CMD)) { + count = cliParser.getOptionValue(LIMIT_CMD); + if (count != null && !count.isEmpty()) { + countNum = Integer.parseInt(count); + if (countNum <= 0) { + sysout.println("The limit value must be greater than 0."); + return exitCode; + } + } + } + + listApplications(appTypes, appStates, finalStatus, user, queue, + sBegin, sEnd, fBegin, fEnd, countNum); } else if (cliParser.hasOption(KILL_CMD)) { if (args.length != 2) { printUsage(opts); @@ -184,7 +329,9 @@ void printUsage(Options opts) { * @throws IOException */ private void listApplications(Set appTypes, - EnumSet appStates) throws YarnException, + EnumSet appStates, String finalStatus, + String user, String queue, long sBegin, long sEnd, + long fBegin, long fEnd, int countNum) throws YarnException, IOException { PrintWriter writer = new PrintWriter(sysout); if (allAppStates) { @@ -202,13 +349,49 @@ private void listApplications(Set appTypes, List appsReport = client.getApplications(appTypes, appStates); + for(Iterator iter = appsReport.iterator(); + iter.hasNext();) { + ApplicationReport report = iter.next(); + + if (finalStatus != null && !finalStatus.isEmpty() && + !report.getFinalApplicationStatus().toString() + .equalsIgnoreCase(finalStatus)) { + iter.remove(); + continue; + } + + if (user != null && !user.isEmpty() && + !report.getUser().equals(user)) { + iter.remove(); + continue; + } + + if (queue != null && !queue.isEmpty() && + !report.getQueue().equals(queue)) { + iter.remove(); + continue; + } + + if (report.getStartTime() < sBegin || sEnd < report.getStartTime()) { + iter.remove(); + continue; + } + + if (report.getFinishTime() < fBegin || fEnd < report.getFinishTime()) { + iter.remove(); + continue; + } + } + writer .println("Total number of applications (application-types: " + appTypes - + " and states: " + appStates + ")" + ":" + appsReport.size()); + + " and states: " + appStates + ")" + ":" + + Math.min(countNum, appsReport.size())); writer.printf(APPLICATIONS_PATTERN, "Application-Id", "Application-Name","Application-Type", "User", "Queue", "State", "Final-State","Progress", "Tracking-URL"); - for (ApplicationReport appReport : appsReport) { + for (ApplicationReport appReport : + appsReport.subList(0, Math.min(countNum, appsReport.size()))) { DecimalFormat formatter = new DecimalFormat("###.##%"); String progress = formatter.format(appReport.getProgress()); writer.printf(APPLICATIONS_PATTERN, appReport.getApplicationId(), @@ -306,4 +489,16 @@ private String getAllValidApplicationStates() { String output = sb.toString(); return output.substring(0, output.length()-1); } + + private String getAllValidFinalApplicationStatus() { + StringBuilder sb = new StringBuilder(); + sb.append("The valid final application status can be" + + " one of the following: "); + for (FinalApplicationStatus finalState : FinalApplicationStatus + .values()) { + sb.append(finalState+","); + } + String output = sb.toString(); + return output.substring(0, output.length()-1); + } } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index 1d08f24..4e727cb 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -49,6 +49,7 @@ import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeReport; import org.apache.hadoop.yarn.api.records.NodeState; +import org.apache.hadoop.yarn.api.records.QueueInfo; import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.client.api.YarnClient; @@ -468,6 +469,322 @@ public void testGetApplications() throws Exception { appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(6)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --finalStatus + sysOutStream.reset(); + Set appType7 = new HashSet(); + EnumSet appState7 = + EnumSet.noneOf(YarnApplicationState.class); + appState7.add(YarnApplicationState.RUNNING); + appState7.add(YarnApplicationState.ACCEPTED); + appState7.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType7, appState7)).thenReturn( + getApplicationReports(applicationReports, appType7, appState7, + false)); + result = + cli.run(new String[] { "-list", "--finalStatus", "SUCCEEDED" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType7 + " and states: " + appState7 + ")" + ":" + 2); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0005\t "); + pw.print("appname\t YARN\t user\t "); + pw.print("queue\t RUNNING\t "); + pw.print("SUCCEEDED\t 53.79%"); + pw.println("\t N/A"); + pw.print(" application_1234_0007\t "); + pw.print("appname3\t MAPREDUCE\t user3\t "); + pw.print("queue3\t RUNNING\t "); + pw.print("SUCCEEDED\t 73.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(7)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --finalStatus with invalid + // finalStatus + sysOutStream.reset(); + result = + cli.run(new String[] { "-list", "--finalStatus", "INVALID" }); + assertEquals(-1, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("The final status INVALID is invalid."); + pw.print("The valid final application status can be one of the" + + " following: "); + sb = new StringBuilder(); + for (FinalApplicationStatus finalState : FinalApplicationStatus + .values()) { + sb.append(finalState+","); + } + output = sb.toString(); + pw.println(output.substring(0, output.length()-1)); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(7)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --user + sysOutStream.reset(); + Set appType8 = new HashSet(); + EnumSet appState8 = + EnumSet.noneOf(YarnApplicationState.class); + appState8.add(YarnApplicationState.RUNNING); + appState8.add(YarnApplicationState.ACCEPTED); + appState8.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType8, appState8)).thenReturn( + getApplicationReports(applicationReports, appType8, appState8, + false)); + result = + cli.run(new String[] { "-list", "--user", "user" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType8 + " and states: " + appState8 + ")" + ":" + 1); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0005\t "); + pw.print("appname\t YARN\t user\t "); + pw.print("queue\t RUNNING\t "); + pw.print("SUCCEEDED\t 53.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(8)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --queue + sysOutStream.reset(); + Set appType9 = new HashSet(); + EnumSet appState9 = + EnumSet.noneOf(YarnApplicationState.class); + appState9.add(YarnApplicationState.RUNNING); + appState9.add(YarnApplicationState.ACCEPTED); + appState9.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType9, appState9)).thenReturn( + getApplicationReports(applicationReports, appType9, appState9, + false)); + String queueName = "queue"; + when(client.getQueueInfo(queueName)).thenReturn( + QueueInfo.newInstance(queueName, 0, 0, 0, null, null, null)); + result = + cli.run(new String[] { "-list", "--queue", queueName }); + verify(client).getQueueInfo(queueName); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType9 + " and states: " + appState9 + ")" + ":" + 1); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0005\t "); + pw.print("appname\t YARN\t user\t "); + pw.print("queue\t RUNNING\t "); + pw.print("SUCCEEDED\t 53.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(9)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --startedTimeBegin + sysOutStream.reset(); + Set appType10 = new HashSet(); + EnumSet appState10 = + EnumSet.noneOf(YarnApplicationState.class); + appState10.add(YarnApplicationState.RUNNING); + appState10.add(YarnApplicationState.ACCEPTED); + appState10.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType10, appState10)).thenReturn( + getApplicationReports(applicationReports, appType10, appState10, + false)); + result = + cli.run(new String[] { "-list", "--startedTimeBegin", "4" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType10 + " and states: " + appState10 + ")" + ":" + 2); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0009\t "); + pw.print("appname5\t HIVE\t user5\t "); + pw.print("queue5\t ACCEPTED\t "); + pw.print("KILLED\t 93.79%"); + pw.println("\t N/A"); + pw.print(" application_1234_0010\t "); + pw.print("appname6\t PIG\t user6\t "); + pw.print("queue6\t SUBMITTED\t "); + pw.print("KILLED\t 99.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(10)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --startedTimeEnd + sysOutStream.reset(); + Set appType11 = new HashSet(); + EnumSet appState11 = + EnumSet.noneOf(YarnApplicationState.class); + appState11.add(YarnApplicationState.RUNNING); + appState11.add(YarnApplicationState.ACCEPTED); + appState11.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType11, appState11)).thenReturn( + getApplicationReports(applicationReports, appType11, appState11, + false)); + result = + cli.run(new String[] { "-list", "--startedTimeEnd", "4" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType11 + " and states: " + appState11 + ")" + ":" + 2); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0005\t "); + pw.print("appname\t YARN\t user\t "); + pw.print("queue\t RUNNING\t "); + pw.print("SUCCEEDED\t 53.79%"); + pw.println("\t N/A"); + pw.print(" application_1234_0007\t "); + pw.print("appname3\t MAPREDUCE\t user3\t "); + pw.print("queue3\t RUNNING\t "); + pw.print("SUCCEEDED\t 73.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(11)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --finishedTimeBegin + sysOutStream.reset(); + Set appType12 = new HashSet(); + EnumSet appState12 = + EnumSet.noneOf(YarnApplicationState.class); + appState12.add(YarnApplicationState.RUNNING); + appState12.add(YarnApplicationState.ACCEPTED); + appState12.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType12, appState12)).thenReturn( + getApplicationReports(applicationReports, appType12, appState12, + false)); + result = + cli.run(new String[] { "-list", "--finishedTimeBegin", "4" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType12 + " and states: " + appState12 + ")" + ":" + 2); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0009\t "); + pw.print("appname5\t HIVE\t user5\t "); + pw.print("queue5\t ACCEPTED\t "); + pw.print("KILLED\t 93.79%"); + pw.println("\t N/A"); + pw.print(" application_1234_0010\t "); + pw.print("appname6\t PIG\t user6\t "); + pw.print("queue6\t SUBMITTED\t "); + pw.print("KILLED\t 99.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(12)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --finishedTimeEnd + sysOutStream.reset(); + Set appType13 = new HashSet(); + EnumSet appState13 = + EnumSet.noneOf(YarnApplicationState.class); + appState13.add(YarnApplicationState.RUNNING); + appState13.add(YarnApplicationState.ACCEPTED); + appState13.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType13, appState13)).thenReturn( + getApplicationReports(applicationReports, appType13, appState13, + false)); + result = + cli.run(new String[] { "-list", "--finishedTimeEnd", "4" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType13 + " and states: " + appState13 + ")" + ":" + 2); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0005\t "); + pw.print("appname\t YARN\t user\t "); + pw.print("queue\t RUNNING\t "); + pw.print("SUCCEEDED\t 53.79%"); + pw.println("\t N/A"); + pw.print(" application_1234_0007\t "); + pw.print("appname3\t MAPREDUCE\t user3\t "); + pw.print("queue3\t RUNNING\t "); + pw.print("SUCCEEDED\t 73.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(13)).write(any(byte[].class), anyInt(), anyInt()); + + // Test command yarn application -list --limit + sysOutStream.reset(); + Set appType14 = new HashSet(); + EnumSet appState14 = + EnumSet.noneOf(YarnApplicationState.class); + appState14.add(YarnApplicationState.RUNNING); + appState14.add(YarnApplicationState.ACCEPTED); + appState14.add(YarnApplicationState.SUBMITTED); + when(client.getApplications(appType14, appState14)).thenReturn( + getApplicationReports(applicationReports, appType14, appState14, + false)); + result = + cli.run(new String[] { "-list", "--limit", "1" }); + assertEquals(0, result); + baos = new ByteArrayOutputStream(); + pw = new PrintWriter(baos); + pw.println("Total number of applications (application-types: " + + appType14 + " and states: " + appState14 + ")" + ":" + 1); + pw.print(" Application-Id\t Application-Name"); + pw.print("\t Application-Type"); + pw.print("\t User\t Queue\t State\t "); + pw.print("Final-State\t Progress"); + pw.println("\t Tracking-URL"); + pw.print(" application_1234_0005\t "); + pw.print("appname\t YARN\t user\t "); + pw.print("queue\t RUNNING\t "); + pw.print("SUCCEEDED\t 53.79%"); + pw.println("\t N/A"); + pw.close(); + appsReportStr = baos.toString("UTF-8"); + Assert.assertEquals(appsReportStr, sysOutStream.toString()); + verify(sysOut, times(14)).write(any(byte[].class), anyInt(), anyInt()); } private List getApplicationReports( @@ -919,23 +1236,47 @@ 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 based"); - pw.println(" on input comma-separated list of application"); - pw.println(" states. The valid application state can be one"); - pw.println(" of the following:"); - pw.println(" ALL,NEW,NEW_SAVING,SUBMITTED,ACCEPTED,RUNNING,"); - pw.println(" FINISHED,FAILED,KILLED"); - pw.println(" -appTypes Works with -list to filter applications based"); - pw.println(" on input comma-separated list of application"); - pw.println(" types."); - pw.println(" -help Displays help for all commands."); - pw.println(" -kill Kills the application."); - pw.println(" -list List applications from the RM. Supports"); - pw.println(" optional use of -appTypes to filter"); - pw.println(" applications based on application type, and"); - pw.println(" -appStates to filter applications based on"); - pw.println(" application state"); - pw.println(" -status Prints the status of the application."); + pw.println(" -appStates Works with -list to filter"); + pw.println(" applications based on input"); + pw.println(" comma-separated list of application"); + pw.println(" states. The valid application state"); + pw.println(" can be one of the following:"); + pw.println(" ALL,NEW,NEW_SAVING,SUBMITTED,ACCEPTED"); + pw.println(" ,RUNNING,FINISHED,FAILED,KILLED"); + pw.println(" -appTypes Works with -list to filter"); + pw.println(" applications based on input"); + pw.println(" comma-separated list of application"); + pw.println(" types."); + pw.println(" -finalStatus Works with -list to filter"); + pw.println(" applications based on final"); + pw.println(" application status. The valid final"); + pw.println(" application status can be one of the"); + pw.println(" following:"); + pw.println(" UNDEFINED,SUCCEEDED,FAILED,KILLED"); + pw.println(" -finishedTimeBegin Works with -list to filter"); + pw.println(" applications based on finished time."); + pw.println(" -finishedTimeEnd Works with -list to filter"); + pw.println(" applications based on finished time."); + pw.println(" -help Displays help for all commands."); + pw.println(" -kill Kills the application."); + pw.println(" -limit Total number of applications to be"); + pw.println(" returned. Works with -list to filter"); + pw.println(" applications."); + pw.println(" -list List applications from the RM."); + pw.println(" Supports optional use of -appTypes to"); + pw.println(" filter applications based on"); + pw.println(" application type, and -appStates to"); + pw.println(" filter applications based on"); + pw.println(" application state"); + pw.println(" -queue Works with -list to filter"); + pw.println(" applications based on queue name."); + pw.println(" -startedTimeBegin Works with -list to filter"); + pw.println(" applications based on started time."); + pw.println(" -startedTimeEnd Works with -list to filter"); + pw.println(" applications based on started time."); + pw.println(" -status Prints the status of the application."); + pw.println(" -user Works with -list to filter"); + pw.println(" applications based on user name."); pw.close(); String appsHelpStr = baos.toString("UTF-8"); return appsHelpStr; diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/apt/YarnCommands.apt.vm hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/apt/YarnCommands.apt.vm index 386be09..d7877a5 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/apt/YarnCommands.apt.vm +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/apt/YarnCommands.apt.vm @@ -69,6 +69,34 @@ Usage: yarn [--config confdir] COMMAND *---------------+--------------+ | -kill ApplicationId | Specify an application id | *---------------+--------------+ +| -finalStatus FinalStatus | The final status of the application - reported by +| | the application itself. Works with -list option. +*---------------+--------------+ +| -finishedTimeBegin FinishedTime | Applications with finish time beginning +| | with this time, specified in ms since +| | epoch. Works with -list option. +*---------------+--------------+ +| -finishedTimeEnd FinishedTime | Applications with finish time ending with +| | this time, specified in ms since epoch. +| | Works with -list option. +*---------------+--------------+ +| -limit Number | Total number of app objects to be returned. Works with +| | -list option. +*---------------+--------------+ +| -queue QueueName | Applications matching the given queue name. Works with +| | -list option. +*---------------+--------------+ +| -startedTimeBegin StartedTime | Applications with start time beginning with +| | this time, specified in ms since epoch. +| | Works with -list option. +*---------------+--------------+ +| -startedTimeEnd StartedTime | Applications with start time ending with this +| | time, specified in ms since epoch. Works with +| | -list option. +*---------------+--------------+ +| -user UserName | Applications matching the given user name. Works with +| | -list option. +*---------------+--------------+ ** node