diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java index d62ee5e..7b0e676 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java @@ -478,6 +478,9 @@ private int printAMContainerLogs(Configuration conf, boolean getAMContainerLists = false; String appId = request.getAppId().toString(); String errorMessage = ""; + // 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 { amContainersList = getAMContainerInfoForRMWebService(conf, appId); if (amContainersList != null && !amContainersList.isEmpty()) { @@ -515,6 +518,9 @@ private int printAMContainerLogs(Configuration conf, System.err.println("Unable to get AM container informations " + "for the application:" + appId); System.err.println(errorMessage); + System.err.println("Can not get AMContainers logs for " + + "the application:" + appId + " with the appOwner:" + + request.getAppOwner()); return -1; } @@ -563,6 +569,9 @@ private void outputAMContainerLogs(ContainerLogsRequest request, if (nodeId != null && !nodeId.isEmpty()) { printContainerLogsForFinishedApplication(request, logCliHelper); + } else { + printContainerLogsForFinishedApplicationWithoutNodeId( + request, logCliHelper); } } } else { @@ -715,38 +724,8 @@ private int fetchAMContainerLogs(ContainerLogsRequest request, logFiles = Arrays.asList("syslog"); } request.setLogTypes(logFiles); - // If the application is running, we will call the RM WebService - // 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 " - + "-containerId --nodeAddress ' " - + "to get the container logs."); - return -1; - } - } + return printAMContainerLogs(getConf(), request, amContainersList, + logCliHelper); } private int fetchContainerLogs(ContainerLogsRequest request,