-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
423 additions
and
357 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "rain_client" | ||
version = "0.3.0" | ||
|
||
description = "Distributed computational framework for large-scale task-based pipelines. Client library in Rust." | ||
# documentation = "https://docs.rs/rain_task/" # default docs.rs | ||
homepage = "https://github.com/substantic/rain" | ||
repository = "https://github.com/substantic/rain/" | ||
readme = "README.md" | ||
authors = [ | ||
"Stanislav Bohm <[email protected]>", | ||
"Tomas Gavenciak <[email protected]>", | ||
"Vojtech Cima <[email protected]>", | ||
] | ||
license = "MIT" | ||
|
||
exclude = ["testing/**/*"] | ||
|
||
[badges] | ||
travis-ci = { repository = "substantic/rain", branch = "master" } | ||
maintenance = { status = "actively-developed" } | ||
|
||
[dependencies] | ||
capnp-rpc = "0.8" | ||
error-chain = "0.11" | ||
futures = "0.1" | ||
log = "0.4" | ||
rain_core = "0.3.0" | ||
tokio-core = "0.1" | ||
serde = "1" | ||
serde_json = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
src/client/dataobject.rs → rain_client/src/client/dataobject.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
use common::Attributes; | ||
use common::id::DataObjectId; | ||
use common::DataType; | ||
use rain_core::types::{DataObjectId, ObjectSpec}; | ||
use std::cell::Cell; | ||
|
||
pub struct DataObject { | ||
pub id: DataObjectId, | ||
pub label: String, | ||
pub keep: Cell<bool>, | ||
pub data: Option<Vec<u8>>, | ||
pub attributes: Attributes, | ||
pub data_type: DataType, | ||
pub spec: ObjectSpec, | ||
} | ||
|
||
impl DataObject { | ||
pub fn keep(&self) { | ||
self.keep.set(true); | ||
} | ||
pub fn id(&self) -> DataObjectId { | ||
self.spec.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::error::Error; | ||
use std::net::SocketAddr; | ||
use super::client::Client; | ||
use std::process::{Child, Command}; | ||
use std::path::PathBuf; | ||
use std::{thread, time}; | ||
use std::process::Stdio; | ||
|
||
pub struct LocalCluster { | ||
listen_addr: SocketAddr, | ||
binary: PathBuf | ||
} | ||
|
||
impl LocalCluster { | ||
pub fn new(binary: &str) -> Result<Self, Box<Error>> { | ||
let mut cluster = LocalCluster { | ||
binary: PathBuf::from(binary), | ||
listen_addr: SocketAddr::new("127.0.0.1".parse()?, 7210) | ||
}; | ||
cluster.start()?; | ||
|
||
Ok(cluster) | ||
} | ||
|
||
fn start(&mut self) -> Result<(), Box<Error>> { | ||
Command::new(&self.binary) | ||
.arg("start") | ||
.arg("--listen") | ||
.arg(self.listen_addr.to_string()) | ||
.arg("--simple") | ||
.stdin(Stdio::null()) | ||
.stdout(Stdio::null()) | ||
.stderr(Stdio::null()) | ||
.spawn()? | ||
.wait()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn create_client(&self) -> Result<Client, Box<Error>> { | ||
Client::new(self.listen_addr) | ||
} | ||
} | ||
|
||
impl Drop for LocalCluster { | ||
fn drop(&mut self) { | ||
Client::new(self.listen_addr).unwrap().terminate_server(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use super::task::Task; | ||
use client::dataobject::DataObject; | ||
use rain_core::client_capnp; | ||
use rain_core::utils::ToCapnp; | ||
use serde_json; | ||
|
||
macro_rules! to_capnp_list { | ||
($builder:expr, $items:expr, $name:ident) => {{ | ||
let mut builder = $builder.$name($items.len() as u32); | ||
for (i, obj) in $items.iter().enumerate() { | ||
obj.to_capnp(&mut builder.reborrow().get(i as u32)); | ||
} | ||
}}; | ||
} | ||
macro_rules! from_capnp_list { | ||
($builder:expr, $items:ident, $obj:ident) => {{ | ||
$builder | ||
.$items()? | ||
.iter() | ||
.map(|item| $obj::from_capnp(&item)) | ||
.collect() | ||
}}; | ||
} | ||
|
||
impl<'a> ToCapnp<'a> for Task { | ||
type Builder = client_capnp::task::Builder<'a>; | ||
|
||
fn to_capnp(&self, builder: &mut Self::Builder) { | ||
builder.set_spec(&serde_json::to_string(&self.spec).unwrap()); | ||
} | ||
} | ||
impl<'a> ToCapnp<'a> for DataObject { | ||
type Builder = client_capnp::data_object::Builder<'a>; | ||
|
||
fn to_capnp(&self, builder: &mut Self::Builder) { | ||
builder.set_spec(&serde_json::to_string(&self.spec).unwrap()); | ||
builder.set_keep(self.keep.get()); | ||
|
||
if let &Some(ref data) = &self.data { | ||
builder.set_data(&data); | ||
builder.set_has_data(true); | ||
} else { | ||
builder.set_has_data(false); | ||
} | ||
} | ||
} |
Oops, something went wrong.