学习 HDFS(十一):WebHDFS

除了 Hadoop 官方提供的基于 Java 的 Apache Hadoop HDFS Client 和基于 C 的 libhdfs 之外,HDFS 还提供了 REST API 操作 HDFS —— WebHDFS。

操作

显示文件状态

显示 /data 文件夹状态:

curl -i "http://RESOURCE_MANAGER:50070/webhdfs/v1/data?op=GETFILESTATUS"  

文件存在:

HTTP/1.1 200 OK  
Cache-Control: no-cache  
Expires: Tue, 25 Jun 2019 01:52:52 GMT  
Date: Tue, 25 Jun 2019 01:52:52 GMT  
Pragma: no-cache  
Expires: Tue, 25 Jun 2019 01:52:52 GMT  
Date: Tue, 25 Jun 2019 01:52:52 GMT  
Pragma: no-cache  
Content-Type: application/json  
Transfer-Encoding: chunked  
Server: Jetty(6.1.26.cloudera.4)

{"FileStatus":{"accessTime":0,"blockSize":0,"childrenNum":1,"fileId":23041928,"group":"dev","length":0,"modificationTime":1561427484230,"owner":"dyingbleed","pathSuffix":"","permission":"777","replication":0,"storagePolicy":0,"type":"DIRECTORY"}}

文件不存在:

HTTP/1.1 404 Not Found  
Cache-Control: no-cache  
Expires: Tue, 25 Jun 2019 01:52:33 GMT  
Date: Tue, 25 Jun 2019 01:52:33 GMT  
Pragma: no-cache  
Expires: Tue, 25 Jun 2019 01:52:33 GMT  
Date: Tue, 25 Jun 2019 01:52:33 GMT  
Pragma: no-cache  
Content-Type: application/json  
Transfer-Encoding: chunked  
Server: Jetty(6.1.26.cloudera.4)

{"RemoteException":{"exception":"FileNotFoundException","javaClassName":"java.io.FileNotFoundException","message":"File does not exist: /data"}}

参考