mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-03-31 16:23:08 +00:00
Use runtime client as primary cfgsync API
This commit is contained in:
parent
ff658e322d
commit
4712f93a68
@ -238,14 +238,16 @@ serve(4400, MyMaterializer).await?;
|
||||
Fetching and writing artifacts:
|
||||
|
||||
```rust
|
||||
use cfgsync_runtime::{OutputMap, fetch_and_write};
|
||||
use cfgsync_runtime::{Client, OutputMap};
|
||||
|
||||
# async fn run(registration: cfgsync_core::NodeRegistration) -> anyhow::Result<()> {
|
||||
let outputs = OutputMap::new()
|
||||
.route("/config.yaml", "/node-data/node-1/config.yaml")
|
||||
.route("deployment-settings.yaml", "/node-data/shared/deployment-settings.yaml");
|
||||
|
||||
fetch_and_write(®istration, "http://127.0.0.1:4400", &outputs).await?;
|
||||
Client::new("http://127.0.0.1:4400")
|
||||
.fetch_and_write(®istration, &outputs)
|
||||
.await?;
|
||||
# Ok(())
|
||||
# }
|
||||
```
|
||||
|
||||
@ -4,7 +4,7 @@ use cfgsync_adapter::{
|
||||
};
|
||||
use cfgsync_artifacts::{ArtifactFile, ArtifactSet};
|
||||
use cfgsync_core::NodeRegistration;
|
||||
use cfgsync_runtime::{OutputMap, fetch_and_write, serve};
|
||||
use cfgsync_runtime::{Client, OutputMap, serve};
|
||||
use tempfile::tempdir;
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
@ -48,7 +48,9 @@ async fn main() -> anyhow::Result<()> {
|
||||
let outputs = OutputMap::new().route("/config.yaml", &config_path);
|
||||
let registration = NodeRegistration::new("node-1", "127.0.0.1".parse()?);
|
||||
|
||||
fetch_and_write(®istration, "http://127.0.0.1:4400", &outputs).await?;
|
||||
Client::new("http://127.0.0.1:4400")
|
||||
.fetch_and_write(®istration, &outputs)
|
||||
.await?;
|
||||
|
||||
println!("{}", std::fs::read_to_string(&config_path)?);
|
||||
|
||||
|
||||
@ -159,34 +159,6 @@ enum ClientEnvError {
|
||||
InvalidIp { value: String },
|
||||
}
|
||||
|
||||
/// Registers a node and fetches its artifact payload from cfgsync.
|
||||
///
|
||||
/// Prefer [`Client::register_and_fetch`] when you already hold a runtime
|
||||
/// client value.
|
||||
pub async fn register_and_fetch(
|
||||
registration: &NodeRegistration,
|
||||
server_addr: &str,
|
||||
) -> Result<NodeArtifactsPayload> {
|
||||
Client::new(server_addr)
|
||||
.register_and_fetch(registration)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Registers a node, fetches its artifact payload, and writes the files using
|
||||
/// the provided output routing policy.
|
||||
///
|
||||
/// Prefer [`Client::fetch_and_write`] when you already hold a runtime client
|
||||
/// value.
|
||||
pub async fn fetch_and_write(
|
||||
registration: &NodeRegistration,
|
||||
server_addr: &str,
|
||||
outputs: &OutputMap,
|
||||
) -> Result<()> {
|
||||
Client::new(server_addr)
|
||||
.fetch_and_write(registration, outputs)
|
||||
.await
|
||||
}
|
||||
|
||||
fn ensure_schema_version(config: &NodeArtifactsPayload) -> Result<()> {
|
||||
if config.schema_version != CFGSYNC_SCHEMA_VERSION {
|
||||
bail!(
|
||||
@ -244,12 +216,12 @@ pub async fn run_client_from_env(default_port: u16) -> Result<()> {
|
||||
let metadata = parse_registration_payload_env()?;
|
||||
let outputs = build_output_map();
|
||||
|
||||
fetch_and_write(
|
||||
&NodeRegistration::new(identifier, ip).with_payload(metadata),
|
||||
&server_addr,
|
||||
&outputs,
|
||||
)
|
||||
.await
|
||||
Client::new(&server_addr)
|
||||
.fetch_and_write(
|
||||
&NodeRegistration::new(identifier, ip).with_payload(metadata),
|
||||
&outputs,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn parse_ip_env(ip_str: &str) -> Result<Ipv4Addr> {
|
||||
@ -325,13 +297,13 @@ mod tests {
|
||||
.expect("run cfgsync server");
|
||||
});
|
||||
|
||||
fetch_and_write(
|
||||
&NodeRegistration::new("node-1", "127.0.0.1".parse().expect("parse ip")),
|
||||
&address,
|
||||
&OutputMap::default(),
|
||||
)
|
||||
.await
|
||||
.expect("pull config files");
|
||||
Client::new(&address)
|
||||
.fetch_and_write(
|
||||
&NodeRegistration::new("node-1", "127.0.0.1".parse().expect("parse ip")),
|
||||
&OutputMap::default(),
|
||||
)
|
||||
.await
|
||||
.expect("pull config files");
|
||||
|
||||
server.abort();
|
||||
let _ = server.await;
|
||||
|
||||
@ -3,7 +3,7 @@ pub use cfgsync_core as core;
|
||||
mod client;
|
||||
mod server;
|
||||
|
||||
pub use client::{Client, OutputMap, fetch_and_write, register_and_fetch, run_client_from_env};
|
||||
pub use client::{Client, OutputMap, run_client_from_env};
|
||||
pub use server::{
|
||||
LoadServerConfigError, ServerConfig, ServerSource, build_persisted_router, build_router, serve,
|
||||
serve_from_config, serve_persisted,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user