Class LogAggregationFileController
java.lang.Object
org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileController
Base class to implement Log Aggregation File Controller.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final FsPermissionPermissions for the Application directory.protected static final FsPermissionUmask for the log file.protected Configurationprotected Stringprotected booleanprotected Pathprotected Stringprotected intprotected static final 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(ApplicationAttemptId appAttemptId, String containerIdStr) protected booleancheckExists(FileSystem fs, Path path, FsPermission fsPerm) protected voidcleanOldLogs(Path remoteNodeLogFileForApp, NodeId nodeId, UserGroupInformation userUgi) protected voidabstract voidClose the writer.voidcreateAppDir(String user, ApplicationId appId, UserGroupInformation userUgi) Create remote Application directory for log aggregation.protected voidcreateDir(FileSystem fs, Path path, FsPermission fsPerm) abstract Map<ApplicationAccessType,String> getApplicationAcls(Path aggregatedLogPath, ApplicationId appId) Returns ACLs for the application.org.apache.hadoop.fs.RemoteIterator<FileStatus>Gets all application directories of a user.abstract StringgetApplicationOwner(Path aggregatedLogPath, ApplicationId appId) Returns the owner of the application.Get the name of the file controller.protected FileSystemgetFileSystem(Configuration conf) getLogMetaFilesOfNode(org.apache.hadoop.yarn.logaggregation.ExtendedLogMetaRequest logRequest, FileStatus currentNodeFile, ApplicationId appId) Returns log file metadata for a node grouped by containers.org.apache.hadoop.fs.RemoteIterator<FileStatus>Gets all node files in an application directory.getOlderRemoteAppLogDir(ApplicationId appId, String appOwner) Get the older remote application directory for log aggregation.getRemoteAppLogDir(ApplicationId appId, String appOwner) Get the remote application directory for log aggregation.getRemoteNodeLogFileForApp(ApplicationId appId, String user, NodeId nodeId) Get the remote aggregated log path.Get the remote root log directory.Get the log aggregation directory suffix.voidinitialize(Configuration conf, String controllerName) Initialize the log file controller.abstract voidinitializeWriter(org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerContext context) Initialize the writer.protected abstract voidinitInternal(Configuration conf) Derived classes initialize themselves using this method.booleanabstract voidpostWrite(org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerContext record) Operations needed after write the log content.abstract booleanreadAggregatedLogs(org.apache.hadoop.yarn.logaggregation.ContainerLogsRequest logRequest, OutputStream os) Output container log.abstract List<org.apache.hadoop.yarn.logaggregation.ContainerLogMeta>readAggregatedLogsMeta(org.apache.hadoop.yarn.logaggregation.ContainerLogsRequest logRequest) Return a list ofContainerLogMetafor an application from Remote FileSystem.abstract voidrenderAggregatedLogsBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock.Block html, org.apache.hadoop.yarn.webapp.View.ViewContext context) Render Aggregated Logs block.voidVerify and create the remote log directory.abstract voidwrite(AggregatedLogFormat.LogKey logKey, org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogValue logValue) Write the log content.
-
Field Details
-
TLDIR_PERMISSIONS
Permissions for the top level directory under which app directories will be created. -
APP_DIR_PERMISSIONS
Permissions for the Application directory. -
APP_LOG_FILE_UMASK
Umask for the log file. -
conf
-
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
Derived classes initialize themselves using this method.- Parameters:
conf- the Configuration
-
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(org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerContext context) throws IOException Initialize the writer.- Parameters:
context- theLogAggregationFileControllerContext- Throws:
IOException- if fails to initialize the writer
-
closeWriter
public abstract void closeWriter() throws org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationDFSExceptionClose the writer.- Throws:
org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationDFSException- if the closing of the writer fails (for example due to HDFS quota being exceeded)
-
write
public abstract void write(AggregatedLogFormat.LogKey logKey, org.apache.hadoop.yarn.logaggregation.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
public abstract void postWrite(org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerContext record) throws Exception Operations needed after write the log content.- Parameters:
record- theLogAggregationFileControllerContext- Throws:
Exception- if anything fails
-
closePrintStream
-
readAggregatedLogs
public abstract boolean readAggregatedLogs(org.apache.hadoop.yarn.logaggregation.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<org.apache.hadoop.yarn.logaggregation.ContainerLogMeta> readAggregatedLogsMeta(org.apache.hadoop.yarn.logaggregation.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<org.apache.hadoop.yarn.logaggregation.ContainerLogFileInfo>> getLogMetaFilesOfNode(org.apache.hadoop.yarn.logaggregation.ExtendedLogMetaRequest logRequest, FileStatus currentNodeFile, 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<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<FileStatus> getNodeFilesOfApplicationDirectory(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
public abstract void renderAggregatedLogsBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock.Block html, org.apache.hadoop.yarn.webapp.View.ViewContext context) Render Aggregated Logs block.- Parameters:
html- the htmlcontext- the ViewContext
-
getApplicationOwner
public abstract String getApplicationOwner(Path aggregatedLogPath, 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<ApplicationAccessType,String> getApplicationAcls(Path aggregatedLogPath, 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
Create remote Application directory for log aggregation.- Parameters:
user- the userappId- the application IDuserUgi- the UGI
-
getFileSystem
- Throws:
IOException
-
createDir
- Throws:
IOException
-
checkExists
- Throws:
IOException
-
getRemoteNodeLogFileForApp
Get the remote aggregated log path.- Parameters:
appId- the ApplicationIduser- the Application OwnernodeId- the NodeManager Id- Returns:
- the remote aggregated log path
-
getRemoteAppLogDir
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
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(Path remoteNodeLogFileForApp, NodeId nodeId, 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
-