HDFS-15591. RBF: Fix webHdfs file display error. Contributed by wangzhaohui.

This commit is contained in:
Ayush Saxena 2020-09-28 23:55:31 +05:30
parent 984875c624
commit fc8a6dd8a9
2 changed files with 36 additions and 2 deletions

View File

@ -1983,7 +1983,8 @@ public class RouterClientProtocol implements ClientProtocol {
* @param date Map with the dates. * @param date Map with the dates.
* @return New HDFS file status representing a mount point. * @return New HDFS file status representing a mount point.
*/ */
private HdfsFileStatus getMountPointStatus( @VisibleForTesting
HdfsFileStatus getMountPointStatus(
String name, int childrenNum, long date) { String name, int childrenNum, long date) {
long modTime = date; long modTime = date;
long accessTime = date; long accessTime = date;
@ -2034,6 +2035,8 @@ public class RouterClientProtocol implements ClientProtocol {
} }
} }
long inodeId = 0; long inodeId = 0;
Path path = new Path(name);
String nameStr = path.getName();
return new HdfsFileStatus.Builder() return new HdfsFileStatus.Builder()
.isdir(true) .isdir(true)
.mtime(modTime) .mtime(modTime)
@ -2042,7 +2045,7 @@ public class RouterClientProtocol implements ClientProtocol {
.owner(owner) .owner(owner)
.group(group) .group(group)
.symlink(new byte[0]) .symlink(new byte[0])
.path(DFSUtil.string2Bytes(name)) .path(DFSUtil.string2Bytes(nameStr))
.fileId(inodeId) .fileId(inodeId)
.children(childrenNum) .children(childrenNum)
.flags(flags) .flags(flags)

View File

@ -342,6 +342,37 @@ public class TestRouterMountTable {
} }
} }
/**
* Verify the getMountPointStatus result of passing in different parameters.
*/
@Test
public void testGetMountPointStatus() throws IOException {
MountTable addEntry = MountTable.newInstance("/testA/testB/testC/testD",
Collections.singletonMap("ns0", "/testA/testB/testC/testD"));
assertTrue(addMountTable(addEntry));
RouterClientProtocol clientProtocol = new RouterClientProtocol(
nnFs0.getConf(), routerContext.getRouter().getRpcServer());
String src = "/";
String child = "testA";
Path childPath = new Path(src, child);
HdfsFileStatus dirStatus =
clientProtocol.getMountPointStatus(childPath.toString(), 0, 0);
assertEquals(child, dirStatus.getLocalName());
String src1 = "/testA";
String child1 = "testB";
Path childPath1 = new Path(src1, child1);
HdfsFileStatus dirStatus1 =
clientProtocol.getMountPointStatus(childPath1.toString(), 0, 0);
assertEquals(child1, dirStatus1.getLocalName());
String src2 = "/testA/testB";
String child2 = "testC";
Path childPath2 = new Path(src2, child2);
HdfsFileStatus dirStatus2 =
clientProtocol.getMountPointStatus(childPath2.toString(), 0, 0);
assertEquals(child2, dirStatus2.getLocalName());
}
/** /**
* GetListing of testPath through router. * GetListing of testPath through router.
*/ */