]>
Commit | Line | Data |
---|---|---|
15e9b4ed DM |
1 | use failure::*; |
2 | ||
15e9b4ed DM |
3 | use crate::api::schema::*; |
4 | use crate::api::router::*; | |
5 | use serde_json::{json, Value}; | |
6 | ||
7 | use crate::config::datastore; | |
8 | ||
9 | use crate::backup::datastore::*; | |
10 | ||
15e9b4ed DM |
11 | // this is just a test for mutability/mutex handling - will remove later |
12 | fn start_garbage_collection(param: Value, _info: &ApiMethod) -> Result<Value, Error> { | |
13 | ||
14 | let name = param["name"].as_str().unwrap(); | |
15 | ||
2c32fdde | 16 | let datastore = DataStore::lookup_datastore(name)?; |
15e9b4ed DM |
17 | |
18 | println!("Starting garbage collection on store {}", name); | |
19 | ||
20 | datastore.garbage_collection()?; | |
21 | ||
22 | Ok(json!(null)) | |
23 | } | |
24 | ||
25 | fn get_datastore_list(_param: Value, _info: &ApiMethod) -> Result<Value, Error> { | |
26 | ||
27 | let config = datastore::config()?; | |
28 | ||
29 | Ok(config.convert_to_array("name")) | |
30 | } | |
31 | ||
32 | pub fn router() -> Router { | |
33 | ||
34 | let datastore_info = Router::new() | |
35 | .get(ApiMethod::new( | |
36 | |_,_| Ok(json!([ | |
37 | {"subdir": "status"}, | |
38 | {"subdir": "gc" } | |
39 | ])), | |
40 | ObjectSchema::new("Directory index.") | |
41 | .required("name", StringSchema::new("Datastore name."))) | |
42 | ) | |
43 | .subdir( | |
44 | "gc", | |
45 | Router::new() | |
46 | .post(ApiMethod::new( | |
47 | start_garbage_collection, | |
48 | ObjectSchema::new("Start garbage collection.") | |
49 | .required("name", StringSchema::new("Datastore name.")) | |
50 | ) | |
51 | )); | |
52 | ||
53 | ||
54 | ||
55 | let route = Router::new() | |
56 | .get(ApiMethod::new( | |
57 | get_datastore_list, | |
58 | ObjectSchema::new("Directory index."))) | |
59 | .match_all("name", datastore_info); | |
60 | ||
61 | ||
62 | ||
63 | route | |
64 | } |