YARN-7724. yarn application status should support application name. Contributed by Jian He

This commit is contained in:
Billie Rinaldi 2018-01-12 15:33:46 -08:00
parent e404650f48
commit 53f2768926
5 changed files with 61 additions and 30 deletions

View File

@ -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();

View File

@ -207,16 +207,16 @@ public abstract class AppAdminClient extends CompositeService {
/**
* <p>
* Get detailed status string for a YARN application.
* Get detailed app specific status string for a YARN application.
* </p>
*
* @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;
}

View File

@ -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 {
AppAdminClient client = AppAdminClient.createAppAdminClient(appType,
getConf());
sysout.println("Detailed Application Status :");
sysout.println(client.getStatusString(cliParser.getOptionValue(
STATUS_CMD)));
// try parsing appIdOrName, if it succeeds, it means it's appId
ApplicationId.fromString(appIdOrName);
exitCode = printApplicationReport(appIdOrName);
} catch (IllegalArgumentException e) {
// app type does not have app admin client implementation
// 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 {
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,

View File

@ -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 <Application ID> Prints the status of the");
pw.println(" application.");
pw.println(" -status <Application Name or ID> 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 <Application Name or ID> Stops application gracefully");
pw.println(" (may be started again later). If");
pw.println(" name is provided, appType must");

View File

@ -61,7 +61,7 @@ Usage: `yarn app [options] `
| -queue \<Queue Name\> | Works with the movetoqueue command to specify which queue to move an application to. |
| -save \<Application Name\> \<File Name\> | 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 \<Application Name\> | Starts a previously saved application. Supports -appTypes option to specify which client implementation to use. |
| -status \<ApplicationId\> | Prints the status of the application. |
| -status \<ApplicationId or ApplicationName\> | 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 \<Application Name or ID\> | 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 \<Timeout\> | Update timeout of an application from NOW. ApplicationId can be passed using 'appId' option. Timeout value is in seconds. |
| -updatePriority \<Priority\> | Update priority of an application. ApplicationId can be passed using 'appId' option. |