WebHDFS REST API

文档约定

Monospaced Used for commands, HTTP request and responses and code blocks.
<Monospaced> User entered values.
[Monospaced] Optional values. When the value is not specified, the default value is used.
斜体 重要短语和词汇。

简介

HTTP REST API 支持完整的HDFS FileSystem/FileContext接口。下一节将展示这些操作及其对应的FileSystem/FileContext方法。HTTP Query Parameter Dictionary章节详细说明了参数的默认值和有效值等细节。

操作

文件系统URI与HTTP URL对比

WebHDFS 的文件系统方案是“webhdfs://”。WebHDFS 文件系统 URI 的格式如下。

  webhdfs://<HOST>:<HTTP_PORT>/<PATH>

上述WebHDFS URI对应以下HDFS URI。

  hdfs://<HOST>:<RPC_PORT>/<PATH>

在REST API中,路径前缀会插入"/webhdfs/v1"并在末尾附加查询参数。因此,对应的HTTP URL具有以下格式。

  http://<HOST>:<HTTP_PORT>/webhdfs/v1/<PATH>?op=...

注意,如果WebHDFS启用了SSL安全连接,那么协议方案应为“swebhdfs://”。

  swebhdfs://<HOST>:<HTTP_PORT>/<PATH>

另请参阅:SSL Configurations for SWebHDFS

HDFS 配置选项

以下是WebHDFS的HDFS配置选项。

属性名称 描述
dfs.web.authentication.kerberos.principal The HTTP Kerberos principal used by Hadoop-Auth in the HTTP endpoint. The HTTP Kerberos principal MUST start with ‘HTTP/’ per Kerberos HTTP SPNEGO specification. A value of “*” will use all HTTP principals found in the keytab.
dfs.web.authentication.kerberos.keytab The Kerberos keytab file with the credentials for the HTTP Kerberos principal used by Hadoop-Auth in the HTTP endpoint.
dfs.webhdfs.socket.connect-timeout How long to wait for a connection to be established before failing. Specified as a time duration, ie numerical value followed by a units symbol, eg 2m for two minutes. Defaults to 60s.
dfs.webhdfs.socket.read-timeout How long to wait for data to arrive before failing. Defaults to 60s.

认证

当安全功能处于关闭状态时,认证用户即为user.name查询参数中指定的用户名。如果未设置user.name参数,服务器可能会将认证用户设为默认的Web用户(如果存在),或者返回错误响应。

当安全机制启用时,认证将通过Hadoop委托令牌或Kerberos SPNEGO进行。如果在delegation查询参数中设置了令牌,则认证用户为令牌中编码的用户。如果未设置delegation参数,则用户将通过Kerberos SPNEGO进行认证。

以下是使用curl命令行工具的示例。

  1. 安全关闭时的认证:

    curl -i "http://:/webhdfs/v1/?[user.name=&]op=..."
    
  2. 在启用安全认证时使用Kerberos SPNEGO进行身份验证:

    curl -i --negotiate -u : "http://:/webhdfs/v1/?op=..."
    
  3. 在启用安全认证时使用Hadoop委托令牌进行身份验证:

    curl -i "http://:/webhdfs/v1/?delegation=&op=..."
    

另请参阅:Authentication for Hadoop HTTP web-consoles

此外,WebHDFS在客户端支持OAuth2协议。目前Namenode和Datanode尚不支持使用OAuth2的客户端,但其他实现了WebHDFS REST接口的后端系统可能支持。

WebHDFS默认支持两种OAuth2授权码模式(用户提供的刷新令牌与访问令牌,或用户提供的凭证),并提供了可插拔机制用于根据OAuth2 RFC规范实现其他OAuth2认证方式或自定义认证。当使用任一内置的授权码机制时,WebHDFS客户端会在必要时自动刷新访问令牌。

OAuth2 应仅针对未使用 Kerberos SPENGO 运行的客户端启用。

OAuth2 code grant mechanism Description Value of dfs.webhdfs.oauth2.access.token.provider that implements code grant
授权码授权 用户提供初始访问令牌和刷新令牌,这些令牌随后分别用于验证WebHDFS请求和获取替换访问令牌。 org.apache.hadoop.hdfs.web.oauth2.ConfRefreshTokenBasedAccessTokenProvider
客户端凭证授权 用户提供凭证用于获取访问令牌,这些令牌随后用于验证WebHDFS请求。 org.apache.hadoop.hdfs.web.oauth2.ConfCredentialBasedAccessTokenProvider

以下属性控制OAuth2认证。

OAuth2 相关属性 描述
dfs.webhdfs.oauth2.enabled Boolean to enable/disable OAuth2 authentication
dfs.webhdfs.oauth2.access.token.provider Class name of an implementation of org.apache.hadoop.hdfs.web.oauth.AccessTokenProvider. Two are provided with the code, as described above, or the user may specify a user-provided implementation. The default value for this configuration key is the ConfCredentialBasedAccessTokenProvider implementation.
dfs.webhdfs.oauth2.client.id Client id used to obtain access token with either credential or refresh token
dfs.webhdfs.oauth2.refresh.url URL against which to post for obtaining bearer token with either credential or refresh token
dfs.webhdfs.oauth2.access.token (required if using ConfRefreshTokenBasedAccessTokenProvider) Initial access token with which to authenticate
dfs.webhdfs.oauth2.refresh.token (required if using ConfRefreshTokenBasedAccessTokenProvider) Initial refresh token to use to obtain new access tokens
dfs.webhdfs.oauth2.refresh.token.expires.ms.since.epoch (required if using ConfRefreshTokenBasedAccessTokenProvider) Access token expiration measured in milliseconds since Jan 1, 1970. Note this is a different value than provided by OAuth providers and has been munged as described in interface to be suitable for a client application
dfs.webhdfs.oauth2.credential (required if using ConfCredentialBasedAccessTokenProvider). Credential used to obtain initial and subsequent access tokens.

SWebHDFS的SSL配置

要使用SWebHDFS文件系统(即使用swebhdfs协议),需要在客户端指定一个SSL配置文件。该文件必须包含以下3个参数:

SSL属性 描述
ssl.client.truststore.location The local-filesystem location of the trust-store file, containing the certificate for the NameNode.
ssl.client.truststore.type (Optional) The format of the trust-store file.
ssl.client.truststore.password (Optional) Password for the trust-store file.

以下是一个SSL配置文件的示例(ssl-client.xml):

<configuration>
  <property>
    <name>ssl.client.truststore.location</name>
    <value>/work/keystore.jks</value>
    <description>Truststore to be used by clients. Must be specified.</description>
  </property>

  <property>
    <name>ssl.client.truststore.password</name>
    <value>changeme</value>
    <description>Optional. Default value is "".</description>
  </property>

  <property>
    <name>ssl.client.truststore.type</name>
    <value>jks</value>
    <description>Optional. Default value is "jks".</description>
  </property>
</configuration>

SSL配置文件必须位于客户端程序的类路径中,且文件名需要在core-site.xml中指定:

<property>
  <name>hadoop.ssl.client.conf</name>
  <value>ssl-client.xml</value>
  <description>
    Resource file from which ssl client keystore information will be extracted.
    This file is looked up in the classpath, typically it should be in Hadoop
    conf/ directory. Default value is "ssl-client.xml".
  </description>
</property>

代理用户

当代理用户功能启用时,代理用户P可以代表另一个用户U提交请求。除非在认证中提供了委托令牌,否则必须在doas查询参数中指定用户U的用户名。在这种情况下,用户PU的信息都必须编码在委托令牌中。

  1. 当安全关闭时的代理请求:

    curl -i "http://:/webhdfs/v1/?[user.name=&]doas=&op=..."
    
  2. 当安全认证开启时,使用Kerberos SPNEGO的代理请求:

    curl -i --negotiate -u : "http://:/webhdfs/v1/?doas=&op=..."
    
  3. 在安全模式下使用Hadoop委托令牌的代理请求:

    curl -i "http://:/webhdfs/v1/?delegation=&op=..."
    

跨站请求伪造防护

WebHDFS支持一个可选的、可配置的跨站请求伪造(CSRF)防护机制。启用该功能后,发送至NameNode或DataNode的WebHDFS HTTP请求必须包含一个自定义HTTP头部。通过配置属性可以调整受保护的具体HTTP方法以及HTTP头部的名称。头部中发送的具体值无关紧要,只需确保存在该名称的头部即可。

启用CSRF防护还会配置WebHdfsFileSystem类发送所需的请求头。这确保当使用webhdfs: URI时,像hdfs dfshadoop distcp这样的CLI命令能继续正常工作。

启用CSRF防护还会设置NameNode网页界面发送所需的标头。在启用CSRF防护并重启NameNode后,现有NameNode网页界面的用户需要刷新浏览器以重新加载页面并获取新配置。

以下属性控制CSRF防护。

属性 描述 默认值
dfs.webhdfs.rest-csrf.enabled If true, then enables WebHDFS protection against cross-site request forgery (CSRF). The WebHDFS client also uses this property to determine whether or not it needs to send the custom CSRF prevention header in its HTTP requests. false
dfs.webhdfs.rest-csrf.custom-header The name of a custom header that HTTP requests must send when protection against cross-site request forgery (CSRF) is enabled for WebHDFS by setting dfs.webhdfs.rest-csrf.enabled to true. The WebHDFS client also uses this property to determine whether or not it needs to send the custom CSRF prevention header in its HTTP requests. X-XSRF-HEADER
dfs.webhdfs.rest-csrf.methods-to-ignore A comma-separated list of HTTP methods that do not require HTTP requests to include a custom header when protection against cross-site request forgery (CSRF) is enabled for WebHDFS by setting dfs.webhdfs.rest-csrf.enabled to true. The WebHDFS client also uses this property to determine whether or not it needs to send the custom CSRF prevention header in its HTTP requests. GET,OPTIONS,HEAD,TRACE
dfs.webhdfs.rest-csrf.browser-useragents-regex A comma-separated list of regular expressions used to match against an HTTP request’s User-Agent header when protection against cross-site request forgery (CSRF) is enabled for WebHDFS by setting dfs.webhdfs.reset-csrf.enabled to true. If the incoming User-Agent matches any of these regular expressions, then the request is considered to be sent by a browser, and therefore CSRF prevention is enforced. If the request’s User-Agent does not match any of these regular expressions, then the request is considered to be sent by something other than a browser, such as scripted automation. In this case, CSRF is not a potential attack vector, so the prevention is not enforced. This helps achieve backwards-compatibility with existing automation that has not been updated to send the CSRF prevention header. ^Mozilla.*,^Opera.*
dfs.datanode.httpserver.filter.handlers Comma separated list of Netty servlet-style filter handlers to inject into the Datanode WebHDFS I/O path org.apache.hadoop.hdfs.server.datanode.web.RestCsrfPreventionFilterHandler

