diff --git a/Cargo.lock b/Cargo.lock index 874818dfc0..1f214b5023 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4954,6 +4954,7 @@ dependencies = [ "const_format", "libloading", "log", + "serde", "serde_json", "zenoh-keyexpr", "zenoh-macros", diff --git a/plugins/zenoh-plugin-trait/Cargo.toml b/plugins/zenoh-plugin-trait/Cargo.toml index a8389a0c54..679feba9a1 100644 --- a/plugins/zenoh-plugin-trait/Cargo.toml +++ b/plugins/zenoh-plugin-trait/Cargo.toml @@ -33,6 +33,7 @@ no_mangle = [] [dependencies] libloading = { workspace = true } log = { workspace = true } +serde = { workspace = true } serde_json = { workspace = true } zenoh-macros = { workspace = true } zenoh-result = { workspace = true } diff --git a/plugins/zenoh-plugin-trait/src/plugin.rs b/plugins/zenoh-plugin-trait/src/plugin.rs index a5f28c77a8..fd2c03369a 100644 --- a/plugins/zenoh-plugin-trait/src/plugin.rs +++ b/plugins/zenoh-plugin-trait/src/plugin.rs @@ -14,21 +14,22 @@ use std::borrow::Cow; use zenoh_keyexpr::keyexpr; use zenoh_result::ZResult; +use serde::{Deserialize, Serialize}; -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum PluginState { Declared, Loaded, Started, } -#[derive(Clone, Debug, PartialEq, Eq, Default)] +#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct PluginCondition { warnings: Vec>, errors: Vec>, } -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct PluginStatus { pub state: PluginState, pub condition: PluginCondition, diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index 91e3d87218..5fe15be8d3 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -21,8 +21,6 @@ use crate::value::Value; use async_std::task; use log::{error, trace}; use serde_json::json; -use zenoh_plugin_trait::PluginControl; -use zenoh_protocol::core::key_expr::keyexpr; use std::collections::HashMap; use std::convert::TryFrom; use std::convert::TryInto; @@ -30,6 +28,8 @@ use std::sync::Arc; use std::sync::Mutex; use zenoh_buffers::SplitBuffer; use zenoh_config::{ConfigValidator, ValidatedMap}; +use zenoh_plugin_trait::PluginControl; +use zenoh_protocol::core::key_expr::keyexpr; use zenoh_protocol::{ core::{key_expr::OwnedKeyExpr, ExprId, KnownEncoding, WireExpr, ZenohId, EMPTY_EXPR_ID}, network::{ @@ -160,9 +160,7 @@ impl AdminSpace { Arc::new(queryables_data), ); handlers.insert( - format!("@/router/{zid_str}/plugins/**") - .try_into() - .unwrap(), + format!("@/router/{zid_str}/plugins/**").try_into().unwrap(), Arc::new(plugins_data), ); handlers.insert( @@ -662,9 +660,23 @@ fn plugins_data(context: &AdminContext, query: Query) { let guard = zlock!(context.plugins_mgr); let root_key = format!("@/router/{}/plugins", &context.zid_str); let root_key = unsafe { keyexpr::from_str_unchecked(&root_key) }; - if let [names,..] = query.key_expr().strip_prefix(root_key)[..] { + log::debug!("requested plugins status {:?}", query.key_expr()); + if let [names, ..] = query.key_expr().strip_prefix(root_key)[..] { let statuses = guard.plugins_status(names); - log::info!("Statuses: {:?}", statuses); + for (name, status) in statuses { + log::debug!("plugin {} status: {:?}", name, status); + let key = root_key.join(&name).unwrap(); + let status = serde_json::to_value(status).unwrap(); + if let Err(e) = query + .reply(Ok(Sample::new( + key, + Value::from(status) + ))) + .res() + { + log::error!("Error sending AdminSpace reply: {:?}", e); + } + } } }