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 };
}
}