|
@@ -240,8 +240,15 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
private static final void logAuditEvent(UserGroupInformation ugi,
|
|
private static final void logAuditEvent(UserGroupInformation ugi,
|
|
InetAddress addr, String cmd, String src, String dst,
|
|
InetAddress addr, String cmd, String src, String dst,
|
|
HdfsFileStatus stat) {
|
|
HdfsFileStatus stat) {
|
|
|
|
+ logAuditEvent(true, ugi, addr, cmd, src, dst, stat);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static final void logAuditEvent(boolean succeeded,
|
|
|
|
+ UserGroupInformation ugi, InetAddress addr, String cmd, String src,
|
|
|
|
+ String dst, HdfsFileStatus stat) {
|
|
final StringBuilder sb = auditBuffer.get();
|
|
final StringBuilder sb = auditBuffer.get();
|
|
sb.setLength(0);
|
|
sb.setLength(0);
|
|
|
|
+ sb.append("allowed=").append(succeeded).append("\t");
|
|
sb.append("ugi=").append(ugi).append("\t");
|
|
sb.append("ugi=").append(ugi).append("\t");
|
|
sb.append("ip=").append(addr).append("\t");
|
|
sb.append("ip=").append(addr).append("\t");
|
|
sb.append("cmd=").append(cmd).append("\t");
|
|
sb.append("cmd=").append(cmd).append("\t");
|
|
@@ -1018,6 +1025,21 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
void setPermission(String src, FsPermission permission)
|
|
void setPermission(String src, FsPermission permission)
|
|
throws AccessControlException, FileNotFoundException, SafeModeException,
|
|
throws AccessControlException, FileNotFoundException, SafeModeException,
|
|
UnresolvedLinkException, IOException {
|
|
UnresolvedLinkException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ setPermissionInt(src, permission);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "setPermission", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setPermissionInt(String src, FsPermission permission)
|
|
|
|
+ throws AccessControlException, FileNotFoundException, SafeModeException,
|
|
|
|
+ UnresolvedLinkException, IOException {
|
|
HdfsFileStatus resultingStat = null;
|
|
HdfsFileStatus resultingStat = null;
|
|
writeLock();
|
|
writeLock();
|
|
try {
|
|
try {
|
|
@@ -1049,6 +1071,21 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
void setOwner(String src, String username, String group)
|
|
void setOwner(String src, String username, String group)
|
|
throws AccessControlException, FileNotFoundException, SafeModeException,
|
|
throws AccessControlException, FileNotFoundException, SafeModeException,
|
|
UnresolvedLinkException, IOException {
|
|
UnresolvedLinkException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ setOwnerInt(src, username, group);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "setOwner", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setOwnerInt(String src, String username, String group)
|
|
|
|
+ throws AccessControlException, FileNotFoundException, SafeModeException,
|
|
|
|
+ UnresolvedLinkException, IOException {
|
|
HdfsFileStatus resultingStat = null;
|
|
HdfsFileStatus resultingStat = null;
|
|
writeLock();
|
|
writeLock();
|
|
try {
|
|
try {
|
|
@@ -1106,6 +1143,22 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
LocatedBlocks getBlockLocations(String src, long offset, long length,
|
|
LocatedBlocks getBlockLocations(String src, long offset, long length,
|
|
boolean doAccessTime, boolean needBlockToken, boolean checkSafeMode)
|
|
boolean doAccessTime, boolean needBlockToken, boolean checkSafeMode)
|
|
throws FileNotFoundException, UnresolvedLinkException, IOException {
|
|
throws FileNotFoundException, UnresolvedLinkException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ return getBlockLocationsInt(src, offset, length, doAccessTime,
|
|
|
|
+ needBlockToken, checkSafeMode);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "open", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private LocatedBlocks getBlockLocationsInt(String src, long offset, long length,
|
|
|
|
+ boolean doAccessTime, boolean needBlockToken, boolean checkSafeMode)
|
|
|
|
+ throws FileNotFoundException, UnresolvedLinkException, IOException {
|
|
if (isPermissionEnabled) {
|
|
if (isPermissionEnabled) {
|
|
checkPathAccess(src, FsAction.READ);
|
|
checkPathAccess(src, FsAction.READ);
|
|
}
|
|
}
|
|
@@ -1202,6 +1255,20 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
*/
|
|
*/
|
|
void concat(String target, String [] srcs)
|
|
void concat(String target, String [] srcs)
|
|
throws IOException, UnresolvedLinkException {
|
|
throws IOException, UnresolvedLinkException {
|
|
|
|
+ try {
|
|
|
|
+ concatInt(target, srcs);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getLoginUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "concat", Arrays.toString(srcs), target, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void concatInt(String target, String [] srcs)
|
|
|
|
+ throws IOException, UnresolvedLinkException {
|
|
if(FSNamesystem.LOG.isDebugEnabled()) {
|
|
if(FSNamesystem.LOG.isDebugEnabled()) {
|
|
FSNamesystem.LOG.debug("concat " + Arrays.toString(srcs) +
|
|
FSNamesystem.LOG.debug("concat " + Arrays.toString(srcs) +
|
|
" to " + target);
|
|
" to " + target);
|
|
@@ -1354,6 +1421,20 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
* written to the edits log but is not flushed.
|
|
* written to the edits log but is not flushed.
|
|
*/
|
|
*/
|
|
void setTimes(String src, long mtime, long atime)
|
|
void setTimes(String src, long mtime, long atime)
|
|
|
|
+ throws IOException, UnresolvedLinkException {
|
|
|
|
+ try {
|
|
|
|
+ setTimesInt(src, mtime, atime);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "setTimes", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setTimesInt(String src, long mtime, long atime)
|
|
throws IOException, UnresolvedLinkException {
|
|
throws IOException, UnresolvedLinkException {
|
|
if (!isAccessTimeSupported() && atime != -1) {
|
|
if (!isAccessTimeSupported() && atime != -1) {
|
|
throw new IOException("Access time for hdfs is not configured. " +
|
|
throw new IOException("Access time for hdfs is not configured. " +
|
|
@@ -1390,6 +1471,21 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
void createSymlink(String target, String link,
|
|
void createSymlink(String target, String link,
|
|
PermissionStatus dirPerms, boolean createParent)
|
|
PermissionStatus dirPerms, boolean createParent)
|
|
throws IOException, UnresolvedLinkException {
|
|
throws IOException, UnresolvedLinkException {
|
|
|
|
+ try {
|
|
|
|
+ createSymlinkInt(target, link, dirPerms, createParent);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "createSymlink", link, target, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void createSymlinkInt(String target, String link,
|
|
|
|
+ PermissionStatus dirPerms, boolean createParent)
|
|
|
|
+ throws IOException, UnresolvedLinkException {
|
|
HdfsFileStatus resultingStat = null;
|
|
HdfsFileStatus resultingStat = null;
|
|
writeLock();
|
|
writeLock();
|
|
try {
|
|
try {
|
|
@@ -1457,8 +1553,22 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
* @return true if successful;
|
|
* @return true if successful;
|
|
* false if file does not exist or is a directory
|
|
* false if file does not exist or is a directory
|
|
*/
|
|
*/
|
|
- boolean setReplication(final String src, final short replication
|
|
|
|
- ) throws IOException {
|
|
|
|
|
|
+ boolean setReplication(final String src, final short replication)
|
|
|
|
+ throws IOException {
|
|
|
|
+ try {
|
|
|
|
+ return setReplicationInt(src, replication);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "setReplication", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean setReplicationInt(final String src, final short replication)
|
|
|
|
+ throws IOException {
|
|
blockManager.verifyReplication(src, replication, null);
|
|
blockManager.verifyReplication(src, replication, null);
|
|
|
|
|
|
final boolean isFile;
|
|
final boolean isFile;
|
|
@@ -1491,7 +1601,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
}
|
|
}
|
|
return isFile;
|
|
return isFile;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
long getPreferredBlockSize(String filename)
|
|
long getPreferredBlockSize(String filename)
|
|
throws IOException, UnresolvedLinkException {
|
|
throws IOException, UnresolvedLinkException {
|
|
readLock();
|
|
readLock();
|
|
@@ -1537,6 +1647,24 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
short replication, long blockSize) throws AccessControlException,
|
|
short replication, long blockSize) throws AccessControlException,
|
|
SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
|
|
SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
|
|
FileNotFoundException, ParentNotDirectoryException, IOException {
|
|
FileNotFoundException, ParentNotDirectoryException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ startFileInt(src, permissions, holder, clientMachine, flag, createParent,
|
|
|
|
+ replication, blockSize);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "create", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void startFileInt(String src, PermissionStatus permissions, String holder,
|
|
|
|
+ String clientMachine, EnumSet<CreateFlag> flag, boolean createParent,
|
|
|
|
+ short replication, long blockSize) throws AccessControlException,
|
|
|
|
+ SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
|
|
|
|
+ FileNotFoundException, ParentNotDirectoryException, IOException {
|
|
writeLock();
|
|
writeLock();
|
|
try {
|
|
try {
|
|
checkOperation(OperationCategory.WRITE);
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -1840,6 +1968,22 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
throws AccessControlException, SafeModeException,
|
|
throws AccessControlException, SafeModeException,
|
|
FileAlreadyExistsException, FileNotFoundException,
|
|
FileAlreadyExistsException, FileNotFoundException,
|
|
ParentNotDirectoryException, IOException {
|
|
ParentNotDirectoryException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ return appendFileInt(src, holder, clientMachine);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "append", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private LocatedBlock appendFileInt(String src, String holder, String clientMachine)
|
|
|
|
+ throws AccessControlException, SafeModeException,
|
|
|
|
+ FileAlreadyExistsException, FileNotFoundException,
|
|
|
|
+ ParentNotDirectoryException, IOException {
|
|
if (!supportAppends) {
|
|
if (!supportAppends) {
|
|
throw new UnsupportedOperationException(
|
|
throw new UnsupportedOperationException(
|
|
"Append is not enabled on this NameNode. Use the " +
|
|
"Append is not enabled on this NameNode. Use the " +
|
|
@@ -2326,6 +2470,20 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
*/
|
|
*/
|
|
@Deprecated
|
|
@Deprecated
|
|
boolean renameTo(String src, String dst)
|
|
boolean renameTo(String src, String dst)
|
|
|
|
+ throws IOException, UnresolvedLinkException {
|
|
|
|
+ try {
|
|
|
|
+ return renameToInt(src, dst);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "rename", src, dst, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean renameToInt(String src, String dst)
|
|
throws IOException, UnresolvedLinkException {
|
|
throws IOException, UnresolvedLinkException {
|
|
boolean status = false;
|
|
boolean status = false;
|
|
HdfsFileStatus resultingStat = null;
|
|
HdfsFileStatus resultingStat = null;
|
|
@@ -2437,20 +2595,35 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
* @see ClientProtocol#delete(String, boolean) for detailed descriptoin and
|
|
* @see ClientProtocol#delete(String, boolean) for detailed descriptoin and
|
|
* description of exceptions
|
|
* description of exceptions
|
|
*/
|
|
*/
|
|
- boolean delete(String src, boolean recursive)
|
|
|
|
- throws AccessControlException, SafeModeException,
|
|
|
|
- UnresolvedLinkException, IOException {
|
|
|
|
- if (NameNode.stateChangeLog.isDebugEnabled()) {
|
|
|
|
- NameNode.stateChangeLog.debug("DIR* NameSystem.delete: " + src);
|
|
|
|
- }
|
|
|
|
- boolean status = deleteInternal(src, recursive, true);
|
|
|
|
- if (status && auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
- logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
|
|
|
+ boolean delete(String src, boolean recursive)
|
|
|
|
+ throws AccessControlException, SafeModeException,
|
|
|
|
+ UnresolvedLinkException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ return deleteInt(src, recursive);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
Server.getRemoteIp(),
|
|
Server.getRemoteIp(),
|
|
"delete", src, null, null);
|
|
"delete", src, null, null);
|
|
}
|
|
}
|
|
- return status;
|
|
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean deleteInt(String src, boolean recursive)
|
|
|
|
+ throws AccessControlException, SafeModeException,
|
|
|
|
+ UnresolvedLinkException, IOException {
|
|
|
|
+ if (NameNode.stateChangeLog.isDebugEnabled()) {
|
|
|
|
+ NameNode.stateChangeLog.debug("DIR* NameSystem.delete: " + src);
|
|
}
|
|
}
|
|
|
|
+ boolean status = deleteInternal(src, recursive, true);
|
|
|
|
+ if (status && auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "delete", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ return status;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Remove a file/directory from the namespace.
|
|
* Remove a file/directory from the namespace.
|
|
@@ -2606,6 +2779,20 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
*/
|
|
*/
|
|
boolean mkdirs(String src, PermissionStatus permissions,
|
|
boolean mkdirs(String src, PermissionStatus permissions,
|
|
boolean createParent) throws IOException, UnresolvedLinkException {
|
|
boolean createParent) throws IOException, UnresolvedLinkException {
|
|
|
|
+ try {
|
|
|
|
+ return mkdirsInt(src, permissions, createParent);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "mkdirs", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean mkdirsInt(String src, PermissionStatus permissions,
|
|
|
|
+ boolean createParent) throws IOException, UnresolvedLinkException {
|
|
boolean status = false;
|
|
boolean status = false;
|
|
if(NameNode.stateChangeLog.isDebugEnabled()) {
|
|
if(NameNode.stateChangeLog.isDebugEnabled()) {
|
|
NameNode.stateChangeLog.debug("DIR* NameSystem.mkdirs: " + src);
|
|
NameNode.stateChangeLog.debug("DIR* NameSystem.mkdirs: " + src);
|
|
@@ -3057,6 +3244,21 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
*/
|
|
*/
|
|
DirectoryListing getListing(String src, byte[] startAfter,
|
|
DirectoryListing getListing(String src, byte[] startAfter,
|
|
boolean needLocation)
|
|
boolean needLocation)
|
|
|
|
+ throws AccessControlException, UnresolvedLinkException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ return getListingInt(src, startAfter, needLocation);
|
|
|
|
+ } catch (AccessControlException e) {
|
|
|
|
+ if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
|
+ logAuditEvent(false, UserGroupInformation.getCurrentUser(),
|
|
|
|
+ Server.getRemoteIp(),
|
|
|
|
+ "listStatus", src, null, null);
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DirectoryListing getListingInt(String src, byte[] startAfter,
|
|
|
|
+ boolean needLocation)
|
|
throws AccessControlException, UnresolvedLinkException, IOException {
|
|
throws AccessControlException, UnresolvedLinkException, IOException {
|
|
DirectoryListing dl;
|
|
DirectoryListing dl;
|
|
readLock();
|
|
readLock();
|