From ba34d19ae2c2d4ddabc412d8613407c178f50a86 Mon Sep 17 00:00:00 2001 From: littlezhou Date: Tue, 21 Nov 2017 14:29:12 +0800 Subject: [PATCH] Fix #858, File Access Event should set user info --- .../java/org/smartdata/hdfs/client/SmartDFSClient.java | 9 ++++++++- .../main/java/org/smartdata/metrics/FileAccessEvent.java | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/smart-hadoop-support/smart-hadoop-client/src/main/java/org/smartdata/hdfs/client/SmartDFSClient.java b/smart-hadoop-support/smart-hadoop-client/src/main/java/org/smartdata/hdfs/client/SmartDFSClient.java index cb9ef4066d0..6797bf278b6 100644 --- a/smart-hadoop-support/smart-hadoop-client/src/main/java/org/smartdata/hdfs/client/SmartDFSClient.java +++ b/smart-hadoop-support/smart-hadoop-client/src/main/java/org/smartdata/hdfs/client/SmartDFSClient.java @@ -22,6 +22,7 @@ import org.apache.hadoop.fs.UnresolvedLinkException; import org.apache.hadoop.hdfs.DFSClient; import org.apache.hadoop.hdfs.DFSInputStream; +import org.apache.hadoop.security.UserGroupInformation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.smartdata.SmartConstants; @@ -141,7 +142,13 @@ private void reportFileAccessEvent(String src) { if (!healthy) { return; } - smartClient.reportFileAccessEvent(new FileAccessEvent(src)); + String userName; + try { + userName = UserGroupInformation.getCurrentUser().getUserName(); + } catch (IOException e) { + userName = "Unknown"; + } + smartClient.reportFileAccessEvent(new FileAccessEvent(src, userName)); } catch (IOException e) { // Here just ignores that failed to report LOG.error("Cannot report file access event to SmartServer: " + src diff --git a/smart-metrics/src/main/java/org/smartdata/metrics/FileAccessEvent.java b/smart-metrics/src/main/java/org/smartdata/metrics/FileAccessEvent.java index aed96d98877..58e705ede22 100644 --- a/smart-metrics/src/main/java/org/smartdata/metrics/FileAccessEvent.java +++ b/smart-metrics/src/main/java/org/smartdata/metrics/FileAccessEvent.java @@ -39,6 +39,10 @@ public FileAccessEvent(String path, long timeStamp, String user) { this.user = user; } + public FileAccessEvent(String path, String user) { + this(path, -1, user); + } + /** * Get the accessed file path. * @return file path