HDFS-14685. DefaultAuditLogger doesn't print CallerContext. Contributed by xuzq.

(cherry picked from commit 6757fc1a1d40ffc771bb685886b0d4a16315eca5)
This commit is contained in:
Wei-Chiu Chuang 2019-08-02 10:51:04 -07:00
parent 490b18fd4f
commit e1659fe009
3 changed files with 10 additions and 6 deletions

View File

@ -1067,7 +1067,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
// Make sure there is at least one logger installed.
if (auditLoggers.isEmpty()) {
auditLoggers.add(new DefaultAuditLogger());
DefaultAuditLogger defaultAuditLogger = new DefaultAuditLogger();
defaultAuditLogger.initialize(conf);
auditLoggers.add(defaultAuditLogger);
}
// Add audit logger to calculate top users

View File

@ -61,13 +61,10 @@ public abstract class HdfsAuditLogger implements AuditLogger {
* @param dtSecretManager The token secret manager, or null if not logging
* token tracking information
*/
public void logAuditEvent(boolean succeeded, String userName,
public abstract void logAuditEvent(boolean succeeded, String userName,
InetAddress addr, String cmd, String src, String dst,
FileStatus stat, CallerContext callerContext, UserGroupInformation ugi,
DelegationTokenSecretManager dtSecretManager) {
logAuditEvent(succeeded, userName, addr, cmd, src, dst, stat,
ugi, dtSecretManager);
}
DelegationTokenSecretManager dtSecretManager);
/**
* Same as

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_CALLER_CONTEXT_ENABLED_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY;
import static org.hamcrest.CoreMatchers.either;
@ -242,10 +243,14 @@ public class TestFSNamesystem {
conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "");
// Disable top logger
conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false);
conf.setBoolean(HADOOP_CALLER_CONTEXT_ENABLED_KEY, true);
fsn = new FSNamesystem(conf, fsImage);
auditLoggers = fsn.getAuditLoggers();
assertTrue(auditLoggers.size() == 1);
assertTrue(auditLoggers.get(0) instanceof FSNamesystem.DefaultAuditLogger);
FSNamesystem.DefaultAuditLogger defaultAuditLogger =
(FSNamesystem.DefaultAuditLogger) auditLoggers.get(0);
assertTrue(defaultAuditLogger.getCallerContextEnabled());
// Not to specify any audit loggers in config
conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "");