-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fcos-policy-engine: fetch graph from fcos-graph-builder instance
Removes previous empty dummy graph returned by fcos-policy-engine and fetches the graph from fcos-graph-builder instance, which is running under the same pod as fcos-policy-engine. Signed-off-by: Allen Bai <[email protected]>
- Loading branch information
Allen Bai
committed
Jul 21, 2020
1 parent
de7f3e3
commit 20b1f74
Showing
4 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use actix::prelude::*; | ||
use commons::graph; | ||
use failure::{bail, Error, Fallible, SyncFailure}; | ||
use reqwest::Method; | ||
use std::time::Duration; | ||
|
||
/// Default timeout for HTTP requests (30 minutes). | ||
const DEFAULT_HTTP_REQ_TIMEOUT: Duration = Duration::from_secs(30 * 60); | ||
/// Default address of fcos-graph-builder, which is the same as fcos-policy-builer | ||
const DEFAULT_GB_ADDR: &str = "http://127.0.0.1:5050/v1/graph"; | ||
|
||
/// Return a request builder with base URL and parameters set. | ||
fn new_request(method: reqwest::Method, url: reqwest::Url) -> Fallible<reqwest::RequestBuilder> { | ||
let client = reqwest::ClientBuilder::new() | ||
.timeout(DEFAULT_HTTP_REQ_TIMEOUT) | ||
.build()?; | ||
let builder = client.request(method, url); | ||
Ok(builder) | ||
} | ||
|
||
/// Fetch the graph from the fcos-graph-builder instance with the query specified. | ||
pub(crate) fn fetch_graph_from_gb( | ||
stream: String, | ||
basearch: String, | ||
) -> impl Future<Output = Result<graph::Graph, Error>> { | ||
async move { | ||
if stream.trim().is_empty() { | ||
bail!("unexpected missing stream"); | ||
} | ||
if basearch.trim().is_empty() { | ||
bail!("unexpected missing basearch"); | ||
} | ||
let query = crate::GraphQuery { | ||
stream: Some(stream), | ||
basearch: Some(basearch), | ||
rollout_wariness: None, | ||
node_uuid: None, | ||
}; | ||
let query_str = serde_qs::to_string(&query).map_err(SyncFailure::new)?; | ||
let mut target = reqwest::Url::parse(DEFAULT_GB_ADDR)?; | ||
target.set_query(Some(&query_str)); | ||
let req = new_request(Method::GET, target)?; | ||
let resp = req.send().await?; | ||
let content = resp.error_for_status()?; | ||
let json = content.json::<graph::Graph>().await?; | ||
Ok(json) | ||
} | ||
} |