monitoring-alerting #30
59
harmony/src/domain/topology/monitoring_alerting.rs
Normal file
59
harmony/src/domain/topology/monitoring_alerting.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use serde::Serialize;
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::interpret::{InterpretError, Outcome};
|
||||
|
||||
use super::{HelmCommand, Topology};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct MonitoringState {
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MonitoringAlertingTopology {
|
||||
monitoring_state: OnceCell<Option<MonitoringState>>,
|
||||
}
|
||||
|
||||
|
||||
impl MonitoringAlertingTopology {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
monitoring_state: OnceCell::new(),
|
||||
}
|
||||
}
|
||||
fn get_monitoring_state(&self) -> Result<Option<MonitoringState>, InterpretError> {
|
||||
let state = MonitoringState {
|
||||
message: "monitoring stack not installed".to_string(),
|
||||
};
|
||||
Ok(Some(state))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Topology for MonitoringAlertingTopology {
|
||||
fn name(&self) -> &str {
|
||||
"MonitoringAlertingTopology"
|
||||
}
|
||||
|
||||
async fn ensure_ready(&self) -> Result<Outcome, InterpretError> {
|
||||
let monitoring_state = self
|
||||
.monitoring_state
|
||||
.get_or_try_init(|| async { self.get_monitoring_state() })
|
||||
.await?;
|
||||
|
||||
if monitoring_state.is_some() {
|
||||
Ok(Outcome::success(
|
||||
"Monitoring stack already installed".to_string(),
|
||||
))
|
||||
} else {
|
||||
Ok(Outcome::success(
|
||||
"Monitoring stack not installed".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HelmCommand for MonitoringAlertingTopology {}
|
||||
Loading…
Reference in New Issue
Block a user