HDFS-17083. Support getErasureCodeCodecs API in WebHDFS (#5836). Contributed by Hualong Zhang.
Reviewed-by: Shilun Fan <slfan1989@apache.org> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
parent
4c8d048f25
commit
dfb351c3a8
@ -75,6 +75,7 @@
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -867,6 +868,15 @@ public static ErasureCodingPolicyInfo toECPolicyInfo(Map<?, ?> m) {
|
||||
return new ErasureCodingPolicyInfo(ecPolicy, ecPolicyState);
|
||||
}
|
||||
|
||||
public static Map<String, String> getErasureCodeCodecs(Map<?, ?> json) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<?, ?> m = (Map<?, ?>) json.get("ErasureCodingCodecs");
|
||||
m.forEach((key, value) -> {
|
||||
map.put((String) key, (String) value);
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
private static List<SnapshotDiffReport.DiffReportEntry> toDiffList(
|
||||
List<?> objs) {
|
||||
if (objs == null) {
|
||||
|
@ -2206,6 +2206,19 @@ Collection<ErasureCodingPolicyInfo> decodeResponse(Map<?, ?> json) {
|
||||
}.run();
|
||||
}
|
||||
|
||||
public Map<String, String> getAllErasureCodingCodecs()
|
||||
throws IOException {
|
||||
statistics.incrementReadOps(1);
|
||||
storageStatistics.incrementOpCounter(OpType.GET_EC_CODECS);
|
||||
final HttpOpParam.Op op = GetOpParam.Op.GETECCODECS;
|
||||
return new FsPathResponseRunner<Map<String, String>>(op, null) {
|
||||
@Override
|
||||
Map<String, String> decodeResponse(Map<?, ?> json) {
|
||||
return JsonUtilClient.getErasureCodeCodecs(json);
|
||||
}
|
||||
}.run();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
InetSocketAddress[] getResolvedNNAddr() {
|
||||
return nnAddrs;
|
||||
|
@ -68,6 +68,7 @@ public enum Op implements HttpOpParam.Op {
|
||||
GETFILELINKSTATUS(false, HttpURLConnection.HTTP_OK),
|
||||
GETSTATUS(false, HttpURLConnection.HTTP_OK),
|
||||
GETECPOLICIES(false, HttpURLConnection.HTTP_OK),
|
||||
GETECCODECS(false, HttpURLConnection.HTTP_OK),
|
||||
GETSNAPSHOTLIST(false, HttpURLConnection.HTTP_OK);
|
||||
|
||||
final boolean redirect;
|
||||
|
@ -33,6 +33,7 @@
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@ -1413,6 +1414,11 @@ protected Response get(
|
||||
final String js = JsonUtil.toJsonString(ecPolicyInfos);
|
||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
case GETECCODECS: {
|
||||
Map<String, String> ecCodecs = cp.getErasureCodingCodecs();
|
||||
final String js = JsonUtil.toJsonString("ErasureCodingCodecs", ecCodecs);
|
||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedOperationException(op + " is not supported");
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ The HTTP REST API supports the complete [FileSystem](../../api/org/apache/hadoop
|
||||
* [`GETFILELINKSTATUS`](#Get_File_Link_Status) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getFileLinkStatus)
|
||||
* [`GETSTATUS`](#Get_Status) (see [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getStatus)
|
||||
* [`GETECPOLICIES`](#Get_EC_Policies)
|
||||
* [`GETECCODECS`](#Get_EC_Codecs)
|
||||
* 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)
|
||||
@ -1252,6 +1253,26 @@ See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getFileLi
|
||||
|
||||
See also: [FileSystem](../../api/org/apache/hadoop/fs/FileSystem.html).getStatus
|
||||
|
||||
### Get EC Codecs
|
||||
|
||||
* Submit a HTTP GET request.
|
||||
|
||||
curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETALLECCODECS"
|
||||
|
||||
The client receives a response with a [`ECCodecs` JSON object](#EC_Codecs_JSON_Schema):
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
{
|
||||
"ErasureCodeCodecs": {
|
||||
"rs": "rs_native, rs_java",
|
||||
"rs-legacy": "rs-legacy_java",
|
||||
"xor":"xor_native, xor_java"
|
||||
}
|
||||
}
|
||||
|
||||
Storage Policy Operations
|
||||
-------------------------
|
||||
|
||||
@ -3244,6 +3265,18 @@ var blockLocationProperties =
|
||||
}
|
||||
```
|
||||
|
||||
### EC Codecs JSON Schema
|
||||
|
||||
```json
|
||||
{
|
||||
"ErasureCodingCodecs": {
|
||||
"rs": "rs_native, rs_java",
|
||||
"rs-legacy": "rs-legacy_java",
|
||||
"xor": "xor_native, xor_java"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
HTTP Query Parameter Dictionary
|
||||
-------------------------------
|
||||
|
||||
|
@ -2318,6 +2318,30 @@ public void testGetErasureCodingPolicies() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllErasureCodingCodecs() throws Exception {
|
||||
final Configuration conf = WebHdfsTestUtil.createConf();
|
||||
cluster = new MiniDFSCluster.Builder(conf).build();
|
||||
try {
|
||||
cluster.waitActive();
|
||||
|
||||
final WebHdfsFileSystem webHdfs =
|
||||
WebHdfsTestUtil.getWebHdfsFileSystem(conf,
|
||||
WebHdfsConstants.WEBHDFS_SCHEME);
|
||||
|
||||
final DistributedFileSystem dfs = cluster.getFileSystem();
|
||||
|
||||
Map<String, String> webHdfsEcCodecs = webHdfs.getAllErasureCodingCodecs();
|
||||
|
||||
Map<String, String> dfsEcCodecs = dfs.getAllErasureCodingCodecs();
|
||||
|
||||
//Validate erasureCodingCodecs are the same as DistributedFileSystem
|
||||
assertEquals(webHdfsEcCodecs, dfsEcCodecs);
|
||||
} finally {
|
||||
cluster.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FileStatus JSONObject from ListStatus response.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user