以下是一个使用curl命令的示例,其中通过-H选项在请求中包含自定义头部。

    curl -i -L -X PUT -H 'X-XSRF-HEADER: ""' 'http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATE'

WebHDFS 重试策略

WebHDFS支持可选的、可配置的重试策略,用于处理可能超时的大文件弹性复制,或在复制过程中可能发生故障转移的高可用性集群之间复制文件。

以下属性控制WebHDFS的重试和故障转移策略。

属性 描述 默认值
dfs.http.client.retry.policy.enabled If “true”, enable the retry policy of WebHDFS client. If “false”, retry policy is turned off. false
dfs.http.client.retry.policy.spec Specify a policy of multiple linear random retry for WebHDFS client, e.g. given pairs of number of retries and sleep time (n0, t0), (n1, t1), …, the first n0 retries sleep t0 milliseconds on average, the following n1 retries sleep t1 milliseconds on average, and so on. 10000,6,60000,10
dfs.http.client.failover.max.attempts Specify the max number of failover attempts for WebHDFS client in case of network exception. 15
dfs.http.client.retry.max.attempts Specify the max number of retry attempts for WebHDFS client, if the difference between retried attempts and failovered attempts is larger than the max number of retry attempts, there will be no more retries. 10
dfs.http.client.failover.sleep.base.millis Specify the base amount of time in milliseconds upon which the exponentially increased sleep time between retries or failovers is calculated for WebHDFS client. 500
dfs.http.client.failover.sleep.max.millis Specify the upper bound of sleep time in milliseconds between retries or failovers for WebHDFS client. 15000

WebHDFS 请求过滤

可以通过WebHDFS协议控制数据的单向传输,仅允许从不安全网络写入数据。要实现此功能,必须确保dfs.datanode.httpserver.filter.handlers包含org.apache.hadoop.hdfs.server.datanode.web.HostRestrictingAuthorizationFilterHandlerHostRestrictingAuthorizationFilter的配置通过以下属性进行控制。

属性 描述 默认值
dfs.datanode.httpserver.filter.handlers Comma separated list of Netty servlet-style filter handlers to inject into the Datanode WebHDFS I/O path org.apache.hadoop.hdfs.server.datanode.web.RestCsrfPreventionFilterHandler
dfs.web.authentication.host.allow.rules Rules allowing users to read files in the format of user,network/bits,path glob newline or |-separated. Use * for a wildcard of all users or network/bits. nothing - defaults to no one may read via WebHDFS

文件和目录操作

创建并写入文件

  • 步骤1:提交一个HTTP PUT请求,不自动跟随重定向且不发送文件数据。

    curl -i -X PUT "http://:/webhdfs/v1/?op=CREATE
                        [&overwrite=][&blocksize=][&replication=]
                        [&permission=][&buffersize=][&noredirect=]"
    

    通常该请求会被重定向到将要写入文件数据的数据节点。

    HTTP/1.1 307 TEMPORARY_REDIRECT
    Location: http://:/webhdfs/v1/?op=CREATE...
    Content-Length: 0
    

    但是,如果您不希望自动重定向,可以设置noredirect标志。

    HTTP/1.1 200 OK
    Content-Type: application/json
    {"Location":"http://:/webhdfs/v1/?op=CREATE..."}
    
  • 步骤2:使用Location头部中的URL(如果指定了noredirect则使用返回的响应)提交另一个HTTP PUT请求,附带要写入的文件数据。

    curl -i -X PUT -T  "http://:/webhdfs/v1/?op=CREATE..."
    

    客户端会收到一个内容长度为零的201 Created响应,并在Location头部中包含文件的WebHDFS URI:

    HTTP/1.1 201 Created
    Location: webhdfs://:/
    Content-Length: 0
    

    如果未指定权限,新创建的文件将被赋予默认的644权限。服务器端不会应用umask模式(因此在Namenode端设置的"fs.permissions.umask-mode"值配置将不会生效)。

注意采用两步创建/追加操作的原因是为了防止客户端在重定向前发送数据。HTTP/1.1中通过"Expect: 100-continue"标头解决了这个问题;详见RFC 2616, Section 8.2.3。遗憾的是,某些软件库存在缺陷(例如Jetty 6 HTTP服务器和Java 6 HTTP客户端),未能正确实现"Expect: 100-continue"功能。两步创建/追加操作是针对这些软件库缺陷的临时解决方案。

另请参阅:overwrite, blocksize, replication, permission, buffersize, FileSystem.create

追加到文件

  • 第一步:提交一个HTTP POST请求,不自动跟随重定向且不发送文件数据。
    curl -i -X POST "http://:/webhdfs/v1/?op=APPEND[&buffersize=][&noredirect=]"
    

    通常该请求会被重定向到将要追加文件数据的数据节点:

    HTTP/1.1 307 TEMPORARY_REDIRECT
    Location: http://:/webhdfs/v1/?op=APPEND...
    Content-Length: 0
    

但是,如果您不希望被自动重定向,可以设置noredirect标志。

    HTTP/1.1 200 OK
    Content-Type: application/json
    {"Location":"http://<DATANODE>:<PORT>/webhdfs/v1/<PATH>?op=APPEND..."}
  • 步骤2:使用Location头部中的URL(如果指定了noredirect则使用返回的响应)提交另一个HTTP POST请求,附带要追加的文件数据。
    curl -i -X POST -T  "http://:/webhdfs/v1/?op=APPEND..."
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

关于此操作需要两个步骤的原因说明,请参阅上一节的注释。

另请参阅:buffersize, FileSystem.append

合并文件

  • 提交一个HTTP POST请求。
    curl -i -X POST "http://:/webhdfs/v1/?op=CONCAT&sources="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:sources, FileSystem.concat

打开并读取文件

  • 提交一个会自动跟随重定向的HTTP GET请求。
    curl -i -L "http://:/webhdfs/v1/?op=OPEN
                        [&offset=][&length=][&buffersize=][&noredirect=]"
    

    通常该请求会被重定向到可以读取文件数据的数据节点:

    HTTP/1.1 307 TEMPORARY_REDIRECT
    Location: http://:/webhdfs/v1/?op=OPEN...
    Content-Length: 0
    

    但如果您不希望自动重定向,可以设置noredirect标志。

    HTTP/1.1 200 OK
    Content-Type: application/json
    {"Location":"http://:/webhdfs/v1/?op=OPEN..."}
    

    客户端跟随重定向到数据节点并接收文件数据:

    HTTP/1.1 200 OK
    Content-Type: application/octet-stream
    Content-Length: 22
    
    Hello, webhdfs user!
    

另请参阅:offset, length, buffersize, FileSystem.open

创建目录

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=MKDIRS[&permission=]"
    

    客户端会收到包含boolean JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"boolean": true}
    

    如果未指定权限,新创建的目录将默认具有755权限。服务器端不会应用umask模式(因此在Namenode端设置的"fs.permissions.umask-mode"配置值将不会生效)。

另请参阅: permission, FileSystem.mkdirs

创建符号链接

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=CREATESYMLINK
                                  &destination=[&createParent=]"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅: destination, createParent, FileSystem.createSymlink

重命名文件/目录

  • 提交一个HTTP PUT请求。
    curl -i -X PUT ":/webhdfs/v1/?op=RENAME&destination="
    

    客户端会收到包含boolean JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"boolean": true}
    

另请参阅:destination, FileSystem.rename

删除文件/目录

  • 提交HTTP DELETE请求。
    curl -i -X DELETE "http://:/webhdfs/v1/?op=DELETE
                                  [&recursive=]"
    

    客户端会收到包含boolean JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"boolean": true}
    

另请参阅:recursive, FileSystem.delete

截断文件

  • 提交一个HTTP POST请求。
    curl -i -X POST "http://:/webhdfs/v1/?op=TRUNCATE&newlength="
    

    客户端会收到包含boolean JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"boolean": true}
    

另请参阅:newlength, FileSystem.truncate

文件/目录状态

  • 提交一个HTTP GET请求。
    curl -i  "http://:/webhdfs/v1/?op=GETFILESTATUS"
    

    客户端会收到包含FileStatus JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
      "FileStatus":
      {
        "accessTime"      : 0,
        "blockSize"       : 0,
        "group"           : "supergroup",
        "length"          : 0,             //以字节为单位,目录为零
        "modificationTime": 1320173277227,
        "owner"           : "webuser",
        "pathSuffix"      : "",
        "permission"      : "777",
        "replication"     : 0,
        "snapshotEnabled" : true
        "type"            : "DIRECTORY"    //枚举类型 {文件, 目录, 符号链接}
        "ecPolicy"        : "RS-6-3-1024k"
      }
    }
    

另请参阅:FileSystem.getFileStatus

