diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 0dbf915693..b33098ec45 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -40,3 +40,5 @@ Branch-2802 Snapshot (Unreleased) HDFS-4133. Add testcases for testing basic snapshot functionalities. (Jing Zhao via suresh) + + HDFS-4116. Add auditlog for some snapshot operations. (Jing Zhao via suresh) 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 d3c945cc97..cd0921bac1 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 @@ -5519,7 +5519,8 @@ public void allowSnapshot(String path) throws SafeModeException, IOException { try { checkOperation(OperationCategory.WRITE); if (isInSafeMode()) { - throw new SafeModeException("Cannot allow snapshot for " + path, safeMode); + throw new SafeModeException("Cannot allow snapshot for " + path, + safeMode); } checkOwner(path); @@ -5531,7 +5532,10 @@ public void allowSnapshot(String path) throws SafeModeException, IOException { } getEditLog().logSync(); - //TODO: audit log + if (auditLog.isInfoEnabled() && isExternalInvocation()) { + logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(), + "allowSnapshot", path, null, null); + } } // Disallow snapshot on a directory. @@ -5539,6 +5543,11 @@ public void allowSnapshot(String path) throws SafeModeException, IOException { public void disallowSnapshot(String snapshotRoot) throws SafeModeException, IOException { // TODO: implement + + if (auditLog.isInfoEnabled() && isExternalInvocation()) { + logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(), + "disallowSnapshot", snapshotRoot, null, null); + } } /** @@ -5552,7 +5561,8 @@ public void createSnapshot(String snapshotName, String path) try { checkOperation(OperationCategory.WRITE); if (isInSafeMode()) { - throw new SafeModeException("Cannot create snapshot for " + path, safeMode); + throw new SafeModeException("Cannot create snapshot for " + path, + safeMode); } checkOwner(path); @@ -5568,6 +5578,10 @@ public void createSnapshot(String snapshotName, String path) } getEditLog().logSync(); - //TODO: audit log + if (auditLog.isInfoEnabled() && isExternalInvocation()) { + Path snapshotRoot = new Path(path, ".snapshot/" + snapshotName); + logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(), + "createSnapshot", path, snapshotRoot.toString(), null); + } } }