HDFS-16952. Support getLinkTarget API in WebHDFS (#5517)
Co-authored-by: Zhtttylz <hualong.z@hotmail.com> Reviewed-by: Shilun Fan <slfan1989@apache.org> Signed-off-by: Shilun Fan <slfan1989@apache.org>
This commit is contained in:
parent
47c22e388e
commit
523ff81624
@ -2147,6 +2147,19 @@ FsServerDefaults decodeResponse(Map<?, ?> json) throws IOException {
|
||||
}.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getLinkTarget(Path f) throws IOException {
|
||||
statistics.incrementReadOps(1);
|
||||
storageStatistics.incrementOpCounter(OpType.GET_LINK_TARGET);
|
||||
final HttpOpParam.Op op = GetOpParam.Op.GETLINKTARGET;
|
||||
return new FsPathResponseRunner<Path>(op, f) {
|
||||
@Override
|
||||
Path decodeResponse(Map<?, ?> json) {
|
||||
return new Path((String) json.get(Path.class.getSimpleName()));
|
||||
}
|
||||
}.run();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
InetSocketAddress[] getResolvedNNAddr() {
|
||||
return nnAddrs;
|
||||
|
@ -64,6 +64,7 @@ public enum Op implements HttpOpParam.Op {
|
||||
GETSNAPSHOTDIFF(false, HttpURLConnection.HTTP_OK),
|
||||
GETSNAPSHOTDIFFLISTING(false, HttpURLConnection.HTTP_OK),
|
||||
GETSNAPSHOTTABLEDIRECTORYLIST(false, HttpURLConnection.HTTP_OK),
|
||||
GETLINKTARGET(false, HttpURLConnection.HTTP_OK),
|
||||
GETSNAPSHOTLIST(false, HttpURLConnection.HTTP_OK);
|
||||
|
||||
final boolean redirect;
|
||||
|
@ -385,6 +385,7 @@ protected Response get(
|
||||
case GETXATTRS:
|
||||
case LISTXATTRS:
|
||||
case CHECKACCESS:
|
||||
case GETLINKTARGET:
|
||||
{
|
||||
return super.get(ugi, delegation, username, doAsUser, fullpath, op,
|
||||
offset, length, renewer, bufferSize, xattrNames, xattrEncoding,
|
||||
|
@ -1383,6 +1383,11 @@ protected Response get(
|
||||
final String js = JsonUtil.toJsonString(snapshotList);
|
||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
case GETLINKTARGET: {
|
||||
String target = cp.getLinkTarget(fullpath);
|
||||
final String js = JsonUtil.toJsonString("Path", target);
|
||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedOperationException(op + " is not supported");
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ The HTTP REST API supports the complete [FileSystem](../../api/org/apache/hadoop
|
||||
* [`GETFILEBLOCKLOCATIONS`](#Get_File_Block_Locations) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getFileBlockLocations)
|
||||
* [`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)
|
||||
* 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)
|
||||
@ -1139,6 +1140,22 @@ See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).access
|
||||
|
||||
See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getServerDefaults
|
||||
|
||||
### Get Link Target
|
||||
|
||||
* Submit a HTTP GET request.
|
||||
|
||||
curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETLINKTARGET"
|
||||
|
||||
The client receives a response with a [`Path` JSON object](#Path_JSON_Schema):
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
{"Path": "/user/username/targetFile"}
|
||||
|
||||
See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getLinkTarget
|
||||
|
||||
Storage Policy Operations
|
||||
-------------------------
|
||||
|
||||
|
@ -2202,6 +2202,34 @@ public void testStatistics() throws Exception {
|
||||
cluster.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkTarget() throws Exception {
|
||||
final Configuration conf = WebHdfsTestUtil.createConf();
|
||||
try {
|
||||
cluster = new MiniDFSCluster.Builder(conf)
|
||||
.numDataNodes(3)
|
||||
.build();
|
||||
cluster.waitActive();
|
||||
|
||||
final WebHdfsFileSystem webHdfs =
|
||||
WebHdfsTestUtil.getWebHdfsFileSystem(conf,
|
||||
WebHdfsConstants.WEBHDFS_SCHEME);
|
||||
|
||||
// Symbolic link
|
||||
Path root = new Path("/webHdfsTest/");
|
||||
Path targetFile = new Path(root, "debug.log");
|
||||
FileSystemTestHelper.createFile(webHdfs, targetFile);
|
||||
|
||||
Path symLink = new Path(root, "debug.link");
|
||||
|
||||
webHdfs.createSymlink(targetFile, symLink, false);
|
||||
assertEquals(webHdfs.getLinkTarget(symLink), targetFile);
|
||||
} finally {
|
||||
cluster.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FileStatus JSONObject from ListStatus response.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user