1
0
mirror of https://github.com/fluencelabs/marine.git synced 2025-03-16 06:20:49 +00:00

Use Vec<u8> instead of String for data ()

This commit is contained in:
vms 2020-12-17 21:24:42 +03:00 committed by GitHub
parent 11674ee856
commit 2d31b7fd63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 24 deletions
Cargo.lock
aquamarine-vm
engine
fluence-app-service
fluence-faas
tools/repl

10
Cargo.lock generated

@ -41,7 +41,7 @@ checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4"
[[package]] [[package]]
name = "aquamarine-vm" name = "aquamarine-vm"
version = "0.1.2" version = "0.1.3"
dependencies = [ dependencies = [
"fluence-faas", "fluence-faas",
"maplit", "maplit",
@ -640,7 +640,7 @@ dependencies = [
[[package]] [[package]]
name = "fce" name = "fce"
version = "0.1.12" version = "0.1.13"
dependencies = [ dependencies = [
"boolinator", "boolinator",
"bytes", "bytes",
@ -743,7 +743,7 @@ dependencies = [
[[package]] [[package]]
name = "fluence-app-service" name = "fluence-app-service"
version = "0.1.14" version = "0.1.15"
dependencies = [ dependencies = [
"fluence-faas", "fluence-faas",
"log", "log",
@ -757,7 +757,7 @@ dependencies = [
[[package]] [[package]]
name = "fluence-faas" name = "fluence-faas"
version = "0.1.14" version = "0.1.15"
dependencies = [ dependencies = [
"cmd_lib", "cmd_lib",
"env_logger 0.7.1", "env_logger 0.7.1",
@ -877,7 +877,7 @@ dependencies = [
[[package]] [[package]]
name = "frepl" name = "frepl"
version = "0.1.19" version = "0.1.20"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

@ -1,7 +1,7 @@
[package] [package]
name = "aquamarine-vm" name = "aquamarine-vm"
description = "Fluence Aquamarine VM" description = "Fluence Aquamarine VM"
version = "0.1.2" version = "0.1.3"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
edition = "2018" edition = "2018"
license = "Apache-2.0" license = "Apache-2.0"
@ -11,7 +11,7 @@ name = "aquamarine_vm"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
fluence-faas = { path = "../fluence-faas", version = "0.1.11" } fluence-faas = { path = "../fluence-faas", version = "0.1.15" }
stepper-interface = { git = "https://github.com/fluencelabs/aquamarine", branch = "new_stepper_outcome" } stepper-interface = { git = "https://github.com/fluencelabs/aquamarine", branch = "new_stepper_outcome" }
maplit = "1.0.2" maplit = "1.0.2"

@ -26,7 +26,6 @@ use stepper_interface::StepperOutcome;
use std::path::PathBuf; use std::path::PathBuf;
use std::path::Path; use std::path::Path;
use crate::errors::AquamarineVMError::InvalidAquamarinePath;
const CALL_SERVICE_NAME: &str = "call_service"; const CALL_SERVICE_NAME: &str = "call_service";
const CURRENT_PEER_ID_ENV_NAME: &str = "CURRENT_PEER_ID"; const CURRENT_PEER_ID_ENV_NAME: &str = "CURRENT_PEER_ID";
@ -60,18 +59,20 @@ impl AquamarineVM {
std::fs::create_dir_all(&particle_data_store) std::fs::create_dir_all(&particle_data_store)
.map_err(|e| InvalidDataStorePath(e, particle_data_store.clone()))?; .map_err(|e| InvalidDataStorePath(e, particle_data_store.clone()))?;
Ok(Self { let aqua_vm = Self {
faas, faas,
particle_data_store, particle_data_store,
wasm_filename, wasm_filename,
}) };
Ok(aqua_vm)
} }
pub fn call( pub fn call(
&mut self, &mut self,
init_user_id: impl Into<String>, init_user_id: impl Into<String>,
aqua: impl Into<String>, aqua: impl Into<String>,
data: impl Into<String>, data: impl Into<Vec<u8>>,
particle_id: impl AsRef<Path>, particle_id: impl AsRef<Path>,
) -> Result<StepperOutcome> { ) -> Result<StepperOutcome> {
use AquamarineVMError::PersistDataError; use AquamarineVMError::PersistDataError;
@ -79,11 +80,14 @@ impl AquamarineVM {
let prev_data_path = self.particle_data_store.join(particle_id); let prev_data_path = self.particle_data_store.join(particle_id);
// TODO: check for errors related to invalid file content (such as invalid UTF8 string) // TODO: check for errors related to invalid file content (such as invalid UTF8 string)
let prev_data = std::fs::read_to_string(&prev_data_path).unwrap_or_default(); let prev_data = std::fs::read_to_string(&prev_data_path).unwrap_or_default();
let prev_data = into_ibytes_array(prev_data.into_bytes());
let data = into_ibytes_array(data.into());
let args = vec![ let args = vec![
IValue::String(init_user_id.into()), IValue::String(init_user_id.into()),
IValue::String(aqua.into()), IValue::String(aqua.into()),
IValue::String(prev_data.into()), IValue::Array(prev_data),
IValue::String(data.into()), IValue::Array(data),
]; ];
let result = let result =
@ -106,6 +110,8 @@ impl AquamarineVM {
/// # Example /// # Example
/// For path `/path/to/aquamarine.wasm` result will be `Ok(PathBuf(/path/to), "aquamarine")` /// For path `/path/to/aquamarine.wasm` result will be `Ok(PathBuf(/path/to), "aquamarine")`
fn split_dirname(path: PathBuf) -> Result<(PathBuf, String)> { fn split_dirname(path: PathBuf) -> Result<(PathBuf, String)> {
use AquamarineVMError::InvalidAquamarinePath;
let metadata = path.metadata().map_err(|err| InvalidAquamarinePath { let metadata = path.metadata().map_err(|err| InvalidAquamarinePath {
invalid_path: path.clone(), invalid_path: path.clone(),
reason: "failed to get file's metadata (doesn't exist or invalid permissions)", reason: "failed to get file's metadata (doesn't exist or invalid permissions)",
@ -166,6 +172,10 @@ fn make_faas_config(
} }
} }
fn into_ibytes_array(byte_array: Vec<u8>) -> Vec<IValue> {
byte_array.into_iter().map(IValue::U8).collect()
}
// This API is intended for testing purposes // This API is intended for testing purposes
#[cfg(feature = "raw-aquamarine-vm-api")] #[cfg(feature = "raw-aquamarine-vm-api")]
impl AquamarineVM { impl AquamarineVM {
@ -173,14 +183,16 @@ impl AquamarineVM {
&mut self, &mut self,
init_user_id: impl Into<String>, init_user_id: impl Into<String>,
aqua: impl Into<String>, aqua: impl Into<String>,
prev_data: impl Into<String>, prev_data: impl Into<Vec<u8>>,
data: impl Into<String>, data: impl Into<Vec<u8>>,
) -> Result<StepperOutcome> { ) -> Result<StepperOutcome> {
let prev_data = into_ibytes_array(prev_data.into());
let data = into_ibytes_array(data.into());
let args = vec![ let args = vec![
IValue::String(init_user_id.into()), IValue::String(init_user_id.into()),
IValue::String(aqua.into()), IValue::String(aqua.into()),
IValue::String(prev_data.into()), IValue::Array(prev_data.into()),
IValue::String(data.into()), IValue::Array(data.into()),
]; ];
let result = let result =

@ -41,4 +41,7 @@ pub use fluence_faas::IType;
pub use fluence_faas::vec1; pub use fluence_faas::vec1;
pub use fluence_faas::Ctx; pub use fluence_faas::Ctx;
pub use stepper_interface::StepperOutcome;
pub use stepper_interface::STEPPER_SUCCESS;
pub(crate) type Result<T> = std::result::Result<T, AquamarineVMError>; pub(crate) type Result<T> = std::result::Result<T, AquamarineVMError>;

@ -1,7 +1,7 @@
[package] [package]
name = "fce" name = "fce"
description = "Fluence Compute Engine" description = "Fluence Compute Engine"
version = "0.1.12" version = "0.1.13"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"

@ -1,13 +1,13 @@
[package] [package]
name = "fluence-app-service" name = "fluence-app-service"
description = "Fluence Application Service" description = "Fluence Application Service"
version = "0.1.14" version = "0.1.15"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
fluence-faas = { path = "../fluence-faas", version = "0.1.14" } fluence-faas = { path = "../fluence-faas", version = "0.1.15" }
maplit = "1.0.2" maplit = "1.0.2"
log = "0.4.8" log = "0.4.8"

@ -1,13 +1,13 @@
[package] [package]
name = "fluence-faas" name = "fluence-faas"
description = "Fluence FaaS" description = "Fluence FaaS"
version = "0.1.14" version = "0.1.15"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
fce = { path = "../engine", version = "0.1.12" } fce = { path = "../engine", version = "0.1.13" }
fce-utils = { path = "../crates/utils", version = "0.1.0" } fce-utils = { path = "../crates/utils", version = "0.1.0" }
fluence-sdk-main = { version = "=0.2.11", features = ["logger"] } fluence-sdk-main = { version = "=0.2.11", features = ["logger"] }

@ -1,7 +1,7 @@
[package] [package]
name = "frepl" name = "frepl"
description = "Fluence FCE REPL intended for testing purposes" description = "Fluence FCE REPL intended for testing purposes"
version = "0.1.19" version = "0.1.20"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/fce/tools/repl" repository = "https://github.com/fluencelabs/fce/tools/repl"
license = "Apache-2.0" license = "Apache-2.0"
@ -12,7 +12,7 @@ name = "fce-repl"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
fluence-app-service = { path = "../../fluence-app-service", version = "0.1.14", features = ["raw-module-api"] } fluence-app-service = { path = "../../fluence-app-service", version = "0.1.15", features = ["raw-module-api"] }
fluence-sdk-main = { version = "=0.2.11", features = ["logger"] } fluence-sdk-main = { version = "=0.2.11", features = ["logger"] }
anyhow = "1.0.31" anyhow = "1.0.31"