This is an automated email from the ASF dual-hosted git repository.
mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git
The following commit(s) were added to refs/heads/develop by this push:
new 1a2932f [worker] Separate worker into worker/function/runtime crates
1a2932f is described below
commit 1a2932f8c76be0810c5114a48e489796b0c8d4f2
Author: Mingshen Sun <[email protected]>
AuthorDate: Tue Mar 24 22:15:25 2020 -0700
[worker] Separate worker into worker/function/runtime crates
---
{worker => function}/Cargo.toml | 12 ++++++----
{worker/src/function => function/src}/context.rs | 4 ++--
{worker/src/function => function/src}/echo.rs | 12 +++-------
.../function => function/src}/gbdt_prediction.rs | 17 ++++----------
.../src/function => function/src}/gbdt_training.rs | 17 ++++----------
worker/src/function/mod.rs => function/src/lib.rs | 26 ++++++++--------------
{worker/src/function => function/src}/mesapy.rs | 19 +++++-----------
{worker => runtime}/Cargo.toml | 11 +++------
{worker/src/runtime => runtime/src}/default.rs | 2 +-
worker/src/runtime/mod.rs => runtime/src/lib.rs | 19 +++-------------
{worker/src/runtime => runtime/src}/raw_io.rs | 2 +-
tests/unit/enclave/Cargo.toml | 6 +++++
tests/unit/enclave/src/lib.rs | 2 ++
types/src/worker.rs | 15 +++++++++++++
worker/Cargo.toml | 7 +++---
worker/src/lib.rs | 14 +-----------
worker/src/worker.rs | 5 +++--
17 files changed, 75 insertions(+), 115 deletions(-)
diff --git a/worker/Cargo.toml b/function/Cargo.toml
similarity index 79%
copy from worker/Cargo.toml
copy to function/Cargo.toml
index bc3b814..883905c 100644
--- a/worker/Cargo.toml
+++ b/function/Cargo.toml
@@ -1,13 +1,13 @@
[package]
-name = "teaclave_worker"
+name = "teaclave_function"
version = "0.1.0"
authors = ["Teaclave Contributors <[email protected]>"]
-description = "Teaclave worker"
+description = "Teaclave function"
license = "Apache-2.0"
edition = "2018"
[lib]
-name = "teaclave_worker"
+name = "teaclave_function"
crate-type = ["staticlib", "rlib"]
[features]
@@ -17,7 +17,10 @@ mesalock_sgx = [
"teaclave_types/mesalock_sgx",
]
cov = ["sgx_cov"]
-enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
+enclave_unit_test = [
+ "teaclave_test_utils/mesalock_sgx",
+ "teaclave_runtime/mesalock_sgx"
+]
[dependencies]
log = { version = "0.4.6" }
@@ -28,6 +31,7 @@ thiserror = { version = "1.0.9" }
gbdt = { version = "0.1.0", features = ["input", "enable_training"] }
itertools = { version = "0.8.0", default-features = false }
teaclave_types = { path = "../types" }
+teaclave_runtime = { path = "../runtime", optional = true }
teaclave_test_utils = { path = "../tests/utils", optional = true }
sgx_cov = { version = "1.1.0", optional = true }
diff --git a/worker/src/function/context.rs b/function/src/context.rs
similarity index 99%
rename from worker/src/function/context.rs
rename to function/src/context.rs
index 0a23338..ff3f056 100644
--- a/worker/src/function/context.rs
+++ b/function/src/context.rs
@@ -28,7 +28,7 @@ use anyhow;
use std::collections::HashMap;
use std::format;
-use crate::runtime::TeaclaveRuntime;
+use teaclave_types::TeaclaveRuntime;
const FFI_OK: c_uint = 0;
const FFI_FILE_ERROR: c_uint = 1;
@@ -236,9 +236,9 @@ pub fn rtc_close_handle(f: FileHandle) ->
anyhow::Result<()> {
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
- use crate::runtime::RawIoRuntime;
use std::path::PathBuf;
use std::str::FromStr;
+ use teaclave_runtime::RawIoRuntime;
use teaclave_test_utils::*;
use teaclave_types::hashmap;
use teaclave_types::StagedFileInfo;
diff --git a/worker/src/function/echo.rs b/function/src/echo.rs
similarity index 87%
rename from worker/src/function/echo.rs
rename to function/src/echo.rs
index 5d46bb2..1c8181f 100644
--- a/worker/src/function/echo.rs
+++ b/function/src/echo.rs
@@ -18,10 +18,9 @@
#[cfg(feature = "mesalock_sgx")]
use std::prelude::v1::*;
-use crate::function::TeaclaveFunction;
-use crate::runtime::TeaclaveRuntime;
use anyhow;
use teaclave_types::FunctionArguments;
+use teaclave_types::{TeaclaveFunction, TeaclaveRuntime};
#[derive(Default)]
pub struct Echo;
@@ -40,14 +39,9 @@ impl TeaclaveFunction for Echo {
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
+ use teaclave_runtime::*;
use teaclave_test_utils::*;
-
- use teaclave_types::hashmap;
- use teaclave_types::FunctionArguments;
- use teaclave_types::StagedFiles;
-
- use crate::function::TeaclaveFunction;
- use crate::runtime::RawIoRuntime;
+ use teaclave_types::*;
pub fn run_tests() -> bool {
run_tests!(test_echo)
diff --git a/worker/src/function/gbdt_prediction.rs
b/function/src/gbdt_prediction.rs
similarity index 92%
rename from worker/src/function/gbdt_prediction.rs
rename to function/src/gbdt_prediction.rs
index 1bcc5bc..670b6e0 100644
--- a/worker/src/function/gbdt_prediction.rs
+++ b/function/src/gbdt_prediction.rs
@@ -24,9 +24,8 @@ use std::io::{self, BufRead, BufReader, Write};
use anyhow;
use serde_json;
-use crate::function::TeaclaveFunction;
-use crate::runtime::TeaclaveRuntime;
use teaclave_types::FunctionArguments;
+use teaclave_types::{TeaclaveFunction, TeaclaveRuntime};
use gbdt::decision_tree::Data;
use gbdt::gradient_boost::GBDT;
@@ -96,18 +95,10 @@ fn parse_test_data(input: impl io::Read) ->
anyhow::Result<Vec<Data>> {
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
- use teaclave_test_utils::*;
-
use std::untrusted::fs;
-
- use teaclave_types::hashmap;
- use teaclave_types::FunctionArguments;
- use teaclave_types::StagedFileInfo;
- use teaclave_types::StagedFiles;
- use teaclave_types::TeaclaveFile128Key;
-
- use crate::function::TeaclaveFunction;
- use crate::runtime::RawIoRuntime;
+ use teaclave_runtime::*;
+ use teaclave_test_utils::*;
+ use teaclave_types::*;
pub fn run_tests() -> bool {
run_tests!(test_gbdt_prediction)
diff --git a/worker/src/function/gbdt_training.rs
b/function/src/gbdt_training.rs
similarity index 94%
rename from worker/src/function/gbdt_training.rs
rename to function/src/gbdt_training.rs
index 046001c..4a7856e 100644
--- a/worker/src/function/gbdt_training.rs
+++ b/function/src/gbdt_training.rs
@@ -24,9 +24,8 @@ use std::io::{self, BufRead, BufReader, Write};
use anyhow;
use serde_json;
-use crate::function::TeaclaveFunction;
-use crate::runtime::TeaclaveRuntime;
use teaclave_types::FunctionArguments;
+use teaclave_types::{TeaclaveFunction, TeaclaveRuntime};
use gbdt::config::Config;
use gbdt::decision_tree::Data;
@@ -131,18 +130,10 @@ fn parse_training_data(input: impl io::Read,
feature_size: usize) -> anyhow::Res
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
- use teaclave_test_utils::*;
-
use std::untrusted::fs;
-
- use teaclave_types::hashmap;
- use teaclave_types::FunctionArguments;
- use teaclave_types::StagedFileInfo;
- use teaclave_types::StagedFiles;
- use teaclave_types::TeaclaveFile128Key;
-
- use crate::function::TeaclaveFunction;
- use crate::runtime::RawIoRuntime;
+ use teaclave_runtime::*;
+ use teaclave_test_utils::*;
+ use teaclave_types::*;
pub fn run_tests() -> bool {
run_tests!(test_gbdt_training, test_gbdt_parse_training_data,)
diff --git a/worker/src/function/mod.rs b/function/src/lib.rs
similarity index 77%
rename from worker/src/function/mod.rs
rename to function/src/lib.rs
index 88d6261..9658ab6 100644
--- a/worker/src/function/mod.rs
+++ b/function/src/lib.rs
@@ -15,39 +15,31 @@
// specific language governing permissions and limitations
// under the License.
+#![cfg_attr(feature = "mesalock_sgx", no_std)]
#[cfg(feature = "mesalock_sgx")]
-use std::prelude::v1::*;
-
-use crate::runtime::TeaclaveRuntime;
-use anyhow;
-use teaclave_types::FunctionArguments;
+extern crate sgx_tstd as std;
-pub trait TeaclaveFunction {
- fn execute(
- &self,
- runtime: Box<dyn TeaclaveRuntime + Send + Sync>,
- args: FunctionArguments,
- ) -> anyhow::Result<String>;
+#[cfg(feature = "mesalock_sgx")]
+use std::prelude::v1::*;
- // TODO: Add more flexible control support on a running function
- // fn stop();
- // fn handle_event();
-}
+#[macro_use]
+extern crate log;
+mod context;
mod echo;
mod gbdt_prediction;
mod gbdt_training;
mod mesapy;
+
pub use echo::Echo;
pub use gbdt_prediction::GbdtPrediction;
pub use gbdt_training::GbdtTraining;
pub use mesapy::Mesapy;
-mod context;
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
- use teaclave_test_utils::*;
+ use teaclave_test_utils::check_all_passed;
pub fn run_tests() -> bool {
check_all_passed!(
diff --git a/worker/src/function/mesapy.rs b/function/src/mesapy.rs
similarity index 91%
rename from worker/src/function/mesapy.rs
rename to function/src/mesapy.rs
index fb7c13b..7d1f987 100644
--- a/worker/src/function/mesapy.rs
+++ b/function/src/mesapy.rs
@@ -21,13 +21,12 @@ use std::prelude::v1::*;
use anyhow;
use itertools::Itertools;
-use crate::function::TeaclaveFunction;
-use crate::runtime::TeaclaveRuntime;
use teaclave_types::FunctionArguments;
+use teaclave_types::{TeaclaveFunction, TeaclaveRuntime};
-use crate::function::context::reset_thread_context;
-use crate::function::context::set_thread_context;
-use crate::function::context::Context;
+use crate::context::reset_thread_context;
+use crate::context::set_thread_context;
+use crate::context::Context;
use std::ffi::CString;
use std::format;
@@ -103,15 +102,9 @@ impl TeaclaveFunction for Mesapy {
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
+ use teaclave_runtime::*;
use teaclave_test_utils::*;
-
- use crate::function::TeaclaveFunction;
- use crate::runtime::RawIoRuntime;
- use teaclave_types::hashmap;
- use teaclave_types::FunctionArguments;
- use teaclave_types::StagedFileInfo;
- use teaclave_types::StagedFiles;
- use teaclave_types::TeaclaveFile128Key;
+ use teaclave_types::*;
pub fn run_tests() -> bool {
run_tests!(test_mesapy,)
diff --git a/worker/Cargo.toml b/runtime/Cargo.toml
similarity index 66%
copy from worker/Cargo.toml
copy to runtime/Cargo.toml
index bc3b814..a36561f 100644
--- a/worker/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -1,13 +1,13 @@
[package]
-name = "teaclave_worker"
+name = "teaclave_runtime"
version = "0.1.0"
authors = ["Teaclave Contributors <[email protected]>"]
-description = "Teaclave worker"
+description = "Teaclave runtime"
license = "Apache-2.0"
edition = "2018"
[lib]
-name = "teaclave_worker"
+name = "teaclave_runtime"
crate-type = ["staticlib", "rlib"]
[features]
@@ -22,11 +22,6 @@ enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
[dependencies]
log = { version = "0.4.6" }
anyhow = { version = "1.0.26" }
-serde_json = { version = "1.0.39" }
-serde = { version = "1.0.92", features = ["derive"] }
-thiserror = { version = "1.0.9" }
-gbdt = { version = "0.1.0", features = ["input", "enable_training"] }
-itertools = { version = "0.8.0", default-features = false }
teaclave_types = { path = "../types" }
teaclave_test_utils = { path = "../tests/utils", optional = true }
diff --git a/worker/src/runtime/default.rs b/runtime/src/default.rs
similarity index 98%
rename from worker/src/runtime/default.rs
rename to runtime/src/default.rs
index 0e47acc..78a3bd2 100644
--- a/worker/src/runtime/default.rs
+++ b/runtime/src/default.rs
@@ -21,8 +21,8 @@ use std::prelude::v1::*;
use anyhow;
use std::io;
-use super::TeaclaveRuntime;
use teaclave_types::StagedFiles;
+use teaclave_types::TeaclaveRuntime;
pub struct DefaultRuntime {
input_files: StagedFiles,
diff --git a/worker/src/runtime/mod.rs b/runtime/src/lib.rs
similarity index 70%
rename from worker/src/runtime/mod.rs
rename to runtime/src/lib.rs
index 948d15b..731cbe1 100644
--- a/worker/src/runtime/mod.rs
+++ b/runtime/src/lib.rs
@@ -15,16 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#![cfg_attr(feature = "mesalock_sgx", no_std)]
#[cfg(feature = "mesalock_sgx")]
-use std::prelude::v1::*;
-
-use std::io;
-
-pub trait TeaclaveRuntime {
- fn open_input(&self, identifier: &str) -> anyhow::Result<Box<dyn
io::Read>>;
- fn create_output(&self, identifier: &str) -> anyhow::Result<Box<dyn
io::Write>>;
- // TODO: add more constrained capabilities
-}
+extern crate sgx_tstd as std;
mod default;
pub use default::DefaultRuntime;
@@ -36,13 +29,7 @@ pub use raw_io::RawIoRuntime;
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
- use super::*;
- use teaclave_test_utils::*;
-
pub fn run_tests() -> bool {
- run_tests!(
- //DefultRuntime::tests::test_open_input();
- //DefultRuntime::tests::test_create_output();
- )
+ true
}
}
diff --git a/worker/src/runtime/raw_io.rs b/runtime/src/raw_io.rs
similarity index 98%
rename from worker/src/runtime/raw_io.rs
rename to runtime/src/raw_io.rs
index 4a58742..73952d1 100644
--- a/worker/src/runtime/raw_io.rs
+++ b/runtime/src/raw_io.rs
@@ -23,8 +23,8 @@ use std::untrusted::fs::File;
use anyhow;
-use super::TeaclaveRuntime;
use teaclave_types::StagedFiles;
+use teaclave_types::TeaclaveRuntime;
pub struct RawIoRuntime {
input_files: StagedFiles,
diff --git a/tests/unit/enclave/Cargo.toml b/tests/unit/enclave/Cargo.toml
index 74408c4..6302df5 100644
--- a/tests/unit/enclave/Cargo.toml
+++ b/tests/unit/enclave/Cargo.toml
@@ -36,6 +36,10 @@ mesalock_sgx = [
"teaclave_scheduler_service_enclave/enclave_unit_test",
"teaclave_worker/mesalock_sgx",
"teaclave_worker/enclave_unit_test",
+ "teaclave_function/mesalock_sgx",
+ "teaclave_function/enclave_unit_test",
+ "teaclave_runtime/mesalock_sgx",
+ "teaclave_runtime/enclave_unit_test",
"rusty-leveldb/mesalock_sgx",
"rusty-leveldb/enclave_unit_test",
]
@@ -55,6 +59,8 @@ teaclave_management_service_enclave = { path =
"../../../services/management/enc
teaclave_scheduler_service_enclave = { path =
"../../../services/scheduler/enclave" }
teaclave_worker = { path = "../../../worker" }
+teaclave_function = { path = "../../../function" }
+teaclave_runtime = { path = "../../../runtime" }
rusty-leveldb = { path = "../../../common/rusty_leveldb_sgx",
default-features = false, optional = true }
teaclave_test_utils = { path = "../../utils" }
diff --git a/tests/unit/enclave/src/lib.rs b/tests/unit/enclave/src/lib.rs
index 2323139..6e76c89 100644
--- a/tests/unit/enclave/src/lib.rs
+++ b/tests/unit/enclave/src/lib.rs
@@ -45,6 +45,8 @@ fn handle_run_test(_: &RunTestInput) ->
TeeServiceResult<RunTestOutput> {
teaclave_execution_service_enclave::tests::run_tests(),
teaclave_authentication_service_enclave::tests::run_tests(),
teaclave_worker::tests::run_tests(),
+ teaclave_runtime::tests::run_tests(),
+ teaclave_function::tests::run_tests(),
teaclave_types::tests::run_tests(),
rusty_leveldb::tests::run_tests(),
);
diff --git a/types/src/worker.rs b/types/src/worker.rs
index ce1a8af..446408c 100644
--- a/types/src/worker.rs
+++ b/types/src/worker.rs
@@ -15,12 +15,27 @@
// specific language governing permissions and limitations
// under the License.
+use crate::FunctionArguments;
use std::collections::HashMap;
use std::collections::HashSet;
+use std::io;
use std::prelude::v1::*;
use anyhow;
+pub trait TeaclaveRuntime {
+ fn open_input(&self, identifier: &str) -> anyhow::Result<Box<dyn
io::Read>>;
+ fn create_output(&self, identifier: &str) -> anyhow::Result<Box<dyn
io::Write>>;
+}
+
+pub trait TeaclaveFunction {
+ fn execute(
+ &self,
+ runtime: Box<dyn TeaclaveRuntime + Send + Sync>,
+ args: FunctionArguments,
+ ) -> anyhow::Result<String>;
+}
+
#[derive(Debug, Copy, Clone)]
pub enum ExecutorType {
Native,
diff --git a/worker/Cargo.toml b/worker/Cargo.toml
index bc3b814..2345ef5 100644
--- a/worker/Cargo.toml
+++ b/worker/Cargo.toml
@@ -15,6 +15,8 @@ default = []
mesalock_sgx = [
"sgx_tstd",
"teaclave_types/mesalock_sgx",
+ "teaclave_function/mesalock_sgx",
+ "teaclave_runtime/mesalock_sgx"
]
cov = ["sgx_cov"]
enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
@@ -23,11 +25,10 @@ enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
log = { version = "0.4.6" }
anyhow = { version = "1.0.26" }
serde_json = { version = "1.0.39" }
-serde = { version = "1.0.92", features = ["derive"] }
thiserror = { version = "1.0.9" }
-gbdt = { version = "0.1.0", features = ["input", "enable_training"] }
-itertools = { version = "0.8.0", default-features = false }
teaclave_types = { path = "../types" }
+teaclave_function = { path = "../function" }
+teaclave_runtime = { path = "../runtime" }
teaclave_test_utils = { path = "../tests/utils", optional = true }
sgx_cov = { version = "1.1.0", optional = true }
diff --git a/worker/src/lib.rs b/worker/src/lib.rs
index b6ed6db..46c8c0f 100644
--- a/worker/src/lib.rs
+++ b/worker/src/lib.rs
@@ -19,24 +19,12 @@
#[cfg(feature = "mesalock_sgx")]
extern crate sgx_tstd as std;
-#[cfg(feature = "mesalock_sgx")]
-use std::prelude::v1::*;
-
-#[macro_use]
-extern crate log;
-
-mod function;
-mod runtime;
mod worker;
-
pub use worker::Worker;
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
- use super::*;
- use teaclave_test_utils::check_all_passed;
-
pub fn run_tests() -> bool {
- check_all_passed!(function::tests::run_tests(),
runtime::tests::run_tests(),)
+ true
}
}
diff --git a/worker/src/worker.rs b/worker/src/worker.rs
index 60aec18..0cb5b73 100644
--- a/worker/src/worker.rs
+++ b/worker/src/worker.rs
@@ -28,8 +28,9 @@ use teaclave_types::{
hashmap, ExecutorType, FunctionArguments, StagedFiles, StagedFunction,
WorkerCapability,
};
-use crate::function::{self, TeaclaveFunction};
-use crate::runtime::{self, TeaclaveRuntime};
+use teaclave_function as function;
+use teaclave_runtime as runtime;
+use teaclave_types::{TeaclaveFunction, TeaclaveRuntime};
macro_rules! register_functions{
($($name: expr => ($executor: expr, $fn_type: ty),)*) => {{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]