use std::{collections::BTreeSet, fmt, future::Future, path::Path, pin::Pin};
use dotcore_domain::SiteNodeId;
pub trait SiteRuntimeCleanups: Send + Sync + fmt::Debug {
fn site_cleanup(
&self,
bound: &BTreeSet<RuntimeBindingKind>,
) -> Result<Box<dyn SiteRuntimeCleanup>, SiteRuntimeResetConfigurationError>;
fn located_workloads(
&self,
root: &Path,
site_id: Option<String>,
site_node_id: Option<SiteNodeId>,
) -> Box<dyn LocatedWorkloadCleanup>;
fn remove_root_owned_site_data<'a>(
&'a self,
site_root: &'a Path,
) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send + 'a>>;
fn remove_workload_caches<'a>(
&'a self,
site_id: &'a str,
) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send + 'a>>;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum RuntimeBindingKind {
Docker,
Native,
Simulated,
}
impl RuntimeBindingKind {
pub const ALL: [Self; 3] = [Self::Docker, Self::Native, Self::Simulated];
}
pub trait LocatedWorkloadCleanup: Send + Sync + fmt::Debug {
fn runtime_name(&self) -> &'static str;
fn inventory(&self) -> Pin<Box<dyn Future<Output = anyhow::Result<Vec<String>>> + Send + '_>>;
fn cleanup(&self) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send + '_>>;
}
pub trait SiteRuntimeCleanup: Send + Sync {
fn inventory<'a>(
&'a self,
site_id: &'a str,
scope: &'a SiteRuntimeScope,
) -> Pin<Box<dyn Future<Output = anyhow::Result<SiteRuntimeInventory>> + Send + 'a>>;
fn cleanup<'a>(
&'a self,
site_id: &'a str,
scope: &'a SiteRuntimeScope,
) -> Pin<Box<dyn Future<Output = anyhow::Result<SiteRuntimeCleanupReport>> + Send + 'a>>;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SiteRuntimeScope {
Site,
ExecutionTargets(BTreeSet<String>),
}
#[derive(Debug, Default)]
pub struct SiteRuntimeInventory {
pub resources: Vec<SiteRuntimeResource>,
pub skipped: Vec<SkippedSiteRuntimeCleanup>,
}
#[derive(Debug)]
pub struct SiteRuntimeResource {
pub runtime: &'static str,
pub description: String,
}
#[derive(Debug, Default)]
pub struct SiteRuntimeCleanupReport {
pub skipped: Vec<SkippedSiteRuntimeCleanup>,
}
#[derive(Debug)]
pub struct SkippedSiteRuntimeCleanup {
pub runtime: &'static str,
pub reason: anyhow::Error,
}
#[derive(Debug, thiserror::Error)]
pub enum SiteRuntimeResetConfigurationError {
#[error(
"an execution target binds unknown runtime adapter {adapter:?}, whose resources site cleanup cannot classify"
)]
UnknownBinding {
adapter: String,
},
}