HDDS-634. OzoneFS: support basic user group and permission for file/dir. Contributed by Xiaoyu Yao.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/604c27c3 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/604c27c3 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/604c27c3 Branch: refs/heads/HDFS-12943 Commit: 604c27c33a3bd30644debaf192cec3cf80dfa36d Parents: 5055247 Author: Anu Engineer <aengin...@apache.org> Authored: Thu Oct 11 17:19:38 2018 -0700 Committer: Anu Engineer <aengin...@apache.org> Committed: Thu Oct 11 17:25:25 2018 -0700 ---------------------------------------------------------------------- .../apache/hadoop/fs/ozone/OzoneFileSystem.java | 16 ++++++++++++++-- .../hadoop/fs/ozone/TestOzoneFileInterfaces.java | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/604c27c3/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java b/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java index 8fbd688..0b721fb 100644 --- a/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java +++ b/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java @@ -448,6 +448,14 @@ public class OzoneFileSystem extends FileSystem { } /** + * Get the username of the FS. + * @return the short name of the user who instantiated the FS + */ + public String getUsername() { + return userName; + } + + /** * Check whether the path is valid and then create directories. * Directory is represented using a key with no value. * All the non-existent parent directories are also created. @@ -528,11 +536,15 @@ public class OzoneFileSystem extends FileSystem { throw new FileNotFoundException(f + ": No such file or directory!"); } else if (isDirectory(meta)) { return new FileStatus(0, true, 1, 0, - meta.getModificationTime(), qualifiedPath); + meta.getModificationTime(), 0, + FsPermission.getDirDefault(), getUsername(), getUsername(), + qualifiedPath); } else { //TODO: Fetch replication count from ratis config return new FileStatus(meta.getDataSize(), false, 1, - getDefaultBlockSize(f), meta.getModificationTime(), qualifiedPath); + getDefaultBlockSize(f), meta.getModificationTime(), 0, + FsPermission.getFileDefault(), getUsername(), getUsername(), + qualifiedPath); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/604c27c3/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java b/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java index a225702..7cf6e3d 100644 --- a/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java +++ b/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java @@ -23,6 +23,7 @@ import java.net.URI; import java.util.Arrays; import java.util.Collection; +import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.ozone.MiniOzoneCluster; import org.apache.hadoop.ozone.OzoneConsts; import org.junit.Before; @@ -167,6 +168,10 @@ public class TestOzoneFileInterfaces { assertTrue("Modification time has not been recorded: " + status, status.getModificationTime() > currentTime); + assertEquals(false, status.isDirectory()); + assertEquals(FsPermission.getFileDefault(), status.getPermission()); + verifyOwnerGroup(status); + try (FSDataInputStream inputStream = fs.open(path)) { byte[] buffer = new byte[stringLen]; inputStream.readFully(0, buffer); @@ -175,6 +180,12 @@ public class TestOzoneFileInterfaces { } } + private void verifyOwnerGroup(FileStatus fileStatus) { + String owner = getCurrentUser(); + assertEquals(owner, fileStatus.getOwner()); + assertEquals(owner, fileStatus.getGroup()); + } + @Test public void testDirectory() throws IOException { @@ -186,6 +197,10 @@ public class TestOzoneFileInterfaces { FileStatus status = fs.getFileStatus(path); assertTrue("The created path is not directory.", status.isDirectory()); + assertEquals(true, status.isDirectory()); + assertEquals(FsPermission.getDirDefault(), status.getPermission()); + verifyOwnerGroup(status); + assertEquals(0, status.getLen()); FileStatus[] statusList = fs.listStatus(createPath("/")); @@ -195,8 +210,6 @@ public class TestOzoneFileInterfaces { FileStatus statusRoot = fs.getFileStatus(createPath("/")); assertTrue("Root dir (/) is not a directory.", status.isDirectory()); assertEquals(0, status.getLen()); - - } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org