Browse Source

Implement `dora graph` subcommand based on coordinator visualization code

tags/v0.0.0-test.4
Philipp Oppermann 3 years ago
parent
commit
d57cafadc4
Failed to extract signature
7 changed files with 79 additions and 29 deletions
  1. +36
    -13
      Cargo.lock
  2. +3
    -0
      binaries/cli/Cargo.toml
  3. +29
    -0
      binaries/cli/src/graph.rs
  4. +8
    -3
      binaries/cli/src/main.rs
  5. +0
    -13
      binaries/coordinator/src/lib.rs
  6. +1
    -0
      libraries/core/Cargo.toml
  7. +2
    -0
      libraries/core/src/descriptor/mod.rs

+ 36
- 13
Cargo.lock View File

@@ -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",


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

@@ -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"

+ 29
- 0
binaries/cli/src/graph.rs View File

@@ -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<Descriptor> {
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)
}

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

@@ -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(())
}

+ 0
- 13
binaries/coordinator/src/lib.rs View File

@@ -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()


+ 1
- 0
libraries/core/Cargo.toml View File

@@ -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"

+ 2
- 0
libraries/core/src/descriptor/mod.rs View File

@@ -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<Node>,
}


Loading…
Cancel
Save