106 lines
2.4 KiB
Rust
106 lines
2.4 KiB
Rust
use std::error::Error;
|
|
|
|
use async_trait::async_trait;
|
|
use derive_new::new;
|
|
use serde::Serialize;
|
|
|
|
use crate::{executors::ExecutorError, topology::Topology};
|
|
|
|
/// An ApplicationFeature provided by harmony, such as Backups, Monitoring, MultisiteAvailability,
|
|
/// ContinuousIntegration, ContinuousDelivery
|
|
#[async_trait]
|
|
pub trait ApplicationFeature<T: Topology>:
|
|
std::fmt::Debug + Send + Sync + ApplicationFeatureClone<T>
|
|
{
|
|
async fn ensure_installed(
|
|
&self,
|
|
topology: &T,
|
|
) -> Result<InstallationOutcome, InstallationError>;
|
|
fn name(&self) -> String;
|
|
}
|
|
|
|
pub trait ApplicationFeatureClone<T: Topology> {
|
|
fn clone_box(&self) -> Box<dyn ApplicationFeature<T>>;
|
|
}
|
|
|
|
impl<A, T: Topology> ApplicationFeatureClone<T> for A
|
|
where
|
|
A: ApplicationFeature<T> + Clone + 'static,
|
|
{
|
|
fn clone_box(&self) -> Box<dyn ApplicationFeature<T>> {
|
|
Box::new(self.clone())
|
|
}
|
|
}
|
|
|
|
impl<T: Topology> Serialize for Box<dyn ApplicationFeature<T>> {
|
|
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: serde::Serializer,
|
|
{
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl<T: Topology> Clone for Box<dyn ApplicationFeature<T>> {
|
|
fn clone(&self) -> Self {
|
|
self.clone_box()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum InstallationOutcome {
|
|
Success { details: Vec<String> },
|
|
Noop,
|
|
}
|
|
|
|
impl InstallationOutcome {
|
|
pub fn success() -> Self {
|
|
Self::Success { details: vec![] }
|
|
}
|
|
|
|
pub fn success_with_details(details: Vec<String>) -> Self {
|
|
Self::Success { details }
|
|
}
|
|
|
|
pub fn noop() -> Self {
|
|
Self::Noop
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, new)]
|
|
pub struct InstallationError {
|
|
msg: String,
|
|
}
|
|
|
|
impl std::fmt::Display for InstallationError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_str(&self.msg)
|
|
}
|
|
}
|
|
|
|
impl Error for InstallationError {}
|
|
|
|
impl From<ExecutorError> for InstallationError {
|
|
fn from(value: ExecutorError) -> Self {
|
|
Self {
|
|
msg: format!("InstallationError : {value}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<kube::Error> for InstallationError {
|
|
fn from(value: kube::Error) -> Self {
|
|
Self {
|
|
msg: format!("InstallationError : {value}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<String> for InstallationError {
|
|
fn from(value: String) -> Self {
|
|
Self {
|
|
msg: format!("PreparationError : {value}"),
|
|
}
|
|
}
|
|
}
|