Rename channelBackend to backend

This commit is contained in:
Dominik Werder
2022-12-16 17:56:14 +01:00
parent f6d92966cd
commit 64233b0ccb
5 changed files with 72 additions and 51 deletions

View File

@@ -37,6 +37,7 @@ pub async fn chconf_from_prebinned(q: &PreBinnedQuery, _ncc: &NodeConfigCached)
.channel()
.series()
.expect("PreBinnedQuery is expected to contain the series id"),
name: q.channel().name().into(),
scalar_type: q.scalar_type().clone(),
shape: q.shape().clone(),
};
@@ -65,8 +66,8 @@ impl ChannelConfigHandler {
.headers()
.get(http::header::ACCEPT)
.map_or(accept_def, |k| k.to_str().unwrap_or(accept_def));
if accept == APP_JSON || accept == ACCEPT_ALL {
match channel_config(req, &node_config).await {
if accept.contains(APP_JSON) || accept.contains(ACCEPT_ALL) {
match self.channel_config(req, &node_config).await {
Ok(k) => Ok(k),
Err(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())?)
}
}
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> {
@@ -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)]
pub struct ConfigsHisto {
scalar_types: Vec<(ScalarType, Vec<(Shape, u32)>)>,
@@ -513,7 +522,7 @@ impl ScyllaChannelsActive {
#[derive(Clone, Debug, Deserialize)]
pub struct IocForChannelQuery {
#[serde(rename = "channelBackend")]
#[serde(rename = "backend")]
backend: String,
#[serde(rename = "channelName")]
name: String,

View File

@@ -487,10 +487,7 @@ impl FromUrl for MapPulseQuery {
.rev();
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();
//.ok_or(Error::with_msg_no_trace("no backend in url path"))?
//.into();
// TODO !!!
// Clients MUST specify the backend
// TODO legacy: use a default backend if not specified.
let backend = if backend == "pulse" {
String::from("sf-databuffer")
} else {