列出目录

  • 提交一个HTTP GET请求。
    curl -i  "http://:/webhdfs/v1/?op=LISTSTATUS"
    

    客户端将收到包含FileStatuses JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Content-Length: 427
    
    {
      "FileStatuses":
      {
        "FileStatus":
        [
          {
            "accessTime"      : 1320171722771,
            "blockSize"       : 33554432,
            "childrenNum"     : 0,
            "fileId"          : 16388,
            "group"           : "supergroup",
            "length"          : 24930,
            "modificationTime": 1320171722771,
            "owner"           : "webuser",
            "pathSuffix"      : "a.patch",
            "permission"      : "644",
            "replication"     : 1,
            "storagePolicy"   : 0,
            "type"            : "FILE"
          },
          {
            "accessTime"      : 0,
            "blockSize"       : 0,
            "childrenNum"     : 0,
            "fileId"          : 16389,
            "group"           : "supergroup",
            "length"          : 0,
            "modificationTime": 1320895981256,
            "owner"           : "username",
            "pathSuffix"      : "bar",
            "permission"      : "711",
            "replication"     : 0,
            "snapshotEnabled" : true
            "type"            : "DIRECTORY"
          },
          ...
        ]
      }
    }
    

另请参阅: FileSystem.listStatus

列出文件

  • 提交一个HTTP GET请求。
    curl -i  "http://:/webhdfs/v1/?op=LISTSTATUS"
    

    客户端将收到包含FileStatuses JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Content-Length: 427
    
    {
      "FileStatuses":
      {
        "FileStatus":
        [
          {
            "accessTime"      : 1320171722771,
            "blockSize"       : 33554432,
            "childrenNum"     : 0,
            "fileId"          : 16390,
            "group"           : "supergroup",
            "length"          : 1366,
            "modificationTime": 1501770633062,
            "owner"           : "webuser",
            "pathSuffix"      : "",
            "permission"      : "644",
            "replication"     : 1,
            "storagePolicy"   : 0,
            "type"            : "FILE"
          }
        ]
      }
    }
    

另请参阅:FileSystem.listStatus

迭代列出目录

  • 提交一个HTTP GET请求。
    curl -i  "http://:/webhdfs/v1/?op=LISTSTATUS_BATCH&startAfter="
    

    客户端会收到包含DirectoryListing JSON对象的响应,该对象包含一个FileStatuses JSON对象以及迭代信息:

    HTTP/1.1 200 OK
    Cache-Control: no-cache
    Expires: Thu, 08 Sep 2016 03:40:38 GMT
    Date: Thu, 08 Sep 2016 03:40:38 GMT
    Pragma: no-cache
    Expires: Thu, 08 Sep 2016 03:40:38 GMT
    Date: Thu, 08 Sep 2016 03:40:38 GMT
    Pragma: no-cache
    Content-Type: application/json
    X-FRAME-OPTIONS: SAMEORIGIN
    Transfer-Encoding: chunked
    Server: Jetty(6.1.26)
    
    {
        "DirectoryListing": {
            "partialListing": {
                "FileStatuses": {
                    "FileStatus": [
                        {
                            "accessTime": 0,
                            "blockSize": 0,
                            "childrenNum": 0,
                            "fileId": 16387,
                            "group": "supergroup",
                            "length": 0,
                            "modificationTime": 1473305882563,
                            "owner": "andrew",
                            "pathSuffix": "bardir",
                            "permission": "755",
                            "replication": 0,
                            "storagePolicy": 0,
                            "type": "DIRECTORY"
                        },
                        {
                            "accessTime": 1473305896945,
                            "blockSize": 1024,
                            "childrenNum": 0,
                            "fileId": 16388,
                            "group": "supergroup",
                            "length": 0,
                            "modificationTime": 1473305896965,
                            "owner": "andrew",
                            "pathSuffix": "bazfile",
                            "permission": "644",
                            "replication": 3,
                            "storagePolicy": 0,
                            "type": "FILE"
                        }
                    ]
                }
            },
            "remainingEntries": 2
        }
    }
    

如果remainingEntries不为零,表示目录中还有更多条目。要查询下一批数据,请将startAfter参数设置为当前批次返回的最后一项的pathSuffix。例如:

    curl -i  "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS_BATCH&startAfter=bazfile"

这将返回下一批目录条目:

    HTTP/1.1 200 OK
    Cache-Control: no-cache
    Expires: Thu, 08 Sep 2016 03:43:20 GMT
    Date: Thu, 08 Sep 2016 03:43:20 GMT
    Pragma: no-cache
    Expires: Thu, 08 Sep 2016 03:43:20 GMT
    Date: Thu, 08 Sep 2016 03:43:20 GMT
    Pragma: no-cache
    Content-Type: application/json
    X-FRAME-OPTIONS: SAMEORIGIN
    Transfer-Encoding: chunked
    Server: Jetty(6.1.26)

    {
        "DirectoryListing": {
            "partialListing": {
                "FileStatuses": {
                    "FileStatus": [
                        {
                            "accessTime": 0,
                            "blockSize": 0,
                            "childrenNum": 0,
                            "fileId": 16386,
                            "group": "supergroup",
                            "length": 0,
                            "modificationTime": 1473305878951,
                            "owner": "andrew",
                            "pathSuffix": "foodir",
                            "permission": "755",
                            "replication": 0,
                            "storagePolicy": 0,
                            "type": "DIRECTORY"
                        },
                        {
                            "accessTime": 1473305902864,
                            "blockSize": 1024,
                            "childrenNum": 0,
                            "fileId": 16389,
                            "group": "supergroup",
                            "length": 0,
                            "modificationTime": 1473305902878,
                            "owner": "andrew",
                            "pathSuffix": "quxfile",
                            "permission": "644",
                            "replication": 3,
                            "storagePolicy": 0,
                            "type": "FILE"
                        }
                    ]
                }
            },
            "remainingEntries": 0
        }
    }

批量大小由NameNode上的dfs.ls.limit选项控制。

另请参阅:FileSystem.listStatusIterator

其他文件系统操作

获取目录的内容摘要

  • 提交HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETCONTENTSUMMARY"
    

    客户端将收到包含ContentSummary JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
      "ContentSummary":
      {
        "directoryCount": 2,
        "ecPolicy"      : "RS-6-3-1024k",
        "fileCount"     : 1,
        "length"        : 24930,
        "quota"         : -1,
        "spaceConsumed" : 24930,
        "spaceQuota"    : -1,
        "typeQuota":
        {
          "ARCHIVE":
          {
            "consumed": 500,
            "quota": 10000
          },
          "DISK":
          {
            "consumed": 500,
            "quota": 10000
          },
          "SSD":
          {
            "consumed": 500,
            "quota": 10000
          }
        }
      }
    }
    

另请参阅:FileSystem.getContentSummary

获取目录的配额使用情况

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETQUOTAUSAGE"
    

    客户端会收到包含QuotaUsage JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
      "QuotaUsage":
      {
        "fileAndDirectoryCount": 1,
        "quota"         : 100,
        "spaceConsumed" : 24930,
        "spaceQuota"    : 100000,
        "typeQuota":
        {
          "ARCHIVE":
          {
            "consumed": 500,
            "quota": 10000
          },
          "DISK":
          {
            "consumed": 500,
            "quota": 10000
          },
          "SSD":
          {
            "consumed": 500,
            "quota": 10000
          }
        }
      }
    }
    

另请参阅:FileSystem.getQuotaUsage

设置配额

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETQUOTA
                                  &namespacequota=[&storagespacequota=]"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.setQuota

按存储类型设置配额

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETQUOTABYSTORAGETYPE
                                  &storagetype=&storagespacequota="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.setQuotaByStorageType

获取文件校验和

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETFILECHECKSUM"
    

    通常该请求会被重定向到数据节点:

    HTTP/1.1 307 TEMPORARY_REDIRECT
    Location: http://:/webhdfs/v1/?op=GETFILECHECKSUM...
    Content-Length: 0
    

    不过,如果您不希望自动重定向,可以设置noredirect标志。

    HTTP/1.1 200 OK
    Content-Type: application/json
    {"Location":"http://:/webhdfs/v1/?op=GETFILECHECKSUM..."}
    

    客户端跟随重定向到数据节点,并接收一个FileChecksum JSON对象

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
      "FileChecksum":
      {
        "algorithm": "MD5-of-1MD5-of-512CRC32",
        "bytes"    : "eadb10de24aa315748930df6e185c0d ...",
        "length"   : 28
      }
    }
    

另请参阅:FileSystem.getFileChecksum

获取主目录

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETHOMEDIRECTORY"
    

    客户端会收到包含Path JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"Path": "/user/username"}
    

另请参阅:FileSystem.getHomeDirectory

获取回收站根目录

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETTRASHROOT"
    

    客户端会收到一个包含Path JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"Path": "/user/username/.Trash"}
    

    如果路径是加密区域路径且用户有该路径的权限,客户端将收到如下响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"Path": "/PATH/.Trash/username"}
    

另请参阅:FileSystem.getTrashRoot

有关加密区域中垃圾回收根目录的更多详情,请参阅透明加密指南

设置权限

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETPERMISSION
                                  [&permission=]"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:permission, FileSystem.setPermission

设置所有者

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETOWNER
                                  [&owner=][&group=]"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅: owner, group, FileSystem.setOwner

设置复制因子

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETREPLICATION
                                  [&replication=]"
    

    客户端会收到包含boolean JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"boolean": true}
    

另请参阅:replication, FileSystem.setReplication

设置访问或修改时间

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETTIMES
                                  [&modificationtime=

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅: modificationtime, accesstime, FileSystem.setTimes

修改ACL条目

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=MODIFYACLENTRIES
                                  &aclspec="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.modifyAclEntries

移除ACL条目

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=REMOVEACLENTRIES
                                  &aclspec="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.removeAclEntries

移除默认ACL

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=REMOVEDEFAULTACL"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.removeDefaultAcl

移除ACL

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=REMOVEACL"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.removeAcl

设置ACL

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETACL
                                  &aclspec="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.setAcl

获取ACL状态

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETACLSTATUS"
    

    客户端将收到包含AclStatus JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "AclStatus": {
            "entries": [
                "user:carla:rw-", 
                "group::r-x"
            ], 
            "group": "supergroup", 
            "owner": "hadoop", 
            "permission":"775",
            "stickyBit": false
        }
    }
    

