Skip to content

Commit

Permalink
example storage plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Oct 17, 2023
1 parent 63346f0 commit a91e0cf
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 16 deletions.
19 changes: 19 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"io/zenoh-links/zenoh-link-unixpipe/",
"io/zenoh-transport",
"plugins/example-plugin",
"plugins/example-storage-plugin",
"plugins/zenoh-backend-traits",
"plugins/zenoh-plugin-rest",
"plugins/zenoh-plugin-storage-manager",
Expand Down
18 changes: 9 additions & 9 deletions DEFAULT_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@
// },
// },

// /// Plugin configuration example using `__config__` property
// plugins: {
// rest: {
// __config__: "./plugins/zenoh-plugin-rest/config.json5",
// },
// storage_manager: {
// __config__: "./plugins/zenoh-plugin-storage-manager/config.json5",
// }
// },
/// Plugin configuration example using `__config__` property
plugins: {
rest: {
__config__: "./plugins/zenoh-plugin-rest/config.json5",
},
storage_manager: {
__config__: "./plugins/zenoh-plugin-storage-manager/config.json5",
}
},

}
39 changes: 39 additions & 0 deletions plugins/example-storage-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright (c) 2023 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh Team, <[email protected]>
#
[package]
rust-version = { workspace = true }
name = "zenoh-plugin-storage-example"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }

[lib]
name = "zenoh_backend_example"
# This crate type will make `cargo` output a dynamic library instead of a rust static library
crate-type = ["cdylib"]

[dependencies]
async-std = { workspace = true, features = ["default"] }
clap = { workspace = true }
env_logger = { workspace = true }
futures = { workspace = true }
log = { workspace = true }
serde_json = { workspace = true }
zenoh = { workspace = true }
zenoh-core = { workspace = true }
zenoh-plugin-trait = { workspace = true }
zenoh-result = { workspace = true }
zenoh-util = { workspace = true }
async-trait = { workspace = true }
zenoh_backend_traits = { workspace = true }
90 changes: 90 additions & 0 deletions plugins/example-storage-plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use std::sync::Arc;

//
// Copyright (c) 2023 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
use async_trait::async_trait;
use zenoh::{prelude::OwnedKeyExpr, sample::Sample, time::Timestamp, value::Value};
use zenoh_backend_traits::{
config::{StorageConfig, VolumeConfig},
Capability, History, Persistence, Storage, StorageInsertionResult, StoredData, Volume,
};
use zenoh_result::ZResult;

#[no_mangle]
pub fn create_volume(_config: VolumeConfig) -> ZResult<Box<dyn Volume>> {
let volume = ExampleBackendStorage {};
Ok(Box::new(volume))
}

pub struct ExampleBackendStorage {}

pub struct ExampleStorage {}

#[async_trait]
impl Volume for ExampleBackendStorage {
fn get_admin_status(&self) -> serde_json::Value {
serde_json::Value::Null
}
fn get_capability(&self) -> Capability {
Capability {
persistence: Persistence::Volatile,
history: History::Latest,
read_cost: 0,
}
}
async fn create_storage(&mut self, _props: StorageConfig) -> ZResult<Box<dyn Storage>> {
Ok(Box::new(ExampleStorage {}))
}
fn incoming_data_interceptor(&self) -> Option<Arc<dyn Fn(Sample) -> Sample + Send + Sync>> {
None
}
fn outgoing_data_interceptor(&self) -> Option<Arc<dyn Fn(Sample) -> Sample + Send + Sync>> {
None
}
}

#[async_trait]
impl Storage for ExampleStorage {
fn get_admin_status(&self) -> serde_json::Value {
serde_json::Value::Null
}
async fn put(
&mut self,
_key: Option<OwnedKeyExpr>,
_value: Value,
_timestamp: Timestamp,
) -> ZResult<StorageInsertionResult> {
Ok(StorageInsertionResult::Inserted)
}

async fn delete(
&mut self,
_key: Option<OwnedKeyExpr>,
_timestamp: Timestamp,
) -> ZResult<StorageInsertionResult> {
Ok(StorageInsertionResult::Deleted)
}

async fn get(
&mut self,
_key: Option<OwnedKeyExpr>,
_parameters: &str,
) -> ZResult<Vec<StoredData>> {
Ok(Vec::new())
}

async fn get_all_entries(&self) -> ZResult<Vec<(Option<OwnedKeyExpr>, Timestamp)>> {
Ok(Vec::new())
}
}
17 changes: 10 additions & 7 deletions plugins/zenoh-plugin-storage-manager/config.json5
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"volumes": {
"influxdb_local": {
"__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib",
"__config__": "config_influxdb_local.json5"
},
"influxdb_remote": {
"__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib",
"__config__": "config_influxdb_remote.json5"
"example" : {
"__path__": "./plugins/example-storage-plugin/target/debug/libexample_storage_plugin.dylib",
}
//"influxdb_local": {
// "__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib",
// "__config__": "config_influxdb_local.json5"
//},
//"influxdb_remote": {
// "__path__": "../zenoh-backend-influxdb/target/debug/libzenoh_backend_influxdb.dylib",
// "__config__": "config_influxdb_remote.json5"
//}
},
"storages": {}
}

0 comments on commit a91e0cf

Please sign in to comment.