Author: cdouglas
Date: Mon Jul 14 12:45:05 2008
New Revision: 676704
URL: http://svn.apache.org/viewvc?rev=676704&view=rev
Log:
HADOOP-3752. Fix audit logging to record rename events.
Modified:
hadoop/core/branches/branch-0.18/CHANGES.txt
hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java
Modified: hadoop/core/branches/branch-0.18/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/CHANGES.txt?rev=676704&r1=676703&r2=676704&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.18/CHANGES.txt Mon Jul 14 12:45:05 2008
@@ -750,6 +750,8 @@
HADOOP-3716. Prevent listStatus in KosmosFileSystem from returning
null for valid, empty directories. (Sriram Rao via cdouglas)
+ HADOOP-3752. Fix audit logging to record rename events. (cdouglas)
+
Release 0.17.2 - Unreleased
BUG FIXES
Modified:
hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java
URL:
http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java?rev=676704&r1=676703&r2=676704&view=diff
==============================================================================
---
hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java
(original)
+++
hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java
Mon Jul 14 12:45:05 2008
@@ -46,6 +46,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.DataOutputStream;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.Map.Entry;
@@ -74,9 +75,31 @@
"ugi=%s\t" + // ugi
"ip=%s\t" + // remote IP
"cmd=%s\t" + // command
- "path=%s\t" + // path
+ "src=%s\t" + // src path
+ "dst=%s\t" + // dst path (optional)
"perm=%s"; // permissions (optional)
+ private static final ThreadLocal<Formatter> auditFormatter =
+ new ThreadLocal<Formatter>() {
+ protected Formatter initialValue() {
+ return new Formatter(new StringBuilder(AUDIT_FORMAT.length() * 4));
+ }
+ };
+
+ private static final void logAuditEvent(UserGroupInformation ugi,
+ InetAddress addr, String cmd, String src, String dst,
+ FileStatus stat) {
+ final Formatter fmt = auditFormatter.get();
+ ((StringBuilder)fmt.out()).setLength(0);
+ auditLog.info(fmt.format(AUDIT_FORMAT, ugi, addr, cmd, src, dst,
+ (stat == null)
+ ? null
+ : stat.getOwner() + ':' + stat.getGroup() + ':' +
+ stat.getPermission()
+ ).toString());
+
+ }
+
public static final Log auditLog = LogFactory.getLog(
"org.apache.hadoop.fs.FSNamesystem.audit");
@@ -635,11 +658,9 @@
getEditLog().logSync();
if (auditLog.isInfoEnabled()) {
final FileStatus stat = dir.getFileInfo(src);
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "setPermission", src, stat.getOwner() + ':' +
- stat.getGroup() + ':' + stat.getPermission()));
+ "setPermission", src, null, stat);
}
}
@@ -663,11 +684,9 @@
getEditLog().logSync();
if (auditLog.isInfoEnabled()) {
final FileStatus stat = dir.getFileInfo(src);
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "setOwner", src, stat.getOwner() + ':' +
- stat.getGroup() + ':' + stat.getPermission()));
+ "setOwner", src, null, stat);
}
}
@@ -709,10 +728,9 @@
final LocatedBlocks ret = getBlockLocationsInternal(dir.getFileINode(src),
offset, length, Integer.MAX_VALUE);
if (auditLog.isInfoEnabled()) {
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "open", src, null));
+ "open", src, null, null);
}
return ret;
}
@@ -800,11 +818,10 @@
throws IOException {
boolean status = setReplicationInternal(src, replication);
getEditLog().logSync();
- if (auditLog.isInfoEnabled()) {
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ if (status && auditLog.isInfoEnabled()) {
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "setReplication", src, null));
+ "setReplication", src, null, null);
}
return status;
}
@@ -889,11 +906,9 @@
getEditLog().logSync();
if (auditLog.isInfoEnabled()) {
final FileStatus stat = dir.getFileInfo(src);
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "create", src, stat.getOwner() + ':' +
- stat.getGroup() + ':' + stat.getPermission()));
+ "create", src, null, stat);
}
}
@@ -1402,6 +1417,12 @@
public boolean renameTo(String src, String dst) throws IOException {
boolean status = renameToInternal(src, dst);
getEditLog().logSync();
+ if (status && auditLog.isInfoEnabled()) {
+ final FileStatus stat = dir.getFileInfo(dst);
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
+ Server.getRemoteIp(),
+ "rename", src, dst, stat);
+ }
return status;
}
@@ -1440,11 +1461,10 @@
}
boolean status = deleteInternal(src, true, true);
getEditLog().logSync();
- if (auditLog.isInfoEnabled()) {
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ if (status && auditLog.isInfoEnabled()) {
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "delete", src, null));
+ "delete", src, null, null);
}
return status;
}
@@ -1528,13 +1548,11 @@
) throws IOException {
boolean status = mkdirsInternal(src, permissions);
getEditLog().logSync();
- if (auditLog.isInfoEnabled()) {
+ if (status && auditLog.isInfoEnabled()) {
final FileStatus stat = dir.getFileInfo(src);
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "mkdirs", src, stat.getOwner() + ':' +
- stat.getGroup() + ':' + stat.getPermission()));
+ "mkdirs", src, null, stat);
}
return status;
}
@@ -1790,10 +1808,9 @@
}
}
if (auditLog.isInfoEnabled()) {
- auditLog.info(String.format(AUDIT_FORMAT,
- UserGroupInformation.getCurrentUGI(),
+ logAuditEvent(UserGroupInformation.getCurrentUGI(),
Server.getRemoteIp(),
- "listStatus", src, null));
+ "listStatus", src, null, null);
}
return dir.getListing(src);
}