-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve modularity of smartengine (#3152)
This PR is part of #3151 (see more context there), containing only trivial code reorganizations, without any actual changes. To summarize: - a new `engine` mod, corresponding to the feature `engine`. The implementations are moved to `engine::wasmtime_engine`. - There are some reusable code not coupled with the engine. So I extracted them into a new module `config`.
- Loading branch information
Showing
21 changed files
with
141 additions
and
129 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use derive_builder::Builder; | ||
use fluvio_smartmodule::dataplane::smartmodule::SmartModuleExtraParams; | ||
|
||
const DEFAULT_SMARTENGINE_VERSION: i16 = 17; | ||
|
||
/// Initial seed data to passed, this will be send back as part of the output | ||
#[derive(Debug, Clone)] | ||
#[non_exhaustive] | ||
pub enum SmartModuleInitialData { | ||
None, | ||
Aggregate { accumulator: Vec<u8> }, | ||
} | ||
|
||
impl SmartModuleInitialData { | ||
pub fn with_aggregate(accumulator: Vec<u8>) -> Self { | ||
Self::Aggregate { accumulator } | ||
} | ||
} | ||
|
||
impl Default for SmartModuleInitialData { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} | ||
|
||
/// SmartModule configuration | ||
#[derive(Builder)] | ||
pub struct SmartModuleConfig { | ||
#[builder(default, setter(strip_option))] | ||
pub(crate) initial_data: SmartModuleInitialData, | ||
#[builder(default)] | ||
pub(crate) params: SmartModuleExtraParams, | ||
// this will be deprecated in the future | ||
#[builder(default, setter(into, strip_option))] | ||
pub(crate) version: Option<i16>, | ||
} | ||
|
||
impl SmartModuleConfigBuilder { | ||
/// add initial parameters | ||
pub fn param(&mut self, key: impl Into<String>, value: impl Into<String>) -> &mut Self { | ||
let mut new = self; | ||
let mut params = new.params.take().unwrap_or_default(); | ||
params.insert(key.into(), value.into()); | ||
new.params = Some(params); | ||
new | ||
} | ||
} | ||
|
||
impl SmartModuleConfig { | ||
pub fn builder() -> SmartModuleConfigBuilder { | ||
SmartModuleConfigBuilder::default() | ||
} | ||
|
||
pub(crate) fn version(&self) -> i16 { | ||
self.version.unwrap_or(DEFAULT_SMARTENGINE_VERSION) | ||
} | ||
} | ||
|
||
#[cfg(feature = "transformation")] | ||
impl From<crate::transformation::TransformationStep> for SmartModuleConfig { | ||
fn from(step: crate::transformation::TransformationStep) -> Self { | ||
Self { | ||
initial_data: SmartModuleInitialData::None, | ||
params: step | ||
.with | ||
.into_iter() | ||
.map(|(k, v)| (k, v.into())) | ||
.collect::<std::collections::BTreeMap<String, String>>() | ||
.into(), | ||
version: None, | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pub mod metrics; | ||
/// SmartModule configuration | ||
mod config; | ||
pub use config::{ | ||
SmartModuleConfig, SmartModuleConfigBuilder, SmartModuleConfigBuilderError, | ||
SmartModuleInitialData, | ||
}; | ||
mod error; | ||
|
||
#[cfg(test)] | ||
mod fixture; | ||
|
||
pub type WasmSlice = (i32, i32, u32); | ||
pub type Version = i16; | ||
|
||
mod wasmtime; | ||
pub use self::wasmtime::{SmartEngine, SmartModuleChainBuilder, SmartModuleChainInstance}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub(crate) mod memory; | ||
pub(crate) mod transforms; | ||
pub(crate) mod init; | ||
pub(crate) mod state; | ||
pub(crate) mod engine; | ||
pub(crate) mod instance; | ||
pub use engine::{SmartEngine, SmartModuleChainBuilder, SmartModuleChainInstance}; | ||
|
||
use super::*; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.