Something went wrong. Try again.
POC : Observability infrastructure managment
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192use std::future::Future;
use serde::Deserialize;use topcoat::context::Cx;use topcoat::router::{content::Form, href, page};use topcoat::view::{View, ViewExt, view};use topcoat::Result;
use crate::deploy::{compose_hub, compose_satellite, ComposeAction};use crate::ui::app;
#[derive(Debug, Deserialize)]pub struct ComposeForm { pub target: String, #[serde(default)] pub name: String, pub action: String,}
fn parse_action(s: &str) -> anyhow::Result<ComposeAction> { match s { "start" => Ok(ComposeAction::Start), "stop" => Ok(ComposeAction::Stop), "restart" => Ok(ComposeAction::Restart), other => anyhow::bail!("unknown compose action: {other}"), }}
#[page(POST)]pub async fn action(cx: &Cx, Form(form): Form<ComposeForm>) -> Result<impl View + use<'_>> { let cfg = app(cx).config_snapshot(); let target = form.target.clone(); let name = form.name.clone(); let action = form.action.clone();
let result = tokio::task::spawn_blocking(move || -> anyhow::Result<String> { let act = parse_action(&action)?; match target.as_str() { "hub" => { compose_hub(&cfg, act)?; Ok(format!("Hub: docker compose {}", act.as_str())) } "satellite" => { if name.is_empty() { anyhow::bail!("name required for target=satellite"); } compose_satellite(&cfg, &name, act)?; Ok(format!( "Satellite {name}: docker compose {}", act.as_str() )) } other => anyhow::bail!("unknown target: {other}"), } }) .await .map_err(|e| topcoat::Error::msg(e.to_string()))?;
match result { Ok(msg) => Ok(view! { <section class="page-hero"> <p class="crumb"> <a href=(href!(super::home))>"Overview"</a> <span class="sep">"/"</span> <span>"Compose"</span> </p> <h1>"Compose"</h1> </section> <div class="panel"> <div class="ok-box">(msg.clone())</div> <div class="actions"> <a class="btn" href=(href!(super::home))>"Overview"</a> <a class="btn-secondary btn" href=(href!(super::hub::page))>"Hub"</a> </div> </div> } .boxed()), Err(e) => Ok(view! { <section class="page-hero"> <h1>"Compose failed"</h1> </section> <div class="panel"> <div class="err"><pre class="log">(format!("{e:#}"))</pre></div> <div class="actions"> <a class="btn" href=(href!(super::home))>"Overview"</a> </div> </div> } .boxed()), }}