Remove Arc from config structs to make them Serialize
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use err::Error;
|
||||
use netpod::{timeunits::*, Channel, ChannelConfig, Cluster, Database, Node, NodeConfig, ScalarType, Shape};
|
||||
use std::sync::Arc;
|
||||
use netpod::NodeConfig;
|
||||
use tokio::io::AsyncReadExt;
|
||||
#[allow(unused_imports)]
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
@@ -20,10 +20,18 @@ async fn go() -> Result<(), Error> {
|
||||
use retrieval::cli::{Opts, SubCmd};
|
||||
let opts = Opts::parse();
|
||||
match opts.subcmd {
|
||||
SubCmd::Retrieval(_subcmd) => {
|
||||
SubCmd::Retrieval(subcmd) => {
|
||||
trace!("testout");
|
||||
info!("testout");
|
||||
error!("testout");
|
||||
let mut config_file = tokio::fs::File::open(subcmd.config).await?;
|
||||
let mut buf = vec![];
|
||||
config_file.read_to_end(&mut buf).await?;
|
||||
let node_config: NodeConfig = serde_json::from_slice(&buf)?;
|
||||
let node = node_config
|
||||
.get_node()
|
||||
.ok_or(Error::with_msg(format!("nodeid config error")))?;
|
||||
retrieval::run_node(node_config.clone(), node.clone()).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -31,10 +39,11 @@ async fn go() -> Result<(), Error> {
|
||||
|
||||
#[test]
|
||||
fn simple_fetch() {
|
||||
use netpod::{timeunits::*, Channel, ChannelConfig, Cluster, Database, Node, NodeConfig, ScalarType, Shape};
|
||||
taskrun::run(async {
|
||||
let t1 = chrono::Utc::now();
|
||||
let node = Node {
|
||||
id: 0,
|
||||
id: format!("{:02}", 0),
|
||||
host: "localhost".into(),
|
||||
listen: "0.0.0.0".into(),
|
||||
port: 8360,
|
||||
@@ -43,7 +52,6 @@ fn simple_fetch() {
|
||||
ksprefix: "daq_swissfel".into(),
|
||||
split: 0,
|
||||
};
|
||||
let node = Arc::new(node);
|
||||
let query = netpod::AggQuerySingleChannel {
|
||||
channel_config: ChannelConfig {
|
||||
channel: Channel {
|
||||
@@ -71,14 +79,13 @@ fn simple_fetch() {
|
||||
pass: "daqbuffer".into(),
|
||||
},
|
||||
};
|
||||
let cluster = Arc::new(cluster);
|
||||
let node_config = NodeConfig {
|
||||
node: cluster.nodes[0].clone(),
|
||||
cluster: cluster,
|
||||
nodeid: cluster.nodes[0].id.clone(),
|
||||
cluster,
|
||||
};
|
||||
let node_config = Arc::new(node_config);
|
||||
let node = node_config.get_node().unwrap();
|
||||
let query_string = serde_json::to_string(&query).unwrap();
|
||||
let host = tokio::spawn(httpret::host(node_config));
|
||||
let host = tokio::spawn(httpret::host(node_config.clone(), node.clone()));
|
||||
let req = hyper::Request::builder()
|
||||
.method(http::Method::POST)
|
||||
.uri("http://localhost:8360/api/1/parsed_raw")
|
||||
|
||||
@@ -15,4 +15,7 @@ pub enum SubCmd {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap)]
|
||||
pub struct Retrieval {}
|
||||
pub struct Retrieval {
|
||||
#[clap(long)]
|
||||
pub config: String,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use err::Error;
|
||||
use netpod::{Cluster, NodeConfig};
|
||||
use std::sync::Arc;
|
||||
use netpod::{Cluster, Node, NodeConfig};
|
||||
use tokio::task::JoinHandle;
|
||||
#[allow(unused_imports)]
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
@@ -9,15 +8,20 @@ pub mod cli;
|
||||
#[cfg(test)]
|
||||
pub mod test;
|
||||
|
||||
pub fn spawn_test_hosts(cluster: Arc<Cluster>) -> Vec<JoinHandle<Result<(), Error>>> {
|
||||
pub fn spawn_test_hosts(cluster: Cluster) -> Vec<JoinHandle<Result<(), Error>>> {
|
||||
let mut ret = vec![];
|
||||
for node in &cluster.nodes {
|
||||
let node_config = NodeConfig {
|
||||
cluster: cluster.clone(),
|
||||
node: node.clone(),
|
||||
nodeid: node.id.clone(),
|
||||
};
|
||||
let h = tokio::spawn(httpret::host(Arc::new(node_config)));
|
||||
let h = tokio::spawn(httpret::host(node_config, node.clone()));
|
||||
ret.push(h);
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub async fn run_node(node_config: NodeConfig, node: Node) -> Result<(), Error> {
|
||||
httpret::host(node_config, node).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,25 +6,21 @@ use err::Error;
|
||||
use futures_util::TryStreamExt;
|
||||
use hyper::Body;
|
||||
use netpod::{Cluster, Database, Node};
|
||||
use std::sync::Arc;
|
||||
#[allow(unused_imports)]
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
fn test_cluster() -> Cluster {
|
||||
let nodes = (0..3)
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
let node = Node {
|
||||
id,
|
||||
host: "localhost".into(),
|
||||
listen: "0.0.0.0".into(),
|
||||
port: 8360 + id as u16,
|
||||
port_raw: 8360 + id as u16 + 100,
|
||||
data_base_path: format!("../tmpdata/node{:02}", id).into(),
|
||||
ksprefix: "ks".into(),
|
||||
split: id,
|
||||
};
|
||||
Arc::new(node)
|
||||
.map(|id| Node {
|
||||
id: format!("{:02}", id),
|
||||
host: "localhost".into(),
|
||||
listen: "0.0.0.0".into(),
|
||||
port: 8360 + id as u16,
|
||||
port_raw: 8360 + id as u16 + 100,
|
||||
data_base_path: format!("../tmpdata/node{:02}", id).into(),
|
||||
ksprefix: "ks".into(),
|
||||
split: id,
|
||||
})
|
||||
.collect();
|
||||
Cluster {
|
||||
@@ -45,7 +41,7 @@ fn get_cached_0() {
|
||||
|
||||
async fn get_cached_0_inner() -> Result<(), Error> {
|
||||
let t1 = chrono::Utc::now();
|
||||
let cluster = Arc::new(test_cluster());
|
||||
let cluster = test_cluster();
|
||||
let node0 = &cluster.nodes[0];
|
||||
let hosts = spawn_test_hosts(cluster.clone());
|
||||
let beg_date: chrono::DateTime<Utc> = "1970-01-01T00:20:10.000Z".parse()?;
|
||||
|
||||
Reference in New Issue
Block a user