|
@@ -370,7 +370,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
|
|
|
|
@Private
|
|
@Private
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
- public void printContainerLogsFromRunningApplication(Configuration conf,
|
|
|
|
|
|
+ public int printContainerLogsFromRunningApplication(Configuration conf,
|
|
ContainerLogsRequest request, LogCLIHelpers logCliHelper)
|
|
ContainerLogsRequest request, LogCLIHelpers logCliHelper)
|
|
throws IOException {
|
|
throws IOException {
|
|
String containerIdStr = request.getContainerId().toString();
|
|
String containerIdStr = request.getContainerId().toString();
|
|
@@ -384,10 +384,12 @@ public class LogsCLI extends Configured implements Tool {
|
|
// filter the log files based on the given --logFiles pattern
|
|
// filter the log files based on the given --logFiles pattern
|
|
List<String> allLogs=
|
|
List<String> allLogs=
|
|
getContainerLogFiles(getConf(), containerIdStr, nodeHttpAddress);
|
|
getContainerLogFiles(getConf(), containerIdStr, nodeHttpAddress);
|
|
- List<String> matchedFiles = getMatchedLogFiles(
|
|
|
|
- request, allLogs, true);
|
|
|
|
|
|
+ List<String> matchedFiles = getMatchedLogFiles(request, allLogs);
|
|
if (matchedFiles.isEmpty()) {
|
|
if (matchedFiles.isEmpty()) {
|
|
- return;
|
|
|
|
|
|
+ System.err.println("Can not find any log file matching the pattern: "
|
|
|
|
+ + request.getLogTypes() + " for the container: " + containerIdStr
|
|
|
|
+ + " within the application: " + request.getAppId());
|
|
|
|
+ return -1;
|
|
}
|
|
}
|
|
ContainerLogsRequest newOptions = new ContainerLogsRequest(request);
|
|
ContainerLogsRequest newOptions = new ContainerLogsRequest(request);
|
|
newOptions.setLogTypes(matchedFiles);
|
|
newOptions.setLogTypes(matchedFiles);
|
|
@@ -397,7 +399,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
+ nodeId;
|
|
+ nodeId;
|
|
out.println(containerString);
|
|
out.println(containerString);
|
|
out.println(StringUtils.repeat("=", containerString.length()));
|
|
out.println(StringUtils.repeat("=", containerString.length()));
|
|
-
|
|
|
|
|
|
+ boolean foundAnyLogs = false;
|
|
for (String logFile : newOptions.getLogTypes()) {
|
|
for (String logFile : newOptions.getLogTypes()) {
|
|
out.println("LogType:" + logFile);
|
|
out.println("LogType:" + logFile);
|
|
out.println("Log Upload Time:"
|
|
out.println("Log Upload Time:"
|
|
@@ -417,6 +419,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
+ " to a running container (" + containerIdStr + ") and so may"
|
|
+ " to a running container (" + containerIdStr + ") and so may"
|
|
+ " not be complete.");
|
|
+ " not be complete.");
|
|
out.flush();
|
|
out.flush();
|
|
|
|
+ foundAnyLogs = true;
|
|
} catch (ClientHandlerException | UniformInterfaceException ex) {
|
|
} catch (ClientHandlerException | UniformInterfaceException ex) {
|
|
System.err.println("Can not find the log file:" + logFile
|
|
System.err.println("Can not find the log file:" + logFile
|
|
+ " for the container:" + containerIdStr + " in NodeManager:"
|
|
+ " for the container:" + containerIdStr + " in NodeManager:"
|
|
@@ -424,7 +427,13 @@ public class LogsCLI extends Configured implements Tool {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// for the case, we have already uploaded partial logs in HDFS
|
|
// for the case, we have already uploaded partial logs in HDFS
|
|
- logCliHelper.dumpAContainersLogsForALogType(newOptions, false);
|
|
|
|
|
|
+ int result = logCliHelper.dumpAContainerLogsForLogType(
|
|
|
|
+ newOptions, false);
|
|
|
|
+ if (result == 0 || foundAnyLogs) {
|
|
|
|
+ return 0;
|
|
|
|
+ } else {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
} finally {
|
|
} finally {
|
|
logCliHelper.closePrintStream(out);
|
|
logCliHelper.closePrintStream(out);
|
|
}
|
|
}
|
|
@@ -436,9 +445,13 @@ public class LogsCLI extends Configured implements Tool {
|
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
|
request, logCliHelper);
|
|
request, logCliHelper);
|
|
if (newOptions == null) {
|
|
if (newOptions == null) {
|
|
|
|
+ System.err.println("Can not find any log file matching the pattern: "
|
|
|
|
+ + request.getLogTypes() + " for the container: "
|
|
|
|
+ + request.getContainerId() + " within the application: "
|
|
|
|
+ + request.getAppId());
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
- return logCliHelper.dumpAContainersLogsForALogType(newOptions);
|
|
|
|
|
|
+ return logCliHelper.dumpAContainerLogsForLogType(newOptions);
|
|
}
|
|
}
|
|
|
|
|
|
private int printContainerLogsForFinishedApplicationWithoutNodeId(
|
|
private int printContainerLogsForFinishedApplicationWithoutNodeId(
|
|
@@ -447,9 +460,13 @@ public class LogsCLI extends Configured implements Tool {
|
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
|
request, logCliHelper);
|
|
request, logCliHelper);
|
|
if (newOptions == null) {
|
|
if (newOptions == null) {
|
|
|
|
+ System.err.println("Can not find any log file matching the pattern: "
|
|
|
|
+ + request.getLogTypes() + " for the container: "
|
|
|
|
+ + request.getContainerId() + " within the application: "
|
|
|
|
+ + request.getAppId());
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
- return logCliHelper.dumpAContainersLogsForALogTypeWithoutNodeId(
|
|
|
|
|
|
+ return logCliHelper.dumpAContainerLogsForLogTypeWithoutNodeId(
|
|
newOptions);
|
|
newOptions);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -634,7 +651,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
amOption.setArgName("AM Containers");
|
|
amOption.setArgName("AM Containers");
|
|
opts.addOption(amOption);
|
|
opts.addOption(amOption);
|
|
Option logFileOpt = new Option(CONTAINER_LOG_FILES, true,
|
|
Option logFileOpt = new Option(CONTAINER_LOG_FILES, true,
|
|
- "Work with -am/-containerId and specify comma-separated value "
|
|
|
|
|
|
+ "Specify comma-separated value "
|
|
+ "to get specified container log files. Use \"ALL\" to fetch all the "
|
|
+ "to get specified container log files. Use \"ALL\" to fetch all the "
|
|
+ "log files for the container. It also supports Java Regex.");
|
|
+ "log files for the container. It also supports Java Regex.");
|
|
logFileOpt.setValueSeparator(',');
|
|
logFileOpt.setValueSeparator(',');
|
|
@@ -812,7 +829,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
logFiles = Arrays.asList("syslog");
|
|
logFiles = Arrays.asList("syslog");
|
|
}
|
|
}
|
|
request.setLogTypes(logFiles);
|
|
request.setLogTypes(logFiles);
|
|
- printContainerLogsFromRunningApplication(getConf(), request,
|
|
|
|
|
|
+ resultCode = printContainerLogsFromRunningApplication(getConf(), request,
|
|
logCliHelper);
|
|
logCliHelper);
|
|
} else {
|
|
} else {
|
|
// If the application is in the final state, we will directly
|
|
// If the application is in the final state, we will directly
|
|
@@ -830,12 +847,14 @@ public class LogsCLI extends Configured implements Tool {
|
|
// If the application is still running, we would get the full
|
|
// If the application is still running, we would get the full
|
|
// list of the containers first, then fetch the logs for each
|
|
// list of the containers first, then fetch the logs for each
|
|
// container from NM.
|
|
// container from NM.
|
|
- int resultCode = 0;
|
|
|
|
|
|
+ int resultCode = -1;
|
|
if (options.isAppFinished()) {
|
|
if (options.isAppFinished()) {
|
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
|
options, logCliHelper);
|
|
options, logCliHelper);
|
|
if (newOptions == null) {
|
|
if (newOptions == null) {
|
|
- resultCode = -1;
|
|
|
|
|
|
+ System.err.println("Can not find any log file matching the pattern: "
|
|
|
|
+ + options.getLogTypes() + " for the application: "
|
|
|
|
+ + options.getAppId());
|
|
} else {
|
|
} else {
|
|
resultCode =
|
|
resultCode =
|
|
logCliHelper.dumpAllContainersLogs(newOptions);
|
|
logCliHelper.dumpAllContainersLogs(newOptions);
|
|
@@ -844,8 +863,11 @@ public class LogsCLI extends Configured implements Tool {
|
|
List<ContainerLogsRequest> containerLogRequests =
|
|
List<ContainerLogsRequest> containerLogRequests =
|
|
getContainersLogRequestForRunningApplication(options);
|
|
getContainersLogRequestForRunningApplication(options);
|
|
for (ContainerLogsRequest container : containerLogRequests) {
|
|
for (ContainerLogsRequest container : containerLogRequests) {
|
|
- printContainerLogsFromRunningApplication(getConf(), container,
|
|
|
|
- logCliHelper);
|
|
|
|
|
|
+ int result = printContainerLogsFromRunningApplication(getConf(),
|
|
|
|
+ container, logCliHelper);
|
|
|
|
+ if (result == 0) {
|
|
|
|
+ resultCode = 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (resultCode == -1) {
|
|
if (resultCode == -1) {
|
|
@@ -878,8 +900,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
List<String> matchedFiles = new ArrayList<String>();
|
|
List<String> matchedFiles = new ArrayList<String>();
|
|
if (!request.getLogTypes().contains(".*")) {
|
|
if (!request.getLogTypes().contains(".*")) {
|
|
Set<String> files = logCliHelper.listContainerLogs(request);
|
|
Set<String> files = logCliHelper.listContainerLogs(request);
|
|
- matchedFiles = getMatchedLogFiles(
|
|
|
|
- request, files, true);
|
|
|
|
|
|
+ matchedFiles = getMatchedLogFiles(request, files);
|
|
if (matchedFiles.isEmpty()) {
|
|
if (matchedFiles.isEmpty()) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -890,7 +911,7 @@ public class LogsCLI extends Configured implements Tool {
|
|
}
|
|
}
|
|
|
|
|
|
private List<String> getMatchedLogFiles(ContainerLogsRequest options,
|
|
private List<String> getMatchedLogFiles(ContainerLogsRequest options,
|
|
- Collection<String> candidate, boolean printError) throws IOException {
|
|
|
|
|
|
+ Collection<String> candidate) throws IOException {
|
|
List<String> matchedFiles = new ArrayList<String>();
|
|
List<String> matchedFiles = new ArrayList<String>();
|
|
List<String> filePattern = options.getLogTypes();
|
|
List<String> filePattern = options.getLogTypes();
|
|
for (String file : candidate) {
|
|
for (String file : candidate) {
|
|
@@ -898,13 +919,6 @@ public class LogsCLI extends Configured implements Tool {
|
|
matchedFiles.add(file);
|
|
matchedFiles.add(file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (matchedFiles.isEmpty()) {
|
|
|
|
- if (printError) {
|
|
|
|
- System.err.println("Can not find any log file matching the pattern: "
|
|
|
|
- + options.getLogTypes() + " for the application: "
|
|
|
|
- + options.getAppId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
return matchedFiles;
|
|
return matchedFiles;
|
|
}
|
|
}
|
|
|
|
|