YARN-7724. yarn application status should support application name. Contributed by Jian He
This commit is contained in:
parent
e404650f48
commit
53f2768926
|
@ -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 {
|
throws IOException, YarnException {
|
||||||
ApplicationReport appReport =
|
ApplicationReport appReport =
|
||||||
yarnClient.getApplicationReport(ApplicationId.fromString(appId));
|
yarnClient.getApplicationReport(ApplicationId.fromString(appId));
|
||||||
|
@ -909,8 +923,7 @@ public class ServiceClient extends AppAdminClient implements SliderExitCodes,
|
||||||
if (StringUtils.isEmpty(appReport.getHost())) {
|
if (StringUtils.isEmpty(appReport.getHost())) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
ClientAMProtocol amProxy =
|
ClientAMProtocol amProxy = createAMProxy(appReport.getName(), appReport);
|
||||||
createAMProxy(appReport.getName(), appReport);
|
|
||||||
GetStatusResponseProto response =
|
GetStatusResponseProto response =
|
||||||
amProxy.getStatus(GetStatusRequestProto.newBuilder().build());
|
amProxy.getStatus(GetStatusRequestProto.newBuilder().build());
|
||||||
return response.getStatus();
|
return response.getStatus();
|
||||||
|
|
|
@ -207,16 +207,16 @@ public abstract class AppAdminClient extends CompositeService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Get detailed status string for a YARN application.
|
* Get detailed app specific status string for a YARN application.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param applicationId application id
|
* @param appIdOrName appId or appName
|
||||||
* @return status string
|
* @return status string
|
||||||
* @throws IOException IOException
|
* @throws IOException IOException
|
||||||
* @throws YarnException exception in client or server
|
* @throws YarnException exception in client or server
|
||||||
*/
|
*/
|
||||||
@Public
|
@Public
|
||||||
@Unstable
|
@Unstable
|
||||||
public abstract String getStatusString(String applicationId) throws
|
public abstract String getStatusString(String appIdOrName) throws
|
||||||
IOException, YarnException;
|
IOException, YarnException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,12 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
.equalsIgnoreCase(APP))) {
|
.equalsIgnoreCase(APP))) {
|
||||||
title = APPLICATION;
|
title = APPLICATION;
|
||||||
opts.addOption(STATUS_CMD, true,
|
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. "
|
opts.addOption(LIST_CMD, false, "List applications. "
|
||||||
+ "Supports optional use of -appTypes to filter applications "
|
+ "Supports optional use of -appTypes to filter applications "
|
||||||
+ "based on application type, -appStates to filter applications "
|
+ "based on application type, -appStates to filter applications "
|
||||||
|
@ -190,7 +195,7 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
opts.addOption(killOpt);
|
opts.addOption(killOpt);
|
||||||
opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID");
|
opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID");
|
||||||
opts.getOption(QUEUE_CMD).setArgName("Queue Name");
|
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(APP_ID).setArgName("Application ID");
|
||||||
opts.getOption(UPDATE_PRIORITY).setArgName("Priority");
|
opts.getOption(UPDATE_PRIORITY).setArgName("Priority");
|
||||||
opts.getOption(UPDATE_LIFETIME).setArgName("Timeout");
|
opts.getOption(UPDATE_LIFETIME).setArgName("Timeout");
|
||||||
|
@ -289,27 +294,31 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cliParser.hasOption(STATUS_CMD)) {
|
if (cliParser.hasOption(STATUS_CMD)) {
|
||||||
if (hasAnyOtherCLIOptions(cliParser, opts, STATUS_CMD)) {
|
if (hasAnyOtherCLIOptions(cliParser, opts, STATUS_CMD, APP_TYPE_CMD)) {
|
||||||
printUsage(title, opts);
|
printUsage(title, opts);
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
if (title.equalsIgnoreCase(APPLICATION) ||
|
if (title.equalsIgnoreCase(APPLICATION) ||
|
||||||
title.equalsIgnoreCase(APP)) {
|
title.equalsIgnoreCase(APP)) {
|
||||||
ApplicationReport report = printApplicationReport(cliParser
|
String appIdOrName = cliParser.getOptionValue(STATUS_CMD);
|
||||||
.getOptionValue(STATUS_CMD));
|
|
||||||
if (report == null) {
|
|
||||||
exitCode = -1;
|
|
||||||
} else {
|
|
||||||
exitCode = 0;
|
|
||||||
String appType = report.getApplicationType();
|
|
||||||
try {
|
try {
|
||||||
AppAdminClient client = AppAdminClient.createAppAdminClient(appType,
|
// try parsing appIdOrName, if it succeeds, it means it's appId
|
||||||
getConf());
|
ApplicationId.fromString(appIdOrName);
|
||||||
sysout.println("Detailed Application Status :");
|
exitCode = printApplicationReport(appIdOrName);
|
||||||
sysout.println(client.getStatusString(cliParser.getOptionValue(
|
|
||||||
STATUS_CMD)));
|
|
||||||
} catch (IllegalArgumentException e) {
|
} 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)) {
|
} else if (title.equalsIgnoreCase(APPLICATION_ATTEMPT)) {
|
||||||
|
@ -891,7 +900,7 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
* @return ApplicationReport
|
* @return ApplicationReport
|
||||||
* @throws YarnException
|
* @throws YarnException
|
||||||
*/
|
*/
|
||||||
private ApplicationReport printApplicationReport(String applicationId)
|
private int printApplicationReport(String applicationId)
|
||||||
throws YarnException, IOException {
|
throws YarnException, IOException {
|
||||||
ApplicationReport appReport = null;
|
ApplicationReport appReport = null;
|
||||||
try {
|
try {
|
||||||
|
@ -900,7 +909,7 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
} catch (ApplicationNotFoundException e) {
|
} catch (ApplicationNotFoundException e) {
|
||||||
sysout.println("Application with id '" + applicationId
|
sysout.println("Application with id '" + applicationId
|
||||||
+ "' doesn't exist in RM or Timeline Server.");
|
+ "' doesn't exist in RM or Timeline Server.");
|
||||||
return null;
|
return -1;
|
||||||
}
|
}
|
||||||
// Use PrintWriter.println, which uses correct platform line ending.
|
// Use PrintWriter.println, which uses correct platform line ending.
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
@ -964,11 +973,11 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
+ "' doesn't exist in RM.");
|
+ "' doesn't exist in RM.");
|
||||||
appReportStr.close();
|
appReportStr.close();
|
||||||
sysout.println(baos.toString("UTF-8"));
|
sysout.println(baos.toString("UTF-8"));
|
||||||
return null;
|
return -1;
|
||||||
}
|
}
|
||||||
appReportStr.close();
|
appReportStr.close();
|
||||||
sysout.println(baos.toString("UTF-8"));
|
sysout.println(baos.toString("UTF-8"));
|
||||||
return appReport;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printResourceUsage(PrintWriter appReportStr,
|
private void printResourceUsage(PrintWriter appReportStr,
|
||||||
|
|
|
@ -2122,8 +2122,17 @@ public class TestYarnCLI {
|
||||||
pw.println(" application. Supports -appTypes");
|
pw.println(" application. Supports -appTypes");
|
||||||
pw.println(" option to specify which client");
|
pw.println(" option to specify which client");
|
||||||
pw.println(" implementation to use.");
|
pw.println(" implementation to use.");
|
||||||
pw.println(" -status <Application ID> Prints the status of the");
|
pw.println(" -status <Application Name or ID> Prints the status of the");
|
||||||
pw.println(" application.");
|
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(" -stop <Application Name or ID> Stops application gracefully");
|
||||||
pw.println(" (may be started again later). If");
|
pw.println(" (may be started again later). If");
|
||||||
pw.println(" name is provided, appType must");
|
pw.println(" name is provided, appType must");
|
||||||
|
|
|
@ -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. |
|
| -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. |
|
| -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. |
|
| -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. |
|
| -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. |
|
| -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. |
|
| -updatePriority \<Priority\> | Update priority of an application. ApplicationId can be passed using 'appId' option. |
|
||||||
|
|
Loading…
Reference in New Issue