diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java index d1ccc4f6f19..bf46d15a650 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java @@ -898,7 +898,21 @@ public class ServiceClient extends AppAdminClient implements SliderExitCodes, } } - public String getStatusString(String appId) + @Override + public String getStatusString(String appIdOrName) + throws IOException, YarnException { + try { + // try parsing appIdOrName, if it succeeds, it means it's appId + ApplicationId.fromString(appIdOrName); + return getStatusByAppId(appIdOrName); + } catch (IllegalArgumentException e) { + // not appId format, it could be appName. + Service status = getStatus(appIdOrName); + return status.toString(); + } + } + + private String getStatusByAppId(String appId) throws IOException, YarnException { ApplicationReport appReport = yarnClient.getApplicationReport(ApplicationId.fromString(appId)); @@ -909,8 +923,7 @@ public class ServiceClient extends AppAdminClient implements SliderExitCodes, if (StringUtils.isEmpty(appReport.getHost())) { return ""; } - ClientAMProtocol amProxy = - createAMProxy(appReport.getName(), appReport); + ClientAMProtocol amProxy = createAMProxy(appReport.getName(), appReport); GetStatusResponseProto response = amProxy.getStatus(GetStatusRequestProto.newBuilder().build()); return response.getStatus(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java index 6310178568a..6aba91a5c2d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java @@ -207,16 +207,16 @@ public abstract class AppAdminClient extends CompositeService { /** *

- * Get detailed status string for a YARN application. + * Get detailed app specific status string for a YARN application. *

* - * @param applicationId application id + * @param appIdOrName appId or appName * @return status string * @throws IOException IOException * @throws YarnException exception in client or server */ @Public @Unstable - public abstract String getStatusString(String applicationId) throws + public abstract String getStatusString(String appIdOrName) throws IOException, YarnException; } 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 fb08fcd4a65..c751f796c64 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 @@ -138,7 +138,12 @@ public class ApplicationCLI extends YarnCLI { .equalsIgnoreCase(APP))) { title = APPLICATION; opts.addOption(STATUS_CMD, true, - "Prints the status of the application."); + "Prints the status of the application. If app ID is" + + " provided, it prints the generic YARN application status." + + " If name is provided, it prints the application specific" + + " status based on app's own implementation, and -appTypes" + + " option must be specified unless it is the default" + + " yarn-service type."); opts.addOption(LIST_CMD, false, "List applications. " + "Supports optional use of -appTypes to filter applications " + "based on application type, -appStates to filter applications " @@ -190,7 +195,7 @@ public class ApplicationCLI extends YarnCLI { opts.addOption(killOpt); opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID"); opts.getOption(QUEUE_CMD).setArgName("Queue Name"); - opts.getOption(STATUS_CMD).setArgName("Application ID"); + opts.getOption(STATUS_CMD).setArgName("Application Name or ID"); opts.getOption(APP_ID).setArgName("Application ID"); opts.getOption(UPDATE_PRIORITY).setArgName("Priority"); opts.getOption(UPDATE_LIFETIME).setArgName("Timeout"); @@ -289,27 +294,31 @@ public class ApplicationCLI extends YarnCLI { } if (cliParser.hasOption(STATUS_CMD)) { - if (hasAnyOtherCLIOptions(cliParser, opts, STATUS_CMD)) { + if (hasAnyOtherCLIOptions(cliParser, opts, STATUS_CMD, APP_TYPE_CMD)) { printUsage(title, opts); return exitCode; } if (title.equalsIgnoreCase(APPLICATION) || title.equalsIgnoreCase(APP)) { - ApplicationReport report = printApplicationReport(cliParser - .getOptionValue(STATUS_CMD)); - if (report == null) { - exitCode = -1; - } else { - exitCode = 0; - String appType = report.getApplicationType(); + String appIdOrName = cliParser.getOptionValue(STATUS_CMD); + try { + // try parsing appIdOrName, if it succeeds, it means it's appId + ApplicationId.fromString(appIdOrName); + exitCode = printApplicationReport(appIdOrName); + } catch (IllegalArgumentException e) { + // not appId format, it could be appName. + // Print app specific report, if app-type is not provided, + // assume it is yarn-service type. + AppAdminClient client = AppAdminClient + .createAppAdminClient(getSingleAppTypeFromCLI(cliParser), + getConf()); try { - AppAdminClient client = AppAdminClient.createAppAdminClient(appType, - getConf()); - sysout.println("Detailed Application Status :"); - sysout.println(client.getStatusString(cliParser.getOptionValue( - STATUS_CMD))); - } catch (IllegalArgumentException e) { - // app type does not have app admin client implementation + sysout.println(client.getStatusString(appIdOrName)); + exitCode = 0; + } catch (ApplicationNotFoundException exception) { + System.err.println("Application with name '" + appIdOrName + + "' doesn't exist in RM or Timeline Server."); + return -1; } } } else if (title.equalsIgnoreCase(APPLICATION_ATTEMPT)) { @@ -891,7 +900,7 @@ public class ApplicationCLI extends YarnCLI { * @return ApplicationReport * @throws YarnException */ - private ApplicationReport printApplicationReport(String applicationId) + private int printApplicationReport(String applicationId) throws YarnException, IOException { ApplicationReport appReport = null; try { @@ -900,7 +909,7 @@ public class ApplicationCLI extends YarnCLI { } catch (ApplicationNotFoundException e) { sysout.println("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server."); - return null; + return -1; } // Use PrintWriter.println, which uses correct platform line ending. ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -964,11 +973,11 @@ public class ApplicationCLI extends YarnCLI { + "' doesn't exist in RM."); appReportStr.close(); sysout.println(baos.toString("UTF-8")); - return null; + return -1; } appReportStr.close(); sysout.println(baos.toString("UTF-8")); - return appReport; + return 0; } private void printResourceUsage(PrintWriter appReportStr, 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 54bd71e3ec6..25b426d7832 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 @@ -2122,8 +2122,17 @@ public class TestYarnCLI { pw.println(" application. Supports -appTypes"); pw.println(" option to specify which client"); pw.println(" implementation to use."); - pw.println(" -status Prints the status of the"); - pw.println(" application."); + pw.println(" -status Prints the status of the"); + pw.println(" application. If app ID is"); + pw.println(" provided, it prints the generic"); + pw.println(" YARN application status. If name"); + pw.println(" is provided, it prints the"); + pw.println(" application specific status"); + pw.println(" based on app's own"); + pw.println(" implementation, and -appTypes"); + pw.println(" option must be specified unless"); + pw.println(" it is the default yarn-service"); + pw.println(" type."); pw.println(" -stop Stops application gracefully"); pw.println(" (may be started again later). If"); pw.println(" name is provided, appType must"); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md index 018aa0b7881..67163c4fa19 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md @@ -61,7 +61,7 @@ Usage: `yarn app [options] ` | -queue \ | Works with the movetoqueue command to specify which queue to move an application to. | | -save \ \ | Saves specification file for an application. Options -updateLifetime and -changeQueue can be specified to alter the values provided in the file. Supports -appTypes option to specify which client implementation to use. | | -start \ | Starts a previously saved application. Supports -appTypes option to specify which client implementation to use. | -| -status \ | Prints the status of the application. | +| -status \ | Prints the status of the application. If app ID is provided, it prints the generic YARN application status. If name is provided, it prints the application specific status based on app's own implementation, and -appTypes option must be specified unless it is the default `yarn-service` type.| | -stop \ | Stops application gracefully (may be started again later). If name is provided, appType must be provided unless it is the default yarn-service. If ID is provided, the appType will be looked up. Supports -appTypes option to specify which client implementation to use. | | -updateLifetime \ | Update timeout of an application from NOW. ApplicationId can be passed using 'appId' option. Timeout value is in seconds. | | -updatePriority \ | Update priority of an application. ApplicationId can be passed using 'appId' option. |