From 604c27c33a3bd30644debaf192cec3cf80dfa36d Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Thu, 11 Oct 2018 17:19:38 -0700 Subject: [PATCH] HDDS-634. OzoneFS: support basic user group and permission for file/dir. Contributed by Xiaoyu Yao. --- .../apache/hadoop/fs/ozone/OzoneFileSystem.java | 16 ++++++++++++++-- .../fs/ozone/TestOzoneFileInterfaces.java | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) 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 8fbd688200d..0b721fb0fbc 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 @@ -447,6 +447,14 @@ public Path getWorkingDirectory() { return workingDir; } + /** + * 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. @@ -528,11 +536,15 @@ public FileStatus getFileStatus(Path f) throws IOException { 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); } } 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 a2257023b61..7cf6e3d9545 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.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 void testOzFsReadWrite() throws IOException { 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 void testOzFsReadWrite() throws IOException { } } + 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 void testDirectory() throws IOException { 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 void testDirectory() throws IOException { FileStatus statusRoot = fs.getFileStatus(createPath("/")); assertTrue("Root dir (/) is not a directory.", status.isDirectory()); assertEquals(0, status.getLen()); - - } @Test