另请参阅:FileSystem.getAclStatus

检查访问权限

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=CHECKACCESS
                                  &fsaction=
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.access

获取服务器默认设置

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETSERVERDEFAULTS"
    

客户端收到一个包含ServerDefaults JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked

    {
        "FsServerDefaults": {
            "replication": 3,
            "encryptDataTransfer": "false",
            "defaultStoragePolicyId":7,
            "writePacketSize": 65536,
            "fileBufferSize": 4096,
            "checksumType": 2,
            "trashInterval": 10080,
            "keyProviderUri": "",
            "blockSize": 134217728,
            "bytesPerChecksum": 512
        }
    }

另请参阅:FileSystem.getServerDefaults

获取链接目标

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETLINKTARGET"
    

    客户端将收到包含Path JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"Path": "/user/username/targetFile"}
    

另请参阅:FileSystem.getLinkTarget

获取文件链接状态

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETFILELINKSTATUS"
    

客户端收到包含FileStatus JSON对象的响应:

    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"
        }
    }

另请参阅:FileSystem.getFileLinkInfo

获取EC策略

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETECPOLICIES"
    

客户端收到一个包含ECPolicies JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked

    {
      "ErasureCodingPolicies": {
        "ErasureCodingPolicyInfo": [
          {
            "state": "ENABLED",
            "policy": {
              "name": "RS-6-3-1024k",
              "schema": {
                "codecName": "rs",
                "numDataUnits": 6,
                "numParityUnits": 3,
                "extraOptions": {}
              },
              "cellSize": 1048576,
              "id": 1,
              "replicationPolicy": false,
              "codecName": "rs",
              "numDataUnits": 6,
              "numParityUnits": 3,
              "systemPolicy": true
            }
          }
        ]
      }
    }

获取状态

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETSTATUS"
    

客户端收到一个包含FsStatus JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked

    {
        "FsStatus": {
            "used": 29229154304,
            "remaining": 292893392896,
            "capacity":322122547200
        }
    }

另请参阅:FileSystem.getStatus

获取EC编解码器

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETALLECCODECS"
    

客户端收到一个包含ECCodecs JSON对象的响应:

    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"
        }
    }

获取回收站根目录

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETTRASHROOTS
                                  &allusers="
    

客户端收到一个包含Paths JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked

    {
        "Paths": [{
            "blocksize": 0,
            "owner": "hadoop",
            "path": "/user/user0/.Trash",
            "length": 0,
            "permission": "755",
            "modification_time": 1693050205747,
            "isdir": true,
            "block_replication": 0,
            "access_time": 0,
            "group": "supergroup"
         }, {
            "blocksize": 0,
            "owner": "hadoop",
            "path": "/user/user1/.Trash",
            "length": 0,
            "permission": "755",
            "modification_time": 1693049382962,
            "isdir": true,
            "block_replication": 0,
            "access_time": 0,
            "group": "supergroup"
         }]
    }

另请参阅:FileSystem.getTrashRoots

存储策略操作

获取所有存储策略

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1?op=GETALLSTORAGEPOLICY"
    

    客户端将收到包含BlockStoragePolicies JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "BlockStoragePolicies": {
            "BlockStoragePolicy": [
               {
                   "copyOnCreateFile": false,
                   "creationFallbacks": [],
                   "id": 2,
                   "name": "COLD",
                   "replicationFallbacks": [],
                   "storageTypes": ["ARCHIVE"]
               },
               {
                   "copyOnCreateFile": false,
                   "creationFallbacks": ["DISK","ARCHIVE"],
                   "id": 5,
                   "name": "WARM",
                   "replicationFallbacks": ["DISK","ARCHIVE"],
                   "storageTypes": ["DISK","ARCHIVE"]
               },
               {
                   "copyOnCreateFile": false,
                   "creationFallbacks": [],
                   "id": 7,
                   "name": "HOT",
                   "replicationFallbacks": ["ARCHIVE"],
                   "storageTypes": ["DISK"]
               },
               {
                   "copyOnCreateFile": false,
                   "creationFallbacks": ["SSD","DISK"],
                   "id": 10,"name": "ONE_SSD",
                   "replicationFallbacks": ["SSD","DISK"],
                   "storageTypes": ["SSD","DISK"]
               },
               {
                   "copyOnCreateFile": false,
                   "creationFallbacks": ["DISK"],
                   "id": 12,
                   "name": "ALL_SSD",
                   "replicationFallbacks": ["DISK"],
                   "storageTypes": ["SSD"]
               },
               {
                   "copyOnCreateFile": false,
                   "creationFallbacks": ["DISK"],
                   "id": 14,
                   "name": "ALL_NVDIMM",
                   "replicationFallbacks": ["DISK"],
                   "storageTypes": ["NVDIMM"]
               },
               {
                   "copyOnCreateFile": true,
                   "creationFallbacks": ["DISK"],
                   "id": 15,
                   "name": "LAZY_PERSIST",
                   "replicationFallbacks": ["DISK"],
                   "storageTypes": ["RAM_DISK","DISK"]
               }
           ]
       }
    }
    

另请参阅:FileSystem.getAllStoragePolicies

设置存储策略

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETSTORAGEPOLICY
                                  &storagepolicy="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.setStoragePolicy

取消存储策略

  • 提交一个HTTP POST请求。
    curl -i -X POST "http://:/webhdfs/v1/?op=UNSETSTORAGEPOLICY"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.unsetStoragePolicy

获取存储策略

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETSTORAGEPOLICY"
    

    客户端将收到包含BlockStoragePolicy JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "BlockStoragePolicy": {
            "copyOnCreateFile": false,
           "creationFallbacks": [],
            "id":7,
            "name":"HOT",
            "replicationFallbacks":["ARCHIVE"],
            "storageTypes":["DISK"]
        }
    }
    

另请参阅:FileSystem.getStoragePolicy

满足存储策略

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SATISFYSTORAGEPOLICY"
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:ArchivalStorage.satisfyStoragePolicy

获取文件块位置

  • 提交HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETFILEBLOCKLOCATIONS
    

    客户端将收到包含BlockLocations JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
      "BlockLocations" :
      {
        "BlockLocation":
        [
          {
            "cachedHosts" : [],
            "corrupt" : false,
            "hosts" : ["host"],
            "length" : 134217728,                             // 该块的长度
            "names" : ["host:ip"],
            "offset" : 0,                                     // 块在文件中的偏移量
            "storageTypes" : ["DISK"],                        // 枚举类型 {RAM_DISK, SSD, DISK, ARCHIVE}
            "topologyPaths" : ["/default-rack/hostname:ip"]
          }, {
            "cachedHosts" : [],
            "corrupt" : false,
            "hosts" : ["host"],
            "length" : 62599364,
            "names" : ["host:ip"],
            "offset" : 134217728,
            "storageTypes" : ["DISK"],
            "topologyPaths" : ["/default-rack/hostname:ip"]
          },
          ...
        ]
      }
    }
    

另请参阅:offset, length, FileSystem.getFileBlockLocations

扩展属性(XAttrs)操作

设置XAttr

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETXATTR
                                  &xattr.name=&xattr.value=
                                  &flag="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.setXAttr

移除XAttr

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=REMOVEXATTR
                                  &xattr.name="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.removeXAttr

获取XAttr

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETXATTRS
                                  &xattr.name=&encoding="
    

    客户端会收到包含XAttrs JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "XAttrs": [
            {
                "name":"XATTRNAME",
                "value":"XATTRVALUE"
            }
        ]
    }
    

另请参阅:FileSystem.getXAttr

获取多个XAttrs

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETXATTRS
                                  &xattr.name=&xattr.name=
                                  &encoding="
    

    客户端会收到包含XAttrs JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "XAttrs": [
            {
                "name":"XATTRNAME1",
                "value":"XATTRVALUE1"
            },
            {
                "name":"XATTRNAME2",
                "value":"XATTRVALUE2"
            }
        ]
    }
    

另请参阅:FileSystem.getXAttrs

获取所有XAttrs

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETXATTRS
                                  &encoding="
    

    客户端会收到包含XAttrs JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "XAttrs": [
            {
                "name":"XATTRNAME1",
                "value":"XATTRVALUE1"
            },
            {
                "name":"XATTRNAME2",
                "value":"XATTRVALUE2"
            },
            {
                "name":"XATTRNAME3",
                "value":"XATTRVALUE3"
            }
        ]
    }
    

另请参阅:FileSystem.getXAttrs

列出所有XAttrs

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=LISTXATTRS"
    

    客户端会收到包含XAttrNames JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "XAttrNames":"[\"XATTRNAME1\",\"XATTRNAME2\",\"XATTRNAME3\"]"
    }
    

另请参阅:FileSystem.listXAttrs

纠删码操作

启用EC策略

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=ENABLEECPOLICY
                                  &ecpolicy="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:HDFSErasureCoding.enablePolicy

禁用EC策略

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=DISABLEECPOLICY
                                  &ecpolicy="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:HDFSErasureCoding.disablePolicy

设置EC策略

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=SETECPOLICY
                                  &ecpolicy="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅: HDFSErasureCoding.setErasureCodingPolicy

获取EC策略

  • 提交一个HTTP GET请求。
    curl -i -X GET "http://:/webhdfs/v1/?op=GETECPOLICY
                                 "
    

客户端收到一个包含ECPolicy JSON对象的响应:

    {
        "name": "RS-10-4-1024k",
        "schema":
        {
        "codecName": "rs",
        "numDataUnits": 10,
        "numParityUnits": 4,
        "extraOptions": {}
        }
        "cellSize": 1048576,
        "id":5,
        "codecname":"rs",
        "numDataUnits": 10,
        "numParityUnits": 4,
        "replicationpolicy":false,
        "systemPolicy":true

    }

