fix(cli): simplify running the CLI by hiding the maestro inside the implemtation #93
@ -1,20 +1,21 @@
|
|||||||
use harmony::{
|
use harmony::{
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
maestro::Maestro,
|
|
||||||
modules::dummy::{ErrorScore, PanicScore, SuccessScore},
|
modules::dummy::{ErrorScore, PanicScore, SuccessScore},
|
||||||
topology::LocalhostTopology,
|
topology::LocalhostTopology,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let inventory = Inventory::autoload();
|
harmony_cli::run(
|
||||||
let topology = LocalhostTopology::new();
|
LocalhostTopology::new(),
|
||||||
let mut maestro = Maestro::initialize(inventory, topology).await.unwrap();
|
Inventory::autoload(),
|
||||||
|
vec![
|
||||||
maestro.register_all(vec![
|
Box::new(SuccessScore {}),
|
||||||
Box::new(SuccessScore {}),
|
Box::new(ErrorScore {}),
|
||||||
Box::new(ErrorScore {}),
|
Box::new(PanicScore {}),
|
||||||
Box::new(PanicScore {}),
|
],
|
||||||
]);
|
None,
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use harmony::{
|
use harmony::{
|
||||||
data::Version,
|
data::Version,
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
maestro::Maestro,
|
|
||||||
modules::lamp::{LAMPConfig, LAMPScore},
|
modules::lamp::{LAMPConfig, LAMPScore},
|
||||||
topology::{K8sAnywhereTopology, Url},
|
topology::{K8sAnywhereTopology, Url},
|
||||||
};
|
};
|
||||||
@ -43,15 +42,13 @@ async fn main() {
|
|||||||
// K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy
|
// K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy
|
||||||
// locally, to development environment from a CI, to staging, and to production with settings
|
// locally, to development environment from a CI, to staging, and to production with settings
|
||||||
// that automatically adapt to each environment grade.
|
// that automatically adapt to each environment grade.
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
harmony_cli::run(
|
||||||
Inventory::autoload(),
|
|
||||||
K8sAnywhereTopology::from_env(),
|
K8sAnywhereTopology::from_env(),
|
||||||
|
Inventory::autoload(),
|
||||||
|
vec![Box::new(lamp_stack)],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(lamp_stack)]);
|
|
||||||
// Here we bootstrap the CLI, this gives some nice features if you need them
|
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
|
||||||
}
|
}
|
||||||
// That's it, end of the infra as code.
|
// That's it, end of the infra as code.
|
||||||
|
@ -2,7 +2,6 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use harmony::{
|
use harmony::{
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
maestro::Maestro,
|
|
||||||
modules::{
|
modules::{
|
||||||
monitoring::{
|
monitoring::{
|
||||||
alert_channel::discord_alert_channel::DiscordWebhook,
|
alert_channel::discord_alert_channel::DiscordWebhook,
|
||||||
@ -74,13 +73,13 @@ async fn main() {
|
|||||||
rules: vec![Box::new(additional_rules), Box::new(additional_rules2)],
|
rules: vec![Box::new(additional_rules), Box::new(additional_rules2)],
|
||||||
service_monitors: vec![service_monitor],
|
service_monitors: vec![service_monitor],
|
||||||
};
|
};
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
|
||||||
Inventory::autoload(),
|
harmony_cli::run(
|
||||||
K8sAnywhereTopology::from_env(),
|
K8sAnywhereTopology::from_env(),
|
||||||
|
Inventory::autoload(),
|
||||||
|
vec![Box::new(alerting_score)],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(alerting_score)]);
|
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ use std::collections::HashMap;
|
|||||||
use harmony::{
|
use harmony::{
|
||||||
data::Id,
|
data::Id,
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
maestro::Maestro,
|
|
||||||
modules::{
|
modules::{
|
||||||
monitoring::{
|
monitoring::{
|
||||||
alert_channel::discord_alert_channel::DiscordWebhook,
|
alert_channel::discord_alert_channel::DiscordWebhook,
|
||||||
@ -78,13 +77,13 @@ async fn main() {
|
|||||||
rules: vec![Box::new(additional_rules)],
|
rules: vec![Box::new(additional_rules)],
|
||||||
service_monitors: vec![service_monitor],
|
service_monitors: vec![service_monitor],
|
||||||
};
|
};
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
|
||||||
Inventory::autoload(),
|
harmony_cli::run(
|
||||||
K8sAnywhereTopology::from_env(),
|
K8sAnywhereTopology::from_env(),
|
||||||
|
Inventory::autoload(),
|
||||||
|
vec![Box::new(tenant), Box::new(alerting_score)],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(tenant), Box::new(alerting_score)]);
|
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
use harmony::{
|
use harmony::{
|
||||||
inventory::Inventory, maestro::Maestro, modules::monitoring::ntfy::ntfy::NtfyScore,
|
inventory::Inventory, modules::monitoring::ntfy::ntfy::NtfyScore, topology::K8sAnywhereTopology,
|
||||||
topology::K8sAnywhereTopology,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
harmony_cli::run(
|
||||||
Inventory::autoload(),
|
|
||||||
K8sAnywhereTopology::from_env(),
|
K8sAnywhereTopology::from_env(),
|
||||||
|
Inventory::autoload(),
|
||||||
|
vec![Box::new(NtfyScore {
|
||||||
|
namespace: "monitoring".to_string(),
|
||||||
|
host: "localhost".to_string(),
|
||||||
|
})],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(NtfyScore {
|
|
||||||
namespace: "monitoring".to_string(),
|
|
||||||
host: "localhost".to_string(),
|
|
||||||
})]);
|
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,15 @@ use std::{path::PathBuf, sync::Arc};
|
|||||||
|
|
||||||
use harmony::{
|
use harmony::{
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
maestro::Maestro,
|
|
||||||
modules::application::{
|
modules::application::{
|
||||||
ApplicationScore, RustWebFramework, RustWebapp,
|
ApplicationScore, RustWebFramework, RustWebapp,
|
||||||
features::{ContinuousDelivery, Monitoring},
|
features::{ContinuousDelivery, Monitoring},
|
||||||
},
|
},
|
||||||
topology::{K8sAnywhereTopology, Url},
|
topology::{K8sAnywhereTopology, Url},
|
||||||
};
|
};
|
||||||
use harmony_cli::cli_logger;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let cli_logger_handle = cli_logger::init();
|
|
||||||
|
|
||||||
let topology = K8sAnywhereTopology::from_env();
|
|
||||||
let mut maestro = Maestro::initialize(Inventory::autoload(), topology)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let application = Arc::new(RustWebapp {
|
let application = Arc::new(RustWebapp {
|
||||||
name: "harmony-example-rust-webapp".to_string(),
|
name: "harmony-example-rust-webapp".to_string(),
|
||||||
domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()),
|
domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()),
|
||||||
@ -39,8 +30,12 @@ async fn main() {
|
|||||||
application,
|
application,
|
||||||
};
|
};
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(app)]);
|
harmony_cli::run(
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
K8sAnywhereTopology::from_env(),
|
||||||
|
Inventory::autoload(),
|
||||||
let _ = tokio::try_join!(cli_logger_handle);
|
vec![Box::new(app)],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use harmony::{
|
use harmony::{
|
||||||
data::Id,
|
data::Id,
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
maestro::Maestro,
|
|
||||||
modules::tenant::TenantScore,
|
modules::tenant::TenantScore,
|
||||||
topology::{K8sAnywhereTopology, tenant::TenantConfig},
|
topology::{K8sAnywhereTopology, tenant::TenantConfig},
|
||||||
};
|
};
|
||||||
@ -16,15 +15,14 @@ async fn main() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
harmony_cli::run(
|
||||||
Inventory::autoload(),
|
|
||||||
K8sAnywhereTopology::from_env(),
|
K8sAnywhereTopology::from_env(),
|
||||||
|
Inventory::autoload(),
|
||||||
|
vec![Box::new(tenant)],
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(tenant)]);
|
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO write tests
|
// TODO write tests
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
|
|
||||||
use log::{debug, info, warn};
|
use log::{debug, warn};
|
||||||
|
|
||||||
use crate::instrumentation::{self, HarmonyEvent};
|
use crate::instrumentation::{self, HarmonyEvent};
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use clap::builder::ArgPredicate;
|
use clap::builder::ArgPredicate;
|
||||||
use harmony;
|
use harmony::inventory::Inventory;
|
||||||
|
use harmony::maestro::Maestro;
|
||||||
use harmony::{score::Score, topology::Topology};
|
use harmony::{score::Score, topology::Topology};
|
||||||
use inquire::Confirm;
|
use inquire::Confirm;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
pub mod cli_logger; // FIXME: Don't make me pub
|
pub mod cli_logger; // FIXME: Don't make me pub
|
||||||
pub mod progress;
|
pub mod progress;
|
||||||
@ -10,7 +12,6 @@ pub mod theme;
|
|||||||
|
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
use harmony_tui;
|
use harmony_tui;
|
||||||
use log::debug;
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
@ -85,6 +86,23 @@ fn list_scores_with_index<T: Topology>(scores_vec: &Vec<Box<dyn Score<T>>>) -> S
|
|||||||
return display_str;
|
return display_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn run<T: Topology + Send + Sync + 'static>(
|
||||||
|
topology: T,
|
||||||
|
inventory: Inventory,
|
||||||
|
scores: Vec<Box<dyn Score<T>>>,
|
||||||
|
args_struct: Option<Args>,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let cli_logger_handle = cli_logger::init();
|
||||||
|
|
||||||
|
let mut maestro = Maestro::initialize(inventory, topology).await.unwrap();
|
||||||
|
maestro.register_all(scores);
|
||||||
|
|
||||||
|
let result = init(maestro, args_struct).await;
|
||||||
|
|
||||||
|
let _ = tokio::try_join!(cli_logger_handle);
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn init<T: Topology + Send + Sync + 'static>(
|
pub async fn init<T: Topology + Send + Sync + 'static>(
|
||||||
maestro: harmony::maestro::Maestro<T>,
|
maestro: harmony::maestro::Maestro<T>,
|
||||||
args_struct: Option<Args>,
|
args_struct: Option<Args>,
|
||||||
|
Loading…
Reference in New Issue
Block a user