Browse Source

Merge pull request #114 from dora-rs/cli-check

CLI check wether dora-runtime and iceoryx daemons are running
tags/v0.0.0-test-pr-120
Philipp Oppermann GitHub 3 years ago
parent
commit
a223504cbf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 119 additions and 18 deletions
  1. +34
    -6
      Cargo.lock
  2. +4
    -0
      binaries/cli/Cargo.toml
  3. +73
    -9
      binaries/cli/src/check.rs
  4. +8
    -3
      binaries/cli/src/main.rs

+ 34
- 6
Cargo.lock View File

@@ -885,12 +885,16 @@ dependencies = [
name = "dora-cli"
version = "0.1.0"
dependencies = [
"atty",
"clap 4.0.3",
"dora-core",
"eyre",
"serde_json",
"serde_yaml 0.9.11",
"sysinfo 0.26.6",
"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]]
@@ -2195,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"
@@ -2429,7 +2442,7 @@ checksum = "a848fb2d43cc8e5adabdedc6b37a88b45653d3a23b000a3d047e6953d5af42ea"
dependencies = [
"indexmap",
"opentelemetry",
"sysinfo",
"sysinfo 0.24.5",
]

[[package]]
@@ -3628,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",
@@ -4040,7 +4068,7 @@ dependencies = [
"lazy_static",
"log",
"serde",
"uuid 1.1.2",
"uuid 1.2.1",
]

[[package]]
@@ -4157,9 +4185,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",
]


+ 4
- 0
binaries/cli/Cargo.toml View File

@@ -18,3 +18,7 @@ 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"] }
sysinfo = "0.26.6"

+ 73
- 9
binaries/cli/src/check.rs View File

@@ -1,14 +1,72 @@
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 sysinfo::SystemExt;
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 error_occured = false;

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")?;
error_occured = true;
}
}
let _ = stdout.reset();

// check whether roudi is running
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 {
bail!("Environment check failed.");
}

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 +85,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
@@ -112,6 +174,8 @@ pub fn check(dataflow_path: &Path, runtime: &Path) -> eyre::Result<()> {
};
}

check_environment()?;

Ok(())
}



+ 8
- 3
binaries/cli/src/main.rs View File

@@ -25,8 +25,10 @@ struct Args {
#[derive(Debug, clap::Subcommand)]
enum Command {
Check {
dataflow: PathBuf,
runtime_path: PathBuf,
#[clap(long)]
dataflow: Option<PathBuf>,
#[clap(long)]
runtime_path: Option<PathBuf>,
},
Graph {
dataflow: PathBuf,
@@ -92,7 +94,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,


Loading…
Cancel
Save