Skip to content

Commit

Permalink
Plugins Host: Implementing Bytesource & Refactoring
Browse files Browse the repository at this point in the history
- Move plugins types to their own modules in sessions lib
- Basic types and methods for byte source
- Fix typos in directory name
  • Loading branch information
AmmarAbouZor committed Aug 1, 2024
1 parent 77134ab commit 6e1387b
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 49 deletions.
3 changes: 2 additions & 1 deletion application/apps/indexer/indexer_cli/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use processor::grabber::LineRange;
use rustyline::{error::ReadlineError, DefaultEditor};
use session::session::Session;
use sources::{
factory::{DltParserSettings, FileFormat, ObserveOptions, ParserType, PluginParserSettings},
factory::{DltParserSettings, FileFormat, ObserveOptions, ParserType},
plugins::PluginParserSettings,
producer::MessageProducer,
socket::udp::UdpSource,
};
Expand Down
28 changes: 28 additions & 0 deletions application/apps/indexer/plugins_host/src/bytesource_shared/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//TODO AAZ: Suppress warnings while developing
#![allow(dead_code, unused_imports, unused)]

use std::path::{Path, PathBuf};

use sources::plugins::{ByteSourceInput, PluginByteSourceGeneralSetttings};

use crate::{v0_1_0, PluginHostInitError};

const BYTESOURCE_INTERFACE_NAME: &str = "chipmunk:plugin/byte-source";

/// Path of input file directory that will presented to the plugins.
pub(crate) const INPUT_DIR_PATH: &str = "./input";

pub enum PluginByteSource {
Ver010(v0_1_0::bytesource::PluginByteSource),
}

impl PluginByteSource {
pub fn create(
plugin_path: impl AsRef<Path>,
input: ByteSourceInput,
general_config: &PluginByteSourceGeneralSetttings,
config_path: Option<impl AsRef<Path>>,
) -> Result<Self, PluginHostInitError> {
todo!()
}
}
3 changes: 3 additions & 0 deletions application/apps/indexer/plugins_host/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod bytesource_shared;
mod parser_shared;
mod plugins_shared;
mod semantic_version;
Expand All @@ -6,6 +7,8 @@ mod wasm_host;

pub use parser_shared::{plugin_parse_message::PluginParseMessage, PluginParser};

//TODO AAZ: Add pubic use for bytesource_shared

pub use plugins_shared::plugin_init_error::{PluginGuestInitError, PluginHostInitError};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use sources::factory::PluginParserGeneralSetttings;
use sources::plugins::PluginParserGeneralSetttings;
use wasmtime::component::Component;

use crate::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@

use std::path::{Path, PathBuf};

use sources::plugins::{ByteSourceInput, PluginByteSourceGeneralSetttings};
use wasmtime_wasi::{DirPerms, FilePerms, WasiCtxBuilder};

use crate::{plugins_shared::get_wasi_ctx_builder, PluginHostInitError};
use crate::{
bytesource_shared::INPUT_DIR_PATH, plugins_shared::get_wasi_ctx_builder, PluginHostInitError,
};

/// Path of input file directory that will presented to the plugins.
const INPUT_DIR_PATH: &str = "./input";

#[derive(Debug, Clone)]
/// Represents The input source for byte source to read from
pub enum ByteSourceInput {
File(PathBuf),
Other,
}

pub struct PluginByteSource {}
pub struct PluginByteSouce {}

