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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use std::fmt::{Display, Formatter, Result as FmtResult};
use serde::{Deserialize};

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

#[derive(Debug, Deserialize)]
pub struct RemoteException {
    pub exception: String,
    #[serde(rename="javaClassName")]
    pub java_class_name: String,
    pub message: String
}

impl Display for RemoteException {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        write!(f, 
            "RemoteException[exception={}, java_class_name={}, msg='{}']", 
            self.exception, self.java_class_name, self.message
        )
    }
}

impl std::error::Error for RemoteException {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
}


/*
{
  "FileStatuses":
  {
    "FileStatus":
    [
      {
        "accessTime"      : 1320171722771,
        "blockSize"       : 33554432,
        "group"           : "supergroup",
        "length"          : 24930,
        "modificationTime": 1320171722771,
        "owner"           : "webuser",
        "pathSuffix"      : "a.patch",
        "permission"      : "644",
        "replication"     : 1,
        "type"            : "FILE"
      },
      {
        "accessTime"      : 0,
        "blockSize"       : 0,
        "group"           : "supergroup",
        "length"          : 0,
        "modificationTime": 1320895981256,
        "owner"           : "username",
        "pathSuffix"      : "bar",
        "permission"      : "711",
        "replication"     : 0,
        "type"            : "DIRECTORY"
      },
      ...
    ]
  }
}
*/

#[derive(Debug, Deserialize)]
pub struct ListStatusResponse {
    #[serde(rename="FileStatuses")]
    pub file_statuses: FileStatuses
}

#[derive(Debug, Deserialize)]
pub struct FileStatuses {
    #[serde(rename="FileStatus")]
    pub file_status: Vec<FileStatus>
}

#[derive(Debug, Deserialize)]
pub struct FileStatus {
    //"accessTime"      : 1320171722771,
    #[serde(rename="accessTime")]
    pub access_time: i64,

    //"blockSize"       : 33554432,
    #[serde(rename="blockSize")]
    pub block_size: i64,

    //"group"           : "supergroup",
    pub group: String,

    //"length"          : 24930,
    pub length: i64,

    //"modificationTime": 1320171722771,
    #[serde(rename="modificationTime")]
    pub modification_time: i64,

    //"owner"           : "webuser",
    pub owner: String,

    //"pathSuffix"      : "a.patch",
    #[serde(rename="pathSuffix")]
    pub path_suffix: String,

    //"permission"      : "644",
    pub permission: String,

    //"replication"     : 1,
    pub replication: i32,

    //"type"            : "FILE"
    #[serde(rename="type")]
    pub type_: String
}

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

{
  "FileStatus":
  {
    "accessTime"      : 0,
    "blockSize"       : 0,
    "group"           : "supergroup",
    "length"          : 0,             //in bytes, zero for directories
    "modificationTime": 1320173277227,
    "owner"           : "webuser",
    "pathSuffix"      : "",
    "permission"      : "777",
    "replication"     : 0,
    "type"            : "DIRECTORY"    //enum {FILE, DIRECTORY, SYMLINK}
  }
}
*/

#[derive(Debug, Deserialize)]
pub struct FileStatusResponse {
    #[serde(rename="FileStatus")]
    pub file_status: FileStatus
}