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
use crate::rpc::*;
use serde::*;
use serde_json::Value;
use serde_repr::*;
use std::collections::BTreeMap;
use std::path::PathBuf;

rpc_interface! {
    trait GolemRes {

        #[id = "res.dirs"]
        fn get_res_dirs(&self) -> Result<CachePaths>;

        #[id = "res.dirs.size"]
        fn get_res_dirs_sizes(&self) -> Result<CacheSizes>;

        //
        #[id = "res.dir"]
        fn get_res_dir(&self, dir_type : DirType) -> Result<Value>;

        #[id = "res.dir.clear"]
        fn clear_dir(&self, dir_type : DirType, #[kwarg] older_than_seconds : Option<usize>) -> Result<()>;

        #[id = "env.hw.caps"]
        fn get_hw_caps(&self) -> Result<HwCaps>;

        #[id = "env.hw.preset"]
        fn get_hw_preset(&self, name : String) -> Result<HwPreset>;

        #[id = "env.hw.presets"]
        fn get_hw_presets(&self) -> Result<Vec<HwPreset>>;

        #[id = "env.hw.preset.create"]
        fn create_hw_preset(&self, preset : HwPreset) -> Result<HwPreset>;

        #[id = "env.hw.preset.update"]
        fn update_hw_preset(&self, preset_update : HwPreset) -> Result<HwPreset>;

        #[id = "env.hw.preset.delete"]
        fn delete_hw_preset(&self, name : String) -> Result<bool>;

        #[id = "env.hw.preset.activate"]
        fn activate_hw_preset(&self, name : String, run_benchmarks : bool) -> Result<Option<BTreeMap<String, f64>>>;

    }

    converter AsGolemRes as_golem_res;
}

#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum DirType {
    Distributed = 1,
    Received = 2,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CachePaths {
    #[serde(rename = "total received data")]
    pub received_files: PathBuf,
    #[serde(rename = "total distributed data")]
    pub distributed_files: PathBuf,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CacheSizes {
    #[serde(rename = "total received data")]
    pub received_files: String,
    #[serde(rename = "total distributed data")]
    pub distributed_files: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct HwCaps {
    pub cpu_cores: u32,
    /// disk in Kb
    pub disk: f64,
    /// memory in kb
    pub memory: u64,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct HwPreset {
    #[serde(flatten)]
    pub caps: HwCaps,
    pub name: String,
}