impl PluginByteSource {
pub fn create(
plugin_path: impl AsRef<Path>,
input: ByteSourceInput,
general_config: &PluginByteSourceGeneralSetttings,
config_path: Option<impl AsRef<Path>>,
) -> Result<Self, PluginHostInitError> {
// This is just handling the case of input file. The rest is missing
Expand Down
2 changes: 1 addition & 1 deletion application/apps/indexer/plugins_host/src/v0_1_0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod bytesoruce;
pub mod bytesource;
pub mod parser;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{PluginGuestInitError, PluginParseMessage};
use sources::factory::PluginParserGeneralSetttings;
use sources::plugins::PluginParserGeneralSetttings;

pub use self::chipmunk::plugin::{parse_types::*, shared_types::*};
//TODO AAZ: Check if `duplicate_if_necessary` should be set to true or false on both plugin and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod parser_plugin_state;

use std::path::Path;

use sources::factory::PluginParserGeneralSetttings;
use sources::plugins::PluginParserGeneralSetttings;
use wasmtime::{
component::{Component, Linker},
Store,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn run_source_intern<S: ByteSource>(
Err(err) => panic!("Retrieving plugin path environment variable failed. Err {err}"),
};
let proto_plugin_path = PathBuf::from(plugin_path);
let settings = sources::factory::PluginParserSettings::prototyping(proto_plugin_path);
let settings = sources::plugins::PluginParserSettings::prototyping(proto_plugin_path);

let parser = PluginParser::create(
&settings.plugin_path,
Expand Down
33 changes: 2 additions & 31 deletions application/apps/indexer/sources/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf};
use uuid::Uuid;

use crate::plugins::PluginParserSettings;

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ParserType {
Expand Down Expand Up @@ -68,37 +70,6 @@ pub struct SomeIpParserSettings {
pub fibex_file_paths: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PluginParserSettings {
pub plugin_path: PathBuf,
pub general_settings: PluginParserGeneralSetttings,
pub custom_config_path: Option<PathBuf>,
}

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

impl PluginParserSettings {
/// Implementation needed during prototyping only
pub fn prototyping(plugin_path: PathBuf) -> Self {
Self {
plugin_path,
general_settings: PluginParserGeneralSetttings {
placeholder: Default::default(),
},
custom_config_path: None,
}
}

/// Default implementation needed during prototyping only
pub fn default_prototyping() -> Self {
Self::prototyping(PathBuf::default())
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Transport {
Process(ProcessTransportConfig),
Expand Down
1 change: 1 addition & 0 deletions application/apps/indexer/sources/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate log;
pub mod binary;
pub mod command;
pub mod factory;
pub mod plugins;
pub mod producer;
pub mod sde;
pub mod serial;
Expand Down
79 changes: 79 additions & 0 deletions application/apps/indexer/sources/src/plugins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PluginParserSettings {
pub plugin_path: PathBuf,
pub general_settings: PluginParserGeneralSetttings,
pub custom_config_path: Option<PathBuf>,
}

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

impl PluginParserSettings {
/// Implementation needed during prototyping only
pub fn prototyping(plugin_path: PathBuf) -> Self {
Self {
plugin_path,
general_settings: PluginParserGeneralSetttings {
placeholder: Default::default(),
},
custom_config_path: None,
}
}

/// Default implementation needed during prototyping only
pub fn default_prototyping() -> Self {
Self::prototyping(PathBuf::default())
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginByteSourceSettings {
pub plugin_path: PathBuf,
pub source_input: ByteSourceInput,
pub general_settings: PluginByteSourceGeneralSetttings,
pub custom_config_path: Option<PathBuf>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
/// Represents The input source for byte source to read from
pub enum ByteSourceInput {
/// File input source with its path
File(PathBuf),
/// Socket Connection, identified with IP address and port
Socket { ip: String, port: u16 },
/// Network source identified with URL
Url(String),
/// Connection String for a Database
DbConnectionString(String),
/// In-Memory bytes buffer
Memory(Vec<u8>),
/// Other types of input sources can be added here.
Other(String),
}

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

impl PluginByteSourceSettings {
/// Implementation needed during prototyping only
pub fn prototyping(plugin_path: PathBuf, source_input: ByteSourceInput) -> Self {
Self {
plugin_path,
source_input,
general_settings: PluginByteSourceGeneralSetttings {
placeholder: Default::default(),
},
custom_config_path: None,
}
}
}

0 comments on commit 6e1387b

Please sign in to comment.