另请参阅: HDFSErasureCoding.getErasureCodingPolicy

取消EC策略

  • 提交一个HTTP POST请求。
    curl -i -X POST "http://:/webhdfs/v1/?op=UNSETECPOLICY
                                 "
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:HDFSErasureCoding.unsetErasureCodingPolicy

快照操作

允许快照

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=ALLOWSNAPSHOT"
    

    客户端在成功时会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

禁止快照

  • 提交HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=DISALLOWSNAPSHOT"
    

    客户端在成功时会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

创建快照

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=CREATESNAPSHOT[&snapshotname=]"
    

    客户端会收到包含Path JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"Path": "/user/username/.snapshot/s1"}
    

另请参阅:FileSystem.createSnapshot

删除快照

  • 提交一个HTTP DELETE请求。
    curl -i -X DELETE "http://:/webhdfs/v1/?op=DELETESNAPSHOT&snapshotname="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.deleteSnapshot

重命名快照

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=RENAMESNAPSHOT
                       &oldsnapshotname=&snapshotname="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:FileSystem.renameSnapshot

获取快照差异

  • 提交一个HTTP GET请求。
    curl -i GET "http://:/webhdfs/v1/?op=GETSNAPSHOTDIFF
                       &oldsnapshotname=&snapshotname="
    

    客户端会收到包含SnapshotDiffReport JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"SnapshotDiffReport":{"diffList":[],"fromSnapshot":"s3","snapshotRoot":"/foo","toSnapshot":"s4"}}
    

获取快照差异迭代

  • 提交一个HTTP GET请求。
    curl -i -X GET "http://:/webhdfs/v1/?op=GETSNAPSHOTDIFFLISTING
                       &oldsnapshotname=&snapshotname=&snapshotdiffstartpath=&snapshotdiffindex=
    

    如果未提供snapshotdiffstartpathsnapshotdiffindex参数,则分别使用""(空字符串)和-1作为默认值,表示首次迭代。

    客户端将收到包含SnapshotDiffReportListing JSON对象的响应。lastPathlastIndex的值应分别作为下一次迭代时snapshotdiffstartpathsnapshotdiffindex的参数值。

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"SnapshotDiffReportListing":{"createList":[],"deleteList":[],"isFromEarlier":true,"lastIndex":-1,"lastPath":"","modifyList":[]}}
    

获取可快照目录列表

  • 提交HTTP GET请求。
    curl -i GET "http://:/webhdfs/v1/?user.name=&op=GETSNAPSHOTTABLEDIRECTORYLIST"
    

    如果USER不是hdfs超级用户,该调用仅列出该用户拥有的可快照目录。如果USER是hdfs超级用户,该调用会列出所有可快照目录。客户端将收到包含SnapshottableDirectoryList JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "SnapshottableDirectoryList":
        [
            {
              "dirStatus":
                {
                    "accessTime":0,
                    "blockSize":0,
                    "childrenNum":0,
                    "fileId":16386,
                    "group":"hadoop",
                    "length":0,
                    "modificationTime":1520761889225,
                    "owner":"random",
                    "pathSuffix":"bar",
                    "permission":"755",
                    "replication":0,
                    "storagePolicy":0,
                    "type":"DIRECTORY"
                },
              "parentFullPath":"/",
              "snapshotNumber":0,
              "snapshotQuota":65536
            }
        ]
    }
    

获取快照列表

  • 提交一个HTTP GET请求。
    curl -i GET "http://:/webhdfs/v1/?"
    

    该调用会列出可快照目录的快照列表。客户端将收到包含SnapshotList JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
        "SnapshotList":
        [
            {
              "dirStatus":
                {
                    "accessTime":0,
                    "blockSize":0,
                    "childrenNum":0,
                    "fileId":16386,
                    "group":"hadoop",
                    "length":0,
                    "modificationTime":1520761889225,
                    "owner":"random",
                    "pathSuffix":"bar",
                    "permission":"755",
                    "replication":0,
                    "storagePolicy":0,
                    "type":"DIRECTORY"
                },
              "fullPath":"/",
              "snapshotID":0,
              "deletionStatus":ACTIVE
            }
        ]
    }
    

委托令牌操作

获取委托令牌

  • 提交一个HTTP GET请求。
    curl -i "http://:/webhdfs/v1/?op=GETDELEGATIONTOKEN
                [&renewer=][&service=][&kind=]"
    

    客户端会收到包含Token JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {
      "Token":
      {
        "urlString": "JQAIaG9y..."
      }
    }
    

另请参阅:renewer, FileSystem.getDelegationToken, kind, service

更新委托令牌

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token="
    

    客户端会收到包含long JSON对象的响应:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Transfer-Encoding: chunked
    
    {"long": 1320962673997}           //新的过期时间
    

另请参阅:token, DelegationTokenAuthenticator.renewDelegationToken

取消委托令牌

  • 提交一个HTTP PUT请求。
    curl -i -X PUT "http://:/webhdfs/v1/?op=CANCELDELEGATIONTOKEN&token="
    

    客户端会收到一个内容长度为零的响应:

    HTTP/1.1 200 OK
    Content-Length: 0
    

另请参阅:token, DelegationTokenAuthenticator.cancelDelegationToken

错误响应

当操作失败时,服务器可能会抛出异常。错误响应的JSON模式定义在RemoteException JSON Schema中。下表展示了异常到HTTP响应代码的映射关系。

HTTP响应码

异常 HTTP响应码
IllegalArgumentException 400 Bad Request
UnsupportedOperationException 400 Bad Request
SecurityException 401 Unauthorized
IOException 403 Forbidden
FileNotFoundException 404 Not Found
RuntimeException 500 Internal Server Error

以下是异常响应的示例。

非法参数异常

HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked

{
  "RemoteException":
  {
    "exception"    : "IllegalArgumentException",
    "javaClassName": "java.lang.IllegalArgumentException",
    "message"      : "Invalid value for webhdfs parameter \"permission\": ..."
  }
}

安全异常

HTTP/1.1 401 Unauthorized
Content-Type: application/json
Transfer-Encoding: chunked

{
  "RemoteException":
  {
    "exception"    : "SecurityException",
    "javaClassName": "java.lang.SecurityException",
    "message"      : "Failed to obtain user group information: ..."
  }
}

访问控制异常

HTTP/1.1 403 Forbidden
Content-Type: application/json
Transfer-Encoding: chunked

{
  "RemoteException":
  {
    "exception"    : "AccessControlException",
    "javaClassName": "org.apache.hadoop.security.AccessControlException",
    "message"      : "Permission denied: ..."
  }
}

文件未找到异常

HTTP/1.1 404 Not Found
Content-Type: application/json
Transfer-Encoding: chunked

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

JSON 模式

OPEN外的所有操作,要么返回零长度响应,要么返回JSON响应。对于OPEN,响应是八位字节流。JSON模式如下所示。有关JSON模式的语法定义,请参阅draft-zyp-json-schema-03

注意additionalProperties的默认值是一个空模式,允许附加属性使用任何值。因此,所有WebHDFS JSON响应都允许任何附加属性。不过,如果响应中包含附加属性,为了保持兼容性,这些属性将被视为可选属性。

ACL状态JSON模式

{
  "name"      : "AclStatus",
  "properties":
  {
    "AclStatus":
    {
      "type"      : "object",
      "properties":
      {
        "entries":
        {
          "type": "array",
          "items":
          {
            "description": "ACL entry.",
            "type": "string"
          }
        },
        "group":
        {
          "description": "The group owner.",
          "type"       : "string",
          "required"   : true
        },
        "owner":
        {
          "description": "The user who is the owner.",
          "type"       : "string",
          "required"   : true
        },
        "stickyBit":
        {
          "description": "True if the sticky bit is on.",
          "type"       : "boolean",
          "required"   : true
        }
      }
    }
  }
}

XAttrs JSON 模式

{
  "name"      : "XAttrs",
  "properties":
  {
    "XAttrs":
    {
      "type"      : "array",
      "items":
      {
        "type"    : "object",
        "properties":
        {
          "name":
          {
            "description": "XAttr name.",
            "type"       : "string",
            "required"   : true
          },
          "value":
          {
            "description": "XAttr value.",
            "type"       : "string"
          }
        }
      }
    }
  }
}

XAttrNames JSON 模式

{
  "name"      : "XAttrNames",
  "properties":
  {
    "XAttrNames":
    {
      "description": "XAttr names.",
      "type"       : "string",
      "required"   : true
    }
  }
}

布尔型JSON模式

{
  "name"      : "boolean",
  "properties":
  {
    "boolean":
    {
      "description": "A boolean value",
      "type"       : "boolean",
      "required"   : true
    }
  }
}

另请参阅:MKDIRS, RENAME, DELETE, SETREPLICATION

ContentSummary JSON 模式

{
  "name"      : "ContentSummary",
  "properties":
  {
    "ContentSummary":
    {
      "type"      : "object",
      "properties":
      {
        "directoryCount":
        {
          "description": "The number of directories.",
          "type"       : "integer",
          "required"   : true
        },
        "fileCount":
        {
          "description": "The number of files.",
          "type"       : "integer",
          "required"   : true
        },
        "length":
        {
          "description": "The number of bytes used by the content.",
          "type"       : "integer",
          "required"   : true
        },
        "quota":
        {
          "description": "The namespace quota of this directory.",
          "type"       : "integer",
          "required"   : true
        },
        "spaceConsumed":
        {
          "description": "The disk space consumed by the content.",
          "type"       : "integer",
          "required"   : true
        },
        "spaceQuota":
        {
          "description": "The disk space quota.",
          "type"       : "integer",
          "required"   : true
        },
        "typeQuota":
        {
          "type"      : "object",
          "properties":
          {
            "ARCHIVE":
            {
              "type"      : "object",
              "properties":
              {
                "consumed":
                {
                  "description": "The storage type space consumed.",
                  "type"       : "integer",
                  "required"   : true
                },
                "quota":
                {
                  "description": "The storage type quota.",
                  "type"       : "integer",
                  "required"   : true
                }
              }
            },
            "DISK":
            {
              "type"      : "object",
              "properties":
              {
                "consumed":
                {
                  "description": "The storage type space consumed.",
                  "type"       : "integer",
                  "required"   : true
                },
                "quota":
                {
                  "description": "The storage type quota.",
                  "type"       : "integer",
                  "required"   : true
                }
              }
            },
            "SSD":
            {
              "type"      : "object",
              "properties":
              {
                "consumed":
                {
                  "description": "The storage type space consumed.",
                  "type"       : "integer",
                  "required"   : true
                },
                "quota":
                {
                  "description": "The storage type quota.",
                  "type"       : "integer",
                  "required"   : true
                }
              }
            }
          }
        }
      }
    }
  }
}

