You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ms...@apache.org on 2019/03/08 16:22:35 UTC

[incubator-openwhisk-runtime-rust] branch master updated (eaa26f0 -> 3fd55cc)

This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git.


    from eaa26f0  hello demo working
     new fccd2ed  Format code, fix typos, quiet clippy
     new 9d79c4b  Use more of serde's superpowers
     new 6617982  Switch to Rust 2018
     new d294fdc  Clarify main loop: lines of input
     new 3fd55cc  Merge pull request #1 from bruceadams/proposal

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 rust1.32/src/Cargo.lock              | 48 ++++++++++++++++++++++++
 rust1.32/src/action_loop/Cargo.toml  |  5 ++-
 rust1.32/src/action_loop/src/main.rs | 71 +++++++++++++++++-------------------
 3 files changed, 86 insertions(+), 38 deletions(-)


[incubator-openwhisk-runtime-rust] 08/10: Switch to Rust 2018

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 66179828c57deb791fe28bb986cb85304469abe7
Author: Bruce Adams <ba...@us.ibm.com>
AuthorDate: Thu Mar 7 08:27:01 2019 -0500

    Switch to Rust 2018
---
 rust1.32/src/action_loop/Cargo.toml  |  1 +
 rust1.32/src/action_loop/src/main.rs | 20 ++++++++------------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/rust1.32/src/action_loop/Cargo.toml b/rust1.32/src/action_loop/Cargo.toml
index 7093ea7..44c18b3 100644
--- a/rust1.32/src/action_loop/Cargo.toml
+++ b/rust1.32/src/action_loop/Cargo.toml
@@ -2,6 +2,7 @@
 name = "action_loop"
 version = "0.1.0"
 authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+edition = "2018"
 
 [dependencies]
 serde = "1.0"
diff --git a/rust1.32/src/action_loop/src/main.rs b/rust1.32/src/action_loop/src/main.rs
index 6bb9d5f..9329648 100644
--- a/rust1.32/src/action_loop/src/main.rs
+++ b/rust1.32/src/action_loop/src/main.rs
@@ -1,18 +1,14 @@
-extern crate actions;
-extern crate libc;
-extern crate serde;
-extern crate serde_derive;
-extern crate serde_json;
-
 use actions::main as actionMain;
-use serde_derive::Deserialize;
 
+use serde_derive::Deserialize;
 use serde_json::{Error, Value};
