hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject hadoop git commit: HDFS-9708. FSNamesystem.initAuditLoggers() doesn't trim classnames (Mingliang Liu via stevel)
Date Mon, 01 Feb 2016 16:02:11 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 8f2622b6a -> af2dccbca


HDFS-9708. FSNamesystem.initAuditLoggers() doesn't trim classnames  (Mingliang Liu via stevel)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/af2dccbc
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/af2dccbc
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/af2dccbc

Branch: refs/heads/trunk
Commit: af2dccbca50b25f84d9d6c88e1a237a42261ce02
Parents: 8f2622b
Author: Steve Loughran <stevel@apache.org>
Authored: Mon Feb 1 16:01:22 2016 +0000
Committer: Steve Loughran <stevel@apache.org>
Committed: Mon Feb 1 16:01:50 2016 +0000

----------------------------------------------------------------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt     |  3 +
 .../hdfs/server/namenode/FSNamesystem.java      |  3 +-
 .../hdfs/server/namenode/TestFSNamesystem.java  | 78 ++++++++++++++++++++
 3 files changed, 83 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/af2dccbc/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index 5a8b525..fdf69d9 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -2661,6 +2661,9 @@ Release 2.8.0 - UNRELEASED
     HDFS-9566. Remove expensive 'BlocksMap#getStorages(Block b, final
     DatanodeStorage.State state)' method (Daryn Sharp via vinayakumarb)
 
+    HDFS-9708. FSNamesystem.initAuditLoggers() doesn't trim classnames
+    (Mingliang Liu via stevel)
+
 Release 2.7.3 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/af2dccbc/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
----------------------------------------------------------------------
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 5e2e975..0387c32 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
@@ -889,7 +889,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
 
   private List<AuditLogger> initAuditLoggers(Configuration conf) {
     // Initialize the custom access loggers if configured.
-    Collection<String> alClasses = conf.getStringCollection(DFS_NAMENODE_AUDIT_LOGGERS_KEY);
+    Collection<String> alClasses =
+        conf.getTrimmedStringCollection(DFS_NAMENODE_AUDIT_LOGGERS_KEY);
     List<AuditLogger> auditLoggers = Lists.newArrayList();
     if (alClasses != null && !alClasses.isEmpty()) {
       for (String className : alClasses) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/af2dccbc/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
----------------------------------------------------------------------
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 6308179..b9a2d15 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
@@ -20,14 +20,18 @@ package org.apache.hadoop.hdfs.server.namenode;
 
 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;
+import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.*;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.URI;
 import java.util.Collection;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.DFSTestUtil;
@@ -38,6 +42,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
 import org.apache.hadoop.hdfs.server.namenode.ha.HAContext;
 import org.apache.hadoop.hdfs.server.namenode.ha.HAState;
 import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
+import org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.test.GenericTestUtils.LogCapturer;
 import org.apache.log4j.Level;
@@ -47,6 +52,7 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.mockito.internal.util.reflection.Whitebox;
 
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -338,4 +344,76 @@ public class TestFSNamesystem {
         "safeReplication");
     assertEquals(2, safeReplication);
   }
+
+  @Test(timeout = 30000)
+  public void testInitAuditLoggers() throws IOException {
+    Configuration conf = new Configuration();
+    FSImage fsImage = Mockito.mock(FSImage.class);
+    FSEditLog fsEditLog = Mockito.mock(FSEditLog.class);
+    Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog);
+    FSNamesystem fsn;
+    List<AuditLogger> auditLoggers;
+
+    // Not to specify any audit loggers in config
+    conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "");
+    // Disable top logger
+    conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false);
+    fsn = new FSNamesystem(conf, fsImage);
+    auditLoggers = fsn.getAuditLoggers();
+    assertTrue(auditLoggers.size() == 1);
+    assertTrue(auditLoggers.get(0) instanceof FSNamesystem.DefaultAuditLogger);
+
+    // Not to specify any audit loggers in config
+    conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "");
+    // Enable top logger
+    conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, true);
+    fsn = new FSNamesystem(conf, fsImage);
+    auditLoggers = fsn.getAuditLoggers();
+    assertTrue(auditLoggers.size() == 2);
+    // the audit loggers order is not defined
+    for (AuditLogger auditLogger : auditLoggers) {
+      assertThat(auditLogger,
+          either(instanceOf(FSNamesystem.DefaultAuditLogger.class))
+              .or(instanceOf(TopAuditLogger.class)));
+    }
+
+    // Configure default audit loggers in config
+    conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY, "default");
+    // Enable top logger
+    conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, true);
+    fsn = new FSNamesystem(conf, fsImage);
+    auditLoggers = fsn.getAuditLoggers();
+    assertTrue(auditLoggers.size() == 2);
+    for (AuditLogger auditLogger : auditLoggers) {
+      assertThat(auditLogger,
+          either(instanceOf(FSNamesystem.DefaultAuditLogger.class))
+              .or(instanceOf(TopAuditLogger.class)));
+    }
+
+    // Configure default and customized audit loggers in config with whitespaces
+    conf.set(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOGGERS_KEY,
+        " default, org.apache.hadoop.hdfs.server.namenode.TestFSNamesystem$DummyAuditLogger
 ");
+    // Enable top logger
+    conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, true);
+    fsn = new FSNamesystem(conf, fsImage);
+    auditLoggers = fsn.getAuditLoggers();
+    assertTrue(auditLoggers.size() == 3);
+    for (AuditLogger auditLogger : auditLoggers) {
+      assertThat(auditLogger,
+          either(instanceOf(FSNamesystem.DefaultAuditLogger.class))
+              .or(instanceOf(TopAuditLogger.class))
+              .or(instanceOf(DummyAuditLogger.class)));
+    }
+  }
+
+  static class DummyAuditLogger implements AuditLogger {
+    @Override
+    public void initialize(Configuration conf) {
+    }
+
+    @Override
+    public void logAuditEvent(boolean succeeded, String userName,
+        InetAddress addr, String cmd, String src, String dst, FileStatus stat) {
+    }
+  }
 }


Mime
View raw message