另请参阅:GETCONTENTSUMMARY

配额使用情况 JSON 模式

{
  "name"      : "QuotaUsage",
  "properties":
  {
    "QuotaUsage":
    {
      "type"      : "object",
      "properties":
      {
        "fileAndDirectoryCount":
        {
          "description": "The number of files and directories.",
          "type"       : "integer",
          "required"   : true
        },
        "quota":
        {
          "description": "The namespace quota of this directory.",
          "type"       : "integer",
          "required"   : true
        },
        "spaceConsumed":
        {
          "description": "The disk space consumed by the content.",
          "type"       : "integer",
          "required"   : true
        },
        "spaceQuota":
        {
          "description": "The disk space quota.",
          "type"       : "integer",
          "required"   : true
        },
        "typeQuota":
        {
          "type"      : "object",
          "properties":
          {
            "ARCHIVE":
            {
              "type"      : "object",
              "properties":
              {
                "consumed":
                {
                  "description": "The storage type space consumed.",
                  "type"       : "integer",
                  "required"   : true
                },
                "quota":
                {
                  "description": "The storage type quota.",
                  "type"       : "integer",
                  "required"   : true
                }
              }
            },
            "DISK":
            {
              "type"      : "object",
              "properties":
              {
                "consumed":
                {
                  "description": "The storage type space consumed.",
                  "type"       : "integer",
                  "required"   : true
                },
                "quota":
                {
                  "description": "The storage type quota.",
                  "type"       : "integer",
                  "required"   : true
                }
              }
            },
            "SSD":
            {
              "type"      : "object",
              "properties":
              {
                "consumed":
                {
                  "description": "The storage type space consumed.",
                  "type"       : "integer",
                  "required"   : true
                },
                "quota":
                {
                  "description": "The storage type quota.",
                  "type"       : "integer",
                  "required"   : true
                }
              }
            }
          }
        }
      }
    }
  }
}

另请参阅:GETQUOTAUSAGE

文件校验和 JSON 模式

{
  "name"      : "FileChecksum",
  "properties":
  {
    "FileChecksum":
    {
      "type"      : "object",
      "properties":
      {
        "algorithm":
        {
          "description": "The name of the checksum algorithm.",
          "type"       : "string",
          "required"   : true
        },
        "bytes":
        {
          "description": "The byte sequence of the checksum in hexadecimal.",
          "type"       : "string",
          "required"   : true
        },
        "length":
        {
          "description": "The length of the bytes (not the length of the string).",
          "type"       : "integer",
          "required"   : true
        }
      }
    }
  }
}

FileStatus JSON 模式

{
  "name"      : "FileStatus",
  "properties":
  {
    "FileStatus": fileStatusProperties      //See FileStatus Properties
  }
}

另请参阅:FileStatus 属性, GETFILESTATUS, FileStatus

FileStatus 属性

使用JavaScript语法定义fileStatusProperties,以便可以在FileStatusFileStatuses JSON模式中引用它。

var fileStatusProperties =
{
  "type"      : "object",
  "properties":
  {
    "accessTime":
    {
      "description": "The access time.",
      "type"       : "integer",
      "required"   : true
    },
    "blockSize":
    {
      "description": "The block size of a file.",
      "type"       : "integer",
      "required"   : true
    },
    "group":
    {
      "description": "The group owner.",
      "type"       : "string",
      "required"   : true
    },
    "length":
    {
      "description": "The number of bytes in a file.",
      "type"       : "integer",
      "required"   : true
    },
    "modificationTime":
    {
      "description": "The modification time.",
      "type"       : "integer",
      "required"   : true
    },
    "owner":
    {
      "description": "The user who is the owner.",
      "type"       : "string",
      "required"   : true
    },
    "pathSuffix":
    {
      "description": "The path suffix.",
      "type"       : "string",
      "required"   : true
    },
    "permission":
    {
      "description": "The permission represented as a octal string.",
      "type"       : "string",
      "required"   : true
    },
    "replication":
    {
      "description": "The number of replication of a file.",
      "type"       : "integer",
      "required"   : true
    },
   "symlink":                                         //an optional property
    {
      "description": "The link target of a symlink.",
      "type"       : "string"
    },
   "type":
    {
      "description": "The type of the path object.",
      "enum"       : ["FILE", "DIRECTORY", "SYMLINK"],
      "required"   : true
    },
    "aclBit":
    {
       "description": "Has ACLs set or not.",
       "type"       : "boolean",
    },
    "encBit":
    {
       "description": "Is Encrypted or not.",
       "type"       : "boolean",
    },
    "ecBit":
    {
       "description": "Is ErasureCoded or not.",
       "type"       : "boolean",
    },
    "ecPolicy":
    {
       "description": "The namenode of ErasureCodePolicy.",
       "type"       : "String",
    }
  }
};

FileStatuses JSON 模式

一个FileStatuses JSON对象表示一个由FileStatus JSON对象组成的数组。

{
  "name"      : "FileStatuses",
  "properties":
  {
    "FileStatuses":
    {
      "type"      : "object",
      "properties":
      {
        "FileStatus":
        {
          "description": "An array of FileStatus",
          "type"       : "array",
          "items"      : fileStatusProperties      //See FileStatus Properties
        }
      }
    }
  }
}

另请参阅:FileStatus 属性, LISTSTATUS, FileStatus

目录列表 JSON 模式

一个DirectoryListing JSON对象表示在迭代列出目录时的一批目录条目。它包含一个FileStatuses JSON对象以及迭代信息。

{
  "name"      : "DirectoryListing",
  "properties":
  {
    "DirectoryListing":
    {
      "type"      : "object",
      "properties":
      {
        "partialListing":
        {
          "description": "A partial directory listing",
          "type"       : "object", // A FileStatuses object
          "required"   : true
        },
        "remainingEntries":
        {
          "description": "Number of remaining entries",
          "type"       : "integer",
          "required"   : true
        }
      }
    }
  }

}

另请参阅:FileStatuses JSON 模式, LISTSTATUS_BATCH, FileStatus

长JSON模式

{
  "name"      : "long",
  "properties":
  {
    "long":
    {
      "description": "A long integer value",
      "type"       : "integer",
      "required"   : true
    }
  }
}

另请参阅:RENEWDELEGATIONTOKEN,

路径 JSON 模式

{
  "name"      : "Path",
  "properties":
  {
    "Path":
    {
      "description": "The string representation a Path.",
      "type"       : "string",
      "required"   : true
    }
  }
}

另请参阅:GETHOMEDIRECTORY, Path

RemoteException JSON 模式

{
  "name"      : "RemoteException",
  "properties":
  {
    "RemoteException":
    {
      "type"      : "object",
      "properties":
      {
        "exception":
        {
          "description": "Name of the exception",
          "type"       : "string",
          "required"   : true
        },
        "message":
        {
          "description": "Exception message",
          "type"       : "string",
          "required"   : true
        },
        "javaClassName":                                     //an optional property
        {
          "description": "Java class name of the exception",
          "type"       : "string"
        }
      }
    }
  }
}

另请参阅:Error Responses

令牌JSON模式

{
  "name"      : "Token",
  "properties":
  {
    "Token": tokenProperties      //See Token Properties
  }
}

另请参阅:Token Properties, GETDELEGATIONTOKEN, Delegation中的说明。

令牌属性

使用JavaScript语法定义tokenProperties,以便可以在Token JSON模式中引用它。

var tokenProperties =
{
  "type"      : "object",
  "properties":
  {
    "urlString":
    {
      "description": "A delegation token encoded as a URL safe string.",
      "type"       : "string",
      "required"   : true
    }
  }
}

另请参阅:Token Properties,以及Delegation中的说明。

块存储策略 JSON 模式

{
  "name"      : "BlockStoragePolicy",
  "properties":
  {
    "BlockStoragePolicy": blockStoragePolicyProperties      //See BlockStoragePolicy Properties
  }
}

另请参阅:BlockStoragePolicy 属性, GETSTORAGEPOLICY

块存储策略属性

使用JavaScript语法定义blockStoragePolicyProperties,以便可以在BlockStoragePolicyBlockStoragePolicies JSON模式中引用它。

var blockStoragePolicyProperties =
{
  "type"      : "object",
  "properties":
  {
    "id":
    {
      "description": "Policy ID.",
      "type"       : "integer",
      "required"   : true
    },
    "name":
    {
      "description": "Policy name.",
      "type"       : "string",
      "required"   : true
    },
    "storageTypes":
    {
      "description": "An array of storage types for block placement.",
      "type"       : "array",
      "required"   : true
      "items"      :
      {
        "type": "string"
      }
    },
    "replicationFallbacks":
    {
      "description": "An array of fallback storage types for replication.",
      "type"       : "array",
      "required"   : true
      "items"      :
      {
        "type": "string"
      }
    },
    "creationFallbacks":
    {
      "description": "An array of fallback storage types for file creation.",
      "type"       : "array",
      "required"   : true
      "items"      :
      {
       "type": "string"
      }
    },
    "copyOnCreateFile":
    {
      "description": "If set then the policy cannot be changed after file creation.",
      "type"       : "boolean",
      "required"   : true
    }
  }
};

ECPolicy JSON 模式

