From 559875a577fb52a76fd484f7d681f7f24af459ac Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Oct 2022 14:43:24 +0200 Subject: [PATCH 1/4] CLI check wether dora-runtime is running --- Cargo.lock | 12 +++++--- binaries/cli/Cargo.toml | 3 ++ binaries/cli/src/check.rs | 60 +++++++++++++++++++++++++++++++++------ binaries/cli/src/main.rs | 11 +++++-- 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6fb1933..b6890767 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -885,12 +885,16 @@ dependencies = [ name = "dora-cli" version = "0.1.0" dependencies = [ + "atty", "clap 4.0.3", + "communication-layer-pub-sub", "dora-core", "eyre", "serde_json", "serde_yaml 0.9.11", "tempfile", + "termcolor", + "uuid 1.2.1", "webbrowser", "zenoh", ] @@ -990,7 +994,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", - "uuid 1.1.2", + "uuid 1.2.1", ] [[package]] @@ -4040,7 +4044,7 @@ dependencies = [ "lazy_static", "log", "serde", - "uuid 1.1.2", + "uuid 1.2.1", ] [[package]] @@ -4157,9 +4161,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.1.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" +checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" dependencies = [ "getrandom", ] diff --git a/binaries/cli/Cargo.toml b/binaries/cli/Cargo.toml index abd7ca4b..33410c25 100644 --- a/binaries/cli/Cargo.toml +++ b/binaries/cli/Cargo.toml @@ -18,3 +18,6 @@ tempfile = "3.3.0" webbrowser = "0.8.0" zenoh = { git = "https://github.com/eclipse-zenoh/zenoh.git" } serde_json = "1.0.86" +termcolor = "1.1.3" +atty = "0.2.14" +uuid = { version = "1.2.1", features = ["v4"] } diff --git a/binaries/cli/src/check.rs b/binaries/cli/src/check.rs index d4163d8c..ac0f86a9 100644 --- a/binaries/cli/src/check.rs +++ b/binaries/cli/src/check.rs @@ -1,14 +1,52 @@ -use crate::graph::read_descriptor; +use crate::{graph::read_descriptor, zenoh_control_session}; use dora_core::{ adjust_shared_library_path, config::{InputMapping, UserInputMapping}, descriptor::{self, source_is_url, CoreNodeKind, OperatorSource}, + topics::ZENOH_CONTROL_LIST, }; use eyre::{bail, eyre, Context}; -use std::{env::consts::EXE_EXTENSION, path::Path}; +use std::{env::consts::EXE_EXTENSION, io::Write, path::Path}; +use termcolor::{Color, ColorChoice, ColorSpec, WriteColor}; +use zenoh::{prelude::Receiver, sync::ZFuture}; -pub fn check(dataflow_path: &Path, runtime: &Path) -> eyre::Result<()> { - let runtime = runtime.with_extension(EXE_EXTENSION); +pub fn check_environment() -> eyre::Result<()> { + let mut control_session = None; + + let color_choice = if atty::is(atty::Stream::Stdout) { + ColorChoice::Auto + } else { + ColorChoice::Never + }; + let mut stdout = termcolor::StandardStream::stdout(color_choice); + + // check whether coordinator is running + let reply_receiver = zenoh_control_session(&mut control_session)? + .get(ZENOH_CONTROL_LIST) + .wait() + .map_err(|err| eyre!(err)) + .wrap_err("failed to create publisher for list message")?; + write!(stdout, "Dora Coordinator: ")?; + match reply_receiver.recv() { + Ok(_) => { + let _ = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green))); + writeln!(stdout, "ok")?; + } + Err(_) => { + let _ = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))); + writeln!(stdout, "not running")?; + } + } + let _ = stdout.reset(); + + // check whether roudi is running + + // TODO, blocked on https://github.com/eclipse-iceoryx/iceoryx-rs/issues/62 + + Ok(()) +} + +pub fn check_dataflow(dataflow_path: &Path, runtime: Option<&Path>) -> eyre::Result<()> { let descriptor = read_descriptor(dataflow_path).wrap_err_with(|| { format!( "failed to read dataflow descriptor at {}", @@ -27,12 +65,16 @@ pub fn check(dataflow_path: &Path, runtime: &Path) -> eyre::Result<()> { if nodes .iter() .any(|n| matches!(n.kind, CoreNodeKind::Runtime(_))) - && !runtime.is_file() { - bail!( - "There is no runtime at {}, or it is not a file", - runtime.display() - ); + let runtime = runtime + .unwrap_or_else(|| Path::new("dora-runtime")) + .with_extension(EXE_EXTENSION); + if !runtime.is_file() { + bail!( + "There is no runtime at {}, or it is not a file", + runtime.display() + ); + } } // check that nodes and operators exist diff --git a/binaries/cli/src/main.rs b/binaries/cli/src/main.rs index 3a9bd4ff..67ea2f06 100644 --- a/binaries/cli/src/main.rs +++ b/binaries/cli/src/main.rs @@ -26,8 +26,10 @@ struct Args { #[derive(Debug, clap::Subcommand)] enum Command { Check { - dataflow: PathBuf, - runtime_path: PathBuf, + #[clap(long)] + dataflow: Option, + #[clap(long)] + runtime_path: Option, }, Graph { dataflow: PathBuf, @@ -93,7 +95,10 @@ fn main() -> eyre::Result<()> { Command::Check { dataflow, runtime_path, - } => check::check(&dataflow, &runtime_path)?, + } => match dataflow { + Some(dataflow) => check::check_dataflow(&dataflow, runtime_path.as_deref())?, + None => check::check_environment()?, + }, Command::Graph { dataflow, mermaid, From 3f8891758f522e95651955a289527f240387a377 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Oct 2022 14:49:36 +0200 Subject: [PATCH 2/4] Error when the environment check fails --- Cargo.lock | 1 - binaries/cli/src/check.rs | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6890767..d23757ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -887,7 +887,6 @@ version = "0.1.0" dependencies = [ "atty", "clap 4.0.3", - "communication-layer-pub-sub", "dora-core", "eyre", "serde_json", diff --git a/binaries/cli/src/check.rs b/binaries/cli/src/check.rs index ac0f86a9..f73b302e 100644 --- a/binaries/cli/src/check.rs +++ b/binaries/cli/src/check.rs @@ -11,6 +11,8 @@ use termcolor::{Color, ColorChoice, ColorSpec, WriteColor}; use zenoh::{prelude::Receiver, sync::ZFuture}; pub fn check_environment() -> eyre::Result<()> { + let mut error_occured = false; + let mut control_session = None; let color_choice = if atty::is(atty::Stream::Stdout) { @@ -35,14 +37,20 @@ pub fn check_environment() -> eyre::Result<()> { Err(_) => { let _ = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))); writeln!(stdout, "not running")?; + error_occured = true; } } let _ = stdout.reset(); // check whether roudi is running - // TODO, blocked on https://github.com/eclipse-iceoryx/iceoryx-rs/issues/62 + writeln!(stdout)?; + + if error_occured { + bail!("Environment check failed."); + } + Ok(()) } From 2adaf1e74b46d00569d48ec07e22eaff82aded4f Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Oct 2022 14:50:15 +0200 Subject: [PATCH 3/4] Also check the environment when checking a dataflow --- binaries/cli/src/check.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/binaries/cli/src/check.rs b/binaries/cli/src/check.rs index f73b302e..f5e4c2f2 100644 --- a/binaries/cli/src/check.rs +++ b/binaries/cli/src/check.rs @@ -162,6 +162,8 @@ pub fn check_dataflow(dataflow_path: &Path, runtime: Option<&Path>) -> eyre::Res }; } + check_environment()?; + Ok(()) } From aec8643366333848c2f75520a10d2eddfba1c82f Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Oct 2022 17:47:04 +0200 Subject: [PATCH 4/4] Check if `iox-roudi` process is running --- Cargo.lock | 29 +++++++++++++++++++++++++++-- binaries/cli/Cargo.toml | 1 + binaries/cli/src/check.rs | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d23757ba..dd3bf953 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,6 +891,7 @@ dependencies = [ "eyre", "serde_json", "serde_yaml 0.9.11", + "sysinfo 0.26.6", "tempfile", "termcolor", "uuid 1.2.1", @@ -2198,6 +2199,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ntapi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc" +dependencies = [ + "winapi", +] + [[package]] name = "num-bigint-dig" version = "0.7.0" @@ -2432,7 +2442,7 @@ checksum = "a848fb2d43cc8e5adabdedc6b37a88b45653d3a23b000a3d047e6953d5af42ea" dependencies = [ "indexmap", "opentelemetry", - "sysinfo", + "sysinfo 0.24.5", ] [[package]] @@ -3631,7 +3641,22 @@ dependencies = [ "cfg-if", "core-foundation-sys", "libc", - "ntapi", + "ntapi 0.3.7", + "once_cell", + "rayon", + "winapi", +] + +[[package]] +name = "sysinfo" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6d0dedf2e65d25b365c588382be9dc3a3ee4b0ed792366cf722d174c359d948" +dependencies = [ + "cfg-if", + "core-foundation-sys", + "libc", + "ntapi 0.4.0", "once_cell", "rayon", "winapi", diff --git a/binaries/cli/Cargo.toml b/binaries/cli/Cargo.toml index 33410c25..c1f99ab4 100644 --- a/binaries/cli/Cargo.toml +++ b/binaries/cli/Cargo.toml @@ -21,3 +21,4 @@ serde_json = "1.0.86" termcolor = "1.1.3" atty = "0.2.14" uuid = { version = "1.2.1", features = ["v4"] } +sysinfo = "0.26.6" diff --git a/binaries/cli/src/check.rs b/binaries/cli/src/check.rs index f5e4c2f2..57ff3a06 100644 --- a/binaries/cli/src/check.rs +++ b/binaries/cli/src/check.rs @@ -7,6 +7,7 @@ use dora_core::{ }; use eyre::{bail, eyre, Context}; use std::{env::consts::EXE_EXTENSION, io::Write, path::Path}; +use sysinfo::SystemExt; use termcolor::{Color, ColorChoice, ColorSpec, WriteColor}; use zenoh::{prelude::Receiver, sync::ZFuture}; @@ -43,8 +44,19 @@ pub fn check_environment() -> eyre::Result<()> { let _ = stdout.reset(); // check whether roudi is running - // TODO, blocked on https://github.com/eclipse-iceoryx/iceoryx-rs/issues/62 - + write!(stdout, "Iceoryx Daemon: ")?; + let system = sysinfo::System::new_all(); + match system.processes_by_exact_name("iox-roudi").next() { + Some(_) => { + let _ = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green))); + writeln!(stdout, "ok")?; + } + None => { + let _ = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))); + writeln!(stdout, "not running")?; + error_occured = true; + } + } writeln!(stdout)?; if error_occured {