-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the Executor interface to allow trait object as executors (#…
…2230) * Refactored the Executor interface yet again I apologize having to refactor this interface yet again. Previously, we introduced the executor to be a function pointer. This works out nicely because the function pointer in rust can be clone-ed without hassel. However, I realized that using function pointer is way to restrictive for our users. The executor may wish to include additional context when calling the exec function. The function pointer limited the input only `oci spec`. Signed-off-by: yihuaf <[email protected]> * fix spell check Signed-off-by: yihuaf <[email protected]> * Fix doc test Signed-off-by: yihuaf <[email protected]> --------- Signed-off-by: yihuaf <[email protected]>
- Loading branch information
Showing
10 changed files
with
120 additions
and
38 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,29 +1,36 @@ | ||
use libcontainer::oci_spec::runtime::Spec; | ||
use libcontainer::workload::{Executor, ExecutorError}; | ||
|
||
pub fn default_executor() -> Executor { | ||
Box::new(|spec: &Spec| -> Result<(), ExecutorError> { | ||
#[derive(Clone)] | ||
pub struct DefaultExecutor {} | ||
|
||
impl Executor for DefaultExecutor { | ||
fn exec(&self, spec: &Spec) -> Result<(), ExecutorError> { | ||
#[cfg(feature = "wasm-wasmer")] | ||
match super::wasmer::get_executor()(spec) { | ||
match super::wasmer::get_executor().exec(spec) { | ||
Ok(_) => return Ok(()), | ||
Err(ExecutorError::CantHandle(_)) => (), | ||
Err(err) => return Err(err), | ||
} | ||
#[cfg(feature = "wasm-wasmedge")] | ||
match super::wasmedge::get_executor()(spec) { | ||
match super::wasmedge::get_executor().exec(spec) { | ||
Ok(_) => return Ok(()), | ||
Err(ExecutorError::CantHandle(_)) => (), | ||
Err(err) => return Err(err), | ||
} | ||
#[cfg(feature = "wasm-wasmtime")] | ||
match super::wasmtime::get_executor()(spec) { | ||
match super::wasmtime::get_executor().exec(spec) { | ||
Ok(_) => return Ok(()), | ||
Err(ExecutorError::CantHandle(_)) => (), | ||
Err(err) => return Err(err), | ||
} | ||
|
||
// Leave the default executor as the last option, which executes normal | ||
// container workloads. | ||
libcontainer::workload::default::get_executor()(spec) | ||
}) | ||
libcontainer::workload::default::get_executor().exec(spec) | ||
} | ||
} | ||
|
||
pub fn default_executor() -> DefaultExecutor { | ||
DefaultExecutor {} | ||
} |
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