Simplify cli option, add channel search

This commit is contained in:
Dominik Werder
2021-05-27 16:23:38 +02:00
parent e55751ad67
commit 53957a261a
9 changed files with 155 additions and 22 deletions

View File

@@ -21,6 +21,7 @@ use task::{Context, Poll};
use tracing::field::Empty;
pub mod gather;
pub mod search;
pub async fn host(node_config: NodeConfigCached) -> Result<(), Error> {
let node_config = node_config.clone();
@@ -115,6 +116,13 @@ async fn data_api_proxy_try(req: Request<Body>, node_config: &NodeConfigCached)
} else {
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
}
} else if path == "/api/4/search/channel" {
if req.method() == Method::GET {
// TODO multi-facility search
Ok(search::channel_search(req, &node_config).await?)
} else {
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
}
} else if path == "/api/4/table_sizes" {
if req.method() == Method::GET {
Ok(table_sizes(req, &node_config).await?)
@@ -254,7 +262,8 @@ async fn binned(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Re
let query = disk::cache::BinnedQuery::from_request(&head)?;
match head.headers.get("accept") {
Some(v) if v == "application/octet-stream" => binned_binary(query, node_config).await,
_ => binned_json(query, node_config).await,
Some(v) if v == "application/json" => binned_json(query, node_config).await,
_ => Err(Error::with_msg("binned with unknown accept")),
}
}

12
httpret/src/search.rs Normal file
View File

@@ -0,0 +1,12 @@
use err::Error;
use hyper::{Body, Request, Response, StatusCode};
use netpod::{ChannelSearchQuery, NodeConfigCached};
pub async fn channel_search(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Response<Body>, Error> {
let (head, _body) = req.into_parts();
let query = ChannelSearchQuery::from_request(head.uri.query())?;
let res = dbconn::search::search_channel(query, node_config).await?;
let body = Body::from(serde_json::to_string(&res)?);
let ret = super::response(StatusCode::OK).body(body)?;
Ok(ret)
}

View File

@@ -10,6 +10,7 @@
</head>
<body>
<h1>Retrieval Documentation</h1>
<h2>HTTP API documentation</h2>
@@ -19,12 +20,13 @@
<p>Currently available:</p>
<ul>
<li><a href="#query-binned">Query binned data</a></li>
<li><a href="#search-channel">Search channel</a></li>
</ul>
<a id="query-binned"></a>
<h2>Query binned data</h2>
<p><strong>Method:</strong> GET</p>
<p><strong>URL:</strong> https://data-api.psi.ch/api/4/binned</p>
<p><strong>URL:</strong> http://sf-daqbuf-21:8380/api/4/binned</p>
<p><strong>Query parameters:</strong></p>
<ul>
<li>channel_backend (e.g. "sf-databuffer")</li>
@@ -89,6 +91,19 @@ curl -H 'Accept: application/json' 'http://sf-daqbuf-21:8380/api/4/binned?channe
then it will add the flag <strong>finalised_range</strong> to the response.</p>
<a id="search-channel"></a>
<h2>Search channel</h2>
<p><strong>Method:</strong> GET</p>
<p><strong>URL:</strong> http://sf-daqbuf-21:8380/api/4/search/channel</p>
<p><strong>Query parameters:</strong></p>
<ul>
<li>nameRegex (e.g. "LSCP.*6")</li>
<li>sourceRegex (e.g. "178:9999")</li>
<li>descriptionRegex (e.g. "celsius")</li>
</ul>
<p><strong>Request header:</strong> "Accept" must be "application/json"</p>
<h2>Feedback and comments very much appreciated!</h2>
<p>dominik.werder@psi.ch</p>
<p>or please assign me a JIRA ticket.</p>