|
@@ -18,8 +18,6 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.logaggregation;
|
|
package org.apache.hadoop.yarn.logaggregation;
|
|
|
|
|
|
-import java.io.DataInputStream;
|
|
|
|
-import java.io.EOFException;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.PrintStream;
|
|
import java.io.PrintStream;
|
|
@@ -37,15 +35,14 @@ import org.apache.hadoop.conf.Configurable;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.FileContext;
|
|
import org.apache.hadoop.fs.FileContext;
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
-import org.apache.hadoop.fs.HarFs;
|
|
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.RemoteIterator;
|
|
import org.apache.hadoop.fs.RemoteIterator;
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
-import org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogKey;
|
|
|
|
-import org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogReader;
|
|
|
|
|
|
+import org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileController;
|
|
|
|
+import org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerFactory;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
|
|
|
public class LogCLIHelpers implements Configurable {
|
|
public class LogCLIHelpers implements Configurable {
|
|
@@ -56,6 +53,7 @@ public class LogCLIHelpers implements Configurable {
|
|
"Container: %s on %s";
|
|
"Container: %s on %s";
|
|
|
|
|
|
private Configuration conf;
|
|
private Configuration conf;
|
|
|
|
+ private LogAggregationFileControllerFactory factory;
|
|
|
|
|
|
@Private
|
|
@Private
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
@@ -130,71 +128,11 @@ public class LogCLIHelpers implements Configurable {
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
public int dumpAContainerLogsForLogType(ContainerLogsRequest options,
|
|
public int dumpAContainerLogsForLogType(ContainerLogsRequest options,
|
|
boolean outputFailure) throws IOException {
|
|
boolean outputFailure) throws IOException {
|
|
- ApplicationId applicationId = options.getAppId();
|
|
|
|
- String jobOwner = options.getAppOwner();
|
|
|
|
- String nodeId = options.getNodeId();
|
|
|
|
- String containerId = options.getContainerId();
|
|
|
|
- String localDir = options.getOutputLocalDir();
|
|
|
|
- List<String> logType = new ArrayList<String>(options.getLogTypes());
|
|
|
|
- RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
|
|
|
- applicationId, jobOwner);
|
|
|
|
- if (nodeFiles == null) {
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- boolean foundContainerLogs = false;
|
|
|
|
- while (nodeFiles.hasNext()) {
|
|
|
|
- FileStatus thisNodeFile = nodeFiles.next();
|
|
|
|
- String fileName = thisNodeFile.getPath().getName();
|
|
|
|
- if (fileName.equals(applicationId + ".har")) {
|
|
|
|
- Path p = new Path("har:///"
|
|
|
|
- + thisNodeFile.getPath().toUri().getRawPath());
|
|
|
|
- nodeFiles = HarFs.get(p.toUri(), conf).listStatusIterator(p);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (fileName.contains(LogAggregationUtils.getNodeString(nodeId))
|
|
|
|
- && !fileName.endsWith(LogAggregationUtils.TMP_FILE_SUFFIX)) {
|
|
|
|
- AggregatedLogFormat.LogReader reader = null;
|
|
|
|
- PrintStream out = createPrintStream(localDir, fileName, containerId);
|
|
|
|
- try {
|
|
|
|
- reader = new AggregatedLogFormat.LogReader(getConf(),
|
|
|
|
- thisNodeFile.getPath());
|
|
|
|
- if (getContainerLogsStream(containerId, reader) == null) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- String containerString = String.format(CONTAINER_ON_NODE_PATTERN,
|
|
|
|
- containerId, thisNodeFile.getPath().getName());
|
|
|
|
- out.println(containerString);
|
|
|
|
- out.println("LogAggregationType: AGGREGATED");
|
|
|
|
- out.println(StringUtils.repeat("=", containerString.length()));
|
|
|
|
- // We have to re-create reader object to reset the stream index
|
|
|
|
- // after calling getContainerLogsStream which would move the stream
|
|
|
|
- // index to the end of the log file.
|
|
|
|
- reader =
|
|
|
|
- new AggregatedLogFormat.LogReader(getConf(),
|
|
|
|
- thisNodeFile.getPath());
|
|
|
|
- if (logType == null || logType.isEmpty()) {
|
|
|
|
- if (dumpAContainerLogs(containerId, reader, out,
|
|
|
|
- thisNodeFile.getModificationTime(), options.getBytes()) > -1) {
|
|
|
|
- foundContainerLogs = true;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (dumpAContainerLogsForALogType(containerId, reader, out,
|
|
|
|
- thisNodeFile.getModificationTime(), logType,
|
|
|
|
- options.getBytes()) > -1) {
|
|
|
|
- foundContainerLogs = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- if (reader != null) {
|
|
|
|
- reader.close();
|
|
|
|
- }
|
|
|
|
- closePrintStream(out);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!foundContainerLogs) {
|
|
|
|
|
|
+ boolean foundAnyLogs = this.getFileController(options.getAppId(),
|
|
|
|
+ options.getAppOwner()).readAggregatedLogs(options, null);
|
|
|
|
+ if (!foundAnyLogs) {
|
|
if (outputFailure) {
|
|
if (outputFailure) {
|
|
- containerLogNotFound(containerId);
|
|
|
|
|
|
+ containerLogNotFound(options.getContainerId());
|
|
}
|
|
}
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
@@ -204,217 +142,25 @@ public class LogCLIHelpers implements Configurable {
|
|
@Private
|
|
@Private
|
|
public int dumpAContainerLogsForLogTypeWithoutNodeId(
|
|
public int dumpAContainerLogsForLogTypeWithoutNodeId(
|
|
ContainerLogsRequest options) throws IOException {
|
|
ContainerLogsRequest options) throws IOException {
|
|
- ApplicationId applicationId = options.getAppId();
|
|
|
|
- String jobOwner = options.getAppOwner();
|
|
|
|
- String containerId = options.getContainerId();
|
|
|
|
- String localDir = options.getOutputLocalDir();
|
|
|
|
- List<String> logType = new ArrayList<String>(options.getLogTypes());
|
|
|
|
- RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
|
|
|
- applicationId, jobOwner);
|
|
|
|
- if (nodeFiles == null) {
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- boolean foundContainerLogs = false;
|
|
|
|
- while(nodeFiles.hasNext()) {
|
|
|
|
- FileStatus thisNodeFile = nodeFiles.next();
|
|
|
|
- if (!thisNodeFile.getPath().getName().endsWith(
|
|
|
|
- LogAggregationUtils.TMP_FILE_SUFFIX)) {
|
|
|
|
- AggregatedLogFormat.LogReader reader = null;
|
|
|
|
- PrintStream out = System.out;
|
|
|
|
- try {
|
|
|
|
- reader =
|
|
|
|
- new AggregatedLogFormat.LogReader(getConf(),
|
|
|
|
- thisNodeFile.getPath());
|
|
|
|
- if (getContainerLogsStream(containerId, reader) == null) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- // We have to re-create reader object to reset the stream index
|
|
|
|
- // after calling getContainerLogsStream which would move the stream
|
|
|
|
- // index to the end of the log file.
|
|
|
|
- reader =
|
|
|
|
- new AggregatedLogFormat.LogReader(getConf(),
|
|
|
|
- thisNodeFile.getPath());
|
|
|
|
- out = createPrintStream(localDir, thisNodeFile.getPath().getName(),
|
|
|
|
- containerId);
|
|
|
|
- String containerString = String.format(CONTAINER_ON_NODE_PATTERN,
|
|
|
|
- containerId, thisNodeFile.getPath().getName());
|
|
|
|
- out.println(containerString);
|
|
|
|
- out.println("LogAggregationType: AGGREGATED");
|
|
|
|
- out.println(StringUtils.repeat("=", containerString.length()));
|
|
|
|
- if (logType == null || logType.isEmpty()) {
|
|
|
|
- if (dumpAContainerLogs(containerId, reader, out,
|
|
|
|
- thisNodeFile.getModificationTime(), options.getBytes()) > -1) {
|
|
|
|
- foundContainerLogs = true;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (dumpAContainerLogsForALogType(containerId, reader, out,
|
|
|
|
- thisNodeFile.getModificationTime(), logType,
|
|
|
|
- options.getBytes()) > -1) {
|
|
|
|
- foundContainerLogs = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- if (reader != null) {
|
|
|
|
- reader.close();
|
|
|
|
- }
|
|
|
|
- closePrintStream(out);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!foundContainerLogs) {
|
|
|
|
- containerLogNotFound(containerId);
|
|
|
|
|
|
+ boolean foundAnyLogs = getFileController(options.getAppId(),
|
|
|
|
+ options.getAppOwner()).readAggregatedLogs(
|
|
|
|
+ options, null);
|
|
|
|
+ if (!foundAnyLogs) {
|
|
|
|
+ containerLogNotFound(options.getContainerId());
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- @Private
|
|
|
|
- public int dumpAContainerLogs(String containerIdStr,
|
|
|
|
- AggregatedLogFormat.LogReader reader, PrintStream out,
|
|
|
|
- long logUploadedTime, long bytes) throws IOException {
|
|
|
|
- DataInputStream valueStream = getContainerLogsStream(
|
|
|
|
- containerIdStr, reader);
|
|
|
|
-
|
|
|
|
- if (valueStream == null) {
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- boolean foundContainerLogs = false;
|
|
|
|
- while (true) {
|
|
|
|
- try {
|
|
|
|
- LogReader.readAContainerLogsForALogType(valueStream, out,
|
|
|
|
- logUploadedTime, bytes);
|
|
|
|
- foundContainerLogs = true;
|
|
|
|
- } catch (EOFException eof) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (foundContainerLogs) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private DataInputStream getContainerLogsStream(String containerIdStr,
|
|
|
|
- AggregatedLogFormat.LogReader reader) throws IOException {
|
|
|
|
- DataInputStream valueStream;
|
|
|
|
- LogKey key = new LogKey();
|
|
|
|
- valueStream = reader.next(key);
|
|
|
|
-
|
|
|
|
- while (valueStream != null && !key.toString().equals(containerIdStr)) {
|
|
|
|
- // Next container
|
|
|
|
- key = new LogKey();
|
|
|
|
- valueStream = reader.next(key);
|
|
|
|
- }
|
|
|
|
- return valueStream;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Private
|
|
|
|
- public int dumpAContainerLogsForALogType(String containerIdStr,
|
|
|
|
- AggregatedLogFormat.LogReader reader, PrintStream out,
|
|
|
|
- long logUploadedTime, List<String> logType, long bytes)
|
|
|
|
- throws IOException {
|
|
|
|
- DataInputStream valueStream = getContainerLogsStream(
|
|
|
|
- containerIdStr, reader);
|
|
|
|
- if (valueStream == null) {
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- boolean foundContainerLogs = false;
|
|
|
|
- while (true) {
|
|
|
|
- try {
|
|
|
|
- int result = LogReader.readContainerLogsForALogType(
|
|
|
|
- valueStream, out, logUploadedTime, logType, bytes);
|
|
|
|
- if (result == 0) {
|
|
|
|
- foundContainerLogs = true;
|
|
|
|
- }
|
|
|
|
- } catch (EOFException eof) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (foundContainerLogs) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Private
|
|
@Private
|
|
public int dumpAllContainersLogs(ContainerLogsRequest options)
|
|
public int dumpAllContainersLogs(ContainerLogsRequest options)
|
|
throws IOException {
|
|
throws IOException {
|
|
- ApplicationId appId = options.getAppId();
|
|
|
|
- String appOwner = options.getAppOwner();
|
|
|
|
- String localDir = options.getOutputLocalDir();
|
|
|
|
- List<String> logTypes = new ArrayList<String>(options.getLogTypes());
|
|
|
|
- RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
|
|
|
- appId, appOwner);
|
|
|
|
- if (nodeFiles == null) {
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- boolean foundAnyLogs = false;
|
|
|
|
- while (nodeFiles.hasNext()) {
|
|
|
|
- FileStatus thisNodeFile = nodeFiles.next();
|
|
|
|
- if (thisNodeFile.getPath().getName().equals(appId + ".har")) {
|
|
|
|
- Path p = new Path("har:///"
|
|
|
|
- + thisNodeFile.getPath().toUri().getRawPath());
|
|
|
|
- nodeFiles = HarFs.get(p.toUri(), conf).listStatusIterator(p);
|
|
|
|
- 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) {
|
|
|
|
- PrintStream out = createPrintStream(localDir,
|
|
|
|
- thisNodeFile.getPath().getName(), key.toString());
|
|
|
|
- try {
|
|
|
|
- String containerString = String.format(
|
|
|
|
- CONTAINER_ON_NODE_PATTERN, key,
|
|
|
|
- thisNodeFile.getPath().getName());
|
|
|
|
- out.println(containerString);
|
|
|
|
- out.println("LogAggregationType: AGGREGATED");
|
|
|
|
- out.println(StringUtils.repeat("=", containerString.length()));
|
|
|
|
- while (true) {
|
|
|
|
- try {
|
|
|
|
- if (logTypes == null || logTypes.isEmpty()) {
|
|
|
|
- LogReader.readAContainerLogsForALogType(valueStream, out,
|
|
|
|
- thisNodeFile.getModificationTime(),
|
|
|
|
- options.getBytes());
|
|
|
|
- foundAnyLogs = true;
|
|
|
|
- } else {
|
|
|
|
- int result = LogReader.readContainerLogsForALogType(
|
|
|
|
- valueStream, out, thisNodeFile.getModificationTime(),
|
|
|
|
- logTypes, options.getBytes());
|
|
|
|
- if (result == 0) {
|
|
|
|
- foundAnyLogs = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } catch (EOFException eof) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- closePrintStream(out);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Next container
|
|
|
|
- key = new LogKey();
|
|
|
|
- valueStream = reader.next(key);
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- reader.close();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ boolean foundAnyLogs = getFileController(options.getAppId(),
|
|
|
|
+ options.getAppOwner()).readAggregatedLogs(
|
|
|
|
+ options, null);
|
|
if (!foundAnyLogs) {
|
|
if (!foundAnyLogs) {
|
|
- emptyLogDir(LogAggregationUtils.getRemoteAppLogDir(conf, appId, appOwner)
|
|
|
|
|
|
+ emptyLogDir(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
+ conf, options.getAppId(), options.getAppOwner())
|
|
.toString());
|
|
.toString());
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
@@ -425,14 +171,13 @@ public class LogCLIHelpers implements Configurable {
|
|
public int printAContainerLogMetadata(ContainerLogsRequest options,
|
|
public int printAContainerLogMetadata(ContainerLogsRequest options,
|
|
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 nodeId = options.getNodeId();
|
|
String containerIdStr = options.getContainerId();
|
|
String containerIdStr = options.getContainerId();
|
|
List<ContainerLogMeta> containersLogMeta;
|
|
List<ContainerLogMeta> containersLogMeta;
|
|
try {
|
|
try {
|
|
- containersLogMeta = LogToolUtils.getContainerLogMetaFromRemoteFS(
|
|
|
|
- conf, appId, containerIdStr, nodeId, appOwner);
|
|
|
|
|
|
+ containersLogMeta = getFileController(options.getAppId(),
|
|
|
|
+ options.getAppOwner()).readAggregatedLogsMeta(
|
|
|
|
+ options);
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
err.println(ex.getMessage());
|
|
err.println(ex.getMessage());
|
|
return -1;
|
|
return -1;
|
|
@@ -473,8 +218,26 @@ public class LogCLIHelpers implements Configurable {
|
|
PrintStream out, PrintStream err) throws IOException {
|
|
PrintStream out, PrintStream err) throws IOException {
|
|
ApplicationId appId = options.getAppId();
|
|
ApplicationId appId = options.getAppId();
|
|
String appOwner = options.getAppOwner();
|
|
String appOwner = options.getAppOwner();
|
|
- RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
|
|
|
- appId, appOwner);
|
|
|
|
|
|
+ LogAggregationFileController fileFormat = null;
|
|
|
|
+ try {
|
|
|
|
+ fileFormat = getFileController(appId, appOwner);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ err.println(ex.getMessage());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ RemoteIterator<FileStatus> nodeFiles = null;
|
|
|
|
+ try {
|
|
|
|
+ nodeFiles = LogAggregationUtils.getRemoteNodeFileDir(conf, appId,
|
|
|
|
+ appOwner, fileFormat.getRemoteRootLogDir(),
|
|
|
|
+ fileFormat.getRemoteRootLogDirSuffix());
|
|
|
|
+ } catch (FileNotFoundException fnf) {
|
|
|
|
+ logDirNotExist(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
+ conf, appId, appOwner).toString());
|
|
|
|
+ } catch (AccessControlException | AccessDeniedException ace) {
|
|
|
|
+ logDirNoAccessPermission(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
+ conf, appId, appOwner).toString(), appOwner,
|
|
|
|
+ ace.getMessage());
|
|
|
|
+ }
|
|
if (nodeFiles == null) {
|
|
if (nodeFiles == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -497,44 +260,21 @@ public class LogCLIHelpers implements Configurable {
|
|
public void printContainersList(ContainerLogsRequest options,
|
|
public void printContainersList(ContainerLogsRequest options,
|
|
PrintStream out, PrintStream err) throws IOException {
|
|
PrintStream out, PrintStream err) throws IOException {
|
|
ApplicationId appId = options.getAppId();
|
|
ApplicationId appId = options.getAppId();
|
|
- String appOwner = options.getAppOwner();
|
|
|
|
String nodeId = options.getNodeId();
|
|
String nodeId = options.getNodeId();
|
|
- String nodeIdStr = (nodeId == null) ? null
|
|
|
|
- : LogAggregationUtils.getNodeString(nodeId);
|
|
|
|
- RemoteIterator<FileStatus> nodeFiles = getRemoteNodeFileDir(
|
|
|
|
- appId, appOwner);
|
|
|
|
- if (nodeFiles == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
boolean foundAnyLogs = false;
|
|
boolean foundAnyLogs = false;
|
|
- 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) {
|
|
|
|
- out.println(String.format(CONTAINER_ON_NODE_PATTERN, key,
|
|
|
|
- thisNodeFile.getPath().getName()));
|
|
|
|
- foundAnyLogs = true;
|
|
|
|
- // Next container
|
|
|
|
- key = new LogKey();
|
|
|
|
- valueStream = reader.next(key);
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- reader.close();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<ContainerLogMeta> containersLogMeta = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ containersLogMeta = getFileController(options.getAppId(),
|
|
|
|
+ options.getAppOwner()).readAggregatedLogsMeta(
|
|
|
|
+ options);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ err.println(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+ for(ContainerLogMeta logMeta : containersLogMeta) {
|
|
|
|
+ out.println(String.format(CONTAINER_ON_NODE_PATTERN,
|
|
|
|
+ logMeta.getContainerId(),
|
|
|
|
+ logMeta.getNodeId()));
|
|
|
|
+ foundAnyLogs = true;
|
|
}
|
|
}
|
|
if (!foundAnyLogs) {
|
|
if (!foundAnyLogs) {
|
|
if (nodeId != null) {
|
|
if (nodeId != null) {
|
|
@@ -547,26 +287,6 @@ public class LogCLIHelpers implements Configurable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private RemoteIterator<FileStatus> getRemoteNodeFileDir(ApplicationId appId,
|
|
|
|
- String appOwner) throws IOException {
|
|
|
|
- RemoteIterator<FileStatus> nodeFiles = null;
|
|
|
|
- try {
|
|
|
|
- nodeFiles = LogAggregationUtils.getRemoteNodeFileDir(
|
|
|
|
- conf, appId, appOwner);
|
|
|
|
- } catch (FileNotFoundException fnf) {
|
|
|
|
- logDirNotExist(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
- conf, appId, appOwner).toString());
|
|
|
|
- } catch (AccessControlException | AccessDeniedException ace) {
|
|
|
|
- logDirNoAccessPermission(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
- conf, appId, appOwner).toString(), appOwner,
|
|
|
|
- ace.getMessage());
|
|
|
|
- } catch (IOException ioe) {
|
|
|
|
- logDirIOError(LogAggregationUtils.getRemoteAppLogDir(
|
|
|
|
- conf, appId, appOwner).toString(), ioe.getMessage());
|
|
|
|
- }
|
|
|
|
- return nodeFiles;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void setConf(Configuration conf) {
|
|
public void setConf(Configuration conf) {
|
|
this.conf = conf;
|
|
this.conf = conf;
|
|
@@ -600,11 +320,6 @@ public class LogCLIHelpers implements Configurable {
|
|
+ ". Error message found: " + errorMessage);
|
|
+ ". Error message found: " + errorMessage);
|
|
}
|
|
}
|
|
|
|
|
|
- private static void logDirIOError(String remoteAppLogDir, String errMsg) {
|
|
|
|
- System.err.println("Cannot access to " + remoteAppLogDir +
|
|
|
|
- ". Error message found: " + errMsg);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Private
|
|
@Private
|
|
public PrintStream createPrintStream(String localDir, String nodeId,
|
|
public PrintStream createPrintStream(String localDir, String nodeId,
|
|
String containerId) throws IOException {
|
|
String containerId) throws IOException {
|
|
@@ -628,59 +343,29 @@ public class LogCLIHelpers implements Configurable {
|
|
@Private
|
|
@Private
|
|
public Set<String> listContainerLogs(ContainerLogsRequest options)
|
|
public Set<String> listContainerLogs(ContainerLogsRequest options)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ List<ContainerLogMeta> containersLogMeta;
|
|
Set<String> logTypes = new HashSet<String>();
|
|
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) {
|
|
|
|
|
|
+ try {
|
|
|
|
+ containersLogMeta = getFileController(options.getAppId(),
|
|
|
|
+ options.getAppOwner()).readAggregatedLogsMeta(
|
|
|
|
+ options);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ System.err.println(ex.getMessage());
|
|
return logTypes;
|
|
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).getFirst();
|
|
|
|
- logTypes.add(logFile);
|
|
|
|
- } catch (EOFException eof) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!getAllContainers) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // Next container
|
|
|
|
- key = new LogKey();
|
|
|
|
- valueStream = reader.next(key);
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- reader.close();
|
|
|
|
- }
|
|
|
|
|
|
+ for (ContainerLogMeta logMeta: containersLogMeta) {
|
|
|
|
+ for (PerContainerLogFileInfo fileInfo : logMeta.getContainerLogMeta()) {
|
|
|
|
+ logTypes.add(fileInfo.getFileName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return logTypes;
|
|
return logTypes;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private LogAggregationFileController getFileController(ApplicationId appId,
|
|
|
|
+ String appOwner) throws IOException {
|
|
|
|
+ if (factory == null) {
|
|
|
|
+ factory = new LogAggregationFileControllerFactory(conf);
|
|
|
|
+ }
|
|
|
|
+ return factory.getFileControllerForRead(appId, appOwner);
|
|
|
|
+ }
|
|
}
|
|
}
|