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:
zhtttylz 2023-04-25 06:00:56 +08:00 committed by GitHub
parent dc78849f27
commit c9e0af9961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 0 deletions

View File

@ -2160,6 +2160,24 @@ Path decodeResponse(Map<?, ?> json) {
}.run(); }.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 @VisibleForTesting
InetSocketAddress[] getResolvedNNAddr() { InetSocketAddress[] getResolvedNNAddr() {
return nnAddrs; return nnAddrs;

View File

@ -65,6 +65,7 @@ public enum Op implements HttpOpParam.Op {
GETSNAPSHOTDIFFLISTING(false, HttpURLConnection.HTTP_OK), GETSNAPSHOTDIFFLISTING(false, HttpURLConnection.HTTP_OK),
GETSNAPSHOTTABLEDIRECTORYLIST(false, HttpURLConnection.HTTP_OK), GETSNAPSHOTTABLEDIRECTORYLIST(false, HttpURLConnection.HTTP_OK),
GETLINKTARGET(false, HttpURLConnection.HTTP_OK), GETLINKTARGET(false, HttpURLConnection.HTTP_OK),
GETFILELINKSTATUS(false, HttpURLConnection.HTTP_OK),
GETSNAPSHOTLIST(false, HttpURLConnection.HTTP_OK); GETSNAPSHOTLIST(false, HttpURLConnection.HTTP_OK);
final boolean redirect; final boolean redirect;

View File

@ -386,6 +386,7 @@ protected Response get(
case LISTXATTRS: case LISTXATTRS:
case CHECKACCESS: case CHECKACCESS:
case GETLINKTARGET: case GETLINKTARGET:
case GETFILELINKSTATUS:
{ {
return super.get(ugi, delegation, username, doAsUser, fullpath, op, return super.get(ugi, delegation, username, doAsUser, fullpath, op,
offset, length, renewer, bufferSize, xattrNames, xattrEncoding, offset, length, renewer, bufferSize, xattrNames, xattrEncoding,

View File

@ -1388,6 +1388,14 @@ protected Response get(
final String js = JsonUtil.toJsonString("Path", target); final String js = JsonUtil.toJsonString("Path", target);
return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); 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: default:
throw new UnsupportedOperationException(op + " is not supported"); throw new UnsupportedOperationException(op + " is not supported");
} }

View File

@ -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) * [`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) * [`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) * [`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 * HTTP PUT
* [`CREATE`](#Create_and_Write_to_a_File) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).create) * [`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) * [`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 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 Storage Policy Operations
------------------------- -------------------------

View File

@ -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. * Get FileStatus JSONObject from ListStatus response.
*/ */