{
  "name": "RS-10-4-1024k",
  schema {
           "codecName": "rs",
           "numDataUnits": 10,
           "numParityUnits": 4,
           "extraOptions": {}
          }
  "cellSize": 1048576,
  "id":5,
  "codecname":"rs",
  "numDataUnits": 10,
  "numParityUnits": 4,
  "replicationpolicy":false,
  "systemPolicy":true
}

块存储策略 JSON 模式

一个BlockStoragePolicies JSON对象表示一个由BlockStoragePolicy JSON对象组成的数组。

{
  "name"      : "BlockStoragePolicies",
  "properties":
  {
    "BlockStoragePolicies":
    {
      "type"      : "object",
      "properties":
      {
        "BlockStoragePolicy":
        {
          "description": "An array of BlockStoragePolicy",
          "type"       : "array",
          "items"      : blockStoragePolicyProperties      //See BlockStoragePolicy Properties
        }
      }
    }
  }
}

SnapshotDiffReport JSON 模式

{
  "name": "SnapshotDiffReport",
  "type": "object",
  "properties":
  {
    "SnapshotDiffReport":
    {
      "type"        : "object",
      "properties"  :
      {
        "diffList":
        {
          "description": "An array of DiffReportEntry",
          "type"        : "array",
          "items"       : diffReportEntries,
          "required"    : true
        },
        "fromSnapshot":
        {
          "description": "Source snapshot",
          "type"        : "string",
          "required"    : true
        },
        "snapshotRoot":
        {
          "description" : "String representation of snapshot root path",
          "type"        : "string",
          "required"    : true
        },
        "toSnapshot":
        {
          "description" : "Destination snapshot",
          "type"        : "string",
          "required"    : true
        }
      }
    }
  }
}

差异报告条目

使用JavaScript语法定义diffReportEntries,以便可以在SnapshotDiffReport JSON模式中引用它。

var diffReportEntries =
{
  "type": "object",
  "properties":
  {
    "sourcePath":
    {
      "description" : "Source path name relative to snapshot root",
      "type"        : "string",
      "required"    : true
    },
    "targetPath":
    {
      "description" : "Target path relative to snapshot root used for renames",
      "type"        : "string",
      "required"    : true
    },
    "type":
    {
      "description" : "Type of diff report entry",
      "enum"        : ["CREATE", "MODIFY", "DELETE", "RENAME"],
      "required"    : true
    }
  }
}

SnapshotDiffReportListing JSON 模式

{
  "name": "SnapshotDiffReportListing",
  "type": "object",
  "properties":
  {
    "SnapshotDiffReportListing":
    {
      "type"        : "object",
      "properties"  :
      {
        "isFromEarlier":
        {
          "description" : "the diff is calculated from older to newer snapshot or not",
          "type"        : "boolean",
          "required"    : true
        },
        "lastIndex":
        {
          "description" : "the last index of listing iteration",
          "type"        : "integer",
          "required"    : true
        },
        "lastPath":
        {
          "description" : "String representation of the last path of the listing iteration",
          "type"        : "string",
          "required"    : true
        },
        "modifyList":
        {
          "description": "An array of DiffReportListingEntry",
          "type"        : "array",
          "items"       : diffReportListingEntries,
          "required"    : true
        },
        "createList":
        {
          "description": "An array of DiffReportListingEntry",
          "type"        : "array",
          "items"       : diffReportListingEntries,
          "required"    : true
        },
        "deleteList":
        {
          "description": "An array of DiffReportListingEntry",
          "type"        : "array",
          "items"       : diffReportListingEntries,
          "required"    : true
        }
      }
    }
  }
}

差异报告列表条目

使用JavaScript语法定义diffReportEntries,以便可以在SnapshotDiffReport JSON模式中引用它。

var diffReportListingEntries =
{
  "type": "object",
  "properties":
  {
    "dirId":
    {
      "description" : "inode id of the directory",
      "type"        : "integer",
      "required"    : true
    },
    "fileId":
    {
      "description" : "inode id of the file",
      "type"        : "integer",
      "required"    : true
    },
    "isRereference":
    {
      "description" : "this is reference or not",
      "type"        : "boolean",
      "required"    : true
    },
    "sourcePath":
    {
      "description" : "string representation of path where changes have happened",
      "type"        : "string",
      "required"    : true
    },
    "targetPath":
    {
      "description" : "string representation of target path of rename op",
      "type"        : "string",
      "required"    : false
    }
  }
}

可快照目录列表 JSON 模式

{
  "name": "SnapshottableDirectoryList",
  "type": "object",
  "properties":
  {
    "SnapshottableDirectoryList":
    {
      "description": "An array of SnapshottableDirectoryStatus",
      "type"        : "array",
      "items"       : snapshottableDirectoryStatus,
      "required"    : true
    }
  }
}

可快照目录状态

使用JavaScript语法定义snapshottableDirectoryStatus,以便可以在SnapshottableDirectoryList JSON模式中引用它。

var snapshottableDirectoryStatus =
{
  "type": "object",
  "properties":
  {
    "dirStatus": fileStatusProperties,
    "parentFullPath":
    {
      "description" : "Full path of the parent of snapshottable directory",
      "type"        : "string",
      "required"    : true
    },
    "snapshotNumber":
    {
      "description" : "Number of snapshots created on the snapshottable directory",
      "type"        : "integer",
      "required"    : true
    },
    "snapshotQuota":
    {
      "description" : "Total number of snapshots allowed on the snapshottable directory",
      "type"        : "integer",
      "required"    : true
    }
  }
}

SnapshotList JSON 模式

{
  "name": "SnapshotList",
  "type": "object",
  "properties":
  {
    "SnapshotList":
    {
      "description": "An array of SnapshotStatus",
      "type"        : "array",
      "items"       : snapshotStatus,
      "required"    : true
    }
  }
}

快照状态

使用JavaScript语法定义snapshotStatus,以便可以在SnapshotList JSON模式中引用它。

var snapshotStatus =
{
  "type": "object",
  "properties":
  {
    "dirStatus": fileStatusProperties,
    "fullPath":
    {
      "description" : "Full path of the parent of the snapshot",
      "type"        : "string",
      "required"    : true
    },
    "snapshotID":
    {
      "description" : "snapshot ID for the snapshot",
      "type"        : "integer",
      "required"    : true
    },
    "deletionStatus":
    {
      "description" : "Status showing whether the snapshot is active or in deleted state",
      "type"        : "string",
      "required"    : true
    }
  }
}

块位置 JSON 模式

一个BlockLocations JSON对象表示一个由BlockLocation JSON对象组成的数组。

{
  "name"      : "BlockLocations",
  "properties":
  {
    "BlockLocations":
    {
      "type"      : "object",
      "properties":
      {
        "BlockLocation":
        {
          "description": "An array of BlockLocation",
          "type"       : "array",
          "items"      : blockLocationProperties      //See BlockLocation Properties
        }
      }
    }
  }
}

另请参阅 BlockLocation 属性, GETFILEBLOCKLOCATIONS, BlockLocation

BlockLocation JSON 模式

{
  "name"      : "BlockLocation",
  "properties":
  {
    "BlockLocation": blockLocationProperties      //See BlockLocation Properties
  }
}

另请参阅 BlockLocation Properties, GETFILEBLOCKLOCATIONS, BlockLocation

BlockLocation 属性

使用JavaScript语法定义blockLocationProperties,以便可以在BlockLocationBlockLocations的JSON模式中引用它。

var blockLocationProperties =
{
  "type"      : "object",
  "properties":
  {
    "cachedHosts":
    {
      "description": "Datanode hostnames with a cached replica",
      "type"       : "array",
      "required"   : "true",
      "items"      :
      {
        "description": "A datanode hostname",
        "type"       : "string"
      }
    },
    "corrupt":
    {
      "description": "True if the block is corrupted",
      "type"       : "boolean",
      "required"   : "true"
    },
    "hosts":
    {
      "description": "Datanode hostnames store the block",
      "type"       : "array",
      "required"   : "true",
      "items"      :
      {
        "description": "A datanode hostname",
        "type"       : "string"
      }
    },
    "length":
    {
      "description": "Length of the block",
      "type"       : "integer",
      "required"   : "true"
    },
    "names":
    {
      "description": "Datanode IP:xferPort for accessing the block",
      "type"       : "array",
      "required"   : "true",
      "items"      :
      {
        "description": "DatanodeIP:xferPort",
        "type"       : "string"
      }
    },
    "offset":
    {
      "description": "Offset of the block in the file",
      "type"       : "integer",
      "required"   : "true"
    },
    "storageTypes":
    {
      "description": "Storage type of each replica",
      "type"       : "array",
      "required"   : "true",
      "items"      :
      {
        "description": "Storage type",
        "enum"       : ["RAM_DISK", "SSD", "DISK", "ARCHIVE"]
      }
    },
    "topologyPaths":
    {
      "description": "Datanode addresses in network topology",
      "type"       : "array",
      "required"   : "true",
      "items"      :
      {
        "description": "/rack/host:ip",
        "type"       : "string"
      }
    }
  }
};

服务器默认值 JSON 模式

{
  "FsServerDefaults": {
    "replication": 3,
    "encryptDataTransfer": false,
    "defaultStoragePolicyId": 7,
    "writePacketSize": 65536,
    "fileBufferSize": 4096,
    "checksumType": 2,
    "trashInterval": 10080,
    "keyProviderUri": "",
    "blockSize": 134217728,
    "bytesPerChecksum": 512
  }
}

FsStatus JSON 模式

{
  "FsStatus": {
    "used": 29229154304,
    "remaining": 292893392896,
    "capacity": 322122547200
  }
}

EC策略JSON模式

