From 0857aba039992437a687d14b82b03dd699d4bc1d Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Wed, 23 Apr 2025 10:15:51 -0400 Subject: [PATCH] Switch HAClusterTopology for K8sAnywhereTopology in lamp example --- examples/lamp/src/main.rs | 7 ++----- harmony_tui/src/lib.rs | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/lamp/src/main.rs b/examples/lamp/src/main.rs index feb8b4f..0887d04 100644 --- a/examples/lamp/src/main.rs +++ b/examples/lamp/src/main.rs @@ -1,9 +1,8 @@ use harmony::{ data::Version, - inventory::Inventory, maestro::Maestro, modules::lamp::{LAMPConfig, LAMPScore}, - topology::{HAClusterTopology, Url}, + topology::{K8sAnywhereTopology, Url}, }; #[tokio::main] @@ -18,9 +17,7 @@ async fn main() { }, }; - let inventory = Inventory::autoload(); - let topology = HAClusterTopology::autoload(); - let mut maestro = Maestro::new(inventory, topology); + let maestro = Maestro::::load_from_env(); maestro.register_all(vec![Box::new(lamp_stack)]); harmony_tui::init(maestro).await.unwrap(); } diff --git a/harmony_tui/src/lib.rs b/harmony_tui/src/lib.rs index c3a8a1a..908b057 100644 --- a/harmony_tui/src/lib.rs +++ b/harmony_tui/src/lib.rs @@ -51,7 +51,7 @@ pub mod tui { /// harmony_tui::init(maestro).await.unwrap(); /// } /// ``` -pub async fn init( +pub async fn init( maestro: Maestro, ) -> Result<(), Box> { HarmonyTUI::new(maestro).init().await @@ -63,12 +63,21 @@ pub struct HarmonyTUI { tui_state: TuiWidgetState, } -#[derive(Debug)] enum HarmonyTuiEvent { LaunchScore(Box>), } -impl HarmonyTUI { +impl std::fmt::Display for HarmonyTuiEvent { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let output = match self { + HarmonyTuiEvent::LaunchScore(score) => format!("LaunchScore({})",score.name()), + }; + + f.write_str(&output) + } +} + +impl HarmonyTUI { pub fn new(maestro: Maestro) -> Self { let maestro = Arc::new(maestro); let (_handle, sender) = Self::start_channel(maestro.clone()); @@ -91,7 +100,7 @@ impl HarmonyTUI { let handle = tokio::spawn(async move { info!("Starting message channel receiver loop"); while let Some(event) = receiver.recv().await { - info!("Received event {event:#?}"); + info!("Received event {event}"); match event { HarmonyTuiEvent::LaunchScore(score_item) => { let maestro = maestro.clone();