Call parameters module (#26)

This commit is contained in:
Dima 2020-09-14 14:22:56 +03:00 committed by GitHub
parent acab656dd9
commit 5259036913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 121 additions and 66 deletions

31
Cargo.lock generated
View File

@ -154,6 +154,13 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "call_parameters"
version = "0.1.0"
dependencies = [
"fluence",
]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.59" version = "1.0.59"
@ -1283,11 +1290,12 @@ dependencies = [
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.4.1" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d7559a8a40d0f97e1edea3220f698f78b1c5ab67532e49f68fde3910323b722" checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9"
dependencies = [ dependencies = [
"adler", "adler",
"autocfg",
] ]
[[package]] [[package]]
@ -1387,15 +1395,14 @@ dependencies = [
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cc", "cc",
"cfg-if", "cfg-if",
"libc", "libc",
"void",
] ]
[[package]] [[package]]
@ -1815,16 +1822,16 @@ checksum = "ccb57833f46c9d679d68f383e81b9a74b82aa8d6f8a9c9aaae7fc29476bc3274"
[[package]] [[package]]
name = "rustyline" name = "rustyline"
version = "6.2.0" version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3358c21cbbc1a751892528db4e1de4b7a2b6a73f001e215aaba97d712cfa9777" checksum = "6f0d5e7b0219a3eadd5439498525d4765c59b7c993ef0c12244865cd2d988413"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"dirs-next", "dirs-next",
"libc", "libc",
"log", "log",
"memchr", "memchr",
"nix 0.17.0", "nix 0.18.0",
"scopeguard", "scopeguard",
"skim", "skim",
"unicode-segmentation", "unicode-segmentation",
@ -1911,9 +1918,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.115" version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -1939,9 +1946,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.115" version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@ -10,9 +10,10 @@ members = [
"examples/records/effector", "examples/records/effector",
"examples/records/pure", "examples/records/pure",
"examples/records/test-record", "examples/records/test-record",
"examples/site-storage/wasm/site-storage", "examples/site-storage/site-storage",
"examples/site-storage/wasm/curl", "examples/site-storage/curl",
"examples/site-storage/wasm/local_storage", "examples/site-storage/local_storage",
"examples/call_parameters",
"fluence-app-service", "fluence-app-service",
"fluence-faas", "fluence-faas",
"tools/cli", "tools/cli",

View File

@ -0,0 +1,12 @@
[package]
name = "call_parameters"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
[[bin]]
name = "call_parameters"
path = "src/main.rs"
[dependencies]
fluence = { git = "https://github.com/fluencelabs/rust-sdk" }

View File

@ -1,6 +1,6 @@
modules_dir = "artifacts/" modules_dir = "artifacts/"
[[module]] [[module]]
name = "greeting_cp" name = "call_parameters"
mem_pages_count = 1 mem_pages_count = 1
logger_enabled = false logger_enabled = false

Binary file not shown.

View File

@ -0,0 +1,7 @@
#!/bin/sh
cargo update
fce build --release
rm -f artifacts/*
cp ../../target/wasm32-wasi/release/call_parameters.wasm artifacts/

View File

@ -14,11 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
use fluence::fce;
pub fn main() {} pub fn main() {}
#[fluence::fce] #[fce]
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
pub fn greeting() -> String { pub fn call_parameters() -> String {
let name = fluence::get_call_parameters().user_name; let cp = fluence::get_call_parameters();
format!("Hi, {}", name) format!("{}\n{}\n{}", cp.call_id, cp.user_name, cp.application_id)
} }

View File

@ -8,9 +8,5 @@ edition = "2018"
name = "greeting" name = "greeting"
path = "src/main.rs" path = "src/main.rs"
[[bin]]
name = "greeting_cp"
path = "src/main_cp.rs"
[dependencies] [dependencies]
fluence = { git = "https://github.com/fluencelabs/rust-sdk" } fluence = { git = "https://github.com/fluencelabs/rust-sdk" }

View File

@ -1,13 +1,13 @@
modules_dir = "wasm/artifacts/modules/" modules_dir = "artifacts/"
[[module]] [[module]]
name = "local_storage" name = "local_storage"
logger_enabled = true logger_enabled = true
[module.wasi] [module.wasi]
preopened_files = ["./../sites"] preopened_files = ["./sites"]
# this is where files will be stored # this is where files will be stored
mapped_dirs = { "sites" = "./../sites" } mapped_dirs = { "sites" = "./sites" }
[[module]] [[module]]
name = "curl" name = "curl"

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# This script builds all subprojects and puts all created Wasm modules in one dir # This script builds all subprojects and puts all created Wasm modules in one dir
cd wasm/site-storage cd site-storage
cargo update cargo update
fce build --release fce build --release
cd ../curl cd ../curl
@ -12,7 +12,7 @@ cargo update
fce build --release fce build --release
cd .. cd ..
rm artifacts/modules/* rm -f artifacts/*
cp ../../../target/wasm32-wasi/release/curl.wasm artifacts/modules cp ../../target/wasm32-wasi/release/curl.wasm artifacts/
cp ../../../target/wasm32-wasi/release/local_storage.wasm artifacts/modules cp ../../target/wasm32-wasi/release/local_storage.wasm artifacts/
cp ../../../target/wasm32-wasi/release/site-storage.wasm artifacts/modules cp ../../target/wasm32-wasi/release/site-storage.wasm artifacts/

View File

@ -0,0 +1,60 @@
/*
* 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::FluenceFaaS;
use fluence_faas::IValue;
#[test]
pub fn call_parameters() {
let call_parameters_config_path = "../examples/call_parameters/Config.toml";
let call_parameters_config_raw = std::fs::read(call_parameters_config_path)
.expect("../examples/call_parameters/Config.toml should presence");
let mut call_parameters_config: fluence_faas::RawModulesConfig =
toml::from_slice(&call_parameters_config_raw)
.expect("call_parameters config should be well-formed");
call_parameters_config.modules_dir =
Some(String::from("../examples/call_parameters/artifacts"));
let mut faas = FluenceFaaS::with_raw_config(call_parameters_config)
.unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let call_id = "0x1337";
let user_name = "root";
let application_id = "0x31337";
let result = faas
.call(
"call_parameters",
"call_parameters",
&[],
fluence_sdk_main::CallParameters {
call_id: call_id.to_string(),
user_name: user_name.to_string(),
application_id: application_id.to_string(),
},
)
.unwrap_or_else(|e| panic!("can't invoke call_parameters: {:?}", e));
assert_eq!(
result,
vec![IValue::String(format!(
"{}\n{}\n{}",
call_id, user_name, application_id
))]
);
}

View File

@ -29,7 +29,7 @@ pub fn greeting() {
greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts")); greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts"));
let mut faas = FluenceFaaS::with_raw_config(greeting_config) let mut faas = FluenceFaaS::with_raw_config(greeting_config)
.unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let result1 = faas let result1 = faas
.call( .call(
@ -65,7 +65,7 @@ pub fn get_interfaces() {
greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts")); greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts"));
let faas = FluenceFaaS::with_raw_config(greeting_config) let faas = FluenceFaaS::with_raw_config(greeting_config)
.unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let interface = faas.get_interface(); let interface = faas.get_interface();
@ -83,33 +83,3 @@ pub fn get_interfaces() {
assert_eq!(interface, fluence_faas::FaaSInterface { modules }); assert_eq!(interface, fluence_faas::FaaSInterface { modules });
} }
#[test]
pub fn call_parameters() {
let greeting_config_path = "../examples/greeting/Config_cp.toml";
let greeting_config_raw = std::fs::read(greeting_config_path)
.expect("../examples/greeting/Config_cp.toml should presence");
let mut greeting_config: fluence_faas::RawModulesConfig =
toml::from_slice(&greeting_config_raw).expect("greeting config should be well-formed");
greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts"));
let mut faas = FluenceFaaS::with_raw_config(greeting_config)
.unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e));
let result = faas
.call(
"greeting_cp",
"greeting",
&[],
fluence_sdk_main::CallParameters {
call_id: "0x1337".to_string(),
user_name: "root".to_string(),
application_id: "0x31337".to_string(),
},
)
.unwrap_or_else(|e| panic!("can't invoke greeting_cp: {:?}", e));
assert_eq!(result, vec![IValue::String(String::from("Hi, root"))]);
}

View File

@ -26,11 +26,11 @@ pub fn records() {
.expect("../examples/records/Config.toml should presence"); .expect("../examples/records/Config.toml should presence");
let mut records_config: fluence_faas::RawModulesConfig = let mut records_config: fluence_faas::RawModulesConfig =
toml::from_slice(&records_config_raw).expect("greeting config should be well-formed"); toml::from_slice(&records_config_raw).expect("records config should be well-formed");
records_config.modules_dir = Some(String::from("../examples/records/artifacts/wasm_modules/")); records_config.modules_dir = Some(String::from("../examples/records/artifacts/wasm_modules/"));
let mut faas = FluenceFaaS::with_raw_config(records_config) let mut faas = FluenceFaaS::with_raw_config(records_config)
.unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let result = faas let result = faas
.call("pure", "invoke", &[], <_>::default()) .call("pure", "invoke", &[], <_>::default())