{
  "ErasureCodingPolicies": {
    "ErasureCodingPolicyInfo": [
      {
        "state": "ENABLED",
        "policy": {
          "name": "RS-6-3-1024k",
          "schema": {
            "codecName": "rs",
            "numDataUnits": 6,
            "numParityUnits": 3,
            "extraOptions": {}
          },
          "cellSize": 1048576,
          "id": 1,
          "replicationPolicy": false,
          "codecName": "rs",
          "numDataUnits": 6,
          "numParityUnits": 3,
          "systemPolicy": true
        }
      }
    ]
  }
}

EC编解码器JSON模式

{
  "ErasureCodingCodecs": {
    "rs": "rs_native, rs_java",
    "rs-legacy": "rs-legacy_java",
    "xor": "xor_native, xor_java"
  }
}

路径 JSON 模式

{
  "Paths": [{
    "blocksize": 0,
    "owner": "hadoop",
    "path": "/user/user0/.Trash",
    "length": 0,
    "permission": "755",
    "modification_time": 1693050205747,
    "isdir": true,
    "block_replication": 0,
    "access_time": 0,
    "group": "supergroup"
  }]
}

HTTP查询参数字典

ACL规范

Name aclspec
描述 ACL修改操作中包含的ACL规范。
类型 字符串
默认值
有效值 参见 Permissions and HDFS
语法 参见 Permissions and HDFS

XAttr名称

Name xattr.name
描述 文件/目录的XAttr名称。
类型 字符串
默认值
有效值 任何以 user./trusted./system./security. 开头的字符串
语法 任何以user./trusted./system./security..为前缀的字符串

XAttr 值

Name xattr.value
描述 文件/目录的XAttr属性值。
类型 字符串
默认值
有效值 编码后的值。
语法 用双引号括起来或以0x或0s为前缀。

另请参阅:Extended Attributes

XAttr 设置标志

Name flag
描述 XAttr 设置标志。
类型 字符串
默认值
有效值 CREATE,REPLACE.
语法 CREATE,REPLACE.

另请参阅:Extended Attributes

XAttr 值编码

Name encoding
描述 XAttr值的编码方式。
类型 字符串
默认值
有效值 text hex base64
语法 文本 十六进制 base64

另请参阅:Extended Attributes

访问时间

Name accesstime
描述 文件/目录的访问时间。
类型 long
默认值 -1 (表示保持不变)
有效值 -1 或时间戳
语法 任意整数。

另请参阅:SETTIMES

块大小

Name blocksize
描述 文件的块大小。
类型 long
默认值 在配置中指定。
有效值 > 0
语法 任意整数。

另请参阅:CREATE

缓冲区大小

Name buffersize
描述 数据传输过程中使用的缓冲区大小。
类型 int
默认值 在配置中指定。
有效值 > 0
语法 任意整数。

另请参阅:CREATE, APPEND, OPEN

创建标志

Name createflag
描述 创建文件时可处理的标志枚举
类型 枚举字符串
默认值 <empty>
有效值 create、overwrite、append 和 sync_block 的合法组合
语法 参见下方说明

以下组合无效:* append,create * create,append,overwrite

另请参阅:CREATE

创建父级

Name createparent
描述 如果父目录不存在,是否应该创建它们?
类型 boolean
默认值 true
有效值 true, false
语法 true

另请参阅: CREATESYMLINK

委托

Name delegation
描述 用于身份验证的委托令牌。
类型 字符串
默认值 <empty>
有效值 一个编码令牌。
语法 请参阅下面的说明。

注意委托令牌被编码为URL安全字符串;有关编码的详细信息,请参阅org.apache.hadoop.security.token.Token中的encodeToUrlString()decodeFromUrlString(String)方法。

另请参阅:Authentication

目标

Name destination
描述 目标路径。
类型 路径
默认值 (无效路径)
有效值 不带方案和权限的绝对文件系统路径。
语法 任意路径。

另请参阅: CREATESYMLINK, RENAME

执行操作

Name doas
描述 允许代理用户以另一个用户的身份执行操作。
类型 字符串
默认值 null
有效值 任何有效的用户名。
语法 任意字符串。

另请参阅:Proxy Users

文件系统操作

Name fsaction
描述 文件系统操作 读/写/执行
类型 字符串
默认值 null (无效值)
有效值 符合正则表达式模式 "[r-][w-][x-]" 的字符串
语法  "[r-][w-][x-] "

另请参阅:CHECKACCESS,

分组

Name group
描述 组的名称。
类型 字符串
默认值 (表示保持原值不变)
有效值 任何有效的组名称。
语法 任意字符串。

另请参阅:SETOWNER

长度

Name length
描述 要处理的字节数。
类型 long
默认值 null (表示整个文件)
有效值 >= 0 或 null
语法 任意整数。

另请参阅:OPEN

修改时间

Name modificationtime
描述 文件/目录的修改时间。
类型 long
默认值 -1 (表示保持不变)
有效值 -1 或时间戳
语法 任意整数。

另请参阅:SETTIMES

新长度

Name newlength
描述 文件将被截断到的大小。
类型 long
有效值 >= 0
语法 任意长度。

偏移量

Name offset
描述 起始字节位置。
类型 long
默认值 0
有效值 >= 0
语法 任意整数。

另请参阅:OPEN

旧快照名称

Name oldsnapshotname
描述 待重命名的旧快照名称。
类型 字符串
默认值 null
有效值 一个已存在的快照名称。
语法 任意字符串。

另请参阅:RENAMESNAPSHOT

操作

Name op
描述 要执行的操作名称。
类型 枚举
默认值 null (无效值)
有效值 任何有效的操作名称。
语法 任意字符串。

另请参阅:Operations

覆盖

Name overwrite
描述 如果文件已存在,是否应覆盖?
类型 boolean
默认值 false
有效值 true
语法 true

另请参阅:CREATE

所有者

Name owner
描述 文件/目录所有者的用户名。
类型 字符串
默认值 (表示保持原值不变)
有效值 任何有效的用户名。
语法 任意字符串。

另请参阅:SETOWNER

权限

Name permission
描述 文件/目录的权限。
类型 八进制
默认值 文件644,目录755
有效值 0 - 1777
语法 任何基数为8的整数(前导零可以省略。)

另请参阅: CREATE, MKDIRS, SETPERMISSION

递归

Name recursive
描述 该操作是否应对子目录中的内容生效?
类型 boolean
默认值 false
有效值 true
语法 true

另请参阅:RENAME

续订器

Name renewer
描述 委托令牌续订者的用户名。
类型 字符串
默认值 (表示当前用户)
有效值 任何有效的用户名。
语法 任意字符串。

另请参阅:GETDELEGATIONTOKEN

复制

Name replication
描述 文件的副本数量。
类型 short
默认值 在配置中指定。
有效值 > 0
语法 任意整数。

另请参阅: CREATE, SETREPLICATION

快照名称

Name snapshotname
描述 要创建/删除的快照名称。或用于重命名快照的新名称。
类型 字符串
默认值 null
有效值 任何有效的快照名称。
语法 任意字符串。

另请参阅: CREATESNAPSHOT, DELETESNAPSHOT, RENAMESNAPSHOT

数据源

Name sources
描述 源路径列表。
类型 字符串
默认值 <empty>
有效值 以逗号分隔的绝对文件系统路径列表,不包含方案和授权信息。
语法 任意字符串。

另请参阅:CONCAT

令牌

Name token
描述 用于操作的代表令牌。
类型 字符串
默认值 <empty>
有效值 一个编码令牌。
语法 请参阅Delegation中的说明。

另请参阅: RENEWDELEGATIONTOKEN, CANCELDELEGATIONTOKEN

令牌类型

Name kind
描述 请求的委托令牌类型
类型 字符串
默认值 (服务器为该服务设置默认类型)
有效值 表示令牌类型的字符串,例如 "HDFS_DELEGATION_TOKEN" 或 "WEBHDFS delegation"
语法 任意字符串。

另请参阅:GETDELEGATIONTOKEN

令牌服务

Name service
描述 令牌预期使用的服务名称,例如namenode的ip:端口
类型 字符串
默认值 <empty>
有效值 字符串格式的ip:port或服务的逻辑名称
语法 任意字符串。

另请参阅:GETDELEGATIONTOKEN

用户名

Name user.name
描述 已认证的用户;参见 Authentication
类型 字符串
默认值 null
有效值 任何有效的用户名。
语法 任意字符串。

另请参阅:Authentication

NoRedirect

Name noredirect
描述 响应应返回HTTP 307重定向还是HTTP 200 OK。参见Create and Write to a File
类型 boolean
默认值 false
有效值 true
语法 true

另请参阅:Create and Write to a File

命名空间配额

Name namespacequota
描述 目录下命名空间使用量的限制,即文件/目录的数量。
类型 字符串
默认值 Long.MAX_VALUE
有效值 > 0.
语法 任意整数。

另请参阅:SETQUOTA

存储空间配额

Name storagespacequota
描述 目录下存储空间使用限制(以字节为单位,包括副本)。
类型 字符串
默认值 Long.MAX_VALUE
有效值 > 0.
语法 任意整数。

另请参阅:SETQUOTA, SETQUOTABYSTORAGETYPE

存储类型

Name storagetype
描述 待修改的特定存储类型配额的存储类型。
类型 字符串
默认值 <empty>
有效值 任何有效的存储类型。
语法 任意字符串。

另请参阅:SETQUOTABYSTORAGETYPE

存储策略

Name storagepolicy
描述 存储策略的名称。
类型 字符串
默认值 <empty>
有效值 任何有效的存储策略名称;参见 GETALLSTORAGEPOLICY
语法 任意字符串。

另请参阅:SETSTORAGEPOLICY

纠删码策略

Name ecpolicy
描述 擦除编码策略的名称。
类型 字符串
默认值 <empty>
有效值 任何有效的擦除编码策略名称;
语法 任意字符串。

另请参阅:ENABLEECPOLICYDISABLEECPOLICY

启动后

Name startAfter
描述 列表状态批次中返回的最后一项。
类型 字符串
默认值 <empty>
有效值 任何有效的文件/目录名称。
语法 任意字符串。

另请参阅:LISTSTATUS_BATCH