Skip to content

Commit

Permalink
fix: consistency between daemon and instance commands. Also remove un…
Browse files Browse the repository at this point in the history
…necessary parameters
  • Loading branch information
Hennzau committed Jan 5, 2025
1 parent 9811911 commit 3eed478
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 65 deletions.
68 changes: 21 additions & 47 deletions zfctl/src/daemon_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ use crate::{

#[derive(Subcommand)]
pub(crate) enum DaemonCommand {
/// List all the Zenoh-Flow daemons reachable on the Zenoh network.
List,
/// Launch a Zenoh-Flow Daemon.
#[command(verbatim_doc_comment)]
#[command(group(
Expand All @@ -52,48 +54,38 @@ pub(crate) enum DaemonCommand {
name: Option<String>,
/// The path of the configuration of the Zenoh-Flow Daemon.
///
/// This configuration allows setting extensions supported by the Runtime
/// This configuration allows setting extensions supported by the Daemon
/// and its name.
#[arg(short, long, verbatim_doc_comment)]
configuration: Option<PathBuf>,
/// The path to a Zenoh configuration to manage the connection to the Zenoh
/// network.
///
/// If no configuration is provided, `zfctl` will default to connecting as
/// a peer with multicast scouting enabled.
#[arg(short = 'z', long, verbatim_doc_comment)]
zenoh_configuration: Option<PathBuf>,
},
/// List all the Zenoh-Flow runtimes reachable on the Zenoh network.
List,
/// Returns the status of the provided Zenoh-Flow runtime.
/// Returns the status of the provided Zenoh-Flow daemon.
///
/// The status consists of general information regarding the runtime and the
/// The status consists of general information regarding the daemon and the
/// machine it runs on:
/// - the name associated with the Zenoh-Flow runtime,
/// - the number of CPUs the machine running the Zenoh-Flow runtime has,
/// - the total amount of RAM the machine running the Zenoh-Flow runtime has,
/// - for each data flow the Zenoh-Flow runtime manages (partially or not):
/// - the name associated with the Zenoh-Flow daemon,
/// - the number of CPUs the machine running the Zenoh-Flow daemon has,
/// - the total amount of RAM the machine running the Zenoh-Flow daemon has,
/// - for each data flow the Zenoh-Flow daemon manages (partially or not):
/// - its unique identifier,
/// - its name,
/// - its status.
#[command(verbatim_doc_comment)]
#[command(group(
ArgGroup::new("exclusive")
.args(&["runtime_id", "runtime_name"])
.args(&["id", "name"])
.required(true)
.multiple(false)
))]
Status {
/// The unique identifier of the Zenoh-Flow runtime to contact.
#[arg(short = 'i', long = "id")]
runtime_id: Option<RuntimeId>,
/// The name of the Zenoh-Flow runtime to contact.
/// The name of the Zenoh-Flow daemon to contact.
///
/// Note that if several runtimes share the same name, the first to
/// Note that if several daemons share the same name, the first to
/// answer will be selected.
#[arg(short = 'n', long = "name")]
runtime_name: Option<String>,
name: Option<String>,
/// The unique identifier of the Zenoh-Flow daemon to contact.
#[arg(short = 'i', long = "id")]
id: Option<RuntimeId>,
},
}

