|
@@ -169,6 +169,7 @@ import org.apache.hadoop.hdfs.server.namenode.ha.StandbyCheckpointer;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.ha.StandbyState;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.metrics.FSNamesystemMBean;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.metrics.NameNodeMetrics;
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
|
|
|
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
|
|
@@ -1071,7 +1072,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setPermission", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1100,7 +1101,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setPermission", src, null, resultingStat);
|
|
|
}
|
|
|
}
|
|
@@ -1117,7 +1118,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setOwner", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1155,7 +1156,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setOwner", src, null, resultingStat);
|
|
|
}
|
|
|
}
|
|
@@ -1190,7 +1191,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"open", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1216,7 +1217,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
offset, length, doAccessTime, needBlockToken);
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"open", src, null, null);
|
|
|
}
|
|
|
if (checkSafeMode && isInSafeMode()) {
|
|
@@ -1301,7 +1302,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getLoginUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"concat", Arrays.toString(srcs), target, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1351,7 +1352,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getLoginUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"concat", Arrays.toString(srcs), target, resultingStat);
|
|
|
}
|
|
|
}
|
|
@@ -1468,7 +1469,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setTimes", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1495,7 +1496,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
final HdfsFileStatus stat = dir.getFileInfo(src, false);
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setTimes", src, null, stat);
|
|
|
}
|
|
|
} else {
|
|
@@ -1517,7 +1518,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"createSymlink", link, target, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1545,7 +1546,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"createSymlink", link, target, resultingStat);
|
|
|
}
|
|
|
}
|
|
@@ -1601,7 +1602,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setReplication", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1637,7 +1638,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
if (isFile && auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"setReplication", src, null, null);
|
|
|
}
|
|
|
return isFile;
|
|
@@ -1694,7 +1695,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"create", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -1719,7 +1720,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
final HdfsFileStatus stat = dir.getFileInfo(src, false);
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"create", src, null, stat);
|
|
|
}
|
|
|
}
|
|
@@ -2017,7 +2018,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"append", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -2055,7 +2056,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"append", src, null, null);
|
|
|
}
|
|
|
return lb;
|
|
@@ -2521,7 +2522,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"rename", src, dst, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -2550,7 +2551,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
if (status && auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"rename", src, dst, resultingStat);
|
|
|
}
|
|
|
return status;
|
|
@@ -2610,7 +2611,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
for (Rename option : options) {
|
|
|
cmd.append(option.value()).append(" ");
|
|
|
}
|
|
|
- logAuditEvent(UserGroupInformation.getCurrentUser(), Server.getRemoteIp(),
|
|
|
+ logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
|
|
|
cmd.toString(), src, dst, resultingStat);
|
|
|
}
|
|
|
}
|
|
@@ -2648,7 +2649,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"delete", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -2664,7 +2665,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
boolean status = deleteInternal(src, recursive, true);
|
|
|
if (status && auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"delete", src, null, null);
|
|
|
}
|
|
|
return status;
|
|
@@ -2802,8 +2803,11 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
*/
|
|
|
HdfsFileStatus getFileInfo(String src, boolean resolveLink)
|
|
|
throws AccessControlException, UnresolvedLinkException,
|
|
|
- StandbyException {
|
|
|
+ StandbyException, IOException {
|
|
|
+ HdfsFileStatus stat = null;
|
|
|
+
|
|
|
readLock();
|
|
|
+
|
|
|
try {
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
|
|
@@ -2813,10 +2817,23 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (isPermissionEnabled) {
|
|
|
checkTraverse(src);
|
|
|
}
|
|
|
- return dir.getFileInfo(src, resolveLink);
|
|
|
+ stat = dir.getFileInfo(src, resolveLink);
|
|
|
+ } catch (AccessControlException e) {
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
+ getRemoteIp(),
|
|
|
+ "getfileinfo", src, null, null);
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
} finally {
|
|
|
readUnlock();
|
|
|
}
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
+ logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
+ getRemoteIp(),
|
|
|
+ "getfileinfo", src, null, null);
|
|
|
+ }
|
|
|
+ return stat;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2829,7 +2846,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"mkdirs", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -2854,7 +2871,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
if (status && auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
final HdfsFileStatus stat = dir.getFileInfo(src, false);
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"mkdirs", src, null, stat);
|
|
|
}
|
|
|
return status;
|
|
@@ -3295,7 +3312,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
} catch (AccessControlException e) {
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"listStatus", src, null, null);
|
|
|
}
|
|
|
throw e;
|
|
@@ -3319,7 +3336,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
- Server.getRemoteIp(),
|
|
|
+ getRemoteIp(),
|
|
|
"listStatus", src, null, null);
|
|
|
}
|
|
|
dl = dir.getListing(src, startAfter, needLocation);
|
|
@@ -5250,7 +5267,15 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
* RPC call context even if the client exits.
|
|
|
*/
|
|
|
private boolean isExternalInvocation() {
|
|
|
- return Server.isRpcInvocation();
|
|
|
+ return Server.isRpcInvocation() || NamenodeWebHdfsMethods.isWebHdfsInvocation();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static InetAddress getRemoteIp() {
|
|
|
+ InetAddress ip = Server.getRemoteIp();
|
|
|
+ if (ip != null) {
|
|
|
+ return ip;
|
|
|
+ }
|
|
|
+ return NamenodeWebHdfsMethods.getRemoteIp();
|
|
|
}
|
|
|
|
|
|
/**
|