HDFS-16981. Support getFileLinkStatus API in WebHDFS (#5572). Contributed by Hualong Zhang.
Reviewed-by: Simbarashe Dzinamarira <sdzinamarira@linkedin.com> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
parent
dc78849f27
commit
c9e0af9961
@ -2160,6 +2160,24 @@ Path decodeResponse(Map<?, ?> json) {
|
||||
}.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStatus getFileLinkStatus(Path f) throws IOException {
|
||||
statistics.incrementReadOps(1);
|
||||
storageStatistics.incrementOpCounter(OpType.GET_FILE_LINK_STATUS);
|
||||
final HttpOpParam.Op op = GetOpParam.Op.GETFILELINKSTATUS;
|
||||
HdfsFileStatus status =
|
||||
new FsPathResponseRunner<HdfsFileStatus>(op, f) {
|
||||
@Override
|
||||
HdfsFileStatus decodeResponse(Map<?, ?> json) {
|
||||
return JsonUtilClient.toFileStatus(json, true);
|
||||
}
|
||||
}.run();
|
||||
if (status == null) {
|
||||
throw new FileNotFoundException("File does not exist: " + f);
|
||||
}
|
||||
return status.makeQualified(getUri(), f);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
InetSocketAddress[] getResolvedNNAddr() {
|
||||
return nnAddrs;
|
||||
|
@ -65,6 +65,7 @@ public enum Op implements HttpOpParam.Op {
|
||||
GETSNAPSHOTDIFFLISTING(false, HttpURLConnection.HTTP_OK),
|
||||
GETSNAPSHOTTABLEDIRECTORYLIST(false, HttpURLConnection.HTTP_OK),
|
||||
GETLINKTARGET(false, HttpURLConnection.HTTP_OK),
|
||||
GETFILELINKSTATUS(false, HttpURLConnection.HTTP_OK),
|
||||
GETSNAPSHOTLIST(false, HttpURLConnection.HTTP_OK);
|
||||
|
||||
final boolean redirect;
|
||||
|
@ -386,6 +386,7 @@ protected Response get(
|
||||
case LISTXATTRS:
|
||||
case CHECKACCESS:
|
||||
case GETLINKTARGET:
|
||||
case GETFILELINKSTATUS:
|
||||
{
|
||||
return super.get(ugi, delegation, username, doAsUser, fullpath, op,
|
||||
offset, length, renewer, bufferSize, xattrNames, xattrEncoding,
|
||||
|
@ -1388,6 +1388,14 @@ protected Response get(
|
||||
final String js = JsonUtil.toJsonString("Path", target);
|
||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
case GETFILELINKSTATUS: {
|
||||
HdfsFileStatus status = cp.getFileLinkInfo(fullpath);
|
||||
if (status == null) {
|
||||
throw new FileNotFoundException("File does not exist: " + fullpath);
|
||||
}
|
||||
final String js = JsonUtil.toJsonString(status, true);
|
||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedOperationException(op + " is not supported");
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ The HTTP REST API supports the complete [FileSystem](../../api/org/apache/hadoop
|
||||
* [`GETECPOLICY`](#Get_EC_Policy) (see [HDFSErasureCoding](./HDFSErasureCoding.html#Administrative_commands).getErasureCodingPolicy)
|
||||
* [`GETSERVERDEFAULTS`](#Get_Server_Defaults) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getServerDefaults)
|
||||
* [`GETLINKTARGET`](#Get_Link_Target) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getLinkTarget)
|
||||
* [`GETFILELINKSTATUS`](#Get_File_Link_Status) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getFileLinkStatus)
|
||||
* HTTP PUT
|
||||
* [`CREATE`](#Create_and_Write_to_a_File) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).create)
|
||||
* [`MKDIRS`](#Make_a_Directory) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).mkdirs)
|
||||
@ -1156,6 +1157,39 @@ See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getServer
|
||||
|
||||
See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getLinkTarget
|
||||
|
||||
### Get File Link Status
|
||||
|
||||
* Submit a HTTP GET request.
|
||||
|
||||
curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILELINKSTATUS"
|
||||
|
||||
The client receives a response with a [`FileStatus` JSON object](#FileStatuses_JSON_Schema):
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
{
|
||||
"FileStatus": {
|
||||
"accessTime": 0,
|
||||
"blockSize": 0,
|
||||
"childrenNum":0,
|
||||
"fileId": 16388,
|
||||
"group": "supergroup",
|
||||
"length": 0,
|
||||
"modificationTime": 1681916788427,
|
||||
"owner": "hadoop",
|
||||
"pathSuffix": "",
|
||||
"permission": "777",
|
||||
"replication": 0,
|
||||
"storagePolicy": 0,
|
||||
"symlink": "/webHdfsTest/file",
|
||||
"type": "SYMLINK"
|
||||
}
|
||||
}
|
||||
|
||||
See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getFileLinkInfo
|
||||
|
||||
Storage Policy Operations
|
||||
-------------------------
|
||||
|
||||
|
@ -2230,6 +2230,31 @@ public void testLinkTarget() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileLinkStatus() throws Exception {
|
||||
final Configuration conf = WebHdfsTestUtil.createConf();
|
||||
try {
|
||||
cluster = new MiniDFSCluster.Builder(conf).build();
|
||||
cluster.waitActive();
|
||||
|
||||
final WebHdfsFileSystem webHdfs =
|
||||
WebHdfsTestUtil.getWebHdfsFileSystem(conf,
|
||||
WebHdfsConstants.WEBHDFS_SCHEME);
|
||||
// Symbolic link
|
||||
Path root = new Path("/webHdfsTest/");
|
||||
Path file = new Path(root, "file");
|
||||
FileSystemTestHelper.createFile(webHdfs, file);
|
||||
|
||||
Path linkToFile = new Path(root, "linkToFile");
|
||||
|
||||
webHdfs.createSymlink(file, linkToFile, false);
|
||||
assertFalse(webHdfs.getFileLinkStatus(file).isSymlink());
|
||||
assertTrue(webHdfs.getFileLinkStatus(linkToFile).isSymlink());
|
||||
} finally {
|
||||
cluster.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FileStatus JSONObject from ListStatus response.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user