3 use crate::api_schema
::schema
::*;
4 use crate::api_schema
::router
::*;
5 //use crate::server::rest::*;
6 use serde_json
::{json, Value}
;
8 //use hyper::StatusCode;
9 //use hyper::rt::{Future, Stream};
11 use crate::config
::datastore
;
17 // this is just a test for mutability/mutex handling - will remove later
18 fn start_garbage_collection(
21 _rpcenv
: &mut RpcEnvironment
,
22 ) -> Result
<Value
, Error
> {
24 let store
= param
["store"].as_str().unwrap();
26 let datastore
= DataStore
::lookup_datastore(store
)?
;
28 println
!("Starting garbage collection on store {}", store
);
30 datastore
.garbage_collection()?
;
35 pub fn api_method_start_garbage_collection() -> ApiMethod
{
37 start_garbage_collection
,
38 ObjectSchema
::new("Start garbage collection.")
39 .required("store", StringSchema
::new("Datastore name."))
43 fn garbage_collection_status(
46 _rpcenv
: &mut RpcEnvironment
,
47 ) -> Result
<Value
, Error
> {
49 let store
= param
["store"].as_str().unwrap();
51 println
!("Garbage collection status on store {}", store
);
57 pub fn api_method_garbage_collection_status() -> ApiMethod
{
59 garbage_collection_status
,
60 ObjectSchema
::new("Garbage collection status.")
61 .required("store", StringSchema
::new("Datastore name."))
68 _rpcenv
: &mut RpcEnvironment
,
69 ) -> Result
<Value
, Error
> {
71 //let config = datastore::config()?;
73 let store
= param
["store"].as_str().unwrap();
75 let datastore
= DataStore
::lookup_datastore(store
)?
;
77 let mut list
= vec
![];
79 for info
in datastore
.list_backups()?
{
81 "backup_type": info
.backup_type
,
82 "backup_id": info
.backup_id
,
83 "backup_time": info
.backup_time
.timestamp(),
87 let result
= json
!(list
);
92 fn get_datastore_list(
95 _rpcenv
: &mut RpcEnvironment
,
96 ) -> Result
<Value
, Error
> {
98 let config
= datastore
::config()?
;
100 Ok(config
.convert_to_array("store"))
104 pub fn router() -> Router
{
106 let datastore_info
= Router
::new()
109 {"subdir": "backups" }
,
110 {"subdir": "catar" }
,
111 {"subdir": "status"}
,
114 ObjectSchema
::new("Directory index.")
115 .required("store", StringSchema
::new("Datastore name.")))
122 ObjectSchema
::new("List backups.")
123 .required("store", StringSchema
::new("Datastore name.")))))
127 .download(catar
::api_method_download_catar())
128 .upload(catar
::api_method_upload_catar()))
132 .get(api_method_garbage_collection_status())
133 .post(api_method_start_garbage_collection()));
137 let route
= Router
::new()
140 ObjectSchema
::new("Directory index.")))
141 .match_all("store", datastore_info
);