diff --git a/Cargo.lock b/Cargo.lock index 5ca9417b..89f666e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -791,6 +791,9 @@ name = "dora-cli" version = "0.1.0" dependencies = [ "clap 3.2.20", + "dora-core", + "eyre", + "serde_yaml 0.9.11", ] [[package]] @@ -807,7 +810,7 @@ dependencies = [ "futures-concurrency", "rand", "serde", - "serde_yaml", + "serde_yaml 0.8.23", "time", "tokio", "tokio-stream", @@ -824,6 +827,7 @@ dependencies = [ "dora-node-api", "eyre", "serde", + "serde_yaml 0.9.11", ] [[package]] @@ -866,7 +870,7 @@ dependencies = [ "flume", "once_cell", "serde", - "serde_yaml", + "serde_yaml 0.8.23", "thiserror", "tokio", "tracing", @@ -892,7 +896,7 @@ dependencies = [ "eyre", "flume", "pyo3", - "serde_yaml", + "serde_yaml 0.8.23", ] [[package]] @@ -944,7 +948,7 @@ dependencies = [ "futures-concurrency", "libloading", "pyo3", - "serde_yaml", + "serde_yaml 0.8.23", "tokio", "tokio-stream", "tracing", @@ -1300,9 +1304,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" @@ -1493,9 +1497,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg 1.1.0", "hashbrown", @@ -2943,18 +2947,18 @@ checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4" [[package]] name = "serde" -version = "1.0.136" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" dependencies = [ "proc-macro2", "quote", @@ -2984,6 +2988,19 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "serde_yaml" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89f31df3f50926cdf2855da5fd8812295c34752cb20438dae42a67f79e021ac3" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha-1" version = "0.8.2" @@ -3594,6 +3611,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514672a55d7380da379785a4d70ca8386c8883ff7eaae877be4d2081cebe73d8" +[[package]] +name = "unsafe-libyaml" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0" + [[package]] name = "untrusted" version = "0.7.1" @@ -4065,7 +4088,7 @@ dependencies = [ "num_cpus", "serde", "serde_json", - "serde_yaml", + "serde_yaml 0.8.23", "validated_struct", "zenoh-cfg-properties", "zenoh-core", diff --git a/binaries/cli/Cargo.toml b/binaries/cli/Cargo.toml index a035fade..3cf09970 100644 --- a/binaries/cli/Cargo.toml +++ b/binaries/cli/Cargo.toml @@ -11,3 +11,6 @@ path = "src/main.rs" [dependencies] clap = { version = "3.2.20", features = ["derive"] } +eyre = "0.6.8" +dora-core = { path = "../../libraries/core" } +serde_yaml = "0.9.11" diff --git a/binaries/cli/src/graph.rs b/binaries/cli/src/graph.rs new file mode 100644 index 00000000..69eb7357 --- /dev/null +++ b/binaries/cli/src/graph.rs @@ -0,0 +1,29 @@ +use std::{ + fs, + path::{Path, PathBuf}, +}; + +use dora_core::descriptor::Descriptor; +use eyre::Context; + +pub fn run(dataflow: PathBuf) -> eyre::Result<()> { + let descriptor = read_descriptor(&dataflow) + .with_context(|| format!("failed to read dataflow at `{}`", dataflow.display()))?; + let visualized = descriptor + .visualize_as_mermaid() + .context("failed to visualize descriptor")?; + println!("{visualized}"); + println!( + "Paste the above output on https://mermaid.live/ or in a \ + ```mermaid code block on GitHub to display it." + ); + + Ok(()) +} + +fn read_descriptor(file: &Path) -> eyre::Result { + let descriptor_file = fs::read(file).context("failed to open given file")?; + let descriptor: Descriptor = + serde_yaml::from_slice(&descriptor_file).context("failed to parse given descriptor")?; + Ok(descriptor) +} diff --git a/binaries/cli/src/main.rs b/binaries/cli/src/main.rs index 7dc70d72..0b1bb713 100644 --- a/binaries/cli/src/main.rs +++ b/binaries/cli/src/main.rs @@ -1,4 +1,7 @@ use clap::Parser; +use std::path::PathBuf; + +mod graph; #[derive(Debug, clap::Parser)] #[clap(version)] @@ -10,7 +13,7 @@ struct Args { #[derive(Debug, clap::Subcommand)] enum Command { Check, - Graph, + Graph { dataflow: PathBuf }, Build, Templates, Dashboard, @@ -24,12 +27,12 @@ enum Command { Upgrade, } -fn main() { +fn main() -> eyre::Result<()> { let args = Args::parse(); match args.command { Command::Check => todo!(), - Command::Graph => todo!(), + Command::Graph { dataflow } => graph::run(dataflow)?, Command::Build => todo!(), Command::Templates => todo!(), Command::Dashboard => todo!(), @@ -42,4 +45,6 @@ fn main() { Command::Get => todo!(), Command::Upgrade => todo!(), } + + Ok(()) } diff --git a/binaries/coordinator/src/lib.rs b/binaries/coordinator/src/lib.rs index 5457be2a..93e295cc 100644 --- a/binaries/coordinator/src/lib.rs +++ b/binaries/coordinator/src/lib.rs @@ -15,8 +15,6 @@ use tokio_stream::wrappers::IntervalStream; #[derive(Debug, Clone, clap::Parser)] #[clap(about = "Dora coordinator")] pub enum Command { - #[clap(about = "Print Graph")] - Visualize { dataflow: PathBuf }, #[clap(about = "Run dataflow pipeline")] Run { dataflow: PathBuf, @@ -26,17 +24,6 @@ pub enum Command { pub async fn run(command: Command) -> eyre::Result<()> { match command { - Command::Visualize { dataflow: file } => { - let descriptor = read_descriptor(&file).await?; - let visualized = descriptor - .visualize_as_mermaid() - .context("failed to visualize descriptor")?; - println!("{visualized}"); - println!( - "Paste the above output on https://mermaid.live/ or in a \ - ```mermaid code block on GitHub to display it." - ); - } Command::Run { dataflow, runtime } => { let runtime_path = runtime.unwrap_or_else(|| { std::env::args() diff --git a/libraries/core/Cargo.toml b/libraries/core/Cargo.toml index 01fa6eca..793bc8ef 100644 --- a/libraries/core/Cargo.toml +++ b/libraries/core/Cargo.toml @@ -10,3 +10,4 @@ license = "Apache-2.0" dora-node-api = { version = "0.1.0", path = "../../apis/rust/node" } eyre = "0.6.8" serde = { version = "1.0.136", features = ["derive"] } +serde_yaml = "0.9.11" diff --git a/libraries/core/src/descriptor/mod.rs b/libraries/core/src/descriptor/mod.rs index 94e5917e..8ebd773b 100644 --- a/libraries/core/src/descriptor/mod.rs +++ b/libraries/core/src/descriptor/mod.rs @@ -15,6 +15,8 @@ mod visualize; #[derive(Debug, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct Descriptor { + // see https://github.com/dtolnay/serde-yaml/issues/298 + #[serde(with = "serde_yaml::with::singleton_map")] pub communication: CommunicationConfig, pub nodes: Vec, }