-use std::collections::HashMap;
-use std::env;
-use std::fs::File;
-use std::io::{stderr, stdin, stdout, Write};
-use std::os::unix::io::FromRawFd;
+use std::{
+    collections::HashMap,
+    env,
+    fs::File,
+    io::{stderr, stdin, stdout, Write},
+    os::unix::io::FromRawFd,
+};
 
 #[derive(Debug, Clone, PartialEq, Deserialize)]
 struct Input {


[incubator-openwhisk-runtime-rust] 07/10: Use more of serde's superpowers

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 9d79c4b413b50d6b899e34b9b3ad03dd45560973
Author: Bruce Adams <ba...@us.ibm.com>
AuthorDate: Thu Mar 7 08:23:03 2019 -0500

    Use more of serde's superpowers
---
 rust1.32/src/Cargo.lock              | 48 ++++++++++++++++++++++++++++++++
 rust1.32/src/action_loop/Cargo.toml  |  4 ++-
 rust1.32/src/action_loop/src/main.rs | 54 +++++++++++++++++-------------------
 3 files changed, 76 insertions(+), 30 deletions(-)

diff --git a/rust1.32/src/Cargo.lock b/rust1.32/src/Cargo.lock
index 2015f28..deb8f40 100644
--- a/rust1.32/src/Cargo.lock
+++ b/rust1.32/src/Cargo.lock
@@ -4,6 +4,8 @@ version = "0.1.0"
 dependencies = [
  "actions 0.1.0",
  "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -25,6 +27,22 @@ version = "0.2.49"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
+name = "proc-macro2"
+version = "0.4.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quote"
+version = "0.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
 name = "ryu"
 version = "0.2.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -35,6 +53,16 @@ version = "1.0.89"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
+name = "serde_derive"
+version = "1.0.89"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
 name = "serde_json"
 version = "1.0.39"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -44,9 +72,29 @@ dependencies = [
  "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "syn"
+version = "0.15.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-xid"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [metadata]
 "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
 "checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e"
+"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
+"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
 "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
 "checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
+"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c"
 "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
+"checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec"
+"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
diff --git a/rust1.32/src/action_loop/Cargo.toml b/rust1.32/src/action_loop/Cargo.toml
index 253fd02..7093ea7 100644
--- a/rust1.32/src/action_loop/Cargo.toml
+++ b/rust1.32/src/action_loop/Cargo.toml
@@ -4,6 +4,8 @@ version = "0.1.0"
 authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
 
 [dependencies]
+serde = "1.0"
+serde_derive = "1.0"
 serde_json = "1.0"
 libc = "0.2.49"
-actions = { path = "../actions" }
\ No newline at end of file
+actions = { path = "../actions" }
diff --git a/rust1.32/src/action_loop/src/main.rs b/rust1.32/src/action_loop/src/main.rs
index ea6da96..6bb9d5f 100644
--- a/rust1.32/src/action_loop/src/main.rs
+++ b/rust1.32/src/action_loop/src/main.rs
@@ -1,52 +1,48 @@
 extern crate actions;
 extern crate libc;
+extern crate serde;
+extern crate serde_derive;
 extern crate serde_json;
 
 use actions::main as actionMain;
+use serde_derive::Deserialize;
+
 use serde_json::{Error, Value};
 use std::collections::HashMap;
 use std::env;
 use std::fs::File;
-use std::io::{self, stderr, stdout, Write};
+use std::io::{stderr, stdin, stdout, Write};
 use std::os::unix::io::FromRawFd;
 
+#[derive(Debug, Clone, PartialEq, Deserialize)]
+struct Input {
+    value: HashMap<String, Value>,
+    #[serde(flatten)]
+    environment: HashMap<String, Value>,
+}
+
 fn main() {
     let mut fd3 = unsafe { File::from_raw_fd(3) };
     loop {
         let mut buffer = String::new();
-        io::stdin().read_line(&mut buffer).unwrap();
-        let parsed_input: Result<HashMap<String, Value>, Error> = serde_json::from_str(&buffer);
-        let mut payload: HashMap<String, Value> = HashMap::new();
+        stdin().read_line(&mut buffer).unwrap();
+        let parsed_input: Result<Input, Error> = serde_json::from_str(&buffer);
         match parsed_input {
-            Ok(n) => {
-                for (key, val) in n {
-                    if key == "value" {
-                        let mut unparsed_payload: Result<HashMap<String, Value>, Error> =
-                            serde_json::from_value(val);
-                        match unparsed_payload {
-                            Ok(value) => payload = value,
-                            Err(err) => {
-                                eprintln!("Error parsing value json: {}", err);
-                                continue;
-                            }
-                        }
-                    } else {
-                        env::set_var(format!("__OW_{}", key.to_uppercase()), val.to_string());
+            Ok(input) => {
+                for (key, val) in input.environment {
+                    env::set_var(format!("__OW_{}", key.to_uppercase()), val.to_string());
+                }
+                match serde_json::to_string(&actionMain(input.value)) {
+                    Ok(result) => {
+                        writeln!(&mut fd3, "{}", result).expect("Error writing on fd3");
+                    }
+                    Err(err) => {
+                        eprintln!("Error formatting result value json: {}", err);
                     }
                 }
             }
-            Err(e) => {
-                eprintln!("Error: {}", e);
-                continue;
-            }
-        }
-
-        match serde_json::to_string(&actionMain(payload)) {
-            Ok(result) => {
-                writeln!(&mut fd3, "{}", result).expect("Error writing on fd3");
-            }
             Err(err) => {
-                eprintln!("Error formatting result value json: {}", err);
+                eprintln!("Error parsing input: {}", err);
             }
         }
         stdout().flush().expect("Error flushing stdout");


[incubator-openwhisk-runtime-rust] 03/10: reworked the source generation

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit c3a89e1e40ea4f1e4b39f709ef74c7e54550c36f
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Tue Mar 5 10:13:49 2019 +0100

    reworked the source generation
---
 example/hello/.gitignore                           | 45 ++++++++++++++++++
 example/hello/Cargo.toml                           |  8 ++++
 example/hello/src/lib.rs                           |  9 ++++
 rust1.32/Dockerfile                                |  3 +-
 rust1.32/compile                                   | 55 +++++++---------------
 rust1.32/src/Cargo.lock                            | 52 ++++++++++++++++++++
 rust1.32/src/Cargo.toml                            |  6 +++
 rust1.32/src/action_loop/Cargo.toml                |  9 ++++
 .../action_loop/src/main.rs}                       | 23 ++++++---
 rust1.32/src/actions/.gitignore                    |  3 ++
 rust1.32/src/actions/Cargo.toml                    |  8 ++++
 rust1.32/src/actions/src/lib.rs                    | 10 ++++
 12 files changed, 186 insertions(+), 45 deletions(-)

diff --git a/example/hello/.gitignore b/example/hello/.gitignore
new file mode 100644
index 0000000..72fc6b4
--- /dev/null
+++ b/example/hello/.gitignore
@@ -0,0 +1,45 @@
+
+# Created by https://www.gitignore.io/api/osx,rust
+# Edit at https://www.gitignore.io/?templates=osx,rust
+
+### OSX ###
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# End of https://www.gitignore.io/api/osx,rust
\ No newline at end of file
diff --git a/example/hello/Cargo.toml b/example/hello/Cargo.toml
new file mode 100644
index 0000000..315401c
--- /dev/null
+++ b/example/hello/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "actions"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+
diff --git a/example/hello/src/lib.rs b/example/hello/src/lib.rs
new file mode 100644
index 0000000..b507a82
--- /dev/null
+++ b/example/hello/src/lib.rs
@@ -0,0 +1,9 @@
+extern crate serde_json;
+
+use std::collections::HashMap;
+use serde_json::Value;
+
+pub fn main(mut input_data: HashMap<String, Value>) -> HashMap<String, Value> {
+    input_data.insert("hello".to_string(),Value::String("world".to_string()));
+    input_data
+}
diff --git a/rust1.32/Dockerfile b/rust1.32/Dockerfile
index 07a6bb9..411b44c 100644
--- a/rust1.32/Dockerfile
+++ b/rust1.32/Dockerfile
@@ -19,7 +19,8 @@ FROM rust:1.32
 COPY --from=builder /bin/proxy /bin/proxy
 RUN mkdir -p /action 
 ADD compile /bin/compile
-ADD compile.launcher.rs /bin/compile.launcher.rs
+ADD src /usr/src
+RUN cd /usr/src ; cargo build 
 ENV OW_COMPILER=/bin/compile
 WORKDIR /action
 ENTRYPOINT ["/bin/proxy"]
diff --git a/rust1.32/compile b/rust1.32/compile
index 0c3228d..343e76a 100755
--- a/rust1.32/compile
+++ b/rust1.32/compile
@@ -21,7 +21,8 @@
 from __future__ import print_function
 import os, sys, codecs, subprocess
 from os.path import abspath, exists, dirname
-import tempfile
+import time
+import shutil
 
 ## utils 
 # write a file creating intermediate directories
@@ -47,59 +48,39 @@ version = "0.1.0"
 serde_json = "1.0"
 """
 
-cargo_actionloop = """[package]
-name = "action_loop"
-version = "0.1.0"
-authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
-
-[dependencies]
-serde_json = "1.0"
-libc = "0.2.49"
-actions = { path = "../actions" }
-"""
-
-cargo_workspace = """
-[workspace]
-
-members = [
-"action_loop",
-"actions",
-]
-"""
-
-def build():
+def build(tgt_dir):
     pass
 
-def sources(main, src_dir, tgt_dir, launcher):
-    src_file = abspath("%s/exec" % src_dir)
-       
+def sources(main, src_dir):
+    # move away the action dir and replace with the new
+    tmpname = str(int(time.time()))
+    shutil.move("/usr/src/actions", "/usr/src/src%s" % tmpname)
+    shutil.move(src_dir, "/usr/src/actions")
+
     # move exec in the right place
+    src_file = "/usr/src/actions/exec"
     if exists(src_file):
-        os.makedirs(src_dir+"/src", mode=0o755, exist_ok=True)
-        copy_replace(src_file, src_dir+"/src/exec__.rs")
+        os.makedirs("/usr/src/actions/src", mode=0o755, exist_ok=True)
+        copy_replace(src_file, "/usr/src/actions/src/lib.rs")
     
     # add a cargo.toml if needed
-    cargo_action_file = src_dir+"/Cargo.toml"
+    cargo_action_file = "/usr/src/actions/Cargo.toml"
     if not exists(cargo_action_file):
         write_file(cargo_action_file, cargo_action)
 
     # write the boilerplate in a temp dir
-    os.makedirs("/tmp/src", mode=0o755, exist_ok=True)
-    tmp_dir = tempfile.mkdtemp(prefix='/tmp/src/')
-    copy_replace(launcher, tmp_dir+"/action_loop/src/main.rs",
+    launcher = "/usr/src/action_loop/tmp%s" % tmpname
+    shutil.move("/usr/src/action_loop/src/main.rs", launcher)
+    copy_replace(launcher, "/usr/src/action_loop/src/main.rs",
           "use actions::main as actionMain;",
           "use actions::%s as actionMain;" % main )
-    write_file(tmp_dir+"/action_loop/Cargo.toml", cargo_actionloop)
-    write_file(tmp_dir+"/Cargo.toml", cargo_workspace)
-    os.rename(src_dir, tmp_dir+"/actions")
-    return tmp_dir
 
 if __name__ == '__main__':
     if len(sys.argv) < 4:
         sys.stdout.write("usage: <main-function> <source-dir> <target-dir>\n")
         sys.stdout.flush()
         sys.exit(1)
-    dir = sources(sys.argv[1], abspath(sys.argv[2]), abspath(sys.argv[3]), abspath(sys.argv[0]+".launcher.rs"))
-    print(dir)
+    sources(sys.argv[1], abspath(sys.argv[2]))
+    build(abspath(sys.argv[3]))
     sys.stdout.flush()
     sys.stderr.flush()
diff --git a/rust1.32/src/Cargo.lock b/rust1.32/src/Cargo.lock
new file mode 100644
index 0000000..2015f28
--- /dev/null
+++ b/rust1.32/src/Cargo.lock
@@ -0,0 +1,52 @@
+[[package]]
+name = "action_loop"
+version = "0.1.0"
+dependencies = [
+ "actions 0.1.0",
+ "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "actions"
+version = "0.1.0"
+dependencies = [
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "itoa"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libc"
+version = "0.2.49"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "ryu"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde"
+version = "1.0.89"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde_json"
+version = "1.0.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[metadata]
+"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
+"checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e"
+"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
+"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
+"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
diff --git a/rust1.32/src/Cargo.toml b/rust1.32/src/Cargo.toml
new file mode 100644
index 0000000..b8121b6
--- /dev/null
+++ b/rust1.32/src/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+members = [
+"action_loop",
+"actions",
+]
diff --git a/rust1.32/src/action_loop/Cargo.toml b/rust1.32/src/action_loop/Cargo.toml
new file mode 100644
index 0000000..253fd02
--- /dev/null
+++ b/rust1.32/src/action_loop/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "action_loop"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+libc = "0.2.49"
+actions = { path = "../actions" }
\ No newline at end of file
diff --git a/rust1.32/compile.launcher.rs b/rust1.32/src/action_loop/src/main.rs
similarity index 61%
rename from rust1.32/compile.launcher.rs
rename to rust1.32/src/action_loop/src/main.rs
index 9f50140..e4e143d 100644
--- a/rust1.32/compile.launcher.rs
+++ b/rust1.32/src/action_loop/src/main.rs
@@ -11,6 +11,7 @@ use serde_json::{Value, Error};
 use actions::main as actionMain;
 
 fn main() {
+    let mut fd3 = unsafe { File::from_raw_fd(3)};
     loop {
         let mut buffer = String::new();
         io::stdin().read_line(&mut buffer).unwrap();
@@ -23,19 +24,27 @@ fn main() {
                         let mut unparsed_payload:Result<HashMap<String,Value>,Error> = serde_json::from_value(val);
                         match unparsed_payload {
                             Ok(value) => payload = value,
-                            Err(_) => eprintln!("Error parsing value json")
+                            Err(err) => {
+                                eprintln!("Error parsing value json: {}", err);
+                                continue
+                            }
                         }
                     } else {
                         env::set_var(format!("__OW_{}", key.to_uppercase()), val.to_string());
                     }
                 }
             }
-            Err(e) => eprintln!("Error: {}", e)
+            Err(e) =>{
+                eprintln!("Error: {}", e);
+                continue
+            }
+        }
+        
+        match serde_json::to_string(&actionMain(payload)){
+            Ok(result) => { write!(&mut fd3, "{}\n", result).expect("Error writting on fd3");}
+            Err(err) => {  eprintln!("Error parsing resul value json: {}", err);}
         }
-        let action_results = actionMain(payload);
-        let mut fd3 = unsafe { File::from_raw_fd(3) };
-        write!(&mut fd3, "{}", action_results);
-        stdout().flush();
-        stderr().flush();
+        stdout().flush().expect("Error flushing stdout");
+        stderr().flush().expect("Error flushing stderr");
     }
 }
diff --git a/rust1.32/src/actions/.gitignore b/rust1.32/src/actions/.gitignore
new file mode 100644
index 0000000..6936990
--- /dev/null
+++ b/rust1.32/src/actions/.gitignore
@@ -0,0 +1,3 @@
+/target
+**/*.rs.bk
+Cargo.lock
diff --git a/rust1.32/src/actions/Cargo.toml b/rust1.32/src/actions/Cargo.toml
new file mode 100644
index 0000000..315401c
--- /dev/null
+++ b/rust1.32/src/actions/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "actions"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+
diff --git a/rust1.32/src/actions/src/lib.rs b/rust1.32/src/actions/src/lib.rs
new file mode 100644
index 0000000..cbeafbd
--- /dev/null
+++ b/rust1.32/src/actions/src/lib.rs
@@ -0,0 +1,10 @@
+extern crate serde_json;
+
+use std::collections::HashMap;
+use serde_json::Value;
+
+
+pub fn main(mut input_data: HashMap<String, Value>) -> HashMap<String, Value> {
+    input_data.insert("added_key".to_string(),Value::String("test".to_string()));
+    input_data
+}


[incubator-openwhisk-runtime-rust] 02/10: action compiler

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 340ca11d071edc5b5d3b109569dbf9d4f88154f8
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Fri Mar 1 10:45:53 2019 +0100

    action compiler
---
 README.md                    |   2 +
 rust1.32/Dockerfile          |  25 +++++++++++
 rust1.32/Makefile            |  12 +++++
 rust1.32/compile             | 105 +++++++++++++++++++++++++++++++++++++++++++
 rust1.32/compile.launcher.rs |  41 +++++++++++++++++
 5 files changed, 185 insertions(+)

diff --git a/README.md b/README.md
index 89ddcdf..ca09760 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
 # incubator-openwhisk-runtime-rust
+
+Work in Progress! Do not use...
diff --git a/rust1.32/Dockerfile b/rust1.32/Dockerfile
new file mode 100644
index 0000000..07a6bb9
--- /dev/null
+++ b/rust1.32/Dockerfile
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+FROM actionloop/actionloop-v2:latest as builder
+FROM rust:1.32
+COPY --from=builder /bin/proxy /bin/proxy
+RUN mkdir -p /action 
+ADD compile /bin/compile
+ADD compile.launcher.rs /bin/compile.launcher.rs
+ENV OW_COMPILER=/bin/compile
+WORKDIR /action
+ENTRYPOINT ["/bin/proxy"]
diff --git a/rust1.32/Makefile b/rust1.32/Makefile
new file mode 100644
index 0000000..46598eb
--- /dev/null
+++ b/rust1.32/Makefile
@@ -0,0 +1,12 @@
+USER?=openwhisk
+IMAGE=actionloop-rust-v1.32
+
+.PHONY: build
+
+build:
+	docker build -t $(USER)/$(IMAGE) .
+
+devel: build
+	docker run -ti -p 8080:8080 --entrypoint=bash  \
+	-v $(PWD):/mnt -e OW_COMPILER=/mnt/compile \
+	$(USER)/$(IMAGE)
diff --git a/rust1.32/compile b/rust1.32/compile
new file mode 100755
index 0000000..0c3228d
--- /dev/null
+++ b/rust1.32/compile
@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+"""Rust Action Builder
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+"""
+
+from __future__ import print_function
+import os, sys, codecs, subprocess
+from os.path import abspath, exists, dirname
+import tempfile
+
+## utils 
+# write a file creating intermediate directories
+def write_file(file, body):
+    os.makedirs(dirname(file), mode=0o755, exist_ok=True)
+    with open(file, mode="w", encoding="utf-8") as f:
+        f.write(body)
+
+# copy a file eventually replacing a substring
+def copy_replace(src, dst, match=None, replacement=""):
+    with codecs.open(src, 'r', 'utf-8') as s:
+        body = s.read()
+        if match:
+            body = body.replace(match, replacement)
+        write_file(dst, body)
+
+## cargo
+cargo_action = """[package]
+name = "actions"
+version = "0.1.0"
+
+[dependencies]
+serde_json = "1.0"
+"""
+
+cargo_actionloop = """[package]
+name = "action_loop"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+libc = "0.2.49"
+actions = { path = "../actions" }
+"""
+
+cargo_workspace = """
+[workspace]
+
+members = [
+"action_loop",
+"actions",
+]
+"""
+
+def build():
+    pass
+
+def sources(main, src_dir, tgt_dir, launcher):
+    src_file = abspath("%s/exec" % src_dir)
+       
+    # move exec in the right place
+    if exists(src_file):
+        os.makedirs(src_dir+"/src", mode=0o755, exist_ok=True)
+        copy_replace(src_file, src_dir+"/src/exec__.rs")
+    
+    # add a cargo.toml if needed
+    cargo_action_file = src_dir+"/Cargo.toml"
+    if not exists(cargo_action_file):
+        write_file(cargo_action_file, cargo_action)
+
+    # write the boilerplate in a temp dir
+    os.makedirs("/tmp/src", mode=0o755, exist_ok=True)
+    tmp_dir = tempfile.mkdtemp(prefix='/tmp/src/')
+    copy_replace(launcher, tmp_dir+"/action_loop/src/main.rs",
+          "use actions::main as actionMain;",
+          "use actions::%s as actionMain;" % main )
+    write_file(tmp_dir+"/action_loop/Cargo.toml", cargo_actionloop)
+    write_file(tmp_dir+"/Cargo.toml", cargo_workspace)
+    os.rename(src_dir, tmp_dir+"/actions")
+    return tmp_dir
+
+if __name__ == '__main__':
+    if len(sys.argv) < 4:
+        sys.stdout.write("usage: <main-function> <source-dir> <target-dir>\n")
+        sys.stdout.flush()
+        sys.exit(1)
+    dir = sources(sys.argv[1], abspath(sys.argv[2]), abspath(sys.argv[3]), abspath(sys.argv[0]+".launcher.rs"))
+    print(dir)
+    sys.stdout.flush()
+    sys.stderr.flush()
diff --git a/rust1.32/compile.launcher.rs b/rust1.32/compile.launcher.rs
new file mode 100644
index 0000000..9f50140
--- /dev/null
+++ b/rust1.32/compile.launcher.rs
@@ -0,0 +1,41 @@
+extern crate serde_json;
+extern crate actions;
+extern crate libc;
+
+use std::env;
+use std::io::{self, Write, stdout, stderr};
+use std::fs::File;
+use std::os::unix::io::FromRawFd;
+use std::collections::HashMap;
+use serde_json::{Value, Error};
+use actions::main as actionMain;
+
+fn main() {
+    loop {
+        let mut buffer = String::new();
+        io::stdin().read_line(&mut buffer).unwrap();
+        let parsed_input:Result<HashMap<String,Value>,Error> = serde_json::from_str(&buffer);
+        let mut payload:HashMap<String, Value> = HashMap::new();
+        match parsed_input {
+            Ok(n) => {
+                for (key, val) in n {
+                    if key == "value" {
+                        let mut unparsed_payload:Result<HashMap<String,Value>,Error> = serde_json::from_value(val);
+                        match unparsed_payload {
+                            Ok(value) => payload = value,
+                            Err(_) => eprintln!("Error parsing value json")
+                        }
+                    } else {
+                        env::set_var(format!("__OW_{}", key.to_uppercase()), val.to_string());
+                    }
+                }
+            }
+            Err(e) => eprintln!("Error: {}", e)
+        }
+        let action_results = actionMain(payload);
+        let mut fd3 = unsafe { File::from_raw_fd(3) };
+        write!(&mut fd3, "{}", action_results);
+        stdout().flush();
+        stderr().flush();
+    }
+}


[incubator-openwhisk-runtime-rust] 05/10: hello demo working

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit eaa26f0d7b08c8b1fd38a48da51bd90fce93a867
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Wed Mar 6 09:18:38 2019 +0100

    hello demo working
---
 README.md                | 15 ++++++++++++++-
 example/hello/src/lib.rs | 13 ++++++++++---
 rust1.32/Makefile        |  7 +++++--
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index ca09760..d4e48bc 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,16 @@
 # incubator-openwhisk-runtime-rust
 
-Work in Progress! Do not use...
+Work in Progress! Do not use yet...
+
+
+# Work Done
+
+- implemented the actionloop
+- implemented the Docker image
+- implemented the action compiler
+
+# Work to do
+
+- Add the gradle build
+- Implement the mandatory scala tests
+- Submit and add to the list of supported runtimes
diff --git a/example/hello/src/lib.rs b/example/hello/src/lib.rs
index b507a82..5f43e8d 100644
--- a/example/hello/src/lib.rs
+++ b/example/hello/src/lib.rs
@@ -3,7 +3,14 @@ extern crate serde_json;
 use std::collections::HashMap;
 use serde_json::Value;
 
-pub fn main(mut input_data: HashMap<String, Value>) -> HashMap<String, Value> {
-    input_data.insert("hello".to_string(),Value::String("world".to_string()));
-    input_data
+pub fn main(args: HashMap<String, Value>) -> HashMap<String, Value> {
+    let name_opt = args.get("name");
+    let name = if name_opt.is_some() {
+        name_opt.unwrap().as_str().unwrap()    
+    } else {
+        "stranger"
+    };
+    let mut out = HashMap::new();
+    out.insert("greeting".to_string(), Value::String(format!("Hello, {}", name)));
+    out
 }
diff --git a/rust1.32/Makefile b/rust1.32/Makefile
index 46598eb..7ee6d5f 100644
--- a/rust1.32/Makefile
+++ b/rust1.32/Makefile
@@ -1,4 +1,4 @@
-USER?=openwhisk
+USER=docker.io/actionloop
 IMAGE=actionloop-rust-v1.32
 
 .PHONY: build
@@ -9,4 +9,7 @@ build:
 devel: build
 	docker run -ti -p 8080:8080 --entrypoint=bash  \
 	-v $(PWD):/mnt -e OW_COMPILER=/mnt/compile \
-	$(USER)/$(IMAGE)
+
+push: build
+	docker login
+	docker push $(USER)/$(IMAGE)


[incubator-openwhisk-runtime-rust] 10/10: Merge pull request #1 from bruceadams/proposal

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 3fd55cc58d5c0a7fd520459a9ceee25adecc1700
Merge: eaa26f0 d294fdc
Author: Michele Sciabarra <30...@users.noreply.github.com>
AuthorDate: Fri Mar 8 17:22:31 2019 +0100

    Merge pull request #1 from bruceadams/proposal
    
    Proposed changes to action_loop

 rust1.32/src/Cargo.lock              | 48 ++++++++++++++++++++++++
 rust1.32/src/action_loop/Cargo.toml  |  5 ++-
 rust1.32/src/action_loop/src/main.rs | 71 +++++++++++++++++-------------------
 3 files changed, 86 insertions(+), 38 deletions(-)


[incubator-openwhisk-runtime-rust] 06/10: Format code, fix typos, quiet clippy

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit fccd2ed18db465301462878e261f2e195ae1ba98
Author: Bruce Adams <ba...@us.ibm.com>
AuthorDate: Thu Mar 7 08:05:15 2019 -0500

    Format code, fix typos, quiet clippy
    
    Ran these two commands:
    - cargo fmt
    - cargo clippy
---
 rust1.32/src/action_loop/src/main.rs | 37 ++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/rust1.32/src/action_loop/src/main.rs b/rust1.32/src/action_loop/src/main.rs
index e4e143d..ea6da96 100644
--- a/rust1.32/src/action_loop/src/main.rs
+++ b/rust1.32/src/action_loop/src/main.rs
@@ -1,32 +1,33 @@
-extern crate serde_json;
 extern crate actions;
 extern crate libc;
+extern crate serde_json;
 
+use actions::main as actionMain;
+use serde_json::{Error, Value};
+use std::collections::HashMap;
 use std::env;
-use std::io::{self, Write, stdout, stderr};
 use std::fs::File;
+use std::io::{self, stderr, stdout, Write};
 use std::os::unix::io::FromRawFd;
-use std::collections::HashMap;
-use serde_json::{Value, Error};
-use actions::main as actionMain;
 
 fn main() {
-    let mut fd3 = unsafe { File::from_raw_fd(3)};
+    let mut fd3 = unsafe { File::from_raw_fd(3) };
     loop {
         let mut buffer = String::new();
         io::stdin().read_line(&mut buffer).unwrap();
-        let parsed_input:Result<HashMap<String,Value>,Error> = serde_json::from_str(&buffer);
-        let mut payload:HashMap<String, Value> = HashMap::new();
+        let parsed_input: Result<HashMap<String, Value>, Error> = serde_json::from_str(&buffer);
+        let mut payload: HashMap<String, Value> = HashMap::new();
         match parsed_input {
             Ok(n) => {
                 for (key, val) in n {
                     if key == "value" {
-                        let mut unparsed_payload:Result<HashMap<String,Value>,Error> = serde_json::from_value(val);
+                        let mut unparsed_payload: Result<HashMap<String, Value>, Error> =
+                            serde_json::from_value(val);
                         match unparsed_payload {
                             Ok(value) => payload = value,
                             Err(err) => {
                                 eprintln!("Error parsing value json: {}", err);
-                                continue
+                                continue;
                             }
                         }
                     } else {
@@ -34,15 +35,19 @@ fn main() {
                     }
                 }
             }
-            Err(e) =>{
+            Err(e) => {
                 eprintln!("Error: {}", e);
-                continue
+                continue;
             }
         }
-        
-        match serde_json::to_string(&actionMain(payload)){
-            Ok(result) => { write!(&mut fd3, "{}\n", result).expect("Error writting on fd3");}
-            Err(err) => {  eprintln!("Error parsing resul value json: {}", err);}
+
+        match serde_json::to_string(&actionMain(payload)) {
+            Ok(result) => {
+                writeln!(&mut fd3, "{}", result).expect("Error writing on fd3");
+            }
+            Err(err) => {
+                eprintln!("Error formatting result value json: {}", err);
+            }
         }
         stdout().flush().expect("Error flushing stdout");
         stderr().flush().expect("Error flushing stderr");


[incubator-openwhisk-runtime-rust] 01/10: first commit

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 36b49303032acb92a5446b1f9c33c1ace2a5389e
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Thu Feb 28 16:54:31 2019 +0100

    first commit
---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..89ddcdf
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# incubator-openwhisk-runtime-rust


[incubator-openwhisk-runtime-rust] 09/10: Clarify main loop: lines of input

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit d294fdccb19315fa497308b8f2a8864359603dd0
Author: Bruce Adams <ba...@us.ibm.com>
AuthorDate: Thu Mar 7 08:30:03 2019 -0500

    Clarify main loop: lines of input
---
 rust1.32/src/action_loop/src/main.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rust1.32/src/action_loop/src/main.rs b/rust1.32/src/action_loop/src/main.rs
index 9329648..7d874c9 100644
--- a/rust1.32/src/action_loop/src/main.rs
+++ b/rust1.32/src/action_loop/src/main.rs
@@ -6,7 +6,7 @@ use std::{
     collections::HashMap,
     env,
     fs::File,
-    io::{stderr, stdin, stdout, Write},
+    io::{stderr, stdin, stdout, BufRead, Write},
     os::unix::io::FromRawFd,
 };
 
@@ -19,9 +19,9 @@ struct Input {
 
 fn main() {
     let mut fd3 = unsafe { File::from_raw_fd(3) };
-    loop {
-        let mut buffer = String::new();
-        stdin().read_line(&mut buffer).unwrap();
+    let stdin = stdin();
+    for line in stdin.lock().lines() {
+        let buffer: String = line.expect("Error reading line");
         let parsed_input: Result<Input, Error> = serde_json::from_str(&buffer);
         match parsed_input {
             Ok(input) => {


[incubator-openwhisk-runtime-rust] 04/10: fixed compilation

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 253b03af8de724bd97e43d059d97a93a9cb74ea4
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Tue Mar 5 17:09:12 2019 +0100

    fixed compilation
---
 rust1.32/compile | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/rust1.32/compile b/rust1.32/compile
index 343e76a..650904e 100755
--- a/rust1.32/compile
+++ b/rust1.32/compile
@@ -49,7 +49,31 @@ serde_json = "1.0"
 """
 
 def build(tgt_dir):
-    pass
+     # support RELEASE
+     cmd = ["cargo", "build"]
+     bin_dir = "debug"
+     if "RELEASE" in os.environ:
+         cmd += "--release"
+         bin_dir = "release"
+     env = {
+         "CARGO_HOME": "/usr/local/cargo",
+         "PATH": "/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+         "RUSTUP_HOME": "/usr/local/rustup"
+     }
+     p = subprocess.Popen(cmd,
+           stdout=subprocess.PIPE,
+           stderr=subprocess.PIPE,
+           cwd="/usr/src", env=env)
+     (o, e) = p.communicate()
+     if isinstance(o, bytes): o = o.decode('utf-8')
+     if isinstance(e, bytes): e = e.decode('utf-8')
+     if p.returncode != 0:
+        sys.stdout.write(o)
+        sys.stdout.write(e)
+     else:
+       shutil.move(
+             "/usr/src/target/%s/action_loop" % bin_dir, 
+             "%s/exec" % tgt_dir)
 
 def sources(main, src_dir):
     # move away the action dir and replace with the new