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
use std::any::Any;
use std::fmt;
pub trait RuntimePlugin: Any + Send + Sync {
fn name(&self) -> String;
fn on_plugin_load(&self) {}
fn on_plugin_unload(&self) {}
fn get_features(&self) -> Vec<RuntimeFeatures>;
fn get_version(&self) -> i32;
fn create_workload(
&self,
id: String,
config: &RuntimeConfig,
options: &Option<SandboxConfig>,
) -> Result<String, RuntimeError>;
fn start_workload(&mut self, id: String) -> Option<RuntimeError>;
fn stop_workload(&self, id: String, timeout: i32) -> Option<RuntimeError>;
fn remove_workload(&self, id: String) -> Option<RuntimeError>;
fn status_workload(&self, id: String) -> Result<WorkloadStatus, RuntimeError>;
fn update_workload_resources(&self, id: String, rez: WorkloadResources)
-> Option<RuntimeError>;
fn exec_sync(
&self,
id: String,
cmd: &[String],
timeout: i32,
) -> (&[u8], &[u8], Option<RuntimeError>);
}
pub struct WorkloadResources {}
pub struct WorkloadStatus {}
#[derive(Debug, PartialEq)]
pub enum RuntimeFeatures {
WorkloadRunner,
Container,
VM,
Function,
}
pub struct RuntimeConfig {}
pub struct SandboxConfig {}
#[derive(Debug)]
pub enum RuntimeErrorType {
Unimplemented,
Timeout,
Unknown,
}
#[derive(Debug)]
pub struct RuntimeError {
error_type: RuntimeErrorType,
}
impl std::error::Error for RuntimeError {
fn description(&self) -> &str {
"This action has failed."
}
}
impl fmt::Display for RuntimeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "RuntimeError has arrived.")
}
}
impl RuntimeError {
pub fn new(kind: RuntimeErrorType) -> Self {
return RuntimeError { error_type: kind };
}
}