YARN-5227. Yarn logs command: no need to specify applicationId when
specifying containerId. Contributed by Gergely Novák
This commit is contained in:
parent
04f6ebb66a
commit
d169f5052f
|
@ -145,18 +145,38 @@ public class LogsCLI extends Configured implements Tool {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (appIdStr == null) {
|
||||
System.err.println("ApplicationId cannot be null!");
|
||||
if (appIdStr == null && containerIdStr == null) {
|
||||
System.err.println("Both applicationId and containerId are missing, "
|
||||
+ " one of them must be specified.");
|
||||
printHelpMessage(printOpts);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ApplicationId appId = null;
|
||||
try {
|
||||
appId = ApplicationId.fromString(appIdStr);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Invalid ApplicationId specified");
|
||||
return -1;
|
||||
if (appIdStr != null) {
|
||||
try {
|
||||
appId = ApplicationId.fromString(appIdStr);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Invalid ApplicationId specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (containerIdStr != null) {
|
||||
try {
|
||||
ContainerId containerId = ContainerId.fromString(containerIdStr);
|
||||
if (appId == null) {
|
||||
appId = containerId.getApplicationAttemptId().getApplicationId();
|
||||
} else if (!containerId.getApplicationAttemptId().getApplicationId()
|
||||
.equals(appId)) {
|
||||
System.err.println("The Application:" + appId
|
||||
+ " does not have the container:" + containerId);
|
||||
return -1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Invalid ContainerId specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
LogCLIHelpers logCliHelper = new LogCLIHelpers();
|
||||
|
@ -218,13 +238,6 @@ public class LogsCLI extends Configured implements Tool {
|
|||
|
||||
int resultCode = 0;
|
||||
if (containerIdStr != null) {
|
||||
ContainerId containerId = ContainerId.fromString(containerIdStr);
|
||||
if (!containerId.getApplicationAttemptId().getApplicationId()
|
||||
.equals(appId)) {
|
||||
System.err.println("The Application:" + appId
|
||||
+ " does not have the container:" + containerId);
|
||||
return -1;
|
||||
}
|
||||
return fetchContainerLogs(request, logCliHelper);
|
||||
} else {
|
||||
if (nodeAddress == null) {
|
||||
|
@ -629,11 +642,11 @@ public class LogsCLI extends Configured implements Tool {
|
|||
opts.addOption(HELP_CMD, false, "Displays help for all commands.");
|
||||
Option appIdOpt =
|
||||
new Option(APPLICATION_ID_OPTION, true, "ApplicationId (required)");
|
||||
appIdOpt.setRequired(true);
|
||||
opts.addOption(appIdOpt);
|
||||
opts.addOption(CONTAINER_ID_OPTION, true, "ContainerId. "
|
||||
+ "By default, it will only print syslog if the application is runing."
|
||||
+ " Work with -logFiles to get other logs.");
|
||||
+ "By default, it will only print syslog if the application is running."
|
||||
+ " Work with -logFiles to get other logs. If specified, the"
|
||||
+ " applicationId can be omitted");
|
||||
opts.addOption(NODE_ADDRESS_OPTION, true, "NodeAddress in the format "
|
||||
+ "nodename:port");
|
||||
opts.addOption(APP_OWNER_OPTION, true,
|
||||
|
|
|
@ -201,8 +201,9 @@ public class TestLogsCLI {
|
|||
pw.println(" not specified)");
|
||||
pw.println(" -containerId <Container ID> ContainerId. By default, it will only");
|
||||
pw.println(" print syslog if the application is");
|
||||
pw.println(" runing. Work with -logFiles to get other");
|
||||
pw.println(" logs.");
|
||||
pw.println(" running. Work with -logFiles to get other");
|
||||
pw.println(" logs. If specified, the applicationId can");
|
||||
pw.println(" be omitted");
|
||||
pw.println(" -help Displays help for all commands.");
|
||||
pw.println(" -list_nodes Show the list of nodes that successfully");
|
||||
pw.println(" aggregated logs. This option can only be");
|
||||
|
@ -498,6 +499,24 @@ public class TestLogsCLI {
|
|||
containerId3 + " on " + LogAggregationUtils.getNodeString(nodeId)));
|
||||
sysOutStream.reset();
|
||||
|
||||
// The same should also work without the applicationId
|
||||
exitCode =
|
||||
cli.run(new String[] { "-containerId", containerId3.toString() });
|
||||
assertTrue(exitCode == 0);
|
||||
assertTrue(sysOutStream.toString().contains(
|
||||
"Hello container_0_0001_01_000003 in syslog!"));
|
||||
assertTrue(sysOutStream.toString().contains(
|
||||
"Hello container_0_0001_01_000003 in stdout!"));
|
||||
assertTrue(sysOutStream.toString().contains(
|
||||
containerId3 + " on " + LogAggregationUtils.getNodeString(nodeId)));
|
||||
sysOutStream.reset();
|
||||
|
||||
exitCode = cli.run(new String[] { "-containerId", "invalid_container" });
|
||||
assertTrue(exitCode == -1);
|
||||
assertTrue(sysErrStream.toString().contains(
|
||||
"Invalid ContainerId specified"));
|
||||
sysErrStream.reset();
|
||||
|
||||
fs.delete(new Path(remoteLogRootDir), true);
|
||||
fs.delete(new Path(rootLogDir), true);
|
||||
}
|
||||
|
@ -863,8 +882,7 @@ public class TestLogsCLI {
|
|||
"-show_meta_info", "-nodeAddress", "localhost", "-containerId",
|
||||
"container_1234" });
|
||||
assertTrue(sysErrStream.toString().contains(
|
||||
"The container container_1234 couldn't be found on the node "
|
||||
+ "specified: localhost"));
|
||||
"Invalid ContainerId specified"));
|
||||
sysErrStream.reset();
|
||||
|
||||
fs.delete(new Path(remoteLogRootDir), true);
|
||||
|
|
Loading…
Reference in New Issue