gary_core/plugins/
runtime.rs1use std::any::Any;
2use std::fmt;
3pub trait RuntimePlugin: Any + Send + Sync {
14 fn name(&self) -> String;
18 fn on_plugin_load(&self) {}
21 fn on_plugin_unload(&self) {}
24 fn get_features(&self) -> Vec<RuntimeFeatures>;
25 fn get_version(&self) -> i32;
26
27 fn create_workload(
29 &self,
30 id: String,
31 config: &RuntimeConfig,
32 options: &Option<SandboxConfig>,
33 ) -> Result<String, RuntimeError>;
34
35 fn start_workload(&mut self, id: String) -> Option<RuntimeError>;
36 fn stop_workload(&self, id: String, timeout: i32) -> Option<RuntimeError>;
37 fn remove_workload(&self, id: String) -> Option<RuntimeError>;
38 fn status_workload(&self, id: String) -> Result<WorkloadStatus, RuntimeError>;
39
40 fn update_workload_resources(&self, id: String, rez: WorkloadResources)
42 -> Option<RuntimeError>;
43 fn exec_sync(
44 &self,
45 id: String,
46 cmd: &[String],
47 timeout: i32,
48 ) -> (&[u8], &[u8], Option<RuntimeError>);
49
50 }
54
55pub struct WorkloadResources {}
56
57pub struct WorkloadStatus {}
58
59#[derive(Debug, PartialEq)]
60pub enum RuntimeFeatures {
61 WorkloadRunner,
62 Container,
63 VM,
64 Function,
65}
66
67pub struct RuntimeConfig {}
68
69pub struct SandboxConfig {}
70
71#[derive(Debug)]
72pub enum RuntimeErrorType {
73 Unimplemented,
74 Timeout,
75 Unknown,
76}
77
78#[derive(Debug)]
79pub struct RuntimeError {
80 error_type: RuntimeErrorType,
81}
82
83impl std::error::Error for RuntimeError {
84 fn description(&self) -> &str {
85 "This action has failed."
86 }
87}
88
89impl fmt::Display for RuntimeError {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 write!(f, "RuntimeError has arrived.")
92 }
93}
94
95impl RuntimeError {
96 pub fn new(kind: RuntimeErrorType) -> Self {
97 return RuntimeError { error_type: kind };
98 }
99}