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

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

10
Cargo.lock generated
View File

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

View File

@ -1,7 +1,7 @@
[package]
name = "aquamarine-vm"
description = "Fluence Aquamarine VM"
version = "0.1.2"
version = "0.1.3"
authors = ["Fluence Labs"]
edition = "2018"
license = "Apache-2.0"
@ -11,7 +11,7 @@ name = "aquamarine_vm"
path = "src/lib.rs"
[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" }
maplit = "1.0.2"

View File

@ -26,7 +26,6 @@ use stepper_interface::StepperOutcome;
use std::path::PathBuf;
use std::path::Path;
use crate::errors::AquamarineVMError::InvalidAquamarinePath;
const CALL_SERVICE_NAME: &str = "call_service";
const CURRENT_PEER_ID_ENV_NAME: &str = "CURRENT_PEER_ID";
@ -60,18 +59,20 @@ impl AquamarineVM {
std::fs::create_dir_all(&particle_data_store)
.map_err(|e| InvalidDataStorePath(e, particle_data_store.clone()))?;
Ok(Self {
let aqua_vm = Self {
faas,
particle_data_store,
wasm_filename,
})
};
Ok(aqua_vm)
}
pub fn call(
&mut self,
init_user_id: impl Into<String>,
aqua: impl Into<String>,
data: impl Into<String>,
data: impl Into<Vec<u8>>,
particle_id: impl AsRef<Path>,
) -> Result<StepperOutcome> {
use AquamarineVMError::PersistDataError;
@ -79,11 +80,14 @@ impl AquamarineVM {
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)
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![
IValue::String(init_user_id.into()),
IValue::String(aqua.into()),
IValue::String(prev_data.into()),
IValue::String(data.into()),
IValue::Array(prev_data),
IValue::Array(data),
];
let result =
@ -106,6 +110,8 @@ impl AquamarineVM {
/// # Example
/// For path `/path/to/aquamarine.wasm` result will be `Ok(PathBuf(/path/to), "aquamarine")`
fn split_dirname(path: PathBuf) -> Result<(PathBuf, String)> {
use AquamarineVMError::InvalidAquamarinePath;
let metadata = path.metadata().map_err(|err| InvalidAquamarinePath {
invalid_path: path.clone(),
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
#[cfg(feature = "raw-aquamarine-vm-api")]
impl AquamarineVM {
@ -173,14 +183,16 @@ impl AquamarineVM {
&mut self,
init_user_id: impl Into<String>,
aqua: impl Into<String>,
prev_data: impl Into<String>,
data: impl Into<String>,
prev_data: impl Into<Vec<u8>>,
data: impl Into<Vec<u8>>,
) -> Result<StepperOutcome> {
let prev_data = into_ibytes_array(prev_data.into());
let data = into_ibytes_array(data.into());
let args = vec![
IValue::String(init_user_id.into()),
IValue::String(aqua.into()),
IValue::String(prev_data.into()),
IValue::String(data.into()),
IValue::Array(prev_data.into()),
IValue::Array(data.into()),
];
let result =

View File

@ -41,4 +41,7 @@ pub use fluence_faas::IType;
pub use fluence_faas::vec1;
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>;

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
[package]
name = "frepl"
description = "Fluence FCE REPL intended for testing purposes"
version = "0.1.19"
version = "0.1.20"
authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/fce/tools/repl"
license = "Apache-2.0"
@ -12,7 +12,7 @@ name = "fce-repl"
path = "src/main.rs"
[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"] }
anyhow = "1.0.31"