Rename channelBackend to backend
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::ErrConv;
|
|||||||
|
|
||||||
pub struct ChConf {
|
pub struct ChConf {
|
||||||
pub series: u64,
|
pub series: u64,
|
||||||
|
pub name: String,
|
||||||
pub scalar_type: ScalarType,
|
pub scalar_type: ScalarType,
|
||||||
pub shape: Shape,
|
pub shape: Shape,
|
||||||
}
|
}
|
||||||
@@ -29,6 +30,7 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
let ret = if channel.name() == "inmem-d0-i32" {
|
let ret = if channel.name() == "inmem-d0-i32" {
|
||||||
let ret = ChConf {
|
let ret = ChConf {
|
||||||
series: 1,
|
series: 1,
|
||||||
|
name: channel.name().into(),
|
||||||
scalar_type: ScalarType::I32,
|
scalar_type: ScalarType::I32,
|
||||||
shape: Shape::Scalar,
|
shape: Shape::Scalar,
|
||||||
};
|
};
|
||||||
@@ -45,6 +47,7 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
let ret = if channel.name() == "scalar-i32-be" {
|
let ret = if channel.name() == "scalar-i32-be" {
|
||||||
let ret = ChConf {
|
let ret = ChConf {
|
||||||
series: 1,
|
series: 1,
|
||||||
|
name: channel.name().into(),
|
||||||
scalar_type: ScalarType::I32,
|
scalar_type: ScalarType::I32,
|
||||||
shape: Shape::Scalar,
|
shape: Shape::Scalar,
|
||||||
};
|
};
|
||||||
@@ -52,6 +55,7 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
} else if channel.name() == "wave-f64-be-n21" {
|
} else if channel.name() == "wave-f64-be-n21" {
|
||||||
let ret = ChConf {
|
let ret = ChConf {
|
||||||
series: 2,
|
series: 2,
|
||||||
|
name: channel.name().into(),
|
||||||
scalar_type: ScalarType::F64,
|
scalar_type: ScalarType::F64,
|
||||||
shape: Shape::Wave(21),
|
shape: Shape::Wave(21),
|
||||||
};
|
};
|
||||||
@@ -59,6 +63,7 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
} else if channel.name() == "const-regular-scalar-i32-be" {
|
} else if channel.name() == "const-regular-scalar-i32-be" {
|
||||||
let ret = ChConf {
|
let ret = ChConf {
|
||||||
series: 3,
|
series: 3,
|
||||||
|
name: channel.name().into(),
|
||||||
scalar_type: ScalarType::I32,
|
scalar_type: ScalarType::I32,
|
||||||
shape: Shape::Scalar,
|
shape: Shape::Scalar,
|
||||||
};
|
};
|
||||||
@@ -75,7 +80,7 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
if let Some(series) = channel.series() {
|
if let Some(series) = channel.series() {
|
||||||
let res = pgclient
|
let res = pgclient
|
||||||
.query(
|
.query(
|
||||||
"select scalar_type, shape_dims from series_by_channel where series = $1",
|
"select channel, scalar_type, shape_dims from series_by_channel where series = $1",
|
||||||
&[&(series as i64)],
|
&[&(series as i64)],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -86,11 +91,13 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
let row = res.first().unwrap();
|
let row = res.first().unwrap();
|
||||||
let scalar_type = ScalarType::from_dtype_index(row.get::<_, i32>(0) as u8)?;
|
let name: String = row.get(0);
|
||||||
|
let scalar_type = ScalarType::from_dtype_index(row.get::<_, i32>(1) as u8)?;
|
||||||
// TODO can I get a slice from psql driver?
|
// TODO can I get a slice from psql driver?
|
||||||
let shape = Shape::from_scylla_shape_dims(&row.get::<_, Vec<i32>>(1))?;
|
let shape = Shape::from_scylla_shape_dims(&row.get::<_, Vec<i32>>(2))?;
|
||||||
let ret = ChConf {
|
let ret = ChConf {
|
||||||
series,
|
series,
|
||||||
|
name,
|
||||||
scalar_type,
|
scalar_type,
|
||||||
shape,
|
shape,
|
||||||
};
|
};
|
||||||
@@ -99,7 +106,7 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
} else {
|
} else {
|
||||||
let res = pgclient
|
let res = pgclient
|
||||||
.query(
|
.query(
|
||||||
"select series, scalar_type, shape_dims from series_by_channel where facility = $1 and channel = $2",
|
"select channel, series, scalar_type, shape_dims from series_by_channel where facility = $1 and channel = $2",
|
||||||
&[&channel.backend(), &channel.name()],
|
&[&channel.backend(), &channel.name()],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -114,12 +121,14 @@ pub async fn chconf_from_database(channel: &Channel, ncc: &NodeConfigCached) ->
|
|||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
let row = res.first().unwrap();
|
let row = res.first().unwrap();
|
||||||
let series = row.get::<_, i64>(0) as u64;
|
let name: String = row.get(0);
|
||||||
let scalar_type = ScalarType::from_dtype_index(row.get::<_, i32>(1) as u8)?;
|
let series = row.get::<_, i64>(1) as u64;
|
||||||
|
let scalar_type = ScalarType::from_dtype_index(row.get::<_, i32>(2) as u8)?;
|
||||||
// TODO can I get a slice from psql driver?
|
// TODO can I get a slice from psql driver?
|
||||||
let shape = Shape::from_scylla_shape_dims(&row.get::<_, Vec<i32>>(2))?;
|
let shape = Shape::from_scylla_shape_dims(&row.get::<_, Vec<i32>>(3))?;
|
||||||
let ret = ChConf {
|
let ret = ChConf {
|
||||||
series,
|
series,
|
||||||
|
name,
|
||||||
scalar_type,
|
scalar_type,
|
||||||
shape,
|
shape,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ pub async fn chconf_from_prebinned(q: &PreBinnedQuery, _ncc: &NodeConfigCached)
|
|||||||
.channel()
|
.channel()
|
||||||
.series()
|
.series()
|
||||||
.expect("PreBinnedQuery is expected to contain the series id"),
|
.expect("PreBinnedQuery is expected to contain the series id"),
|
||||||
|
name: q.channel().name().into(),
|
||||||
scalar_type: q.scalar_type().clone(),
|
scalar_type: q.scalar_type().clone(),
|
||||||
shape: q.shape().clone(),
|
shape: q.shape().clone(),
|
||||||
};
|
};
|
||||||
@@ -65,8 +66,8 @@ impl ChannelConfigHandler {
|
|||||||
.headers()
|
.headers()
|
||||||
.get(http::header::ACCEPT)
|
.get(http::header::ACCEPT)
|
||||||
.map_or(accept_def, |k| k.to_str().unwrap_or(accept_def));
|
.map_or(accept_def, |k| k.to_str().unwrap_or(accept_def));
|
||||||
if accept == APP_JSON || accept == ACCEPT_ALL {
|
if accept.contains(APP_JSON) || accept.contains(ACCEPT_ALL) {
|
||||||
match channel_config(req, &node_config).await {
|
match self.channel_config(req, &node_config).await {
|
||||||
Ok(k) => Ok(k),
|
Ok(k) => Ok(k),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("ChannelConfigHandler::handle: got error from channel_config: {e:?}");
|
warn!("ChannelConfigHandler::handle: got error from channel_config: {e:?}");
|
||||||
@@ -80,6 +81,40 @@ impl ChannelConfigHandler {
|
|||||||
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn channel_config(
|
||||||
|
&self,
|
||||||
|
req: Request<Body>,
|
||||||
|
node_config: &NodeConfigCached,
|
||||||
|
) -> Result<Response<Body>, Error> {
|
||||||
|
info!("channel_config");
|
||||||
|
let url = Url::parse(&format!("dummy:{}", req.uri()))?;
|
||||||
|
let q = ChannelConfigQuery::from_url(&url)?;
|
||||||
|
info!("channel_config for q {q:?}");
|
||||||
|
let conf = if let Some(_scyco) = &node_config.node_config.cluster.scylla {
|
||||||
|
let c = dbconn::channelconfig::chconf_from_database(&q.channel, node_config).await?;
|
||||||
|
ChannelConfigResponse {
|
||||||
|
channel: Channel {
|
||||||
|
series: Some(c.series),
|
||||||
|
backend: q.channel.backend().into(),
|
||||||
|
name: c.name,
|
||||||
|
},
|
||||||
|
scalar_type: c.scalar_type,
|
||||||
|
byte_order: None,
|
||||||
|
shape: c.shape,
|
||||||
|
}
|
||||||
|
} else if let Some(_) = &node_config.node.channel_archiver {
|
||||||
|
return Err(Error::with_msg_no_trace("no archiver"));
|
||||||
|
} else if let Some(_) = &node_config.node.archiver_appliance {
|
||||||
|
return Err(Error::with_msg_no_trace("no archapp"));
|
||||||
|
} else {
|
||||||
|
parse::channelconfig::channel_config(&q, &node_config.node).await?
|
||||||
|
};
|
||||||
|
let ret = response(StatusCode::OK)
|
||||||
|
.header(http::header::CONTENT_TYPE, APP_JSON)
|
||||||
|
.body(Body::from(serde_json::to_string(&conf)?))?;
|
||||||
|
Ok(ret)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ErrConv<T> {
|
trait ErrConv<T> {
|
||||||
@@ -122,32 +157,6 @@ impl<T> ErrConv<T> for Result<T, NextRowError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn channel_config(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Response<Body>, Error> {
|
|
||||||
info!("channel_config");
|
|
||||||
let url = Url::parse(&format!("dummy:{}", req.uri()))?;
|
|
||||||
let q = ChannelConfigQuery::from_url(&url)?;
|
|
||||||
info!("channel_config for q {q:?}");
|
|
||||||
let conf = if let Some(_scyco) = &node_config.node_config.cluster.scylla {
|
|
||||||
let c = dbconn::channelconfig::chconf_from_database(&q.channel, node_config).await?;
|
|
||||||
ChannelConfigResponse {
|
|
||||||
channel: q.channel,
|
|
||||||
scalar_type: c.scalar_type,
|
|
||||||
byte_order: None,
|
|
||||||
shape: c.shape,
|
|
||||||
}
|
|
||||||
} else if let Some(_) = &node_config.node.channel_archiver {
|
|
||||||
return Err(Error::with_msg_no_trace("no archiver"));
|
|
||||||
} else if let Some(_) = &node_config.node.archiver_appliance {
|
|
||||||
return Err(Error::with_msg_no_trace("no archapp"));
|
|
||||||
} else {
|
|
||||||
parse::channelconfig::channel_config(&q, &node_config.node).await?
|
|
||||||
};
|
|
||||||
let ret = response(StatusCode::OK)
|
|
||||||
.header(http::header::CONTENT_TYPE, APP_JSON)
|
|
||||||
.body(Body::from(serde_json::to_string(&conf)?))?;
|
|
||||||
Ok(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct ConfigsHisto {
|
pub struct ConfigsHisto {
|
||||||
scalar_types: Vec<(ScalarType, Vec<(Shape, u32)>)>,
|
scalar_types: Vec<(ScalarType, Vec<(Shape, u32)>)>,
|
||||||
@@ -513,7 +522,7 @@ impl ScyllaChannelsActive {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct IocForChannelQuery {
|
pub struct IocForChannelQuery {
|
||||||
#[serde(rename = "channelBackend")]
|
#[serde(rename = "backend")]
|
||||||
backend: String,
|
backend: String,
|
||||||
#[serde(rename = "channelName")]
|
#[serde(rename = "channelName")]
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@@ -487,10 +487,7 @@ impl FromUrl for MapPulseQuery {
|
|||||||
.rev();
|
.rev();
|
||||||
let pulsestr = pit.next().ok_or(Error::with_msg_no_trace("no pulse in url path"))?;
|
let pulsestr = pit.next().ok_or(Error::with_msg_no_trace("no pulse in url path"))?;
|
||||||
let backend = pit.next().unwrap_or("sf-databuffer").into();
|
let backend = pit.next().unwrap_or("sf-databuffer").into();
|
||||||
//.ok_or(Error::with_msg_no_trace("no backend in url path"))?
|
// TODO legacy: use a default backend if not specified.
|
||||||
//.into();
|
|
||||||
// TODO !!!
|
|
||||||
// Clients MUST specify the backend
|
|
||||||
let backend = if backend == "pulse" {
|
let backend = if backend == "pulse" {
|
||||||
String::from("sf-databuffer")
|
String::from("sf-databuffer")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/map/pulse/sf-d
|
|||||||
<p><strong>URL:</strong> https://data-api.psi.ch/api/4/events</p>
|
<p><strong>URL:</strong> https://data-api.psi.ch/api/4/events</p>
|
||||||
<p><strong>Query parameters:</strong></p>
|
<p><strong>Query parameters:</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>channelBackend (e.g. "sf-databuffer")</li>
|
<li>backend (e.g. "sf-databuffer")</li>
|
||||||
<li>channelName (e.g. "S10CB02-RBOC-DCP10:FOR-AMPLT-AVG")</li>
|
<li>channelName (e.g. "S10CB02-RBOC-DCP10:FOR-AMPLT-AVG")</li>
|
||||||
<li>begDate (e.g. "2021-05-26T07:10:00.000Z")</li>
|
<li>begDate (e.g. "2021-05-26T07:10:00.000Z")</li>
|
||||||
<li>endDate (e.g. "2021-05-26T07:16:00.000Z")</li>
|
<li>endDate (e.g. "2021-05-26T07:16:00.000Z")</li>
|
||||||
@@ -192,7 +192,7 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/map/pulse/sf-d
|
|||||||
|
|
||||||
<h4>CURL example:</h4>
|
<h4>CURL example:</h4>
|
||||||
<pre>
|
<pre>
|
||||||
curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?channelBackend=sf-databuffer
|
curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?backend=sf-databuffer
|
||||||
&channelName=S10CB02-RBOC-DCP10:FOR-AMPLT-AVG&begDate=2021-05-26T07:10:00.000Z&endDate=2021-05-26T07:16:00.000Z'
|
&channelName=S10CB02-RBOC-DCP10:FOR-AMPLT-AVG&begDate=2021-05-26T07:10:00.000Z&endDate=2021-05-26T07:16:00.000Z'
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?channel
|
|||||||
<p><strong>URL:</strong> https://data-api.psi.ch/api/4/binned</p>
|
<p><strong>URL:</strong> https://data-api.psi.ch/api/4/binned</p>
|
||||||
<p><strong>Query parameters:</strong></p>
|
<p><strong>Query parameters:</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>channelBackend (e.g. "sf-databuffer")</li>
|
<li>backend (e.g. "sf-databuffer")</li>
|
||||||
<li>channelName (e.g. "SLAAR-LSCP4-LAS6891:CH7:1")</li>
|
<li>channelName (e.g. "SLAAR-LSCP4-LAS6891:CH7:1")</li>
|
||||||
<li>begDate (e.g. "2021-05-26T07:10:00.000Z")</li>
|
<li>begDate (e.g. "2021-05-26T07:10:00.000Z")</li>
|
||||||
<li>endDate (e.g. "2021-05-26T07:16:00.000Z")</li>
|
<li>endDate (e.g. "2021-05-26T07:16:00.000Z")</li>
|
||||||
@@ -257,7 +257,7 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?channel
|
|||||||
|
|
||||||
<h4>CURL example:</h4>
|
<h4>CURL example:</h4>
|
||||||
<pre>
|
<pre>
|
||||||
curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/binned?channelBackend=sf-databuffer
|
curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/binned?backend=sf-databuffer
|
||||||
&channelName=SLAAR-LSCP4-LAS6891:CH7:1&begDate=2021-05-25T00:00:00.000Z&endDate=2021-05-26T00:00:00.000Z&binCount=3'
|
&channelName=SLAAR-LSCP4-LAS6891:CH7:1&begDate=2021-05-25T00:00:00.000Z&endDate=2021-05-26T00:00:00.000Z&binCount=3'
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|||||||
+13
-7
@@ -596,8 +596,8 @@ impl FromUrl for Channel {
|
|||||||
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Error> {
|
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Error> {
|
||||||
let ret = Channel {
|
let ret = Channel {
|
||||||
backend: pairs
|
backend: pairs
|
||||||
.get("channelBackend")
|
.get("backend")
|
||||||
.ok_or(Error::with_public_msg("missing channelBackend"))?
|
.ok_or(Error::with_public_msg("missing backend"))?
|
||||||
.into(),
|
.into(),
|
||||||
name: pairs
|
name: pairs
|
||||||
.get("channelName")
|
.get("channelName")
|
||||||
@@ -614,10 +614,10 @@ impl FromUrl for Channel {
|
|||||||
impl AppendToUrl for Channel {
|
impl AppendToUrl for Channel {
|
||||||
fn append_to_url(&self, url: &mut Url) {
|
fn append_to_url(&self, url: &mut Url) {
|
||||||
let mut g = url.query_pairs_mut();
|
let mut g = url.query_pairs_mut();
|
||||||
g.append_pair("channelBackend", &self.backend);
|
g.append_pair("backend", &self.backend);
|
||||||
g.append_pair("channelName", &self.name);
|
g.append_pair("channelName", &self.name);
|
||||||
if let Some(series) = self.series {
|
if let Some(series) = self.series {
|
||||||
g.append_pair("seriesId", &format!("{series}"));
|
g.append_pair("seriesId", &series.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2032,8 +2032,14 @@ impl FromUrl for ChannelConfigQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Error> {
|
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Error> {
|
||||||
let beg_date = pairs.get("begDate").ok_or(Error::with_public_msg("missing begDate"))?;
|
let beg_date = pairs
|
||||||
let end_date = pairs.get("endDate").ok_or(Error::with_public_msg("missing endDate"))?;
|
.get("begDate")
|
||||||
|
.map(String::from)
|
||||||
|
.unwrap_or_else(|| String::from("2000-01-01T00:00:00Z"));
|
||||||
|
let end_date = pairs
|
||||||
|
.get("endDate")
|
||||||
|
.map(String::from)
|
||||||
|
.unwrap_or_else(|| String::from("3000-01-01T00:00:00Z"));
|
||||||
let expand = pairs.get("expand").map(|s| s == "true").unwrap_or(false);
|
let expand = pairs.get("expand").map(|s| s == "true").unwrap_or(false);
|
||||||
let ret = Self {
|
let ret = Self {
|
||||||
channel: Channel::from_pairs(&pairs)?,
|
channel: Channel::from_pairs(&pairs)?,
|
||||||
@@ -2072,7 +2078,7 @@ pub struct ChannelConfigResponse {
|
|||||||
pub channel: Channel,
|
pub channel: Channel,
|
||||||
#[serde(rename = "scalarType")]
|
#[serde(rename = "scalarType")]
|
||||||
pub scalar_type: ScalarType,
|
pub scalar_type: ScalarType,
|
||||||
#[serde(rename = "byteOrder")]
|
#[serde(rename = "byteOrder", default, skip_serializing_if = "Option::is_none")]
|
||||||
pub byte_order: Option<ByteOrder>,
|
pub byte_order: Option<ByteOrder>,
|
||||||
#[serde(rename = "shape")]
|
#[serde(rename = "shape")]
|
||||||
pub shape: Shape,
|
pub shape: Shape,
|
||||||
|
|||||||
Reference in New Issue
Block a user