HDDS-634. OzoneFS: support basic user group and permission for file/dir.
Contributed by Xiaoyu Yao.
This commit is contained in:
parent
50552479c4
commit
604c27c33a
|
@ -447,6 +447,14 @@ public class OzoneFileSystem extends FileSystem {
|
|||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue