diff --git a/plugin_test_config.json5 b/plugin_test_config.json5 deleted file mode 100644 index d6c430cc3e..0000000000 --- a/plugin_test_config.json5 +++ /dev/null @@ -1,130 +0,0 @@ -// Config for testing all available plugins -// -// To run it do these steps: -// -// 1. Clone these repositories: -// ``` -// git clone https://github.com/eclipse-zenoh/zenoh.git -// git clone https://github.com/eclipse-zenoh/zenoh-backend-influxdb.git -// git clone https://github.com/eclipse-zenoh/zenoh-backend-rocksdb.git -// git clone https://github.com/eclipse-zenoh/zenoh-backend-filesystem.git -// git clone https://github.com/eclipse-zenoh/zenoh-plugin-webserver.git -// git clone https://github.com/eclipse-zenoh/zenoh-plugin-mqtt.git -// git clone https://github.com/eclipse-zenoh/zenoh-plugin-dds.git -// git clone https://github.com/eclipse-zenoh/zenoh-plugin-ros1.git -// git clone https://github.com/eclipse-zenoh/zenoh-plugin-ros2dds.git -// ``` -// -// 1.1. Init submodules for zenoh-plugin-ros1 -// ``` -// cd zenoh-plugin-ros1 -// git submodule init -// git submodule update -// ``` -// -// 2. Build projects -// ``` -// cd zenoh && cargo build && cd .. -// cd zenoh-backend-influxdb && cargo build && cd .. -// ... -// ``` -// -// 3. Run the zenohd server with this config file. -// -// Explicit setting RUST_LOG=info is important: without it the logs are printed by zenohd itsellf, but not by plugins. -// ``` -// cd zenoh -// RUST_LOG=info cargo run -- --config plugin_test_config.json5 -// ``` -// -// Some errors on plugin initalisation are expected due to some mandtatory properties missing in the config file, like for "influxdb" and "influxdb2" volumes. -// Though there supposedly should not be plugin loading errors due to not found files or version incompatibility -// -// -// 4. Test access plugin status through admin space -// -// The plugins information is available by "@/router/{router_id}/plugins/**". Each plugin provides by this key the json object with its status. -// Subplugins are also available by this key, e.g. "@/router/{router_id}/plugins/storage_manager/influxdb". -// ``` -// cargo run --example z_get -- -s "@/router/*/plugins/**" -// ``` -// result is -// ``` -// Received ('@/router/b04a929103101296abec19ea6cddd034/plugins/example': '{"long_version":"v0.11.0-dev-182-g48060b9c","name":"example","path":"/Users/milyin/ZS2/zenoh/target/debug/libzenoh_plugin_example.dylib","report":{"level":"Normal"},"state":"Started","version":"0.11.0-dev"}') -/// Received ('@/router/b04a929103101296abec19ea6cddd034/plugins/storage_manager': '{"long_version":"v0.11.0-dev-182-g48060b9c","name":"storage_manager","path":"/Users/milyin/ZS2/zenoh/target/debug/libzenoh_plugin_storage_manager.dylib","report":{"level":"Normal"},"state":"Started","version":"0.11.0-dev"}') -/// Received ('@/router/b04a929103101296abec19ea6cddd034/plugins/storage_manager/memory': '{"long_version":"v0.11.0-dev-182-g48060b9c","name":"storage_manager/memory","path":"","report":{"level":"Normal"},"state":"Started","version":"0.11.0-dev"}') -// ... -// ``` -// -// There is also plugin information by path "@/router/*/status/plugins/**". Later these paths should be combined -// ``` -// cargo run --example z_get -- -s "@/router/*/status/plugins/**" -// ``` -// result is -// ``` -// >> Received ('@/router/b04a929103101296abec19ea6cddd034/status/plugins/example/__path__': '/Users/milyin/ZS2/zenoh/target/debug/libzenoh_plugin_example.dylib') -// >> Received ('@/router/b04a929103101296abec19ea6cddd034/status/plugins/storage_manager/__path__': '/Users/milyin/ZS2/zenoh/target/debug/libzenoh_plugin_storage_manager.dylib') -// >> Received ('@/router/b04a929103101296abec19ea6cddd034/status/plugins/storage_manager/volumes/memory/__path__': '""') -// >> Received ('@/router/b04a929103101296abec19ea6cddd034/status/plugins/storage_manager/volumes/memory': '{"__required__":false}') -// >> Received ('@/router/b04a929103101296abec19ea6cddd034/status/plugins/storage_manager/storages/memory': '{"key_expr":"demo/memory/**","volume":"memory"}') -// ``` -// -{ - "plugins_search_dirs": [ - "target/debug", - "../zenoh-plugin-webserver/target/debug", - "../zenoh-plugin-mqtt/target/debug", - "../zenoh-plugin-dds/target/debug", - "../zenoh-plugin-ros1/target/debug", - "../zenoh-plugin-ros2dds/target/debug" - ], - - "plugins": { - // mqtt plugin, see "../zenoh-plugin-mqtt" - "mqtt": {}, - // dds plugin, see "../zenoh-plugin-dds" - "dds": {}, - // ros1 plugin, see "../zenoh-plugin-ros1" - "ros1": {}, - // ros2dds plugin, see "../zenoh-plugin-ros2dds" - "ros2dds": {}, - // example plugin, see "plugins/zenog-plugin-example" - "example": {}, - // rest plugin, see "plugins/zenoh-plugin-rest" - "rest": { - "http_port": 8080, - }, - // storage mangaer plugin, see "plugins/zenoh-plugin-storage-manager" - // supports different backends implemented as plugins also - "storage_manager": { - backend_search_dirs: [ - "target/debug", - "../zenoh-backend-influxdb/target/debug", - "../zenoh-backend-rocksdb/target/debug", - "../zenoh-backend-filesystem/target/debug" - ], - "volumes": { - // example backend, see "plugins/zenoh-backend-example" - "example": {}, - // influxdb backend from "../zenoh-backend-influxdb/v1" - "influxdb": {}, - // influxdb backend from "../zenoh-backend-influxdb/v2" - "influxdb2": {}, - // rocksdb backend, see "plugins/zenoh-backend-rocksdb" - "rocksdb": {}, - // filesystem backend, see "plugins/zenoh-backend-filesystem" - "fs": {} - }, - "storages": { - "memory": { - "volume": "memory", - "key_expr": "demo/memory/**" - }, - "example": { - "volume": "example", - "key_expr": "demo/example/**" - }, - } - }, - } -} diff --git a/plugins/zenoh-backend-example/config.json5 b/plugins/zenoh-backend-example/config.json5 deleted file mode 100644 index 9e26dfeeb6..0000000000 --- a/plugins/zenoh-backend-example/config.json5 +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/plugins/zenoh-backend-example/src/lib.rs b/plugins/zenoh-backend-example/src/lib.rs index 36586e51f0..602d29f375 100644 --- a/plugins/zenoh-backend-example/src/lib.rs +++ b/plugins/zenoh-backend-example/src/lib.rs @@ -1,9 +1,3 @@ -use std::{ - collections::{hash_map::Entry, HashMap}, - sync::Arc, -}; - -use async_std::sync::RwLock; // // Copyright (c) 2023 ZettaScale Technology // @@ -17,7 +11,12 @@ use async_std::sync::RwLock; // Contributors: // ZettaScale Zenoh Team, // +use async_std::sync::RwLock; use async_trait::async_trait; +use std::{ + collections::{hash_map::Entry, HashMap}, + sync::Arc, +}; use zenoh::{prelude::OwnedKeyExpr, sample::Sample, time::Timestamp, value::Value}; use zenoh_backend_traits::{ config::{StorageConfig, VolumeConfig}, diff --git a/plugins/zenoh-plugin-storage-manager/src/lib.rs b/plugins/zenoh-plugin-storage-manager/src/lib.rs index b1f1e15da7..eed1cc8a9d 100644 --- a/plugins/zenoh-plugin-storage-manager/src/lib.rs +++ b/plugins/zenoh-plugin-storage-manager/src/lib.rs @@ -316,7 +316,7 @@ impl RunningPluginTrait for StorageRuntime { }); let guard = self.0.lock().unwrap(); with_extended_string(&mut key, &["/volumes/"], |key| { - for plugin in guard.plugins_manager.started_plugins() { + for plugin in guard.plugins_manager.started_plugins_iter() { with_extended_string(key, &[plugin.name()], |key| { with_extended_string(key, &["/__path__"], |key| { if keyexpr::new(key.as_str()) diff --git a/plugins/zenoh-plugin-trait/src/compatibility.rs b/plugins/zenoh-plugin-trait/src/compatibility.rs index 2887270a85..7b52bc5fbf 100644 --- a/plugins/zenoh-plugin-trait/src/compatibility.rs +++ b/plugins/zenoh-plugin-trait/src/compatibility.rs @@ -203,9 +203,9 @@ impl Display for Compatibility { #[repr(C)] #[derive(Debug, PartialEq, Eq, Clone)] pub struct RustVersion { - major: u64, - minor: u64, - patch: u64, + major: u32, + minor: u32, + patch: u32, stable: bool, commit: &'static str, } diff --git a/plugins/zenoh-plugin-trait/src/manager.rs b/plugins/zenoh-plugin-trait/src/manager.rs index 48988dfe22..940d389789 100644 --- a/plugins/zenoh-plugin-trait/src/manager.rs +++ b/plugins/zenoh-plugin-trait/src/manager.rs @@ -175,7 +175,7 @@ impl } /// Lists all plugins - pub fn declared_plugins( + pub fn declared_plugins_iter( &self, ) -> impl Iterator> + '_ { self.plugins @@ -184,7 +184,7 @@ impl } /// Lists all plugins mutable - pub fn declared_plugins_mut( + pub fn declared_plugins_iter_mut( &mut self, ) -> impl Iterator> + '_ { self.plugins @@ -193,41 +193,41 @@ impl } /// Lists the loaded plugins - pub fn loaded_plugins( + pub fn loaded_plugins_iter( &self, ) -> impl Iterator> + '_ { - self.declared_plugins().filter_map(|p| p.loaded()) + self.declared_plugins_iter().filter_map(|p| p.loaded()) } /// Lists the loaded plugins mutable - pub fn loaded_plugins_mut( + pub fn loaded_plugins_iter_mut( &mut self, ) -> impl Iterator> + '_ { // self.plugins_mut().filter_map(|p| p.loaded_mut()) - self.declared_plugins_mut().filter_map(|p| p.loaded_mut()) + self.declared_plugins_iter_mut().filter_map(|p| p.loaded_mut()) } /// Lists the started plugins - pub fn started_plugins( + pub fn started_plugins_iter( &self, ) -> impl Iterator> + '_ { - self.loaded_plugins().filter_map(|p| p.started()) + self.loaded_plugins_iter().filter_map(|p| p.started()) } /// Lists the started plugins mutable - pub fn started_plugins_mut( + pub fn started_plugins_iter_mut( &mut self, ) -> impl Iterator> + '_ { - self.loaded_plugins_mut().filter_map(|p| p.started_mut()) + self.loaded_plugins_iter_mut().filter_map(|p| p.started_mut()) } - /// Returns single plugin record + /// Returns single plugin record by name pub fn plugin(&self, name: &str) -> Option<&dyn DeclaredPlugin> { let index = self.get_plugin_index(name)?; Some(&self.plugins[index]) } - /// Returns mutable plugin record + /// Returns mutable plugin record by name pub fn plugin_mut( &mut self, name: &str, @@ -236,12 +236,12 @@ impl Some(&mut self.plugins[index]) } - /// Returns loaded plugin record + /// Returns loaded plugin record by name pub fn loaded_plugin(&self, name: &str) -> Option<&dyn LoadedPlugin> { self.plugin(name)?.loaded() } - /// Returns mutable loaded plugin record + /// Returns mutable loaded plugin record by name pub fn loaded_plugin_mut( &mut self, name: &str, @@ -249,12 +249,12 @@ impl self.plugin_mut(name)?.loaded_mut() } - /// Returns started plugin record + /// Returns started plugin record by name pub fn started_plugin(&self, name: &str) -> Option<&dyn StartedPlugin> { self.loaded_plugin(name)?.started() } - /// Returns mutable started plugin record + /// Returns mutable started plugin record by name pub fn started_plugin_mut( &mut self, name: &str, @@ -273,7 +273,7 @@ impl P names ); let mut plugins = Vec::new(); - for plugin in self.declared_plugins() { + for plugin in self.declared_plugins_iter() { let name = unsafe { keyexpr::from_str_unchecked(plugin.name()) }; if names.includes(name) { let status = PluginStatusRec::new(plugin.as_status()); diff --git a/plugins/zenoh-plugin-trait/src/plugin.rs b/plugins/zenoh-plugin-trait/src/plugin.rs index 2ebe520f5e..f1c2d09385 100644 --- a/plugins/zenoh-plugin-trait/src/plugin.rs +++ b/plugins/zenoh-plugin-trait/src/plugin.rs @@ -35,7 +35,7 @@ pub enum PluginState { #[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, PartialOrd, Ord)] pub enum PluginReportLevel { #[default] - Normal, + Info, Warning, Error, } @@ -203,8 +203,8 @@ impl PluginReport { self.level |= PluginReportLevel::Warning; self.messages.push(warning.into()); } - pub fn add_message>>(&mut self, message: S) { - self.level |= PluginReportLevel::Normal; + pub fn add_info>>(&mut self, message: S) { + self.level |= PluginReportLevel::Info; self.messages.push(message.into()); } pub fn messages(&self) -> &[Cow<'static, str>] { @@ -215,7 +215,7 @@ impl PluginReport { pub trait PluginConditionSetter { fn add_error(self, report: &mut PluginReport) -> Self; fn add_warning(self, report: &mut PluginReport) -> Self; - fn add_message(self, report: &mut PluginReport) -> Self; + fn add_info(self, report: &mut PluginReport) -> Self; } impl PluginConditionSetter for core::result::Result { @@ -231,9 +231,9 @@ impl PluginConditionSetter for core::result::Result { } self } - fn add_message(self, report: &mut PluginReport) -> Self { + fn add_info(self, report: &mut PluginReport) -> Self { if let Err(e) = &self { - report.add_message(e.to_string()); + report.add_info(e.to_string()); } self } diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index 629662e22a..b109774054 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -171,7 +171,7 @@ impl AdminSpace { ); let mut active_plugins = plugins_mgr - .started_plugins() + .started_plugins_iter() .map(|rec| (rec.name().to_string(), rec.path().to_string())) .collect::>(); @@ -458,7 +458,7 @@ fn router_data(context: &AdminContext, query: Query) { let plugins: serde_json::Value = { let plugins_mgr = zlock!(context.plugins_mgr); plugins_mgr - .started_plugins() + .started_plugins_iter() .map(|rec| (rec.name(), json!({ "path": rec.path() }))) .collect() }; @@ -681,7 +681,7 @@ fn plugins_status(context: &AdminContext, query: Query) { let guard = zlock!(context.plugins_mgr); let mut root_key = format!("@/router/{}/status/plugins/", &context.zid_str); - for plugin in guard.started_plugins() { + for plugin in guard.started_plugins_iter() { with_extended_string(&mut root_key, &[plugin.name()], |plugin_key| { // TODO: response to "__version__", this need not to be implemented by each plugin with_extended_string(plugin_key, &["/__path__"], |plugin_path_key| { diff --git a/zenohd/src/main.rs b/zenohd/src/main.rs index c6ea00a9d4..b0d29ea89b 100644 --- a/zenohd/src/main.rs +++ b/zenohd/src/main.rs @@ -154,7 +154,7 @@ fn main() { } }; - for plugin in plugin_mgr.loaded_plugins_mut() { + for plugin in plugin_mgr.loaded_plugins_iter_mut() { let required = required_plugins.contains(plugin.name()); log::info!( "Starting {req} plugin \"{name}\"",