Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
The 0.6.0 release (#22)
Browse files Browse the repository at this point in the history
* Initial commit - support for multiple instances of the same capability provider to be loaded and disambiguated via named bindings

* Adding the multi-binding example

* Refactoring out 'option proliferation' and adding back support for manifest application

* Make tests pass

* More updates and samples

* Updating rustdoc on from_instance function

* minor fix for consistency

* Adding manifest sample

* Enabling all features for the CI build
  • Loading branch information
autodidaddict committed Apr 6, 2020
1 parent 8f67f65 commit 690d76a
Show file tree
Hide file tree
Showing 48 changed files with 1,303 additions and 856 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
run: cargo build --verbose --all-features
- name: Run tests
run: cargo test --verbose
run: cargo test --verbose --all-features
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wascc-host"
version = "0.5.3"
version = "0.6.0"
authors = ["Kevin Hoffman <[email protected]>"]
edition = "2018"
homepage = "https://wascc.dev"
Expand All @@ -15,16 +15,15 @@ exclude = ["examples/.assets"]

[badges]
maintenance = { status = "actively-developed" }
travis-ci = { repository = "wascc/wascc-host", branch = "master" }

[dependencies]
libloading = "0.5.2"
crossbeam-channel = "0.4.2"
crossbeam = "0.7.3"
crossbeam-utils = "^0.7.0"
wapc = "0.4.2"
wascc-codec = "0.5.0"
wascap = "0.4.4"
wapc = "0.5.0"
wascc-codec = "0.6.0"
wascap = "0.4.5"
log = "0.4.8"
lazy_static = "1.4.0"
rand = "0.7.3"
Expand All @@ -39,7 +38,7 @@ serde_yaml = { version = "0.8.11", optional = true }
serde_json = { version = "1.0", optional = true }
envmnt = { version = "0.8.1", optional = true }

structopt = { version = "0.3.11", optional = true }
structopt = { version = "0.3.12", optional = true }

[features]
default = []
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Where the example name is the name (without the `.rs`) of any of the examples in

**Pre-Requisites** - For the `subscriber` example, you will need an instance of [NATS](https://nats.io) running locally. For the `kvcounter` example, you will need **Redis** running locally on the default port.

**WARNING** - This API is experimental and subject to breaking changes.

**NOTE** - All of these examples use _native_ capability providers, and therefore utilize the linux dynamic libraries (`.so` files). To use these examples on a Mac, you will need to manully build Mac dynamic libraries (`.dylib` files) and modify the examples to read those files instead.

## waSCC on Kubernetes
Expand Down
Binary file added examples/.assets/as-actor.wasm
Binary file not shown.
Binary file modified examples/.assets/echo.wasm
Binary file not shown.
Binary file modified examples/.assets/echo2.wasm
Binary file not shown.
Binary file modified examples/.assets/extras.wasm
Binary file not shown.
Binary file modified examples/.assets/kvcounter.wasm
Binary file not shown.
Binary file modified examples/.assets/kvcounter_tweaked.wasm
Binary file not shown.
Binary file modified examples/.assets/libkeyvalue.so
Binary file not shown.
Binary file modified examples/.assets/libnats_provider.so
Binary file not shown.
Binary file modified examples/.assets/libredis_provider.so
Binary file not shown.
Binary file modified examples/.assets/libwascc_httpsrv.so
Binary file not shown.
Binary file added examples/.assets/libwascc_log.so
Binary file not shown.
Binary file added examples/.assets/logger.wasm
Binary file not shown.
Binary file added examples/.assets/multibinding.wasm
Binary file not shown.
Binary file modified examples/.assets/subscriber.wasm
Binary file not shown.
Binary file modified examples/.assets/subscriber2.wasm
Binary file not shown.
Binary file modified examples/.assets/wasi_consumer.wasm
Binary file not shown.
Binary file modified examples/.assets/wasi_provider.wasm
Binary file not shown.
24 changes: 14 additions & 10 deletions examples/add_remove.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
use std::collections::HashMap;
use wascc_host::{host, Actor, NativeCapability};
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
host::add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host::add_actor(Actor::from_file("./examples/.assets/echo2.wasm")?)?;
host::add_native_capability(NativeCapability::from_file(
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host.add_actor(Actor::from_file("./examples/.assets/echo2.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;

host::configure(
host.bind_actor(
"MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2",
"wascc:http_server",
None,
generate_port_config(8081),
)?;
host::configure(
host.bind_actor(
"MDFD7XZ5KBOPLPHQKHJEMPR54XIW6RAG5D7NNKN22NP7NSEWNTJZP7JN",
"wascc:http_server",
None,
generate_port_config(8082),
)?;

println!("Actors (before removal):");
for (id, _claims) in host::actors() {
for (id, _claims) in host.actors() {
println!(" - {}", id);
}
println!("Capabilities:");
for cap in host::capabilities() {
for cap in host.capabilities() {
println!("{:?}", cap);
}

Expand All @@ -35,13 +39,13 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
std::thread::sleep(std::time::Duration::from_millis(1000));

// This will terminate the actor and free up the HTTP port
host::remove_actor("MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2")?;
host.remove_actor("MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2")?;

println!("Sleeping 2s...");
std::thread::sleep(std::time::Duration::from_millis(1000));

println!("Actors (after removal of second echo):");
for (id, _claims) in host::actors() {
for (id, _claims) in host.actors() {
println!(" - {}", id);
}

Expand Down
48 changes: 48 additions & 0 deletions examples/assemblyscript.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::collections::HashMap;
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/as-actor.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libredis_provider.so",
None,
)?)?;

host.bind_actor(
"MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2",
"wascc:http_server",
None,
generate_port_config(8081),
)?;

host.bind_actor(
"MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2",
"wascc:keyvalue",
None,
redis_config(),
)?;

std::thread::park();

Ok(())
}

fn generate_port_config(port: u16) -> HashMap<String, String> {
let mut hm = HashMap::new();
hm.insert("PORT".to_string(), port.to_string());

hm
}

fn redis_config() -> HashMap<String, String> {
let mut hm = HashMap::new();
hm.insert("URL".to_string(), "redis://127.0.0.1:6379".to_string());

hm
}
13 changes: 8 additions & 5 deletions examples/auth_hook.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use std::collections::HashMap;
use wascap::jwt::Token;
use wascc_host::{host, Actor, NativeCapability};
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
host::set_auth_hook(verify_issuer); // This MUST be set before you load an actor, otherwise it won't run
host::add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host::add_native_capability(NativeCapability::from_file(
let host = WasccHost::new();
host.set_auth_hook(verify_issuer); // This MUST be set before you load an actor, otherwise it won't run
host.add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;

host::configure(
host.bind_actor(
"MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2",
"wascc:http_server",
None,
generate_port_config(8081),
)?;

Expand Down
19 changes: 11 additions & 8 deletions examples/echo_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
use std::collections::HashMap;
use wascc_host::host::{self, Invocation, InvocationResponse};
use wascc_host::{Actor, Middleware, NativeCapability};
use wascc_host::{Actor, Invocation, InvocationResponse, Middleware, NativeCapability, WasccHost};

#[macro_use]
extern crate log;

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
host::add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host::add_actor(Actor::from_file("./examples/.assets/echo2.wasm")?)?;
host::add_native_capability(NativeCapability::from_file(
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host.add_actor(Actor::from_file("./examples/.assets/echo2.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;

host::add_middleware(LoggingMiddleware::default());
host.add_middleware(LoggingMiddleware::default());

host::configure(
host.bind_actor(
"MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2",
"wascc:http_server",
None,
generate_port_config(8081),
)?;
host::configure(
host.bind_actor(
"MDFD7XZ5KBOPLPHQKHJEMPR54XIW6RAG5D7NNKN22NP7NSEWNTJZP7JN",
"wascc:http_server",
None,
generate_port_config(8082),
)?;

Expand Down
16 changes: 10 additions & 6 deletions examples/echoserver.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
use std::collections::HashMap;
use wascc_host::{host, Actor, NativeCapability};
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
host::add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host::add_actor(Actor::from_file("./examples/.assets/echo2.wasm")?)?;
host::add_native_capability(NativeCapability::from_file(
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/echo.wasm")?)?;
host.add_actor(Actor::from_file("./examples/.assets/echo2.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;

host::configure(
host.bind_actor(
"MB4OLDIC3TCZ4Q4TGGOVAZC43VXFE2JQVRAXQMQFXUCREOOFEKOKZTY2",
"wascc:http_server",
None,
generate_port_config(8081),
)?;
host::configure(
host.bind_actor(
"MDFD7XZ5KBOPLPHQKHJEMPR54XIW6RAG5D7NNKN22NP7NSEWNTJZP7JN",
"wascc:http_server",
None,
generate_port_config(8082),
)?;

Expand Down
11 changes: 7 additions & 4 deletions examples/extras.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use std::collections::HashMap;
use wascc_host::{host, Actor, NativeCapability};
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
host::add_actor(Actor::from_file("./examples/.assets/extras.wasm")?)?;
host::add_native_capability(NativeCapability::from_file(
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/extras.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;

host::configure(
host.bind_actor(
"MDOYAT2KHJ6N5DAY5X7JKGIBMKABTPXRX2KHUJI6APOVNKQDMRTIUSY2",
"wascc:http_server",
None,
http_config(),
)?;

Expand Down
17 changes: 11 additions & 6 deletions examples/kvcounter.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
use std::collections::HashMap;
use wascc_host::{host, Actor, NativeCapability};
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
host::add_actor(Actor::from_file("./examples/.assets/kvcounter.wasm")?)?;
host::add_native_capability(NativeCapability::from_file(
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/kvcounter.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;
host::add_native_capability(NativeCapability::from_file(
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libredis_provider.so",
None,
)?)?;

host::configure(
host.bind_actor(
"MASCXFM4R6X63UD5MSCDZYCJNPBVSIU6RKMXUPXRKAOSBQ6UY3VT3NPZ",
"wascc:keyvalue",
None,
redis_config(),
)?;
host::configure(
host.bind_actor(
"MASCXFM4R6X63UD5MSCDZYCJNPBVSIU6RKMXUPXRKAOSBQ6UY3VT3NPZ",
"wascc:http_server",
None,
http_config(),
)?;

Expand Down
15 changes: 15 additions & 0 deletions examples/kvcounter_manifest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// An example demonstrating loading a manifest
// For this to run, you'll need both the `manifest` and `gantry`
// features enabled, you can do that as follows from the root wascc-host directory:
// cargo run --example kvcounter_manfifest --all-features

use wascc_host::{WasccHost, HostManifest};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let host = WasccHost::new();
host.apply_manifest(HostManifest::from_yaml("./examples/sample_manifest.yaml", false)?)?;

std::thread::park();
Ok(())
}
34 changes: 34 additions & 0 deletions examples/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::collections::HashMap;
use wascc_host::{Actor, NativeCapability, WasccHost};

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let host = WasccHost::new();
host.add_actor(Actor::from_file("./examples/.assets/logger.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_log.so",
None,
)?)?;

host.bind_actor(
"MDW7BWQDVYBRC6WKSJRRZL27R73EVBWQINYLPFDRCWDZDFQO4JMO4U6J",
"wascc:http_server",
None,
generate_port_config(8081),
)?;

std::thread::park();

Ok(())
}

fn generate_port_config(port: u16) -> HashMap<String, String> {
let mut hm = HashMap::new();
hm.insert("PORT".to_string(), port.to_string());

hm
}
Loading

0 comments on commit 690d76a

Please sign in to comment.