From 68d618acd23e944c5906e650594479618f8ad04a Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Fri, 2 Aug 2019 10:51:04 -0700 Subject: [PATCH] HDFS-14685. DefaultAuditLogger doesn't print CallerContext. Contributed by xuzq. (cherry picked from commit 6757fc1a1d40ffc771bb685886b0d4a16315eca5) (cherry picked from commit e1659fe0090b478d823f1c8f7b0859021496be05) --- .../apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 4 +++- .../hadoop/hdfs/server/namenode/HdfsAuditLogger.java | 7 ++----- .../hadoop/hdfs/server/namenode/TestFSNamesystem.java | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index 3b885a8f707..e2542489a25 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -1065,7 +1065,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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/HdfsAuditLogger.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/HdfsAuditLogger.java index 894c4df1945..0a355d0ec3e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/HdfsAuditLogger.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/HdfsAuditLogger.java @@ -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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java index 6a0dd6fd9db..021421a1558 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java @@ -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, "");