Skip to content

Commit

Permalink
adminspace works
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Nov 14, 2023
1 parent d850216 commit 50564bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions plugins/zenoh-plugin-trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
7 changes: 4 additions & 3 deletions plugins/zenoh-plugin-trait/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cow<'static, str>>,
errors: Vec<Cow<'static, str>>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct PluginStatus {
pub state: PluginState,
pub condition: PluginCondition,
Expand Down
26 changes: 19 additions & 7 deletions zenoh/src/net/runtime/adminspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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;
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::{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
}
}

Expand Down

0 comments on commit 50564bb

Please sign in to comment.