Return only facade interface in AppService get_interface (#44)

This commit is contained in:
vms 2020-11-25 13:12:08 +03:00 committed by GitHub
parent afa612a563
commit 1094d8e504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 265 additions and 184 deletions

177
Cargo.lock generated
View File

@ -96,9 +96,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.54" version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2baad346b2d4e94a24347adeee9c7a93f412ee94b9cc26e5b59dea23848e9f28" checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598"
dependencies = [ dependencies = [
"addr2line", "addr2line",
"cfg-if 1.0.0", "cfg-if 1.0.0",
@ -114,6 +114,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]] [[package]]
name = "bincode" name = "bincode"
version = "1.3.1" version = "1.3.1"
@ -189,9 +195,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.62" version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40" checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -248,6 +254,16 @@ version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "475bd7aa7680b4ed8f6bb59745e882bcbaeb39326532bb79ffb1716480d9a274" checksum = "475bd7aa7680b4ed8f6bb59745e882bcbaeb39326532bb79ffb1716480d9a274"
[[package]]
name = "console_error_panic_hook"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
dependencies = [
"cfg-if 0.1.10",
"wasm-bindgen",
]
[[package]] [[package]]
name = "const_fn" name = "const_fn"
version = "0.4.3" version = "0.4.3"
@ -538,12 +554,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "dtoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"
@ -729,15 +739,6 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "fluence"
version = "0.2.9"
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
dependencies = [
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
"fluence-sdk-main 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
]
[[package]] [[package]]
name = "fluence" name = "fluence"
version = "0.2.9" version = "0.2.9"
@ -748,6 +749,15 @@ dependencies = [
"fluence-sdk-main 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "fluence-sdk-main 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "fluence"
version = "0.2.9"
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
dependencies = [
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
"fluence-sdk-main 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
]
[[package]] [[package]]
name = "fluence-app-service" name = "fluence-app-service"
version = "0.1.12" version = "0.1.12"
@ -786,14 +796,6 @@ dependencies = [
"wasmer-wasi-fl", "wasmer-wasi-fl",
] ]
[[package]]
name = "fluence-sdk-macro"
version = "0.2.9"
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
dependencies = [
"fluence-sdk-wit 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
]
[[package]] [[package]]
name = "fluence-sdk-macro" name = "fluence-sdk-macro"
version = "0.2.9" version = "0.2.9"
@ -804,13 +806,11 @@ dependencies = [
] ]
[[package]] [[package]]
name = "fluence-sdk-main" name = "fluence-sdk-macro"
version = "0.2.9" version = "0.2.9"
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a" source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
dependencies = [ dependencies = [
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)", "fluence-sdk-wit 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
"log",
"serde",
] ]
[[package]] [[package]]
@ -825,9 +825,20 @@ dependencies = [
] ]
[[package]] [[package]]
name = "fluence-sdk-wit" name = "fluence-sdk-main"
version = "0.2.9" version = "0.2.9"
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a" source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
dependencies = [
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
"log",
"serde",
]
[[package]]
name = "fluence-sdk-wit"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9c68c4d07e821e1be23b01c278acdae4e825d03c46879f453426ea3160b3e25"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -840,8 +851,7 @@ dependencies = [
[[package]] [[package]]
name = "fluence-sdk-wit" name = "fluence-sdk-wit"
version = "0.2.9" version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
checksum = "f9c68c4d07e821e1be23b01c278acdae4e825d03c46879f453426ea3160b3e25"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -950,7 +960,7 @@ checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-task", "futures-task",
"pin-project 1.0.1", "pin-project 1.0.2",
"pin-utils", "pin-utils",
] ]
@ -1144,7 +1154,7 @@ dependencies = [
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project 1.0.1", "pin-project 1.0.2",
"socket2", "socket2",
"tokio", "tokio",
"tower-service", "tower-service",
@ -1678,11 +1688,11 @@ dependencies = [
[[package]] [[package]]
name = "pin-project" name = "pin-project"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841" checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7"
dependencies = [ dependencies = [
"pin-project-internal 1.0.1", "pin-project-internal 1.0.2",
] ]
[[package]] [[package]]
@ -1698,9 +1708,9 @@ dependencies = [
[[package]] [[package]]
name = "pin-project-internal" name = "pin-project-internal"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86" checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1713,6 +1723,12 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
[[package]]
name = "pin-project-lite"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
[[package]] [[package]]
name = "pin-utils" name = "pin-utils"
version = "0.1.0" version = "0.1.0"
@ -1917,11 +1933,11 @@ dependencies = [
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.10.8" version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e" checksum = "fb15d6255c792356a0f578d8a645c677904dc02e862bebe2ecc18e0c01b9a0ce"
dependencies = [ dependencies = [
"base64", "base64 0.13.0",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
@ -1938,7 +1954,7 @@ dependencies = [
"mime_guess", "mime_guess",
"native-tls", "native-tls",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite 0.2.0",
"serde", "serde",
"serde_urlencoded", "serde_urlencoded",
"tokio", "tokio",
@ -1946,6 +1962,7 @@ dependencies = [
"url", "url",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"wasm-bindgen-test",
"web-sys", "web-sys",
"winreg", "winreg",
] ]
@ -1956,7 +1973,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19" checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
dependencies = [ dependencies = [
"base64", "base64 0.12.3",
"blake2b_simd", "blake2b_simd",
"constant_time_eq", "constant_time_eq",
"crossbeam-utils 0.7.2", "crossbeam-utils 0.7.2",
@ -2035,6 +2052,12 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "scoped-tls"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -2131,14 +2154,14 @@ dependencies = [
[[package]] [[package]]
name = "serde_urlencoded" name = "serde_urlencoded"
version = "0.6.1" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
dependencies = [ dependencies = [
"dtoa", "form_urlencoded",
"itoa", "itoa",
"ryu",
"serde", "serde",
"url",
] ]
[[package]] [[package]]
@ -2189,9 +2212,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.4.2" version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
[[package]] [[package]]
name = "socket2" name = "socket2"
@ -2285,9 +2308,9 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.0" version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]
@ -2359,9 +2382,9 @@ dependencies = [
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.0.1" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b78a366903f506d2ad52ca8dc552102ffdd3e937ba8a227f024dc1d1eae28575" checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
dependencies = [ dependencies = [
"tinyvec_macros", "tinyvec_macros",
] ]
@ -2374,9 +2397,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "0.2.22" version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" checksum = "a6d7ad61edd59bfcc7e80dababf0f4aed2e6d5e0ba1659356ae889752dfc12ff"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -2385,7 +2408,7 @@ dependencies = [
"lazy_static", "lazy_static",
"memchr", "memchr",
"mio", "mio",
"pin-project-lite", "pin-project-lite 0.1.11",
"slab", "slab",
"tokio-macros", "tokio-macros",
] ]
@ -2421,7 +2444,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"log", "log",
"pin-project-lite", "pin-project-lite 0.1.11",
"tokio", "tokio",
] ]
@ -2448,7 +2471,7 @@ checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
"log", "log",
"pin-project-lite", "pin-project-lite 0.1.11",
"tracing-core", "tracing-core",
] ]
@ -2541,18 +2564,18 @@ dependencies = [
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
version = "0.1.14" version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f98e67a4d84f730d343392f9bfff7d21e3fca562b9cb7a43b768350beeddc6" checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606"
dependencies = [ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.6.0" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" checksum = "db8716a166f290ff49dabc18b44aa407cb7c6dbe1aa0971b44b8a24b0ca35aae"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
@ -2748,6 +2771,30 @@ version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
[[package]]
name = "wasm-bindgen-test"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34d1cdc8b98a557f24733d50a1199c4b0635e465eecba9c45b214544da197f64"
dependencies = [
"console_error_panic_hook",
"js-sys",
"scoped-tls",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8fb9c67be7439ee8ab1b7db502a49c05e51e2835b66796c705134d9b8e1a585"
dependencies = [
"proc-macro2",
"quote",
]
[[package]] [[package]]
name = "wasm-greeting" name = "wasm-greeting"
version = "0.1.0" version = "0.1.0"

View File

@ -18,12 +18,14 @@ use super::*;
use crate::module::FCEModule; use crate::module::FCEModule;
use crate::module::RecordTypes; use crate::module::RecordTypes;
use serde::Serialize;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
/// Represent FCE module interface. /// Represent FCE module interface.
#[derive(PartialEq, Eq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone, Serialize)]
pub struct FCEModuleInterface<'a> { pub struct FCEModuleInterface<'a> {
pub record_types: &'a RecordTypes, pub record_types: &'a RecordTypes,
pub function_signatures: Vec<FCEFunctionSignature>, pub function_signatures: Vec<FCEFunctionSignature>,

View File

@ -29,6 +29,9 @@ use wasmer_runtime::compile;
use wasmer_runtime::ImportObject; use wasmer_runtime::ImportObject;
use wasmer_wit::interpreter::Interpreter; use wasmer_wit::interpreter::Interpreter;
use serde::Serialize;
use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
@ -46,7 +49,7 @@ pub(super) struct WITModuleFunc {
} }
/// Represent a function type inside FCE module. /// Represent a function type inside FCE module.
#[derive(PartialEq, Eq, Debug, Clone, Hash)] #[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
pub struct FCEFunctionSignature { pub struct FCEFunctionSignature {
pub name: Rc<String>, pub name: Rc<String>,
pub arguments: Rc<Vec<IFunctionArg>>, pub arguments: Rc<Vec<IFunctionArg>>,

View File

@ -27,20 +27,20 @@
mod config; mod config;
mod errors; mod errors;
mod service; mod service;
mod service_interface;
mod raw_toml_config; mod raw_toml_config;
pub(crate) type Result<T> = std::result::Result<T, AppServiceError>; pub(crate) type Result<T> = std::result::Result<T, AppServiceError>;
pub use errors::AppServiceError; pub use errors::AppServiceError;
pub use service::AppService; pub use service::AppService;
pub use service_interface::FunctionSignature;
pub use service_interface::RecordType;
pub use service_interface::ServiceInterface;
pub use config::AppServiceConfig; pub use config::AppServiceConfig;
pub use raw_toml_config::TomlAppServiceConfig; pub use raw_toml_config::TomlAppServiceConfig;
pub use fluence_faas::FaaSInterface as ServiceInterface;
pub use fluence_faas::FaaSModuleInterface as ServiceModuleInterface;
pub use fluence_faas::FaaSFunctionSignature as ServiceFunctionSignature;
pub use fluence_faas::FaaSConfig; pub use fluence_faas::FaaSConfig;
pub use fluence_faas::FaaSModuleConfig; pub use fluence_faas::FaaSModuleConfig;
pub use fluence_faas::FaaSWASIConfig; pub use fluence_faas::FaaSWASIConfig;

View File

@ -16,6 +16,7 @@
use crate::Result; use crate::Result;
use crate::config::AppServiceConfig; use crate::config::AppServiceConfig;
use crate::service_interface::ServiceInterface;
use super::AppServiceError; use super::AppServiceError;
use fluence_faas::FluenceFaaS; use fluence_faas::FluenceFaaS;
@ -86,9 +87,19 @@ impl AppService {
.map_err(Into::into) .map_err(Into::into)
} }
/// Return all export functions (name and signatures) of loaded modules. /// Return interface (function signatures and record types) of this service.
pub fn get_interface(&self) -> fluence_faas::FaaSInterface<'_> { pub fn get_interface(&self) -> ServiceInterface {
self.faas.get_interface() use crate::service_interface::into_service_interface;
let faas_facade_interface = self
.faas
.get_interface()
.modules
.remove(self.facade_module_name.as_str())
// facade module must be loaded in FaaS, so unwrap is safe here
.unwrap();
into_service_interface(faas_facade_interface)
} }
/// Prepare service before starting by: /// Prepare service before starting by:
@ -200,6 +211,11 @@ impl AppService {
self.faas.unload_module(module_name).map_err(Into::into) self.faas.unload_module(module_name).map_err(Into::into)
} }
/// Return raw interface of the underlying [[FluenceFaaS]] instance
pub fn get_full_interface(&self) -> fluence_faas::FaaSInterface<'_> {
self.faas.get_interface()
}
pub fn get_wasi_state<S: AsRef<str>>( pub fn get_wasi_state<S: AsRef<str>>(
&mut self, &mut self,
module_name: S, module_name: S,

View File

@ -0,0 +1,106 @@
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use fluence_faas::FaaSModuleInterface;
use fluence_faas::FaaSFunctionSignature;
use fluence_faas::IRecordType;
use fluence_faas::RecordTypes;
use fluence_faas::itype_text_view;
use serde::Serialize;
use std::rc::Rc;
#[derive(Serialize)]
pub struct FunctionSignature {
pub name: String,
pub arguments: Vec<(String, String)>,
pub output_types: Vec<String>,
}
#[derive(Serialize)]
pub struct RecordType {
pub name: String,
pub id: u64,
pub fields: Vec<(String, String)>,
}
#[derive(Serialize)]
pub struct ServiceInterface {
pub function_signatures: Vec<FunctionSignature>,
pub record_types: Vec<RecordType>,
}
pub(crate) fn into_service_interface(faas_interface: FaaSModuleInterface<'_>) -> ServiceInterface {
let record_types = faas_interface.record_types;
let function_signatures = faas_interface
.function_signatures
.into_iter()
.map(|sign| serialize_function_signature(sign, record_types))
.collect();
let record_types = record_types
.iter()
.map(|(id, record)| serialize_record_type(*id, record.clone(), record_types))
.collect::<Vec<_>>();
ServiceInterface {
record_types,
function_signatures,
}
}
fn serialize_function_signature(
signature: FaaSFunctionSignature,
record_types: &RecordTypes,
) -> FunctionSignature {
let arguments = signature
.arguments
.iter()
.map(|arg| (arg.name.clone(), itype_text_view(&arg.ty, record_types)))
.collect();
let output_types = signature
.outputs
.iter()
.map(|itype| itype_text_view(itype, record_types))
.collect();
FunctionSignature {
name: signature.name.to_string(),
arguments,
output_types,
}
}
fn serialize_record_type<'a, 'b>(
id: u64,
record: Rc<IRecordType>,
record_types: &RecordTypes,
) -> RecordType {
let fields = record
.fields
.iter()
.map(|field| (field.name.clone(), itype_text_view(&field.ty, record_types)))
.collect::<Vec<_>>();
RecordType {
name: record.name.clone(),
id,
fields,
}
}

View File

@ -17,40 +17,22 @@
use super::IType; use super::IType;
use super::IRecordType; use super::IRecordType;
use crate::FaaSModuleInterface; use crate::FaaSModuleInterface;
use crate::FaaSFunctionSignature;
use fce::RecordTypes; use fce::RecordTypes;
use itertools::Itertools;
use serde::Serialize; use serde::Serialize;
use serde::Serializer;
use std::fmt; use std::fmt;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::rc::Rc;
use itertools::Itertools;
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone, Serialize)]
pub struct FaaSInterface<'a> { pub struct FaaSInterface<'a> {
pub modules: HashMap<&'a str, FaaSModuleInterface<'a>>, pub modules: HashMap<&'a str, FaaSModuleInterface<'a>>,
} }
impl<'a> fmt::Display for FaaSInterface<'a> { impl<'a> fmt::Display for FaaSInterface<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn type_text_view(arg_ty: &IType, record_types: &RecordTypes) -> String {
match arg_ty {
IType::Record(record_type_id) => {
// unwrap is safe because FaaSInterface here is well-formed
// (it was checked on the module startup stage)
let record = record_types.get(record_type_id).unwrap();
record.name.clone()
}
IType::Array(array_ty) => {
format!("Array<{}>", type_text_view(array_ty, record_types))
}
t => format!("{:?}", t),
}
};
let mut printed_record_types: HashSet<&IRecordType> = HashSet::new(); let mut printed_record_types: HashSet<&IRecordType> = HashSet::new();
for (_, module_interface) in self.modules.iter() { for (_, module_interface) in self.modules.iter() {
@ -67,7 +49,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
f, f,
" {}: {}", " {}: {}",
field.name, field.name,
type_text_view(&field.ty, &module_interface.record_types) itype_text_view(&field.ty, &module_interface.record_types)
)?; )?;
} }
@ -88,7 +70,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
format!( format!(
"{}: {}", "{}: {}",
arg.name, arg.name,
type_text_view(&arg.ty, &module_interface.record_types) itype_text_view(&arg.ty, &module_interface.record_types)
) )
}) })
.join(", "); .join(", ");
@ -101,7 +83,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
f, f,
"{}) -> {}", "{}) -> {}",
args, args,
type_text_view(&outputs[0], &module_interface.record_types) itype_text_view(&outputs[0], &module_interface.record_types)
)?; )?;
} else { } else {
// At now, multi values aren't supported - only one output type is possible // At now, multi values aren't supported - only one output type is possible
@ -114,92 +96,15 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
} }
} }
impl<'a> Serialize for FaaSInterface<'a> { pub fn itype_text_view(arg_ty: &IType, record_types: &RecordTypes) -> String {
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> match arg_ty {
where IType::Record(record_type_id) => {
S: Serializer, // unwrap is safe because FaaSInterface here is well-formed
{ // (it was checked on the module startup stage)
#[derive(Serialize)] let record = record_types.get(record_type_id).unwrap();
pub struct FunctionSignature<'a> { record.name.clone()
pub name: &'a Rc<String>,
pub arguments: Vec<(&'a String, &'a IType)>,
pub output_types: &'a Rc<Vec<IType>>,
} }
IType::Array(array_ty) => format!("Array<{}>", itype_text_view(array_ty, record_types)),
#[derive(Serialize)] t => format!("{:?}", t),
pub struct RecordType<'a> {
pub name: &'a str,
pub id: u64,
pub fields: Vec<(&'a String, &'a IType)>,
}
#[derive(Serialize)]
pub struct Module<'a> {
pub name: &'a str,
pub function_signatures: Vec<FunctionSignature<'a>>,
pub record_types: Vec<RecordType<'a>>,
}
#[derive(Serialize)]
pub struct Interface<'a> {
pub modules: Vec<Module<'a>>,
}
fn serialize_function_signature(
signature: &FaaSFunctionSignature,
) -> FunctionSignature<'_> {
let arguments = signature
.arguments
.iter()
.map(|arg| (&arg.name, &arg.ty))
.collect();
FunctionSignature {
name: &signature.name,
arguments,
output_types: &signature.outputs,
}
}
fn serialize_record_type<'a, 'b>(record: (&'a u64, &'b Rc<IRecordType>)) -> RecordType<'b> {
let fields = record
.1
.fields
.iter()
.map(|field| (&field.name, &field.ty))
.collect::<Vec<_>>();
RecordType {
name: record.1.name.as_str(),
id: *record.0,
fields,
}
}
let modules: Vec<_> = self
.modules
.iter()
.map(|(name, interface)| {
let function_signatures = interface
.function_signatures
.iter()
.map(serialize_function_signature)
.collect();
let record_types: Vec<_> = interface
.record_types
.iter()
.map(serialize_record_type)
.collect();
Module {
name,
function_signatures,
record_types,
}
})
.collect();
Interface { modules }.serialize(serializer)
} }
} }