Expand All @@ -103,22 +95,7 @@ impl DaemonCommand {
DaemonCommand::Start {
name,
configuration,
zenoh_configuration,
} => {
let zenoh_config = match zenoh_configuration {
Some(path) => zenoh::Config::from_file(path.clone()).unwrap_or_else(|e| {
panic!(
"Failed to parse the Zenoh configuration from < {} >:\n{e:?}",
path.display()
)
}),
None => zenoh::Config::default(),
};

let zenoh_session = zenoh::open(zenoh_config)
.await
.unwrap_or_else(|e| panic!("Failed to open Zenoh session:\n{e:?}"));

let daemon = match configuration {
Some(path) => {
let (zenoh_flow_configuration, _) =
Expand All @@ -131,13 +108,13 @@ impl DaemonCommand {
)
});

Daemon::spawn_from_config(zenoh_session, zenoh_flow_configuration)
Daemon::spawn_from_config(session, zenoh_flow_configuration)
.await
.expect("Failed to spawn the Zenoh-Flow Daemon")
}
None => Daemon::spawn(
Runtime::builder(name.unwrap())
.session(zenoh_session)
.session(session)
.build()
.await
.expect("Failed to build the Zenoh-Flow Runtime"),
Expand Down Expand Up @@ -178,11 +155,8 @@ impl DaemonCommand {

println!("{table}");
}
DaemonCommand::Status {
runtime_id,
runtime_name,
} => {
let runtime_id = match (runtime_id, runtime_name) {
DaemonCommand::Status { id, name } => {
let runtime_id = match (id, name) {
(Some(id), _) => id,
(None, Some(name)) => get_runtime_by_name(&session, &name).await,
(None, None) => {
Expand Down Expand Up @@ -272,7 +246,7 @@ impl DaemonCommand {
}
}

Err(e) => tracing::error!("Reply to runtime status failed with: {:?}", e),
Err(e) => tracing::error!("Reply to daemon status failed with: {:?}", e),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions zfctl/src/instance_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ pub(crate) enum InstanceCommand {
/// zfctl instance status <uuid>
///
/// - This call will **not** start the data flow instance, only load on all
/// the involved runtimes the nodes composing the data flow.
/// the involved daemons the nodes composing the data flow.
///
/// - If Zenoh-Flow runtimes are specified in the data flow descriptor,
/// - If Zenoh-Flow daemons are specified in the data flow descriptor,
/// there is no need to contact them separately or even to make the
/// `create` query on any of them. The Zenoh-Flow runtime orchestrating
/// the creation will query the appropriate Zenoh-Flow runtimes.
/// `create` query on any of them. The Zenoh-Flow daemon orchestrating
/// the creation will query the appropriate Zenoh-Flow daemons.
#[command(verbatim_doc_comment)]
Create {
/// The path, on your machine, of the data flow descriptor.
Expand All @@ -64,11 +64,11 @@ pub(crate) enum InstanceCommand {
Delete { instance_id: Uuid },
/// Obtain the status of the data flow instance.
Status { instance_id: Uuid },
/// List all the data flow instances on the contacted Zenoh-Flow runtime
/// List all the data flow instances on the contacted Zenoh-Flow daemon
List,
/// Start the data flow instance, on all the involved Zenoh-Flow runtimes.
/// Start the data flow instance, on all the involved Zenoh-Flow daemons.
Start { instance_id: Uuid },
/// Abort the data flow instance, on all the involved Zenoh-Flow runtimes.
/// Abort the data flow instance, on all the involved Zenoh-Flow daemons.
Abort { instance_id: Uuid },
}

Expand Down
28 changes: 17 additions & 11 deletions zfctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod utils;
use std::path::PathBuf;

use anyhow::anyhow;
use clap::{Parser, Subcommand};
use clap::{ArgGroup, Parser, Subcommand};
use utils::{get_random_runtime, get_runtime_by_name};
use zenoh_flow_commons::{parse_vars, Result, RuntimeId};

Expand Down Expand Up @@ -55,6 +55,7 @@ struct Zfctl {
/// a peer with multicast scouting enabled.
#[arg(short = 'z', long, verbatim_doc_comment)]
zenoh_configuration: Option<PathBuf>,

#[command(subcommand)]
command: Command,
}
Expand All @@ -63,21 +64,26 @@ struct Zfctl {
enum Command {
/// To manage a data flow instance.
///
/// This command accepts an optional `name` or `id` of a Zenoh-Flow Runtime
/// This command accepts an optional `name` or `id` of a Zenoh-Flow Daemon
/// to contact. If no name or id is provided, one is randomly selected.
#[group(required = false, multiple = false)]
#[command(group(
ArgGroup::new("exclusive")
.args(&["runtime_id", "daemon_name"])
.required(false)
.multiple(false)
))]
Instance {
#[command(subcommand)]
command: InstanceCommand,
/// The unique identifier of the Zenoh-Flow runtime to contact.
#[arg(short = 'i', long = "id", verbatim_doc_comment, group = "runtime")]
/// The unique identifier of the Zenoh-Flow daemon to contact.
#[arg(short = 'i', long = "id", verbatim_doc_comment)]
runtime_id: Option<RuntimeId>,
/// The name of the Zenoh-Flow runtime to contact.
/// The name of the Zenoh-Flow daemon to contact.
///
/// If several runtimes share the same name, `zfctl` will abort
/// If several daemons share the same name, `zfctl` will abort
/// its execution asking you to instead use their `id`.
#[arg(short = 'n', long = "name", verbatim_doc_comment, group = "runtime")]
runtime_name: Option<String>,
#[arg(short = 'n', long = "name", verbatim_doc_comment)]
daemon_name: Option<String>,
},

/// To interact with a Zenoh-Flow daemon.
Expand Down Expand Up @@ -137,9 +143,9 @@ async fn main() -> Result<()> {
Command::Instance {
command,
runtime_id,
runtime_name,
daemon_name,
} => {
let orchestrator_id = match (runtime_id, runtime_name) {
let orchestrator_id = match (runtime_id, daemon_name) {
(Some(id), _) => id,
(None, Some(name)) => get_runtime_by_name(&session, &name).await,
(None, None) => get_random_runtime(&session).await,
Expand Down

0 comments on commit 3eed478

Please sign in to comment.