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
use crate::objects::*;
use crate::registry::AppRegistry;
use juniper::FieldResult;
use kubos_app::RunLevel;
use kubos_service;
type Context = kubos_service::Context<AppRegistry>;
pub struct QueryRoot;
graphql_object!(QueryRoot : Context as "Query" |&self| {
field ping() -> FieldResult<String>
as "Test service query"
{
Ok(String::from("pong"))
}
field apps(&executor,
name: Option<String>,
version: Option<String>,
active: Option<bool>)
-> FieldResult<Vec<KAppRegistryEntry>> as "Kubos Apps Query"
{
let mut result: Vec<KAppRegistryEntry> = Vec::new();
let entries = executor.context().subsystem().entries.lock()?;
let final_iter = entries.iter().filter(|ref e| {
if name.is_some() && &e.app.name != name.as_ref().unwrap() {
return false;
}
if version.is_some() && &e.app.version != version.as_ref().unwrap() {
return false;
}
if active.is_some() && e.active_version != active.unwrap() {
return false;
}
true
});
for entry in final_iter {
result.push(KAppRegistryEntry(entry.clone()));
}
Ok(result)
}
});
pub struct MutationRoot;
graphql_object!(MutationRoot : Context as "Mutation" |&self| {
field register(&executor, path: String) -> FieldResult<RegisterResponse>
as "Register App"
{
let registry = executor.context().subsystem();
Ok(match registry.register(&path) {
Ok(app) => RegisterResponse { success: true, errors: "".to_owned(), entry: Some(KAppRegistryEntry(app))},
Err(error) => RegisterResponse {
success: false,
errors: error.to_string(),
entry: None
}
})
}
field uninstall(&executor, name: String, version: Option<String>) -> FieldResult<GenericResponse>
as "Uninstall App"
{
if let Some(val) = version {
Ok(match executor.context().subsystem().uninstall(&name, &val) {
Ok(v) => GenericResponse { success: true, errors: "".to_owned() },
Err(error) => GenericResponse { success: false, errors: error.to_string() },
})
} else {
Ok(match executor.context().subsystem().uninstall_all(&name) {
Ok(v) => GenericResponse { success: true, errors: "".to_owned() },
Err(error) => GenericResponse { success: false, errors: error.to_string() },
})
}
}
field set_version(&executor, name: String, version: String) -> FieldResult<GenericResponse>
as "Set App Active Version"
{
Ok(match executor.context().subsystem().set_version(&name, &version) {
Ok(v) => GenericResponse { success: true, errors: "".to_owned() },
Err(error) => GenericResponse { success: false, errors: error.to_string() },
})
}
field start_app(&executor, name: String, run_level: String, args: Option<Vec<String>>) -> FieldResult<StartResponse>
as "Start App"
{
let run_level_o = {
match run_level.as_ref() {
"OnBoot" => RunLevel::OnBoot,
_ => RunLevel::OnCommand
}
};
let args = if let Some(mut params) = args {
let mut temp = vec!["--".to_owned()];
temp.append(&mut params);
Some(temp)
} else {
None
};
Ok(match executor.context().subsystem().start_app(&name, &run_level_o, args) {
Ok(num) => StartResponse { success: true, errors: "".to_owned(), pid: Some(num as i32)},
Err(error) => StartResponse { success: false, errors: error.to_string(), pid: None },
})
}
});