HADOOP-13820. Replace ugi.getUsername() with ugi.getShortUserName() in viewFS. Contributed By Brahma Reddy Battula.

This commit is contained in:
Brahma Reddy Battula 2016-11-25 19:54:50 +05:30
parent bb1b5e083b
commit ee3d437a33
4 changed files with 52 additions and 10 deletions

View File

@ -951,7 +951,7 @@ public FileChecksum getFileChecksum(final Path f)
public FileStatus getFileStatus(Path f) throws IOException { public FileStatus getFileStatus(Path f) throws IOException {
checkPathIsSlash(f); checkPathIsSlash(f);
return new FileStatus(0, true, 0, 0, creationTime, creationTime, return new FileStatus(0, true, 0, 0, creationTime, creationTime,
PERMISSION_555, ugi.getUserName(), ugi.getPrimaryGroupName(), PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),
new Path(theInternalDir.fullPath).makeQualified( new Path(theInternalDir.fullPath).makeQualified(
myUri, ROOT_PATH)); myUri, ROOT_PATH));
@ -972,14 +972,14 @@ public FileStatus[] listStatus(Path f) throws AccessControlException,
result[i++] = new FileStatus(0, false, 0, 0, result[i++] = new FileStatus(0, false, 0, 0,
creationTime, creationTime, PERMISSION_555, creationTime, creationTime, PERMISSION_555,
ugi.getUserName(), ugi.getPrimaryGroupName(), ugi.getShortUserName(), ugi.getPrimaryGroupName(),
link.getTargetLink(), link.getTargetLink(),
new Path(inode.fullPath).makeQualified( new Path(inode.fullPath).makeQualified(
myUri, null)); myUri, null));
} else { } else {
result[i++] = new FileStatus(0, true, 0, 0, result[i++] = new FileStatus(0, true, 0, 0,
creationTime, creationTime, PERMISSION_555, creationTime, creationTime, PERMISSION_555,
ugi.getUserName(), ugi.getGroupNames()[0], ugi.getShortUserName(), ugi.getGroupNames()[0],
new Path(inode.fullPath).makeQualified( new Path(inode.fullPath).makeQualified(
myUri, null)); myUri, null));
} }
@ -1103,7 +1103,7 @@ public void setAcl(Path path, List<AclEntry> aclSpec) throws IOException {
@Override @Override
public AclStatus getAclStatus(Path path) throws IOException { public AclStatus getAclStatus(Path path) throws IOException {
checkPathIsSlash(path); checkPathIsSlash(path);
return new AclStatus.Builder().owner(ugi.getUserName()) return new AclStatus.Builder().owner(ugi.getShortUserName())
.group(ugi.getPrimaryGroupName()) .group(ugi.getPrimaryGroupName())
.addEntries(AclUtil.getMinimalAcl(PERMISSION_555)) .addEntries(AclUtil.getMinimalAcl(PERMISSION_555))
.stickyBit(false).build(); .stickyBit(false).build();

View File

@ -845,7 +845,7 @@ public FileChecksum getFileChecksum(final Path f)
public FileStatus getFileStatus(final Path f) throws IOException { public FileStatus getFileStatus(final Path f) throws IOException {
checkPathIsSlash(f); checkPathIsSlash(f);
return new FileStatus(0, true, 0, 0, creationTime, creationTime, return new FileStatus(0, true, 0, 0, creationTime, creationTime,
PERMISSION_555, ugi.getUserName(), ugi.getPrimaryGroupName(), PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),
new Path(theInternalDir.fullPath).makeQualified( new Path(theInternalDir.fullPath).makeQualified(
myUri, null)); myUri, null));
} }
@ -865,13 +865,13 @@ public FileStatus getFileLinkStatus(final Path f)
INodeLink<AbstractFileSystem> inodelink = INodeLink<AbstractFileSystem> inodelink =
(INodeLink<AbstractFileSystem>) inode; (INodeLink<AbstractFileSystem>) inode;
result = new FileStatus(0, false, 0, 0, creationTime, creationTime, result = new FileStatus(0, false, 0, 0, creationTime, creationTime,
PERMISSION_555, ugi.getUserName(), ugi.getPrimaryGroupName(), PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),
inodelink.getTargetLink(), inodelink.getTargetLink(),
new Path(inode.fullPath).makeQualified( new Path(inode.fullPath).makeQualified(
myUri, null)); myUri, null));
} else { } else {
result = new FileStatus(0, true, 0, 0, creationTime, creationTime, result = new FileStatus(0, true, 0, 0, creationTime, creationTime,
PERMISSION_555, ugi.getUserName(), ugi.getPrimaryGroupName(), PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),
new Path(inode.fullPath).makeQualified( new Path(inode.fullPath).makeQualified(
myUri, null)); myUri, null));
} }
@ -910,14 +910,14 @@ public FileStatus[] listStatus(final Path f) throws AccessControlException,
result[i++] = new FileStatus(0, false, 0, 0, result[i++] = new FileStatus(0, false, 0, 0,
creationTime, creationTime, creationTime, creationTime,
PERMISSION_555, ugi.getUserName(), ugi.getPrimaryGroupName(), PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),
link.getTargetLink(), link.getTargetLink(),
new Path(inode.fullPath).makeQualified( new Path(inode.fullPath).makeQualified(
myUri, null)); myUri, null));
} else { } else {
result[i++] = new FileStatus(0, true, 0, 0, result[i++] = new FileStatus(0, true, 0, 0,
creationTime, creationTime, creationTime, creationTime,
PERMISSION_555, ugi.getUserName(), ugi.getGroupNames()[0], PERMISSION_555, ugi.getShortUserName(), ugi.getGroupNames()[0],
new Path(inode.fullPath).makeQualified( new Path(inode.fullPath).makeQualified(
myUri, null)); myUri, null));
} }
@ -1043,7 +1043,7 @@ public void setAcl(Path path, List<AclEntry> aclSpec) throws IOException {
@Override @Override
public AclStatus getAclStatus(Path path) throws IOException { public AclStatus getAclStatus(Path path) throws IOException {
checkPathIsSlash(path); checkPathIsSlash(path);
return new AclStatus.Builder().owner(ugi.getUserName()) return new AclStatus.Builder().owner(ugi.getShortUserName())
.group(ugi.getPrimaryGroupName()) .group(ugi.getPrimaryGroupName())
.addEntries(AclUtil.getMinimalAcl(PERMISSION_555)) .addEntries(AclUtil.getMinimalAcl(PERMISSION_555))
.stickyBit(false).build(); .stickyBit(false).build();

View File

@ -20,6 +20,7 @@
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -1088,4 +1089,23 @@ public void testViewFileSystemUtil() throws Exception {
// Case 7: Verify FsStatus of a non MountPoint path throws exception // Case 7: Verify FsStatus of a non MountPoint path throws exception
ViewFileSystemUtil.getStatus(fileSystem, new Path("/non-existing")); ViewFileSystemUtil.getStatus(fileSystem, new Path("/non-existing"));
} }
@Test
public void testCheckOwnerWithFileStatus()
throws IOException, InterruptedException {
final UserGroupInformation userUgi = UserGroupInformation
.createUserForTesting("user@HADOOP.COM", new String[]{"hadoop"});
userUgi.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws IOException {
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
String doAsUserName = ugi.getUserName();
assertEquals(doAsUserName, "user@HADOOP.COM");
FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
FileStatus stat = vfs.getFileStatus(new Path("/internalDir"));
assertEquals(userUgi.getShortUserName(), stat.getOwner());
return null;
}
});
}
} }

View File

@ -29,6 +29,8 @@
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -798,4 +800,24 @@ public void testInternalRenameSnapshot() throws IOException {
public void testInternalDeleteSnapshot() throws IOException { public void testInternalDeleteSnapshot() throws IOException {
fcView.deleteSnapshot(new Path("/internalDir"), "snap1"); fcView.deleteSnapshot(new Path("/internalDir"), "snap1");
} }
@Test
public void testOwnerForInternalDir()
throws IOException, InterruptedException, URISyntaxException {
final UserGroupInformation userUgi = UserGroupInformation
.createUserForTesting("user@HADOOP.COM", new String[]{"hadoop"});
userUgi.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws IOException, URISyntaxException {
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
String doAsUserName = ugi.getUserName();
assertEquals(doAsUserName, "user@HADOOP.COM");
FileContext
viewFS = FileContext.getFileContext(FsConstants.VIEWFS_URI, conf);
FileStatus stat = viewFS.getFileStatus(new Path("/internalDir"));
assertEquals(userUgi.getShortUserName(), stat.getOwner());
return null;
}
});
}
} }