Skip to content

Commit

Permalink
diagnostic improved, test config partially made, path renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Jan 17, 2024
1 parent 8ccf6da commit 328371e
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 116 deletions.
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ members = [
"io/zenoh-links/zenoh-link-ws/",
"io/zenoh-links/zenoh-link-unixpipe/",
"io/zenoh-transport",
"plugins/example-plugin",
"plugins/example-storage-plugin",
"plugins/zenoh-backend-example",
"plugins/zenoh-plugin-example",
"plugins/zenoh-backend-traits",
"plugins/zenoh-plugin-rest",
"plugins/zenoh-plugin-storage-manager",
Expand Down
62 changes: 56 additions & 6 deletions plugin_test_config.json5
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
// Config for testing all available plugins
//
// To run it do these steps:
//
// - 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
// ```
//
// - Init submodules for zenoh-plugin-ros1
// ```
// cd zenoh-plugin-ros1
// git submodule init
// git submodule update
// ```
//
// - Build projects
// ```
// cd zenoh && cargo build && cd ..
// cd zenoh-backend-influxdb && cargo build && cd ..
// ...
// ```
//
// - Run the zenohd server with this config file.
// Explicit setting RUST_LOG=info is important: without it the logs with default le are printed by zenohd itsellf, but not by plugins.
// ```
// cd zenoh
// RUST_LOG=info cargo run -- --config plugin_test_config.json5
// ```
//
//
{
"plugins": {
// demonstrate "nof found" error
"not_found": {
},
// 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: [
"../zenoh-backend-influxdb/target/debug",
],
"volumes": {
// example backend, see "plugins/zenoh-backend-example"
"example": {
"__path__": ["target/debug/libzenoh_backend_example.so","target/debug/libzenoh_backend_example.dylib"],
}
},
// influxdb backend from "../zenoh-backend-influxdb"
"influxdb": {
},
},
"storages": {
"memory": {
Expand All @@ -20,10 +74,6 @@
},
}
},
"not_found": {
},
"example": {
},
"dds": {
"__path__": ["../zenoh-plugin-dds/target/debug/libzenoh_plugin_dds.so","../zenoh-plugin-dds/target/debug/libzenoh_plugin_dds.dylib"],
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/zenoh-backend-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
[package]
rust-version = { workspace = true }
name = "zenoh-plugin-storage-example"
name = "zenoh-backend-example"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions plugins/zenoh-backend-traits/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ impl VolumeConfig {
}
}
impl StorageConfig {
pub fn name(&self) -> &str {
&self.name
}
pub fn to_json_value(&self) -> Value {
let mut result = serde_json::Map::new();
result.insert("key_expr".into(), Value::String(self.key_expr.to_string()));
Expand Down
2 changes: 1 addition & 1 deletion plugins/zenoh-plugin-storage-manager/src/backends_mgt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) async fn create_and_start_storage(
out_interceptor: Option<Arc<dyn Fn(Sample) -> Sample + Send + Sync>>,
zenoh: Arc<Session>,
) -> ZResult<Sender<StorageMessage>> {
log::trace!("Create storage {}", &admin_key);
log::trace!("Create storage '{}'", &admin_key);
let capability = backend.get_capability();
let storage = backend.create_storage(config.clone()).await?;
let store_intercept = StoreIntercept {
Expand Down
38 changes: 19 additions & 19 deletions plugins/zenoh-plugin-storage-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,28 @@ impl StorageRuntimeInner {
plugins_manager,
};
new_self
.spawn_volume(VolumeConfig {
.spawn_volume(&VolumeConfig {
name: MEMORY_BACKEND_NAME.into(),
backend: None,
paths: None,
required: false,
rest: Default::default(),
})
.map_or_else(|e| log::error!("Cannot spawn memory volume: {}", e), |_| ());
for volume in volumes {
.map_or_else(|e| log::error!("Cannot spawn static volume '{}': {}", MEMORY_BACKEND_NAME, e), |_| ());
for volume in &volumes {
new_self
.spawn_volume(volume)
.map_or_else(|e| log::error!("Cannot spawn volume: {}", e), |_| ());
.map_or_else(|e| log::error!("Cannot spawn volume '{}': {}", volume.name(), e), |_| ());
}
for storage in storages {
for storage in &storages {
new_self
.spawn_storage(storage)
.map_or_else(|e| log::error!("Cannot spawn storage: {}", e), |_| ());
.map_or_else(|e| log::error!("Cannot spawn storage '{}': {}", storage.name(), e), |_| ());
}
Ok(new_self)
}
fn update<I: IntoIterator<Item = ConfigDiff>>(&mut self, diffs: I) -> ZResult<()> {
for diff in diffs {
for ref diff in diffs {
match diff {
ConfigDiff::DeleteVolume(volume) => self.kill_volume(&volume.name)?,
ConfigDiff::AddVolume(volume) => {
Expand All @@ -159,7 +159,7 @@ impl StorageRuntimeInner {
}
fn kill_volume<T: AsRef<str>>(&mut self, name: T) -> ZResult<()> {
let name = name.as_ref();
log::info!("Killing volume {}", name);
log::info!("Killing volume '{}'", name);
if let Some(storages) = self.storages.remove(name) {
async_std::task::block_on(futures::future::join_all(
storages
Expand All @@ -169,15 +169,15 @@ impl StorageRuntimeInner {
}
self.plugins_manager
.started_plugin_mut(name)
.ok_or(format!("Cannot find volume {} to stop it", name))?
.ok_or(format!("Cannot find volume '{}' to stop it", name))?
.stop();
Ok(())
}
fn spawn_volume(&mut self, config: VolumeConfig) -> ZResult<()> {
fn spawn_volume(&mut self, config: &VolumeConfig) -> ZResult<()> {
let volume_id = config.name();
let backend_name = config.backend();
log::info!(
"Spawning volume {} with backend {}",
"Spawning volume '{}' with backend '{}'",
volume_id,
backend_name
);
Expand All @@ -191,16 +191,16 @@ impl StorageRuntimeInner {
.declare_dynamic_plugin_by_name(volume_id, backend_name)?
};
let loaded = declared.load()?;
loaded.start(&config)?;
loaded.start(config)?;
Ok(())
}
fn kill_storage(&mut self, config: StorageConfig) {
fn kill_storage(&mut self, config: &StorageConfig) {
let volume = &config.volume_id;
log::info!("Killing storage {} from volume {}", config.name, volume);
log::info!("Killing storage '{}' from volume '{}'", config.name, volume);
if let Some(storages) = self.storages.get_mut(volume) {
if let Some(storage) = storages.get_mut(&config.name) {
log::debug!(
"Closing storage {} from volume {}",
"Closing storage '{}' from volume '{}'",
config.name,
config.volume_id
);
Expand All @@ -209,19 +209,19 @@ impl StorageRuntimeInner {
}
}
}
fn spawn_storage(&mut self, storage: StorageConfig) -> ZResult<()> {
fn spawn_storage(&mut self, storage: &StorageConfig) -> ZResult<()> {
let admin_key = self.status_key() + "/storages/" + &storage.name;
let volume_id = storage.volume_id.clone();
let backend = self
.plugins_manager
.started_plugin(&volume_id)
.ok_or(format!(
"Cannot find volume {} to spawn storage {}",
"Cannot find volume '{}' to spawn storage '{}'",
volume_id, storage.name
))?;
let storage_name = storage.name.clone();
log::info!(
"Spawning storage {} from volume {} with backend {}",
"Spawning storage '{}' from volume '{}' with backend '{}'",
storage_name,
volume_id,
backend.name()
Expand All @@ -230,7 +230,7 @@ impl StorageRuntimeInner {
let out_interceptor = backend.instance().outgoing_data_interceptor();
let stopper = async_std::task::block_on(create_and_start_storage(
admin_key,
storage,
storage.clone(),
backend.instance(),
in_interceptor,
out_interceptor,
Expand Down
Loading

0 comments on commit 328371e

Please sign in to comment.