YARN-5089. Improve "yarn log" command-line "logFiles" option to support
regex. Contributed by Xuan Gong
This commit is contained in:
parent
cfb860dee7
commit
bde819abbb
|
@ -23,9 +23,11 @@ import java.io.PrintStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
@ -53,6 +55,7 @@ import org.apache.hadoop.yarn.client.api.YarnClient;
|
||||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||||
import org.apache.hadoop.yarn.exceptions.YarnException;
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||||
import org.apache.hadoop.yarn.logaggregation.LogCLIHelpers;
|
import org.apache.hadoop.yarn.logaggregation.LogCLIHelpers;
|
||||||
|
import org.apache.hadoop.yarn.logaggregation.ContainerLogsRequest;
|
||||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||||
import org.apache.hadoop.yarn.util.Times;
|
import org.apache.hadoop.yarn.util.Times;
|
||||||
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
||||||
|
@ -181,9 +184,16 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> logs = new ArrayList<String>();
|
||||||
|
if (fetchAllLogFiles(logFiles)) {
|
||||||
|
logs.add(".*");
|
||||||
|
} else if (logFiles != null && logFiles.length > 0) {
|
||||||
|
logs = Arrays.asList(logFiles);
|
||||||
|
}
|
||||||
|
|
||||||
ContainerLogsRequest request = new ContainerLogsRequest(appId,
|
ContainerLogsRequest request = new ContainerLogsRequest(appId,
|
||||||
isApplicationFinished(appState), appOwner,
|
isApplicationFinished(appState), appOwner, nodeAddress, null,
|
||||||
nodeAddress, null, containerIdStr);
|
containerIdStr, localDir, logs);
|
||||||
|
|
||||||
if (showMetaInfo) {
|
if (showMetaInfo) {
|
||||||
return showMetaInfo(request, logCliHelper);
|
return showMetaInfo(request, logCliHelper);
|
||||||
|
@ -196,7 +206,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
// To get am logs
|
// To get am logs
|
||||||
if (getAMContainerLogs) {
|
if (getAMContainerLogs) {
|
||||||
return fetchAMContainerLogs(request, amContainersList,
|
return fetchAMContainerLogs(request, amContainersList,
|
||||||
logFiles, logCliHelper, localDir);
|
logCliHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
int resultCode = 0;
|
int resultCode = 0;
|
||||||
|
@ -208,12 +218,10 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
+ " does not have the container:" + containerId);
|
+ " does not have the container:" + containerId);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return fetchContainerLogs(request, logFiles,
|
return fetchContainerLogs(request, logCliHelper);
|
||||||
logCliHelper, localDir);
|
|
||||||
} else {
|
} else {
|
||||||
if (nodeAddress == null) {
|
if (nodeAddress == null) {
|
||||||
resultCode = fetchApplicationLogs(appId, appOwner,
|
resultCode = fetchApplicationLogs(request, logCliHelper);
|
||||||
logCliHelper, localDir);
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Should at least provide ContainerId!");
|
System.err.println("Should at least provide ContainerId!");
|
||||||
printHelpMessage(printOpts);
|
printHelpMessage(printOpts);
|
||||||
|
@ -307,14 +315,14 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
private boolean fetchAllLogFiles(String[] logFiles) {
|
private boolean fetchAllLogFiles(String[] logFiles) {
|
||||||
if(logFiles != null) {
|
if(logFiles != null) {
|
||||||
List<String> logs = Arrays.asList(logFiles);
|
List<String> logs = Arrays.asList(logFiles);
|
||||||
if(logs.contains("ALL")) {
|
if(logs.contains("ALL") || logs.contains(".*")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getContainerLogFiles(Configuration conf,
|
private List<String> getContainerLogFiles(Configuration conf,
|
||||||
String containerIdStr, String nodeHttpAddress) throws IOException {
|
String containerIdStr, String nodeHttpAddress) throws IOException {
|
||||||
List<String> logFiles = new ArrayList<>();
|
List<String> logFiles = new ArrayList<>();
|
||||||
Client webServiceClient = Client.create();
|
Client webServiceClient = Client.create();
|
||||||
|
@ -348,32 +356,37 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
System.err.println("Unable to fetch log files list");
|
System.err.println("Unable to fetch log files list");
|
||||||
throw new IOException(ex);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
return logFiles.toArray(new String[0]);
|
return logFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printContainerLogsFromRunningApplication(Configuration conf,
|
private void printContainerLogsFromRunningApplication(Configuration conf,
|
||||||
ContainerLogsRequest request, String[] logFiles,
|
ContainerLogsRequest request, LogCLIHelpers logCliHelper)
|
||||||
LogCLIHelpers logCliHelper, String localDir) throws IOException {
|
throws IOException {
|
||||||
String appId = request.getAppId().toString();
|
|
||||||
String containerIdStr = request.getContainerId().toString();
|
String containerIdStr = request.getContainerId().toString();
|
||||||
String[] requestedLogFiles = logFiles;
|
String localDir = request.getOutputLocalDir();
|
||||||
String nodeHttpAddress = request.getNodeHttpAddress();
|
String nodeHttpAddress = request.getNodeHttpAddress();
|
||||||
String nodeId = request.getNodeId();
|
String nodeId = request.getNodeId();
|
||||||
String appOwner = request.getAppOwner();
|
|
||||||
PrintStream out = logCliHelper.createPrintStream(localDir, nodeId,
|
PrintStream out = logCliHelper.createPrintStream(localDir, nodeId,
|
||||||
containerIdStr);
|
containerIdStr);
|
||||||
try {
|
try {
|
||||||
// fetch all the log files for the container
|
// fetch all the log files for the container
|
||||||
if (fetchAllLogFiles(logFiles)) {
|
// filter the log files based on the given --logFiles pattern
|
||||||
requestedLogFiles =
|
List<String> allLogs=
|
||||||
getContainerLogFiles(getConf(), containerIdStr, nodeHttpAddress);
|
getContainerLogFiles(getConf(), containerIdStr, nodeHttpAddress);
|
||||||
|
List<String> matchedFiles = getMatchedLogFiles(
|
||||||
|
request, allLogs, true);
|
||||||
|
if (matchedFiles.isEmpty()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
ContainerLogsRequest newOptions = new ContainerLogsRequest(request);
|
||||||
|
newOptions.setLogTypes(matchedFiles);
|
||||||
|
|
||||||
Client webServiceClient = Client.create();
|
Client webServiceClient = Client.create();
|
||||||
String containerString = "\n\nContainer: " + containerIdStr;
|
String containerString = "\n\nContainer: " + containerIdStr;
|
||||||
out.println(containerString);
|
out.println(containerString);
|
||||||
out.println(StringUtils.repeat("=", containerString.length()));
|
out.println(StringUtils.repeat("=", containerString.length()));
|
||||||
|
|
||||||
for (String logFile : requestedLogFiles) {
|
for (String logFile : newOptions.getLogTypes()) {
|
||||||
out.println("LogType:" + logFile);
|
out.println("LogType:" + logFile);
|
||||||
out.println("Log Upload Time:"
|
out.println("Log Upload Time:"
|
||||||
+ Times.format(System.currentTimeMillis()));
|
+ Times.format(System.currentTimeMillis()));
|
||||||
|
@ -395,31 +408,34 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
+ nodeId);
|
+ nodeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// for the case, we have already uploaded partial logs in HDFS
|
||||||
|
logCliHelper.dumpAContainersLogsForALogType(newOptions, false);
|
||||||
} finally {
|
} finally {
|
||||||
logCliHelper.closePrintStream(out);
|
logCliHelper.closePrintStream(out);
|
||||||
}
|
}
|
||||||
// for the case, we have already uploaded partial logs in HDFS
|
|
||||||
logCliHelper.dumpAContainersLogsForALogType(appId, containerIdStr, nodeId,
|
|
||||||
appOwner, Arrays.asList(requestedLogFiles), false, localDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printContainerLogsForFinishedApplication(
|
private int printContainerLogsForFinishedApplication(
|
||||||
ContainerLogsRequest request, String[] logFiles,
|
ContainerLogsRequest request, LogCLIHelpers logCliHelper)
|
||||||
LogCLIHelpers logCliHelper, String localDir)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
logCliHelper.dumpAContainersLogsForALogType(request.getAppId().toString(),
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
||||||
request.getContainerId().toString(), request.getNodeId(),
|
request, logCliHelper);
|
||||||
request.getAppOwner(), logFiles != null ? Arrays.asList(logFiles)
|
if (newOptions == null) {
|
||||||
: null, localDir);
|
return -1;
|
||||||
|
}
|
||||||
|
return logCliHelper.dumpAContainersLogsForALogType(newOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int printContainerLogsForFinishedApplicationWithoutNodeId(
|
private int printContainerLogsForFinishedApplicationWithoutNodeId(
|
||||||
String appId, String containerId, String[] logFiles,
|
ContainerLogsRequest request, LogCLIHelpers logCliHelper)
|
||||||
LogCLIHelpers logCliHelper, String appOwner, String localDir)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return logCliHelper.dumpAContainersLogsForALogTypeWithoutNodeId(appId,
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
||||||
containerId, appOwner, logFiles != null ?
|
request, logCliHelper);
|
||||||
Arrays.asList(logFiles) : null, localDir);
|
if (newOptions == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return logCliHelper.dumpAContainersLogsForALogTypeWithoutNodeId(
|
||||||
|
newOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContainerReport getContainerReport(String containerIdStr)
|
private ContainerReport getContainerReport(String containerIdStr)
|
||||||
|
@ -441,8 +457,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
|
|
||||||
private int printAMContainerLogs(Configuration conf,
|
private int printAMContainerLogs(Configuration conf,
|
||||||
ContainerLogsRequest request, List<String> amContainers,
|
ContainerLogsRequest request, List<String> amContainers,
|
||||||
String[] logFiles, LogCLIHelpers logCliHelper, String localDir)
|
LogCLIHelpers logCliHelper) throws Exception {
|
||||||
throws Exception {
|
|
||||||
List<JSONObject> amContainersList = null;
|
List<JSONObject> amContainersList = null;
|
||||||
List<ContainerLogsRequest> requests =
|
List<ContainerLogsRequest> requests =
|
||||||
new ArrayList<ContainerLogsRequest>();
|
new ArrayList<ContainerLogsRequest>();
|
||||||
|
@ -491,8 +506,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
|
|
||||||
if (amContainers.contains("ALL")) {
|
if (amContainers.contains("ALL")) {
|
||||||
for (ContainerLogsRequest amRequest : requests) {
|
for (ContainerLogsRequest amRequest : requests) {
|
||||||
outputAMContainerLogs(amRequest, conf, logFiles,
|
outputAMContainerLogs(amRequest, conf, logCliHelper);
|
||||||
logCliHelper, localDir);
|
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Specified ALL for -am option. "
|
System.out.println("Specified ALL for -am option. "
|
||||||
|
@ -502,11 +516,11 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
int amContainerId = Integer.parseInt(amContainer.trim());
|
int amContainerId = Integer.parseInt(amContainer.trim());
|
||||||
if (amContainerId == -1) {
|
if (amContainerId == -1) {
|
||||||
outputAMContainerLogs(requests.get(requests.size() - 1), conf,
|
outputAMContainerLogs(requests.get(requests.size() - 1), conf,
|
||||||
logFiles, logCliHelper, localDir);
|
logCliHelper);
|
||||||
} else {
|
} else {
|
||||||
if (amContainerId <= requests.size()) {
|
if (amContainerId <= requests.size()) {
|
||||||
outputAMContainerLogs(requests.get(amContainerId - 1), conf,
|
outputAMContainerLogs(requests.get(amContainerId - 1), conf,
|
||||||
logFiles, logCliHelper, localDir);
|
logCliHelper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -515,8 +529,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void outputAMContainerLogs(ContainerLogsRequest request,
|
private void outputAMContainerLogs(ContainerLogsRequest request,
|
||||||
Configuration conf, String[] logFiles,
|
Configuration conf, LogCLIHelpers logCliHelper) throws Exception {
|
||||||
LogCLIHelpers logCliHelper, String localDir) throws Exception {
|
|
||||||
String nodeHttpAddress = request.getNodeHttpAddress();
|
String nodeHttpAddress = request.getNodeHttpAddress();
|
||||||
String containerId = request.getContainerId();
|
String containerId = request.getContainerId();
|
||||||
String nodeId = request.getNodeId();
|
String nodeId = request.getNodeId();
|
||||||
|
@ -534,25 +547,15 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nodeId != null && !nodeId.isEmpty()) {
|
if (nodeId != null && !nodeId.isEmpty()) {
|
||||||
String[] requestedLogFilesList = null;
|
|
||||||
if(!fetchAllLogFiles(logFiles)) {
|
|
||||||
requestedLogFilesList = logFiles;
|
|
||||||
}
|
|
||||||
printContainerLogsForFinishedApplication(request,
|
printContainerLogsForFinishedApplication(request,
|
||||||
requestedLogFilesList, logCliHelper, localDir);
|
logCliHelper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (nodeHttpAddress != null && containerId != null
|
if (nodeHttpAddress != null && containerId != null
|
||||||
&& !nodeHttpAddress.isEmpty() && !containerId.isEmpty()) {
|
&& !nodeHttpAddress.isEmpty() && !containerId.isEmpty()) {
|
||||||
String[] requestedLogFiles = logFiles;
|
|
||||||
// fetch all the log files for the AM
|
|
||||||
if (fetchAllLogFiles(logFiles)) {
|
|
||||||
requestedLogFiles =
|
|
||||||
getContainerLogFiles(getConf(), containerId, nodeHttpAddress);
|
|
||||||
}
|
|
||||||
printContainerLogsFromRunningApplication(conf,
|
printContainerLogsFromRunningApplication(conf,
|
||||||
request, requestedLogFiles, logCliHelper, localDir);
|
request, logCliHelper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,9 +567,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
+ "with finished applications");
|
+ "with finished applications");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
logCliHelper.printLogMetadata(request.getAppId(),
|
logCliHelper.printLogMetadata(request, System.out, System.err);
|
||||||
request.getContainerId(), request.getNodeId(),
|
|
||||||
request.getAppOwner(), System.out, System.err);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -578,8 +579,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
+ "finished applications");
|
+ "finished applications");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
logCliHelper.printNodesList(request.getAppId(), request.getAppOwner(),
|
logCliHelper.printNodesList(request, System.out, System.err);
|
||||||
System.out, System.err);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -614,7 +614,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
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 "
|
"Work with -am/-containerId and 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.");
|
+ "log files for the container. It also supports Java Regex.");
|
||||||
logFileOpt.setValueSeparator(',');
|
logFileOpt.setValueSeparator(',');
|
||||||
logFileOpt.setArgs(Option.UNLIMITED_VALUES);
|
logFileOpt.setArgs(Option.UNLIMITED_VALUES);
|
||||||
logFileOpt.setArgName("Log File Name");
|
logFileOpt.setArgName("Log File Name");
|
||||||
|
@ -687,13 +687,15 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fetchAMContainerLogs(ContainerLogsRequest request,
|
private int fetchAMContainerLogs(ContainerLogsRequest request,
|
||||||
List<String> amContainersList, String[] logFiles,
|
List<String> amContainersList, LogCLIHelpers logCliHelper)
|
||||||
LogCLIHelpers logCliHelper, String localDir) throws Exception {
|
throws Exception {
|
||||||
|
List<String> logFiles = request.getLogTypes();
|
||||||
// if we do not specify the value for CONTAINER_LOG_FILES option,
|
// if we do not specify the value for CONTAINER_LOG_FILES option,
|
||||||
// we will only output syslog
|
// we will only output syslog
|
||||||
if (logFiles == null || logFiles.length == 0) {
|
if (logFiles == null || logFiles.isEmpty()) {
|
||||||
logFiles = new String[] {"syslog"};
|
logFiles = Arrays.asList("syslog");
|
||||||
}
|
}
|
||||||
|
request.setLogTypes(logFiles);
|
||||||
// If the application is running, we will call the RM WebService
|
// If the application is running, we will call the RM WebService
|
||||||
// to get the AppAttempts which includes the nodeHttpAddress
|
// to get the AppAttempts which includes the nodeHttpAddress
|
||||||
// and containerId for all the AM Containers.
|
// and containerId for all the AM Containers.
|
||||||
|
@ -701,7 +703,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
// related logs
|
// related logs
|
||||||
if (!request.isAppFinished()) {
|
if (!request.isAppFinished()) {
|
||||||
return printAMContainerLogs(getConf(), request, amContainersList,
|
return printAMContainerLogs(getConf(), request, amContainersList,
|
||||||
logFiles, logCliHelper, localDir);
|
logCliHelper);
|
||||||
} else {
|
} else {
|
||||||
// If the application is in the final state, we will call RM webservice
|
// If the application is in the final state, we will call RM webservice
|
||||||
// to get all AppAttempts information first. If we get nothing,
|
// to get all AppAttempts information first. If we get nothing,
|
||||||
|
@ -712,7 +714,7 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
if (getConf().getBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
|
if (getConf().getBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
|
||||||
YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED)) {
|
YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED)) {
|
||||||
return printAMContainerLogs(getConf(), request, amContainersList,
|
return printAMContainerLogs(getConf(), request, amContainersList,
|
||||||
logFiles, logCliHelper, localDir);
|
logCliHelper);
|
||||||
} else {
|
} else {
|
||||||
ApplicationId appId = request.getAppId();
|
ApplicationId appId = request.getAppId();
|
||||||
String appOwner = request.getAppOwner();
|
String appOwner = request.getAppOwner();
|
||||||
|
@ -729,29 +731,21 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fetchContainerLogs(ContainerLogsRequest request,
|
private int fetchContainerLogs(ContainerLogsRequest request,
|
||||||
String[] logFiles, LogCLIHelpers logCliHelper, String localDir)
|
LogCLIHelpers logCliHelper) throws IOException {
|
||||||
throws IOException {
|
|
||||||
int resultCode = 0;
|
int resultCode = 0;
|
||||||
String appIdStr = request.getAppId().toString();
|
String appIdStr = request.getAppId().toString();
|
||||||
String containerIdStr = request.getContainerId();
|
String containerIdStr = request.getContainerId();
|
||||||
String nodeAddress = request.getNodeId();
|
String nodeAddress = request.getNodeId();
|
||||||
String appOwner = request.getAppOwner();
|
String appOwner = request.getAppOwner();
|
||||||
boolean isAppFinished = request.isAppFinished();
|
boolean isAppFinished = request.isAppFinished();
|
||||||
|
List<String> logFiles = request.getLogTypes();
|
||||||
// if we provide the node address and the application is in the final
|
// if we provide the node address and the application is in the final
|
||||||
// state, we could directly get logs from HDFS.
|
// state, we could directly get logs from HDFS.
|
||||||
if (nodeAddress != null && isAppFinished) {
|
if (nodeAddress != null && isAppFinished) {
|
||||||
// if user specified "ALL" as the logFiles param, pass null
|
// if user specified "ALL" as the logFiles param, pass empty list
|
||||||
// to logCliHelper so that it fetches all the logs
|
// to logCliHelper so that it fetches all the logs
|
||||||
List<String> logs;
|
return printContainerLogsForFinishedApplication(
|
||||||
if (logFiles == null) {
|
request, logCliHelper);
|
||||||
logs = null;
|
|
||||||
} else if (fetchAllLogFiles(logFiles)) {
|
|
||||||
logs = null;
|
|
||||||
} else {
|
|
||||||
logs = Arrays.asList(logFiles);
|
|
||||||
}
|
|
||||||
return logCliHelper.dumpAContainersLogsForALogType(appIdStr,
|
|
||||||
containerIdStr, nodeAddress, appOwner, logs, localDir);
|
|
||||||
}
|
}
|
||||||
String nodeHttpAddress = null;
|
String nodeHttpAddress = null;
|
||||||
String nodeId = null;
|
String nodeId = null;
|
||||||
|
@ -768,13 +762,8 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
request.setNodeHttpAddress(nodeHttpAddress);
|
request.setNodeHttpAddress(nodeHttpAddress);
|
||||||
} catch (IOException | YarnException ex) {
|
} catch (IOException | YarnException ex) {
|
||||||
if (isAppFinished) {
|
if (isAppFinished) {
|
||||||
String[] requestedLogFiles = logFiles;
|
|
||||||
if(fetchAllLogFiles(logFiles)) {
|
|
||||||
requestedLogFiles = null;
|
|
||||||
}
|
|
||||||
return printContainerLogsForFinishedApplicationWithoutNodeId(
|
return printContainerLogsForFinishedApplicationWithoutNodeId(
|
||||||
appIdStr, containerIdStr, requestedLogFiles, logCliHelper,
|
request, logCliHelper);
|
||||||
appOwner, localDir);
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Unable to get logs for this container:"
|
System.err.println("Unable to get logs for this container:"
|
||||||
+ containerIdStr + "for the application:" + appIdStr
|
+ containerIdStr + "for the application:" + appIdStr
|
||||||
|
@ -790,31 +779,39 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
// we will provide the NodeHttpAddress and get the container logs
|
// we will provide the NodeHttpAddress and get the container logs
|
||||||
// by calling NodeManager webservice.
|
// by calling NodeManager webservice.
|
||||||
if (!isAppFinished) {
|
if (!isAppFinished) {
|
||||||
if (logFiles == null || logFiles.length == 0) {
|
// if we do not specify the value for CONTAINER_LOG_FILES option,
|
||||||
logFiles = new String[] {"syslog"};
|
// we will only output syslog
|
||||||
|
if (logFiles == null || logFiles.isEmpty()) {
|
||||||
|
logFiles = Arrays.asList("syslog");
|
||||||
}
|
}
|
||||||
|
request.setLogTypes(logFiles);
|
||||||
printContainerLogsFromRunningApplication(getConf(), request,
|
printContainerLogsFromRunningApplication(getConf(), request,
|
||||||
logFiles, logCliHelper, localDir);
|
logCliHelper);
|
||||||
} else {
|
} else {
|
||||||
String[] requestedLogFiles = logFiles;
|
|
||||||
if(fetchAllLogFiles(logFiles)) {
|
|
||||||
requestedLogFiles = null;
|
|
||||||
}
|
|
||||||
// If the application is in the final state, we will directly
|
// If the application is in the final state, we will directly
|
||||||
// get the container logs from HDFS.
|
// get the container logs from HDFS.
|
||||||
printContainerLogsForFinishedApplication(request,
|
resultCode = printContainerLogsForFinishedApplication(
|
||||||
requestedLogFiles, logCliHelper, localDir);
|
request, logCliHelper);
|
||||||
}
|
}
|
||||||
return resultCode;
|
return resultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fetchApplicationLogs(ApplicationId appId, String appOwner,
|
private int fetchApplicationLogs(ContainerLogsRequest options,
|
||||||
LogCLIHelpers logCliHelper, String localDir) throws IOException {
|
LogCLIHelpers logCliHelper) throws IOException {
|
||||||
int resultCode =
|
// TODO: YARN-5141. To get container logs for the Running applications.
|
||||||
logCliHelper.dumpAllContainersLogs(appId, appOwner, localDir);
|
int resultCode = 0;
|
||||||
|
ContainerLogsRequest newOptions = getMatchedLogOptions(
|
||||||
|
options, logCliHelper);
|
||||||
|
if (newOptions == null) {
|
||||||
|
resultCode = -1;
|
||||||
|
} else {
|
||||||
|
resultCode =
|
||||||
|
logCliHelper.dumpAllContainersLogs(newOptions);
|
||||||
|
}
|
||||||
if (resultCode == -1) {
|
if (resultCode == -1) {
|
||||||
System.err.println("Can not find the logs for the application: "
|
System.err.println("Can not find the logs for the application: "
|
||||||
+ appId + " with the appOwner: " + appOwner);
|
+ options.getAppId() + " with the appOwner: "
|
||||||
|
+ options.getAppOwner());
|
||||||
}
|
}
|
||||||
return resultCode;
|
return resultCode;
|
||||||
}
|
}
|
||||||
|
@ -833,80 +830,53 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
return appOwner;
|
return appOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ContainerLogsRequest {
|
private ContainerLogsRequest getMatchedLogOptions(
|
||||||
private ApplicationId appId;
|
ContainerLogsRequest request, LogCLIHelpers logCliHelper)
|
||||||
private String containerId;
|
throws IOException {
|
||||||
private String nodeId;
|
ContainerLogsRequest newOptions = new ContainerLogsRequest(request);
|
||||||
private String nodeHttpAddress;
|
if (request.getLogTypes() != null && !request.getLogTypes().isEmpty()) {
|
||||||
private String appOwner;
|
List<String> matchedFiles = new ArrayList<String>();
|
||||||
private boolean appFinished;
|
if (!request.getLogTypes().contains(".*")) {
|
||||||
|
Set<String> files = logCliHelper.listContainerLogs(request);
|
||||||
public ContainerLogsRequest(ContainerLogsRequest request) {
|
matchedFiles = getMatchedLogFiles(
|
||||||
this.setAppId(request.getAppId());
|
request, files, true);
|
||||||
this.setAppFinished(request.isAppFinished());
|
if (matchedFiles.isEmpty()) {
|
||||||
this.setAppOwner(request.getAppOwner());
|
return null;
|
||||||
this.setNodeId(request.getNodeId());
|
}
|
||||||
this.setNodeHttpAddress(request.getNodeHttpAddress());
|
}
|
||||||
this.setContainerId(request.getContainerId());
|
newOptions.setLogTypes(matchedFiles);
|
||||||
}
|
}
|
||||||
|
return newOptions;
|
||||||
|
}
|
||||||
|
|
||||||
public ContainerLogsRequest(ApplicationId applicationId,
|
private List<String> getMatchedLogFiles(ContainerLogsRequest options,
|
||||||
boolean isAppFinished, String owner,
|
Collection<String> candidate, boolean printError) throws IOException {
|
||||||
String address, String httpAddress, String container) {
|
List<String> matchedFiles = new ArrayList<String>();
|
||||||
this.setAppId(applicationId);
|
List<String> filePattern = options.getLogTypes();
|
||||||
this.setAppFinished(isAppFinished);
|
for (String file : candidate) {
|
||||||
this.setAppOwner(owner);
|
if (isFileMatching(file, filePattern)) {
|
||||||
this.setNodeId(address);
|
matchedFiles.add(file);
|
||||||
this.setNodeHttpAddress(httpAddress);
|
}
|
||||||
this.setContainerId(container);
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public ApplicationId getAppId() {
|
private boolean isFileMatching(String fileType,
|
||||||
return appId;
|
List<String> logTypes) {
|
||||||
}
|
for (String logType : logTypes) {
|
||||||
|
Pattern filterPattern = Pattern.compile(logType);
|
||||||
public void setAppId(ApplicationId appId) {
|
boolean match = filterPattern.matcher(fileType).find();
|
||||||
this.appId = appId;
|
if (match) {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
public String getContainerId() {
|
|
||||||
return containerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContainerId(String containerId) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNodeId() {
|
|
||||||
return nodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeId(String nodeAddress) {
|
|
||||||
this.nodeId = nodeAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppOwner() {
|
|
||||||
return appOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppOwner(String appOwner) {
|
|
||||||
this.appOwner = appOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNodeHttpAddress() {
|
|
||||||
return nodeHttpAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeHttpAddress(String nodeHttpAddress) {
|
|
||||||
this.nodeHttpAddress = nodeHttpAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAppFinished() {
|
|
||||||
return appFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppFinished(boolean appFinished) {
|
|
||||||
this.appFinished = appFinished;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,8 @@ public class TestLogsCLI {
|
||||||
pw.println(" -logFiles <Log File Name> Work with -am/-containerId and specify");
|
pw.println(" -logFiles <Log File Name> Work with -am/-containerId and specify");
|
||||||
pw.println(" comma-separated value to get specified");
|
pw.println(" comma-separated value to get specified");
|
||||||
pw.println(" container log files. Use \"ALL\" to fetch");
|
pw.println(" container log files. Use \"ALL\" to fetch");
|
||||||
pw.println(" all the log files for the container.");
|
pw.println(" all the log files for the container. It");
|
||||||
|
pw.println(" also supports Java Regex.");
|
||||||
pw.println(" -nodeAddress <Node Address> NodeAddress in the format nodename:port");
|
pw.println(" -nodeAddress <Node Address> NodeAddress in the format nodename:port");
|
||||||
pw.println(" -out <Local Directory> Local directory for storing individual");
|
pw.println(" -out <Local Directory> Local directory for storing individual");
|
||||||
pw.println(" container logs. The container logs will");
|
pw.println(" container logs. The container logs will");
|
||||||
|
@ -288,6 +289,39 @@ public class TestLogsCLI {
|
||||||
"Hello container_0_0001_01_000003 in stdout!"));
|
"Hello container_0_0001_01_000003 in stdout!"));
|
||||||
sysOutStream.reset();
|
sysOutStream.reset();
|
||||||
|
|
||||||
|
exitCode = cli.run(new String[] {"-applicationId", appId.toString(),
|
||||||
|
"-logFiles", ".*"});
|
||||||
|
assertTrue(exitCode == 0);
|
||||||
|
assertTrue(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000001 in syslog!"));
|
||||||
|
assertTrue(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000002 in syslog!"));
|
||||||
|
assertTrue(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000003 in syslog!"));
|
||||||
|
assertTrue(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000003 in stdout!"));
|
||||||
|
sysOutStream.reset();
|
||||||
|
|
||||||
|
exitCode = cli.run(new String[] {"-applicationId", appId.toString(),
|
||||||
|
"-logFiles", "std*"});
|
||||||
|
assertTrue(exitCode == 0);
|
||||||
|
assertFalse(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000001 in syslog!"));
|
||||||
|
assertFalse(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000002 in syslog!"));
|
||||||
|
assertFalse(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000003 in syslog!"));
|
||||||
|
assertTrue(sysOutStream.toString().contains(
|
||||||
|
"Hello container_0_0001_01_000003 in stdout!"));
|
||||||
|
sysOutStream.reset();
|
||||||
|
|
||||||
|
exitCode = cli.run(new String[] {"-applicationId", appId.toString(),
|
||||||
|
"-logFiles", "123"});
|
||||||
|
assertTrue(exitCode == -1);
|
||||||
|
assertTrue(sysErrStream.toString().contains(
|
||||||
|
"Can not find any log file matching the pattern: [123]"));
|
||||||
|
sysErrStream.reset();
|
||||||
|
|
||||||
// uploaded two logs for container1. The first log is empty.
|
// uploaded two logs for container1. The first log is empty.
|
||||||
// The second one is not empty.
|
// The second one is not empty.
|
||||||
// We can still successfully read logs for container1.
|
// We can still successfully read logs for container1.
|
||||||
|
|
|
@ -875,23 +875,25 @@ public class AggregatedLogFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
public static void readContainerMetaDataAndSkipData(
|
public static String readContainerMetaDataAndSkipData(
|
||||||
DataInputStream valueStream, PrintStream out) throws IOException {
|
DataInputStream valueStream, PrintStream out) throws IOException {
|
||||||
|
|
||||||
String fileType = valueStream.readUTF();
|
String fileType = valueStream.readUTF();
|
||||||
String fileLengthStr = valueStream.readUTF();
|
String fileLengthStr = valueStream.readUTF();
|
||||||
long fileLength = Long.parseLong(fileLengthStr);
|
long fileLength = Long.parseLong(fileLengthStr);
|
||||||
out.print("LogType:");
|
if (out != null) {
|
||||||
out.println(fileType);
|
out.print("LogType:");
|
||||||
out.print("LogLength:");
|
out.println(fileType);
|
||||||
out.println(fileLengthStr);
|
out.print("LogLength:");
|
||||||
|
out.println(fileLengthStr);
|
||||||
|
}
|
||||||
long totalSkipped = 0;
|
long totalSkipped = 0;
|
||||||
long currSkipped = 0;
|
long currSkipped = 0;
|
||||||
while (currSkipped != -1 && totalSkipped < fileLength) {
|
while (currSkipped != -1 && totalSkipped < fileLength) {
|
||||||
currSkipped = valueStream.skip(fileLength - totalSkipped);
|
currSkipped = valueStream.skip(fileLength - totalSkipped);
|
||||||
totalSkipped += currSkipped;
|
totalSkipped += currSkipped;
|
||||||
}
|
}
|
||||||
|
return fileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.hadoop.yarn.logaggregation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||||
|
|
||||||
|
public class ContainerLogsRequest {
|
||||||
|
private ApplicationId appId;
|
||||||
|
private String containerId;
|
||||||
|
private String nodeId;
|
||||||
|
private String nodeHttpAddress;
|
||||||
|
private String appOwner;
|
||||||
|
private boolean appFinished;
|
||||||
|
private String outputLocalDir;
|
||||||
|
private List<String> logTypes;
|
||||||
|
|
||||||
|
public ContainerLogsRequest() {}
|
||||||
|
|
||||||
|
public ContainerLogsRequest(ContainerLogsRequest request) {
|
||||||
|
this.setAppId(request.getAppId());
|
||||||
|
this.setAppFinished(request.isAppFinished());
|
||||||
|
this.setAppOwner(request.getAppOwner());
|
||||||
|
this.setNodeId(request.getNodeId());
|
||||||
|
this.setNodeHttpAddress(request.getNodeHttpAddress());
|
||||||
|
this.setContainerId(request.getContainerId());
|
||||||
|
this.setOutputLocalDir(request.getOutputLocalDir());
|
||||||
|
this.setLogTypes(request.getLogTypes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerLogsRequest(ApplicationId applicationId,
|
||||||
|
boolean isAppFinished, String owner,
|
||||||
|
String address, String httpAddress, String container, String localDir,
|
||||||
|
List<String> logs) {
|
||||||
|
this.setAppId(applicationId);
|
||||||
|
this.setAppFinished(isAppFinished);
|
||||||
|
this.setAppOwner(owner);
|
||||||
|
this.setNodeId(address);
|
||||||
|
this.setNodeHttpAddress(httpAddress);
|
||||||
|
this.setContainerId(container);
|
||||||
|
this.setOutputLocalDir(localDir);
|
||||||
|
this.setLogTypes(logs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationId getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(ApplicationId appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContainerId() {
|
||||||
|
return containerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContainerId(String containerId) {
|
||||||
|
this.containerId = containerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNodeId() {
|
||||||
|
return nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodeId(String nodeAddress) {
|
||||||
|
this.nodeId = nodeAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppOwner() {
|
||||||
|
return appOwner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppOwner(String appOwner) {
|
||||||
|
this.appOwner = appOwner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNodeHttpAddress() {
|
||||||
|
return nodeHttpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodeHttpAddress(String nodeHttpAddress) {
|
||||||
|
this.nodeHttpAddress = nodeHttpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAppFinished() {
|
||||||
|
return appFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppFinished(boolean appFinished) {
|
||||||
|
this.appFinished = appFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOutputLocalDir() {
|
||||||
|
return outputLocalDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputLocalDir(String outputLocalDir) {
|
||||||
|
this.outputLocalDir = outputLocalDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLogTypes() {
|
||||||
|
return logTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogTypes(List<String> logTypes) {
|
||||||
|
this.logTypes = logTypes;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,7 +26,10 @@ import java.io.PrintStream;
|
||||||
import java.nio.file.AccessDeniedException;
|
import java.nio.file.AccessDeniedException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
||||||
|
@ -55,8 +58,14 @@ public class LogCLIHelpers implements Configurable {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public int dumpAContainersLogs(String appId, String containerId,
|
public int dumpAContainersLogs(String appId, String containerId,
|
||||||
String nodeId, String jobOwner) throws IOException {
|
String nodeId, String jobOwner) throws IOException {
|
||||||
return dumpAContainersLogsForALogType(appId, containerId, nodeId, jobOwner,
|
ContainerLogsRequest options = new ContainerLogsRequest();
|
||||||
null, null);
|
options.setAppId(ConverterUtils.toApplicationId(appId));
|
||||||
|
options.setContainerId(containerId);
|
||||||
|
options.setNodeId(nodeId);
|
||||||
|
options.setAppOwner(jobOwner);
|
||||||
|
List<String> logs = new ArrayList<String>();
|
||||||
|
options.setLogTypes(logs);
|
||||||
|
return dumpAContainersLogsForALogType(options, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
|
@ -108,19 +117,21 @@ public class LogCLIHelpers implements Configurable {
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public int dumpAContainersLogsForALogType(String appId, String containerId,
|
public int dumpAContainersLogsForALogType(ContainerLogsRequest options)
|
||||||
String nodeId, String jobOwner, List<String> logType, String localDir)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return dumpAContainersLogsForALogType(appId, containerId, nodeId,
|
return dumpAContainersLogsForALogType(options, true);
|
||||||
jobOwner, logType, true, localDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public int dumpAContainersLogsForALogType(String appId, String containerId,
|
public int dumpAContainersLogsForALogType(ContainerLogsRequest options,
|
||||||
String nodeId, String jobOwner, List<String> logType,
|
boolean outputFailure) throws IOException {
|
||||||
boolean outputFailure, String localDir) throws IOException {
|
ApplicationId applicationId = options.getAppId();
|
||||||
ApplicationId applicationId = ConverterUtils.toApplicationId(appId);
|
String jobOwner = options.getAppOwner();
|
||||||
|
String nodeId = options.getNodeId();
|
||||||
|
String containerId = options.getContainerId();
|
||||||
|
String localDir = options.getOutputLocalDir();
|
||||||
|
List<String> logType = options.getLogTypes();
|
||||||
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
||||||
applicationId, jobOwner);
|
applicationId, jobOwner);
|
||||||
if (nodeFiles == null) {
|
if (nodeFiles == null) {
|
||||||
|
@ -147,7 +158,7 @@ public class LogCLIHelpers implements Configurable {
|
||||||
reader =
|
reader =
|
||||||
new AggregatedLogFormat.LogReader(getConf(),
|
new AggregatedLogFormat.LogReader(getConf(),
|
||||||
thisNodeFile.getPath());
|
thisNodeFile.getPath());
|
||||||
if (logType == null) {
|
if (logType == null || logType.isEmpty()) {
|
||||||
if (dumpAContainerLogs(containerId, reader, out,
|
if (dumpAContainerLogs(containerId, reader, out,
|
||||||
thisNodeFile.getModificationTime()) > -1) {
|
thisNodeFile.getModificationTime()) > -1) {
|
||||||
foundContainerLogs = true;
|
foundContainerLogs = true;
|
||||||
|
@ -176,10 +187,13 @@ public class LogCLIHelpers implements Configurable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
public int dumpAContainersLogsForALogTypeWithoutNodeId(String appId,
|
public int dumpAContainersLogsForALogTypeWithoutNodeId(
|
||||||
String containerId, String jobOwner, List<String> logType,
|
ContainerLogsRequest options) throws IOException {
|
||||||
String localDir) throws IOException {
|
ApplicationId applicationId = options.getAppId();
|
||||||
ApplicationId applicationId = ConverterUtils.toApplicationId(appId);
|
String jobOwner = options.getAppOwner();
|
||||||
|
String containerId = options.getContainerId();
|
||||||
|
String localDir = options.getOutputLocalDir();
|
||||||
|
List<String> logType = options.getLogTypes();
|
||||||
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
||||||
applicationId, jobOwner);
|
applicationId, jobOwner);
|
||||||
if (nodeFiles == null) {
|
if (nodeFiles == null) {
|
||||||
|
@ -206,7 +220,7 @@ public class LogCLIHelpers implements Configurable {
|
||||||
containerId);
|
containerId);
|
||||||
out.println(containerId);
|
out.println(containerId);
|
||||||
out.println(StringUtils.repeat("=", containerId.length()));
|
out.println(StringUtils.repeat("=", containerId.length()));
|
||||||
if (logType == null) {
|
if (logType == null || logType.isEmpty()) {
|
||||||
if (dumpAContainerLogs(containerId, reader, out,
|
if (dumpAContainerLogs(containerId, reader, out,
|
||||||
thisNodeFile.getModificationTime()) > -1) {
|
thisNodeFile.getModificationTime()) > -1) {
|
||||||
foundContainerLogs = true;
|
foundContainerLogs = true;
|
||||||
|
@ -303,8 +317,12 @@ public class LogCLIHelpers implements Configurable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
public int dumpAllContainersLogs(ApplicationId appId, String appOwner,
|
public int dumpAllContainersLogs(ContainerLogsRequest options)
|
||||||
String localDir) throws IOException {
|
throws IOException {
|
||||||
|
ApplicationId appId = options.getAppId();
|
||||||
|
String appOwner = options.getAppOwner();
|
||||||
|
String localDir = options.getOutputLocalDir();
|
||||||
|
List<String> logTypes = options.getLogTypes();
|
||||||
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
||||||
appId, appOwner);
|
appId, appOwner);
|
||||||
if (nodeFiles == null) {
|
if (nodeFiles == null) {
|
||||||
|
@ -341,9 +359,18 @@ public class LogCLIHelpers implements Configurable {
|
||||||
out.println(StringUtils.repeat("=", containerString.length()));
|
out.println(StringUtils.repeat("=", containerString.length()));
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
LogReader.readAContainerLogsForALogType(valueStream, out,
|
if (logTypes == null || logTypes.isEmpty()) {
|
||||||
thisNodeFile.getModificationTime());
|
LogReader.readAContainerLogsForALogType(valueStream, out,
|
||||||
foundAnyLogs = true;
|
thisNodeFile.getModificationTime());
|
||||||
|
foundAnyLogs = true;
|
||||||
|
} else {
|
||||||
|
int result = LogReader.readContainerLogsForALogType(
|
||||||
|
valueStream, out, thisNodeFile.getModificationTime(),
|
||||||
|
logTypes);
|
||||||
|
if (result == 0) {
|
||||||
|
foundAnyLogs = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (EOFException eof) {
|
} catch (EOFException eof) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -369,10 +396,13 @@ public class LogCLIHelpers implements Configurable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
public void printLogMetadata(ApplicationId appId,
|
public void printLogMetadata(ContainerLogsRequest options,
|
||||||
String containerIdStr, String nodeId, String appOwner,
|
|
||||||
PrintStream out, PrintStream err)
|
PrintStream out, PrintStream err)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
ApplicationId appId = options.getAppId();
|
||||||
|
String appOwner = options.getAppOwner();
|
||||||
|
String nodeId = options.getNodeId();
|
||||||
|
String containerIdStr = options.getContainerId();
|
||||||
boolean getAllContainers = (containerIdStr == null);
|
boolean getAllContainers = (containerIdStr == null);
|
||||||
String nodeIdStr = (nodeId == null) ? null
|
String nodeIdStr = (nodeId == null) ? null
|
||||||
: LogAggregationUtils.getNodeString(nodeId);
|
: LogAggregationUtils.getNodeString(nodeId);
|
||||||
|
@ -443,8 +473,10 @@ public class LogCLIHelpers implements Configurable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Private
|
@Private
|
||||||
public void printNodesList(ApplicationId appId, String appOwner,
|
public void printNodesList(ContainerLogsRequest options,
|
||||||
PrintStream out, PrintStream err) throws IOException {
|
PrintStream out, PrintStream err) throws IOException {
|
||||||
|
ApplicationId appId = options.getAppId();
|
||||||
|
String appOwner = options.getAppOwner();
|
||||||
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
||||||
appId, appOwner);
|
appId, appOwner);
|
||||||
if (nodeFiles == null) {
|
if (nodeFiles == null) {
|
||||||
|
@ -547,4 +579,63 @@ public class LogCLIHelpers implements Configurable {
|
||||||
IOUtils.closeQuietly(out);
|
IOUtils.closeQuietly(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Private
|
||||||
|
public Set<String> listContainerLogs(ContainerLogsRequest options)
|
||||||
|
throws IOException {
|
||||||
|
Set<String> logTypes = new HashSet<String>();
|
||||||
|
ApplicationId appId = options.getAppId();
|
||||||
|
String appOwner = options.getAppOwner();
|
||||||
|
String nodeId = options.getNodeId();
|
||||||
|
String containerIdStr = options.getContainerId();
|
||||||
|
boolean getAllContainers = (containerIdStr == null);
|
||||||
|
String nodeIdStr = (nodeId == null) ? null
|
||||||
|
: LogAggregationUtils.getNodeString(nodeId);
|
||||||
|
RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
||||||
|
appId, appOwner);
|
||||||
|
if (nodeFiles == null) {
|
||||||
|
return logTypes;
|
||||||
|
}
|
||||||
|
while (nodeFiles.hasNext()) {
|
||||||
|
FileStatus thisNodeFile = nodeFiles.next();
|
||||||
|
if (nodeIdStr != null) {
|
||||||
|
if (!thisNodeFile.getPath().getName().contains(nodeIdStr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!thisNodeFile.getPath().getName()
|
||||||
|
.endsWith(LogAggregationUtils.TMP_FILE_SUFFIX)) {
|
||||||
|
AggregatedLogFormat.LogReader reader =
|
||||||
|
new AggregatedLogFormat.LogReader(getConf(),
|
||||||
|
thisNodeFile.getPath());
|
||||||
|
try {
|
||||||
|
DataInputStream valueStream;
|
||||||
|
LogKey key = new LogKey();
|
||||||
|
valueStream = reader.next(key);
|
||||||
|
while (valueStream != null) {
|
||||||
|
if (getAllContainers || (key.toString().equals(containerIdStr))) {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
String logFile = LogReader.readContainerMetaDataAndSkipData(
|
||||||
|
valueStream, null);
|
||||||
|
logTypes.add(logFile);
|
||||||
|
} catch (EOFException eof) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!getAllContainers) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Next container
|
||||||
|
key = new LogKey();
|
||||||
|
valueStream = reader.next(key);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return logTypes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue