Skip to content

Commit

Permalink
Plugin Manager: Loading ... (in progress)
Browse files Browse the repository at this point in the history
* Add tests for debugging temporally
* Fixing typos
  • Loading branch information
AmmarAbouZor committed Dec 5, 2024
1 parent 9941076 commit 581d45e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is example of the plugin metadata file which should placed in the plugin directory
# next to plugin wasm file.
name = "String Parser"
description = "Example for parser plugins. It parses the bytes to UTF-8 strings"
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl PluginsParser {
/// session.
pub async fn initialize(
plugin_path: impl AsRef<Path>,
general_config: &pl::PluginParserGeneralSetttings,
general_config: &pl::PluginParserGeneralSettings,
plugin_configs: Vec<pl::ConfigItem>,
) -> Result<Self, PluginHostInitError> {
let (component, version) = Self::load(&plugin_path).await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod paths;
#[cfg(test)]
mod tests;

use std::{
fs::{self, read_to_string},
Expand All @@ -18,7 +20,7 @@ use super::{InitError, PluginEntity, PluginMetadata};
pub async fn load_plugins() -> Result<Vec<PluginEntity>, InitError> {
let plugins_dir = paths::plugins_dir()?;
if !plugins_dir.exists() {
log::trace!("Plugins directory doens't exist. Creating it...");
log::trace!("Plugins directory doesn't exist. Creating it...");
fs::create_dir_all(plugins_dir)?;
}

Expand All @@ -37,7 +39,7 @@ async fn load_all_parsers() -> Result<Vec<PluginEntity>, InitError> {

let parsers_dir = paths::parser_dir()?;
if !parsers_dir.exists() {
log::trace!("Parsers directory deosn't exist. Creating it ...");
log::trace!("Parsers directory doesn't exist. Creating it ...");
fs::create_dir_all(&parsers_dir)?;

return Ok(parsers);
Expand Down Expand Up @@ -96,13 +98,13 @@ async fn load_parser(dir: PathBuf) -> Result<PluginEntity, InitError> {
}

if let Some(err_msg) = error_msg {
let invaid_entity = PluginEntity {
let invalid_entity = PluginEntity {
dir_path: dir,
plugin_type: PluginType::Parser,
state: PluginState::Invalid(Box::new(InvalidPluginInfo::new(err_msg))),
metadata: None,
};
return Ok(invaid_entity);
return Ok(invalid_entity);
}

let wasm_file = match wasm_file {
Expand All @@ -126,7 +128,7 @@ async fn load_parser(dir: PathBuf) -> Result<PluginEntity, InitError> {
return Err(err.into())
}
Err(err) => {
let err_msg = format!("Loading plugin binray fail. Error: {err}");
let err_msg = format!("Loading plugin binary fail. Error: {err}");
let invalid = PluginEntity {
dir_path: dir,
plugin_type: PluginType::Parser,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use super::*;

//TODO AAZ: Write meaningful tests for loading to ensure loading can't fail because of
//misconfigured plugins in any case.
#[tokio::test]
#[ignore]
async fn prototype_load() {
let plugins = load_plugins().await;
dbg!(&plugins);

panic!("This test is for debugging purpose only");
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
PluginParseMessage,
};
use sources::plugins as pl;
use sources::plugins::PluginParserGeneralSetttings;
use sources::plugins::PluginParserGeneralSettings;

pub use self::chipmunk::plugin::{parse_types::*, shared_types::*};
wasmtime::component::bindgen!({
Expand All @@ -15,8 +15,8 @@ wasmtime::component::bindgen!({
},
});

impl From<&PluginParserGeneralSetttings> for ParserConfig {
fn from(_value: &PluginParserGeneralSetttings) -> Self {
impl From<&PluginParserGeneralSettings> for ParserConfig {
fn from(_value: &PluginParserGeneralSettings) -> Self {
// We must use the current log level form chipmunk because we are using the same log
// functionality to log the message from the plugins.
let current_log_level = log::max_level().to_level().unwrap_or(log::Level::Error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl PluginParser {
/// session.
pub async fn initialize(
component: Component,
general_config: &pl::PluginParserGeneralSetttings,
general_config: &pl::PluginParserGeneralSettings,
plugin_configs: Vec<pl::ConfigItem>,
) -> Result<Self, PluginHostInitError> {
let mut ctx = get_wasi_ctx_builder(&plugin_configs)?;
Expand Down
6 changes: 3 additions & 3 deletions application/apps/indexer/sources/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PluginParserSettings {
pub plugin_path: PathBuf,
pub general_settings: PluginParserGeneralSetttings,
pub general_settings: PluginParserGeneralSettings,
pub plugin_configs: Vec<ConfigItem>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
/// General settings for all parsers as plugins
pub struct PluginParserGeneralSetttings {
pub struct PluginParserGeneralSettings {
pub placeholder: String,
}

Expand All @@ -20,7 +20,7 @@ impl PluginParserSettings {
pub fn prototyping(plugin_path: PathBuf, plugin_configs: Vec<ConfigItem>) -> Self {
Self {
plugin_path,
general_settings: PluginParserGeneralSetttings {
general_settings: PluginParserGeneralSettings {
placeholder: Default::default(),
},
plugin_configs,
Expand Down

0 comments on commit 581d45e

Please sign in to comment.