YARN-5226. Remove AHS enable check from LogsCLI#fetchAMContainerLogs. Contributed by Xuan Gong.
(cherry picked from commit 3818393297
)
This commit is contained in:
parent
41882bd5ff
commit
7e213844a7
|
@ -556,7 +556,10 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
new ArrayList<ContainerLogsRequest>();
|
new ArrayList<ContainerLogsRequest>();
|
||||||
boolean getAMContainerLists = false;
|
boolean getAMContainerLists = false;
|
||||||
String appId = request.getAppId().toString();
|
String appId = request.getAppId().toString();
|
||||||
String errorMessage = "";
|
StringBuilder errorMessage = new StringBuilder();
|
||||||
|
// We will call RM webservice to get all AppAttempts information.
|
||||||
|
// If we get nothing, we will try to call AHS webservice to get AppAttempts
|
||||||
|
// which includes nodeAddress for the AM Containers.
|
||||||
try {
|
try {
|
||||||
amContainersList = getAMContainerInfoForRMWebService(conf, appId);
|
amContainersList = getAMContainerInfoForRMWebService(conf, appId);
|
||||||
if (amContainersList != null && !amContainersList.isEmpty()) {
|
if (amContainersList != null && !amContainersList.isEmpty()) {
|
||||||
|
@ -573,21 +576,28 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
errorMessage = ex.getMessage();
|
errorMessage.append(ex.getMessage() + "\n");
|
||||||
if (request.isAppFinished()) {
|
if (request.isAppFinished()) {
|
||||||
try {
|
if (!conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
|
||||||
amContainersList = getAMContainerInfoForAHSWebService(conf, appId);
|
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
|
||||||
if (amContainersList != null && !amContainersList.isEmpty()) {
|
errorMessage.append("Please enable the timeline service "
|
||||||
getAMContainerLists = true;
|
+ "and make sure the timeline server is running.");
|
||||||
for (JSONObject amContainer : amContainersList) {
|
} else {
|
||||||
ContainerLogsRequest amRequest = new ContainerLogsRequest(
|
try {
|
||||||
request);
|
amContainersList = getAMContainerInfoForAHSWebService(conf, appId);
|
||||||
amRequest.setContainerId(amContainer.getString("amContainerId"));
|
if (amContainersList != null && !amContainersList.isEmpty()) {
|
||||||
requests.add(amRequest);
|
getAMContainerLists = true;
|
||||||
|
for (JSONObject amContainer : amContainersList) {
|
||||||
|
ContainerLogsRequest amRequest = new ContainerLogsRequest(
|
||||||
|
request);
|
||||||
|
amRequest.setContainerId(
|
||||||
|
amContainer.getString("amContainerId"));
|
||||||
|
requests.add(amRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
errorMessage.append(e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
errorMessage = e.getMessage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -596,6 +606,9 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
System.err.println("Unable to get AM container informations "
|
System.err.println("Unable to get AM container informations "
|
||||||
+ "for the application:" + appId);
|
+ "for the application:" + appId);
|
||||||
System.err.println(errorMessage);
|
System.err.println(errorMessage);
|
||||||
|
System.err.println("Can not get AMContainers logs for "
|
||||||
|
+ "the application:" + appId + " with the appOwner:"
|
||||||
|
+ request.getAppOwner());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,19 +649,12 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
|
|
||||||
if (request.isAppFinished()) {
|
if (request.isAppFinished()) {
|
||||||
if (containerId != null && !containerId.isEmpty()) {
|
if (containerId != null && !containerId.isEmpty()) {
|
||||||
if (nodeId == null || nodeId.isEmpty()) {
|
|
||||||
try {
|
|
||||||
nodeId =
|
|
||||||
getContainerReport(containerId).getAssignedNode().toString();
|
|
||||||
request.setNodeId(nodeId);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.err.println(ex);
|
|
||||||
nodeId = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nodeId != null && !nodeId.isEmpty()) {
|
if (nodeId != null && !nodeId.isEmpty()) {
|
||||||
printContainerLogsForFinishedApplication(request,
|
printContainerLogsForFinishedApplication(request,
|
||||||
logCliHelper);
|
logCliHelper);
|
||||||
|
} else {
|
||||||
|
printContainerLogsForFinishedApplicationWithoutNodeId(
|
||||||
|
request, logCliHelper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -826,39 +832,8 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
private int fetchAMContainerLogs(ContainerLogsRequest request,
|
private int fetchAMContainerLogs(ContainerLogsRequest request,
|
||||||
List<String> amContainersList, LogCLIHelpers logCliHelper)
|
List<String> amContainersList, LogCLIHelpers logCliHelper)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
return printAMContainerLogs(getConf(), request, amContainersList,
|
||||||
// If the application is running, we will call the RM WebService
|
logCliHelper);
|
||||||
// to get the AppAttempts which includes the nodeHttpAddress
|
|
||||||
// and containerId for all the AM Containers.
|
|
||||||
// After that, we will call NodeManager webService to get the
|
|
||||||
// related logs
|
|
||||||
if (!request.isAppFinished()) {
|
|
||||||
return printAMContainerLogs(getConf(), request, amContainersList,
|
|
||||||
logCliHelper);
|
|
||||||
} else {
|
|
||||||
// If the application is in the final state, we will call RM webservice
|
|
||||||
// to get all AppAttempts information first. If we get nothing,
|
|
||||||
// we will try to call AHS webservice to get related AppAttempts
|
|
||||||
// which includes nodeAddress for the AM Containers.
|
|
||||||
// After that, we will use nodeAddress and containerId
|
|
||||||
// to get logs from HDFS directly.
|
|
||||||
if (getConf().getBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
|
|
||||||
YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED)) {
|
|
||||||
return printAMContainerLogs(getConf(), request, amContainersList,
|
|
||||||
logCliHelper);
|
|
||||||
} else {
|
|
||||||
ApplicationId appId = request.getAppId();
|
|
||||||
String appOwner = request.getAppOwner();
|
|
||||||
System.err.println("Can not get AMContainers logs for "
|
|
||||||
+ "the application:" + appId + " with the appOwner:" + appOwner);
|
|
||||||
System.err.println("This application:" + appId + " has finished."
|
|
||||||
+ " Please enable the application-history service or explicitly"
|
|
||||||
+ " use 'yarn logs -applicationId <appId> "
|
|
||||||
+ "-containerId <containerId> --nodeAddress <nodeHttpAddress>' "
|
|
||||||
+ "to get the container logs.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fetchContainerLogs(ContainerLogsRequest request,
|
private int fetchContainerLogs(ContainerLogsRequest request,
|
||||||
|
@ -869,13 +844,18 @@ public class LogsCLI extends Configured implements Tool {
|
||||||
String nodeAddress = request.getNodeId();
|
String nodeAddress = request.getNodeId();
|
||||||
String appOwner = request.getAppOwner();
|
String appOwner = request.getAppOwner();
|
||||||
boolean isAppFinished = request.isAppFinished();
|
boolean isAppFinished = request.isAppFinished();
|
||||||
// if we provide the node address and the application is in the final
|
// if the application is in the final state,
|
||||||
// state, we could directly get logs from HDFS.
|
// we could directly get logs from HDFS.
|
||||||
if (nodeAddress != null && isAppFinished) {
|
if (isAppFinished) {
|
||||||
// if user specified "ALL" as the logFiles param, pass empty list
|
// 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
|
||||||
return printContainerLogsForFinishedApplication(
|
if (nodeAddress != null && !nodeAddress.isEmpty()) {
|
||||||
request, logCliHelper);
|
return printContainerLogsForFinishedApplication(
|
||||||
|
request, logCliHelper);
|
||||||
|
} else {
|
||||||
|
return printContainerLogsForFinishedApplicationWithoutNodeId(
|
||||||
|
request, logCliHelper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String nodeHttpAddress = null;
|
String nodeHttpAddress = null;
|
||||||
String nodeId = null;
|
String nodeId = null;
|
||||||
|
|
Loading…
Reference in New Issue