View File

@ -35,6 +35,7 @@ pub(crate) type Result<T> = std::result::Result<T, FaaSError>;
pub use faas::FluenceFaaS; pub use faas::FluenceFaaS;
pub use faas_interface::FaaSInterface; pub use faas_interface::FaaSInterface;
pub use faas_interface::itype_text_view;
pub use config::FaaSConfig; pub use config::FaaSConfig;
pub use config::FaaSModuleConfig; pub use config::FaaSModuleConfig;
@ -58,6 +59,7 @@ pub use fce::IFunctionArg;
pub use fce::IType; pub use fce::IType;
pub use fce::FCEModuleInterface as FaaSModuleInterface; pub use fce::FCEModuleInterface as FaaSModuleInterface;
pub use fce::FCEFunctionSignature as FaaSFunctionSignature; pub use fce::FCEFunctionSignature as FaaSFunctionSignature;
pub use fce::RecordTypes;
pub use fce::HostExportedFunc; pub use fce::HostExportedFunc;
pub use fce::HostImportDescriptor; pub use fce::HostImportDescriptor;
pub use fce::HostImportError; pub use fce::HostImportError;

View File

@ -144,7 +144,7 @@ impl REPL {
}; };
} }
Some("interface") => { Some("interface") => {
let interface = self.app_service.get_interface(); let interface = self.app_service.get_full_interface();
print!("Application service interface:\n{}", interface); print!("Application service interface:\n{}", interface);
} }
Some("h") | Some("help") | None => { Some("h") | Some("help") | None => {