diff --git a/zfctl/src/daemon_command.rs b/zfctl/src/daemon_command.rs index 6789cec7..9f86c09f 100644 --- a/zfctl/src/daemon_command.rs +++ b/zfctl/src/daemon_command.rs @@ -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( @@ -52,48 +54,38 @@ pub(crate) enum DaemonCommand { name: Option, /// 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, - /// 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, }, - /// 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, - /// 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, + name: Option, + /// The unique identifier of the Zenoh-Flow daemon to contact. + #[arg(short = 'i', long = "id")] + id: Option, }, } @@ -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, _) = @@ -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"), @@ -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) => { @@ -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), } } } diff --git a/zfctl/src/instance_command.rs b/zfctl/src/instance_command.rs index 814de969..329afff9 100644 --- a/zfctl/src/instance_command.rs +++ b/zfctl/src/instance_command.rs @@ -42,12 +42,12 @@ pub(crate) enum InstanceCommand { /// zfctl instance status /// /// - 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. @@ -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 }, } diff --git a/zfctl/src/main.rs b/zfctl/src/main.rs index 63a52b2b..936fa145 100644 --- a/zfctl/src/main.rs +++ b/zfctl/src/main.rs @@ -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}; @@ -55,6 +55,7 @@ struct Zfctl { /// a peer with multicast scouting enabled. #[arg(short = 'z', long, verbatim_doc_comment)] zenoh_configuration: Option, + #[command(subcommand)] command: Command, } @@ -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, - /// 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, + #[arg(short = 'n', long = "name", verbatim_doc_comment)] + daemon_name: Option, }, /// To interact with a Zenoh-Flow daemon. @@ -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,