Factor out maintenance handlers

This commit is contained in:
Dominik Werder
2023-12-11 12:19:50 +01:00
parent 44e37c7dbc
commit 3d110f1ea6
16 changed files with 746 additions and 595 deletions

View File

@@ -99,7 +99,7 @@ impl PythonDataApi1Query {
Ok(response(StatusCode::INTERNAL_SERVER_ERROR).body(body_empty())?)
} else {
info!("backend returned OK");
let riq_def = HeaderValue::from_static("(none)");
let riq_def = HeaderValue::from_static("none");
let riq = head.headers.get(X_DAQBUF_REQID).unwrap_or(&riq_def);
Ok(response(StatusCode::OK)
.header(X_DAQBUF_REQID, riq)

View File

@@ -51,6 +51,9 @@ impl RequestStatusHandler {
let _body_data = read_body_bytes(body).await?;
let status_id = &head.uri.path()[Self::path_prefix().len()..];
debug!("RequestStatusHandler status_id {:?}", status_id);
if status_id.len() < 8 {
return Err(Error::with_msg_no_trace(format!("bad status id {}", status_id)));
}
let back = {
let mut ret = None;
@@ -63,7 +66,14 @@ impl RequestStatusHandler {
ret
};
if let Some(back) = back {
let url_str = format!("{}{}{}", back.url, Self::path_prefix(), status_id);
let (status_id, url) = if back.url.contains("sf-daqbuf-23.psi.ch") {
// TODO split_at may panic on bad input
let (status_id, node_tgt) = status_id.split_at(status_id.len() - 2);
(status_id, back.url.replace("-23.", &format!("-{}.", node_tgt)))
} else {
(status_id, back.url.clone())
};
let url_str = format!("{}{}{}", url, Self::path_prefix(), status_id);
debug!("try to ask {url_str}");
let uri: Uri = url_str.parse()?;
let req = Request::builder()

View File

@@ -41,7 +41,7 @@ use url::Url;
// The aggregators and leaf nodes behind should as well not depend on backend,
// but simply answer all matching.
pub async fn channel_search(req: Requ, proxy_config: &ProxyConfig) -> Result<ChannelSearchResult, Error> {
pub async fn channel_search(req: Requ, ctx: &ReqCtx, proxy_config: &ProxyConfig) -> Result<ChannelSearchResult, Error> {
let (head, _body) = req.into_parts();
let inpurl = req_uri_to_url(&head.uri)?;
let query = ChannelSearchQuery::from_url(&inpurl)?;
@@ -112,6 +112,7 @@ pub async fn channel_search(req: Requ, proxy_config: &ProxyConfig) -> Result<Cha
nt,
ft,
Duration::from_millis(3000),
ctx,
)
.await?;
Ok(ret)
@@ -128,7 +129,7 @@ impl ChannelSearchAggHandler {
}
}
pub async fn handle(&self, req: Requ, node_config: &ProxyConfig) -> Result<StreamResponse, Error> {
pub async fn handle(&self, req: Requ, ctx: &ReqCtx, node_config: &ProxyConfig) -> Result<StreamResponse, Error> {
if req.method() == Method::GET {
let accept_def = APP_JSON;
let accept = req
@@ -136,7 +137,7 @@ impl ChannelSearchAggHandler {
.get(http::header::ACCEPT)
.map_or(accept_def, |k| k.to_str().unwrap_or(accept_def));
if accept.contains(APP_JSON) || accept.contains(ACCEPT_ALL) {
match channel_search(req, node_config).await {
match channel_search(req, ctx, node_config).await {
Ok(item) => Ok(response(StatusCode::OK).body(ToJsonBody::from(&item).into_body())?),
Err(e) => {
warn!("ChannelConfigHandler::handle: got error from channel_config: {e:?}");
@@ -186,7 +187,7 @@ impl StatusNodesRecursive {
async fn status(
&self,
_req: Requ,
_ctx: &ReqCtx,
ctx: &ReqCtx,
proxy_config: &ProxyConfig,
service_version: &ServiceVersion,
) -> Result<NodeStatus, Error> {
@@ -268,6 +269,7 @@ impl StatusNodesRecursive {
nt,
ft,
Duration::from_millis(1200),
ctx,
)
.await?;
Ok(ret)