Class LogAggregationFileController
java.lang.Object
org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileController
- Direct Known Subclasses:
LogAggregationIndexedFileController,LogAggregationTFileController
Base class to implement Log Aggregation File Controller.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.hadoop.fs.permission.FsPermissionPermissions for the Application directory.protected static final org.apache.hadoop.fs.permission.FsPermissionUmask for the log file.protected org.apache.hadoop.conf.Configurationprotected Stringprotected booleanprotected org.apache.hadoop.fs.Pathprotected Stringprotected intprotected static final org.apache.hadoop.fs.permission.FsPermissionPermissions for the top level directory under which app directories will be created. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringaggregatedLogSuffix(String fileName) Create the aggregated log suffix.protected booleanbelongsToAppAttempt(org.apache.hadoop.yarn.api.records.ApplicationAttemptId appAttemptId, String containerIdStr) protected booleancheckExists(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, org.apache.hadoop.fs.permission.FsPermission fsPerm) protected voidcleanOldLogs(org.apache.hadoop.fs.Path remoteNodeLogFileForApp, org.apache.hadoop.yarn.api.records.NodeId nodeId, org.apache.hadoop.security.UserGroupInformation userUgi) protected voidabstract voidClose the writer.voidcreateAppDir(String user, org.apache.hadoop.yarn.api.records.ApplicationId appId, org.apache.hadoop.security.UserGroupInformation userUgi) Create remote Application directory for log aggregation.protected voidcreateDir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, org.apache.hadoop.fs.permission.FsPermission fsPerm) getApplicationAcls(org.apache.hadoop.fs.Path aggregatedLogPath, org.apache.hadoop.yarn.api.records.ApplicationId appId) Returns ACLs for the application.org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.FileStatus>Gets all application directories of a user.abstract StringgetApplicationOwner(org.apache.hadoop.fs.Path aggregatedLogPath, org.apache.hadoop.yarn.api.records.ApplicationId appId) Returns the owner of the application.Get the name of the file controller.protected org.apache.hadoop.fs.FileSystemgetFileSystem(org.apache.hadoop.conf.Configuration conf) getLogMetaFilesOfNode(ExtendedLogMetaRequest logRequest, org.apache.hadoop.fs.FileStatus currentNodeFile, org.apache.hadoop.yarn.api.records.ApplicationId appId) Returns log file metadata for a node grouped by containers.org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.FileStatus>getNodeFilesOfApplicationDirectory(org.apache.hadoop.fs.FileStatus appDir) Gets all node files in an application directory.org.apache.hadoop.fs.PathgetOlderRemoteAppLogDir(org.apache.hadoop.yarn.api.records.ApplicationId appId, String appOwner) Get the older remote application directory for log aggregation.org.apache.hadoop.fs.PathgetRemoteAppLogDir(org.apache.hadoop.yarn.api.records.ApplicationId appId, String appOwner) Get the remote application directory for log aggregation.org.apache.hadoop.fs.PathgetRemoteNodeLogFileForApp(org.apache.hadoop.yarn.api.records.ApplicationId appId, String user, org.apache.hadoop.yarn.api.records.NodeId nodeId) Get the remote aggregated log path.org.apache.hadoop.fs.PathGet the remote root log directory.Get the log aggregation directory suffix.voidinitialize(org.apache.hadoop.conf.Configuration conf, String controllerName) Initialize the log file controller.abstract voidInitialize the writer.protected abstract voidinitInternal(org.apache.hadoop.conf.Configuration conf) Derived classes initialize themselves using this method.booleanabstract voidOperations needed after write the log content.abstract booleanreadAggregatedLogs(ContainerLogsRequest logRequest, OutputStream os) Output container log.abstract List<ContainerLogMeta>readAggregatedLogsMeta(ContainerLogsRequest logRequest) Return a list ofContainerLogMetafor an application from Remote FileSystem.abstract voidrenderAggregatedLogsBlock(HtmlBlock.Block html, View.ViewContext context) Render Aggregated Logs block.voidVerify and create the remote log directory.abstract voidwrite(AggregatedLogFormat.LogKey logKey, AggregatedLogFormat.LogValue logValue) Write the log content.
-
Field Details
-
TLDIR_PERMISSIONS
protected static final org.apache.hadoop.fs.permission.FsPermission TLDIR_PERMISSIONSPermissions for the top level directory under which app directories will be created. -
APP_DIR_PERMISSIONS
protected static final org.apache.hadoop.fs.permission.FsPermission APP_DIR_PERMISSIONSPermissions for the Application directory. -
APP_LOG_FILE_UMASK
protected static final org.apache.hadoop.fs.permission.FsPermission APP_LOG_FILE_UMASKUmask for the log file. -
conf
protected org.apache.hadoop.conf.Configuration conf -
remoteRootLogDir
protected org.apache.hadoop.fs.Path remoteRootLogDir -
remoteRootLogDirSuffix
-
retentionSize
protected int retentionSize -
fileControllerName
-
fsSupportsChmod
protected boolean fsSupportsChmod
-
-
Constructor Details
-
LogAggregationFileController
public LogAggregationFileController()
-
-
Method Details
-
initialize
Initialize the log file controller.- Parameters:
conf- the ConfigurationcontrollerName- the log controller class name
-
initInternal
protected abstract void initInternal(org.apache.hadoop.conf.Configuration conf) Derived classes initialize themselves using this method.- Parameters:
conf- the Configuration
-
getRemoteRootLogDir
public org.apache.hadoop.fs.Path getRemoteRootLogDir()Get the remote root log directory.- Returns:
- the remote root log directory path
-
getRemoteRootLogDirSuffix
Get the log aggregation directory suffix.- Returns:
- the log aggregation directory suffix
-
getFileControllerName
Get the name of the file controller.- Returns:
- name of the file controller.
-
initializeWriter
public abstract void initializeWriter(LogAggregationFileControllerContext context) throws IOException Initialize the writer.- Parameters:
context- theLogAggregationFileControllerContext- Throws:
IOException- if fails to initialize the writer
-
closeWriter
Close the writer.- Throws:
LogAggregationDFSException- if the closing of the writer fails (for example due to HDFS quota being exceeded)
-
write
public abstract void write(AggregatedLogFormat.LogKey logKey, AggregatedLogFormat.LogValue logValue) throws IOException Write the log content.- Parameters:
logKey- the log keylogValue- the log content- Throws:
IOException- if fails to write the logs
-
postWrite
Operations needed after write the log content.- Parameters:
record- theLogAggregationFileControllerContext- Throws:
Exception- if anything fails
-
closePrintStream
-
readAggregatedLogs
public abstract boolean readAggregatedLogs(ContainerLogsRequest logRequest, OutputStream os) throws IOException Output container log.- Parameters:
logRequest-ContainerLogsRequestos- the output stream- Returns:
- true if we can read the aggregated logs successfully
- Throws:
IOException- if we can not access the log file.
-
readAggregatedLogsMeta
public abstract List<ContainerLogMeta> readAggregatedLogsMeta(ContainerLogsRequest logRequest) throws IOException Return a list ofContainerLogMetafor an application from Remote FileSystem.- Parameters:
logRequest-ContainerLogsRequest- Returns:
- a list of
ContainerLogMeta - Throws:
IOException- if there is no available log file
-
getLogMetaFilesOfNode
public Map<String,List<ContainerLogFileInfo>> getLogMetaFilesOfNode(ExtendedLogMetaRequest logRequest, org.apache.hadoop.fs.FileStatus currentNodeFile, org.apache.hadoop.yarn.api.records.ApplicationId appId) throws IOException Returns log file metadata for a node grouped by containers.- Parameters:
logRequest- extended query information holdercurrentNodeFile- file status of a node in an application directoryappId- id of the application, which is the same as in node path- Returns:
- log file metadata
- Throws:
IOException- if there is no node file
-
getApplicationDirectoriesOfUser
public org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.FileStatus> getApplicationDirectoriesOfUser(String user) throws IOException Gets all application directories of a user.- Parameters:
user- name of the user- Returns:
- a lazy iterator of directories
- Throws:
IOException- if user directory does not exist
-
getNodeFilesOfApplicationDirectory
public org.apache.hadoop.fs.RemoteIterator<org.apache.hadoop.fs.FileStatus> getNodeFilesOfApplicationDirectory(org.apache.hadoop.fs.FileStatus appDir) throws IOException Gets all node files in an application directory.- Parameters:
appDir- application directory- Returns:
- a lazy iterator of files
- Throws:
IOException- if file context is not reachable
-
renderAggregatedLogsBlock
Render Aggregated Logs block.- Parameters:
html- the htmlcontext- the ViewContext
-
getApplicationOwner
public abstract String getApplicationOwner(org.apache.hadoop.fs.Path aggregatedLogPath, org.apache.hadoop.yarn.api.records.ApplicationId appId) throws IOException Returns the owner of the application.- Parameters:
aggregatedLogPath- the aggregatedLog pathappId- the ApplicationId- Returns:
- the application owner
- Throws:
IOException- if we can not get the application owner
-
getApplicationAcls
public abstract Map<org.apache.hadoop.yarn.api.records.ApplicationAccessType,String> getApplicationAcls(org.apache.hadoop.fs.Path aggregatedLogPath, org.apache.hadoop.yarn.api.records.ApplicationId appId) throws IOException Returns ACLs for the application. An empty map is returned if no ACLs are found.- Parameters:
aggregatedLogPath- the aggregatedLog path.appId- the ApplicationId- Returns:
- a map of the Application ACLs.
- Throws:
IOException- if we can not get the application acls
-
verifyAndCreateRemoteLogDir
public void verifyAndCreateRemoteLogDir()Verify and create the remote log directory. -
createAppDir
public void createAppDir(String user, org.apache.hadoop.yarn.api.records.ApplicationId appId, org.apache.hadoop.security.UserGroupInformation userUgi) Create remote Application directory for log aggregation.- Parameters:
user- the userappId- the application IDuserUgi- the UGI
-
getFileSystem
@VisibleForTesting protected org.apache.hadoop.fs.FileSystem getFileSystem(org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
createDir
protected void createDir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, org.apache.hadoop.fs.permission.FsPermission fsPerm) throws IOException - Throws:
IOException
-
checkExists
protected boolean checkExists(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, org.apache.hadoop.fs.permission.FsPermission fsPerm) throws IOException - Throws:
IOException
-
getRemoteNodeLogFileForApp
public org.apache.hadoop.fs.Path getRemoteNodeLogFileForApp(org.apache.hadoop.yarn.api.records.ApplicationId appId, String user, org.apache.hadoop.yarn.api.records.NodeId nodeId) Get the remote aggregated log path.- Parameters:
appId- the ApplicationIduser- the Application OwnernodeId- the NodeManager Id- Returns:
- the remote aggregated log path
-
getRemoteAppLogDir
public org.apache.hadoop.fs.Path getRemoteAppLogDir(org.apache.hadoop.yarn.api.records.ApplicationId appId, String appOwner) throws IOException Get the remote application directory for log aggregation.- Parameters:
appId- the Application IDappOwner- the Application Owner- Returns:
- the remote application directory
- Throws:
IOException- if can not find the remote application directory
-
getOlderRemoteAppLogDir
public org.apache.hadoop.fs.Path getOlderRemoteAppLogDir(org.apache.hadoop.yarn.api.records.ApplicationId appId, String appOwner) throws IOException Get the older remote application directory for log aggregation.- Parameters:
appId- the Application IDappOwner- the Application Owner- Returns:
- the older remote application directory
- Throws:
IOException- if can not find the remote application directory
-
cleanOldLogs
protected void cleanOldLogs(org.apache.hadoop.fs.Path remoteNodeLogFileForApp, org.apache.hadoop.yarn.api.records.NodeId nodeId, org.apache.hadoop.security.UserGroupInformation userUgi) -
aggregatedLogSuffix
Create the aggregated log suffix. The LogAggregationFileController should call this to get the suffix and append the suffix to the end of each log. This would keep the aggregated log format consistent.- Parameters:
fileName- the File Name- Returns:
- the aggregated log suffix String
-
isFsSupportsChmod
public boolean isFsSupportsChmod() -
belongsToAppAttempt
protected boolean belongsToAppAttempt(org.apache.hadoop.yarn.api.records.ApplicationAttemptId appAttemptId, String containerIdStr)
-