webhdfs/datatypes.rs
1use std::fmt::{Display, Formatter, Result as FmtResult};
2use serde::{Deserialize};
3
4/*
5HTTP/1.1 404 Not Found
6Content-Type: application/json
7Transfer-Encoding: chunked
8
9{
10 "RemoteException":
11 {
12 "exception" : "FileNotFoundException",
13 "javaClassName": "java.io.FileNotFoundException",
14 "message" : "File does not exist: /foo/a.patch"
15 }
16}
17*/
18
19#[derive(Debug, Deserialize)]
20pub struct RemoteExceptionResponse {
21 #[serde(rename="RemoteException")]
22 pub remote_exception: RemoteException
23}
24
25#[derive(Debug, Deserialize)]
26pub struct RemoteException {
27 pub exception: String,
28 #[serde(rename="javaClassName")]
29 pub java_class_name: String,
30 pub message: String
31}
32
33impl Display for RemoteException {
34 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
35 write!(f,
36 "RemoteException[exception={}, java_class_name={}, msg='{}']",
37 self.exception, self.java_class_name, self.message
38 )
39 }
40}
41
42impl std::error::Error for RemoteException {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
44}
45
46
47/*
48{
49 "FileStatuses":
50 {
51 "FileStatus":
52 [
53 {
54 "accessTime" : 1320171722771,
55 "blockSize" : 33554432,
56 "group" : "supergroup",
57 "length" : 24930,
58 "modificationTime": 1320171722771,
59 "owner" : "webuser",
60 "pathSuffix" : "a.patch",
61 "permission" : "644",
62 "replication" : 1,
63 "type" : "FILE"
64 },
65 {
66 "accessTime" : 0,
67 "blockSize" : 0,
68 "group" : "supergroup",
69 "length" : 0,
70 "modificationTime": 1320895981256,
71 "owner" : "username",
72 "pathSuffix" : "bar",
73 "permission" : "711",
74 "replication" : 0,
75 "type" : "DIRECTORY"
76 },
77 ...
78 ]
79 }
80}
81*/
82
83#[derive(Debug, Deserialize)]
84pub struct ListStatusResponse {
85 #[serde(rename="FileStatuses")]
86 pub file_statuses: FileStatuses
87}
88
89#[derive(Debug, Deserialize)]
90pub struct FileStatuses {
91 #[serde(rename="FileStatus")]
92 pub file_status: Vec<FileStatus>
93}
94
95#[derive(Debug, Deserialize)]
96pub struct FileStatus {
97 //"accessTime" : 1320171722771,
98 #[serde(rename="accessTime")]
99 pub access_time: i64,
100
101 //"blockSize" : 33554432,
102 #[serde(rename="blockSize")]
103 pub block_size: i64,
104
105 //"group" : "supergroup",
106 pub group: String,
107
108 //"length" : 24930,
109 pub length: i64,
110
111 //"modificationTime": 1320171722771,
112 #[serde(rename="modificationTime")]
113 pub modification_time: i64,
114
115 //"owner" : "webuser",
116 pub owner: String,
117
118 //"pathSuffix" : "a.patch",
119 #[serde(rename="pathSuffix")]
120 pub path_suffix: String,
121
122 //"permission" : "644",
123 pub permission: String,
124
125 //"replication" : 1,
126 pub replication: i32,
127
128 //"type" : "FILE"
129 #[serde(rename="type")]
130 pub type_: String
131}
132
133/*
134HTTP/1.1 200 OK
135Content-Type: application/json
136Transfer-Encoding: chunked
137
138{
139 "FileStatus":
140 {
141 "accessTime" : 0,
142 "blockSize" : 0,
143 "group" : "supergroup",
144 "length" : 0, //in bytes, zero for directories
145 "modificationTime": 1320173277227,
146 "owner" : "webuser",
147 "pathSuffix" : "",
148 "permission" : "777",
149 "replication" : 0,
150 "type" : "DIRECTORY" //enum {FILE, DIRECTORY, SYMLINK}
151 }
152}
153*/
154
155/// Directory entry types (as returmed by stat and dir)
156pub mod dirent_type {
157 /// Value of `FileStatus.type` corresponding to a regular file (`"FILE"`)
158 pub const FILE: &'static str = "FILE";
159 /// Value of `FileStatus.type` corresponding to a directory (`"DIRECTORY"`)
160 pub const DIRECTORY: &'static str = "DIRECTORY";
161 /// Value of `FileStatus.type` corresponding to a symbolic link (`"SYMLINK"`)
162 pub const SYMLINK: &'static str = "SYMLINK";
163}
164
165#[derive(Debug, Deserialize)]
166pub struct FileStatusResponse {
167 #[serde(rename="FileStatus")]
168 pub file_status: FileStatus
169}
170
171/*
172HTTP/1.1 200 OK
173Content-Type: application/json
174Transfer-Encoding: chunked
175
176{"boolean": true}
177*/
178
179/// Response to MKDIRS, DELETE, RENAME, TRUNCATE
180#[derive(Debug, Deserialize)]
181pub struct Boolean {
182 pub boolean: bool
183}