获取指定目录文件列表
功能介绍
在MRS集群中获取指定目录文件列表。
接口约束
无
调用方法
请参见如何调用API。
URI
GET /v2/{project_id}/clusters/{cluster_id}/files
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目编号。获取方法,请参见获取项目ID。 |
cluster_id |
是 |
String |
集群ID。获取方法,请参见获取集群ID。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
path |
是 |
String |
文件目录。 比如访问“/tmp/test”目录列表,此处必须是目录,整体URI为/v2/{project_id}/clusters/{cluster_id}/files?path=%2Ftmp%2Ftest 单层目录要遵循以下规则:
|
offset |
否 |
String |
分页参数,表示从该偏移量开始查询文件列表,默认值为1。 |
limit |
否 |
String |
分页参数,列表当前分页的数量限制,默认为100,最大1000。 |
sort_key |
否 |
String |
列表排序按该属性排序。缺省值:path_suffix
|
order |
否 |
String |
列表排序方式,desc为降序,asc为升序,默认值为desc。 |
请求参数
无
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
total_count |
Long |
文件总数,与分页无关。 |
files |
Array of FileStatusV2 objects |
文件列表。 |
参数 |
参数类型 |
描述 |
---|---|---|
path_suffix |
String |
文件在当前目录下的后缀,如获取“/tmp”目录,下面的“/tmp/test”文件,此处path_suffix内容为“test”。 |
owner |
String |
文件拥有者。 |
group |
String |
文件属组。 |
permission |
String |
权限信息。 |
replication |
Integer |
副本数。 |
block_size |
Integer |
块大小。 |
length |
Integer |
文件长度。 |
type |
String |
文件类型:
|
children_num |
Integer |
该目录下的文件条目数。 |
access_time |
Long |
文件访问时间。 |
modification_time |
Long |
文件修改时间。 |
请求示例
获取指定目录文件列表请求示例
GET /v2/{project_id}/clusters/{cluster_id}/files?path={directory}&offset={offset}&limit={limit}&sort_key={sort_key}&order={order}
响应示例
状态码: 200
获取指定目录文件列表成功
{ "total_count" : 2, "files" : [ { "access_time" : 0, "block_size" : 0, "children_num" : 0, "group" : "hadoop", "length" : 0, "modification_time" : 1587179516623, "owner" : "hdfs", "path_suffix" : "app-logs", "permission" : 777, "replication" : 0, "type" : "DIRECTORY" }, { "access_time" : 1587267212761, "block_size" : 134217728, "children_num" : 0, "group" : "hadoop", "length" : 23666188, "modification_time" : 1587222156003, "owner" : "root", "path_suffix" : "data-m-00000", "permission" : "644", "replication" : 3, "type" : "FILE" } ] }
SDK代码示例
SDK代码示例如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.mrs.v2.region.MrsRegion; import com.huaweicloud.sdk.mrs.v2.*; import com.huaweicloud.sdk.mrs.v2.model.*; public class ShowHdfsFileListSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); MrsClient client = MrsClient.newBuilder() .withCredential(auth) .withRegion(MrsRegion.valueOf("<YOUR REGION>")) .build(); ShowHdfsFileListRequest request = new ShowHdfsFileListRequest(); request.withPath("<path>"); request.withOffset("<offset>"); request.withLimit("<limit>"); request.withSortKey(ShowHdfsFileListRequest.SortKeyEnum.fromValue("<sort_key>")); request.withOrder(ShowHdfsFileListRequest.OrderEnum.fromValue("<order>")); try { ShowHdfsFileListResponse response = client.showHdfsFileList(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmrs.v2.region.mrs_region import MrsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmrs.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = MrsClient.new_builder() \ .with_credentials(credentials) \ .with_region(MrsRegion.value_of("<YOUR REGION>")) \ .build() try: request = ShowHdfsFileListRequest() request.path = "<path>" request.offset = "<offset>" request.limit = "<limit>" request.sort_key = "<sort_key>" request.order = "<order>" response = client.show_hdfs_file_list(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := mrs.NewMrsClient( mrs.MrsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ShowHdfsFileListRequest{} request.Path = "<path>" offsetRequest:= "<offset>" request.Offset = &offsetRequest limitRequest:= "<limit>" request.Limit = &limitRequest sortKeyRequest:= model.GetShowHdfsFileListRequestSortKeyEnum().<SORT_KEY> request.SortKey = &sortKeyRequest orderRequest:= model.GetShowHdfsFileListRequestOrderEnum().<ORDER> request.Order = &orderRequest response, err := client.ShowHdfsFileList(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
获取指定目录文件列表成功 |
错误码
请参见错误码。