From 5cc499fe4838585c4f6d199467debf3e12abd5ae Mon Sep 17 00:00:00 2001 From: Santtu Lakkala Date: Mon, 28 Oct 2024 16:37:03 +0200 Subject: [PATCH 1/3] Reduce duplicate dependency crates Signed-off-by: Santtu Lakkala --- Cargo.lock | 164 +++++++++------------------------------------- Cargo.toml | 7 +- client/Cargo.toml | 4 +- common/Cargo.toml | 2 - 4 files changed, 34 insertions(+), 143 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff4b3b1..f43a105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,8 +187,8 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "http-body-util", "itoa", "matchit", @@ -213,8 +213,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "http-body-util", "mime", "pin-project-lite", @@ -312,7 +312,7 @@ version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn", @@ -591,14 +591,11 @@ dependencies = [ "console", "givc-client", "givc-common", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.30", - "prost 0.12.6", + "prost", "regex", "serde", "serde_json", - "strum 0.25.0", + "strum", "tokio", "tokio-listener", "tokio-stream", @@ -621,8 +618,6 @@ dependencies = [ "async-channel", "async-stream", "givc-common", - "http 0.2.12", - "http-body 0.4.6", "hyper-util", "serde", "tokio", @@ -640,11 +635,9 @@ version = "0.0.1" dependencies = [ "anyhow", "async-stream", - "http 0.2.12", - "http-body 0.4.6", - "prost 0.13.2", + "prost", "serde", - "strum 0.26.3", + "strum", "tokio", "tokio-stream", "tokio-vsock", @@ -666,7 +659,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.1.0", + "http", "indexmap 2.5.0", "slab", "tokio", @@ -686,12 +679,6 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -704,17 +691,6 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "http" version = "1.1.0" @@ -726,17 +702,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.1" @@ -744,7 +709,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http", ] [[package]] @@ -755,8 +720,8 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "pin-project-lite", ] @@ -772,28 +737,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hyper" -version = "0.14.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.4.1" @@ -804,8 +747,8 @@ dependencies = [ "futures-channel", "futures-util", "h2", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "httparse", "httpdate", "itoa", @@ -821,7 +764,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" dependencies = [ - "hyper 1.4.1", + "hyper", "hyper-util", "pin-project-lite", "tokio", @@ -837,9 +780,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", - "http-body 1.0.1", - "hyper 1.4.1", + "http", + "http-body", + "hyper", "pin-project-lite", "socket2", "tokio", @@ -1192,16 +1135,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" -dependencies = [ - "bytes", - "prost-derive 0.12.6", -] - [[package]] name = "prost" version = "0.13.2" @@ -1209,7 +1142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" dependencies = [ "bytes", - "prost-derive 0.13.2", + "prost-derive", ] [[package]] @@ -1219,33 +1152,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8650aabb6c35b860610e9cff5dc1af886c9e25073b7b1712a68972af4281302" dependencies = [ "bytes", - "heck 0.5.0", + "heck", "itertools", "log", "multimap", "once_cell", "petgraph", "prettyplease", - "prost 0.13.2", + "prost", "prost-types", "regex", "syn", "tempfile", ] -[[package]] -name = "prost-derive" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "prost-derive" version = "0.13.2" @@ -1265,7 +1185,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" dependencies = [ - "prost 0.13.2", + "prost", ] [[package]] @@ -1532,35 +1452,13 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" -dependencies = [ - "strum_macros 0.25.3", -] - [[package]] name = "strum" version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros 0.26.4", -] - -[[package]] -name = "strum_macros" -version = "0.25.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" -dependencies = [ - "heck 0.4.1", - "proc-macro2", - "quote", - "rustversion", - "syn", + "strum_macros", ] [[package]] @@ -1569,7 +1467,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "rustversion", @@ -1797,15 +1695,15 @@ dependencies = [ "base64", "bytes", "h2", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-timeout", "hyper-util", "percent-encoding", "pin-project", - "prost 0.13.2", + "prost", "rustls-pemfile", "socket2", "tokio", @@ -1837,7 +1735,7 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b56b874eedb04f89907573b408eab1e87c1c1dce43aac6ad63742f57faa99ff" dependencies = [ - "prost 0.13.2", + "prost", "prost-types", "tokio", "tokio-stream", @@ -1850,7 +1748,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0081d8ee0847d01271392a5aebe960a4600f5d4da6c67648a6382a0940f8b367" dependencies = [ - "prost 0.13.2", + "prost", "prost-types", "tonic", ] diff --git a/Cargo.toml b/Cargo.toml index 0b5915e..46550d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,10 @@ version = "0.0.1" anyhow = "1.0.86" async-stream = "0.3" async-channel = "2.3.1" -strum = {version = "0.25", features = ["derive"]} +strum = {version = "0.26", features = ["derive"]} clap = {version = "4.5.4", features = ["derive", "env"]} console = "0.15" -http = "0.2" -http-body = "0.4.2" -hyper = "0.14" -prost = "0.12" +prost = "0.13" regex = "1.11" tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros", "fs"]} tokio-stream = "0.1" diff --git a/client/Cargo.toml b/client/Cargo.toml index a6b138c..51264f0 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -10,9 +10,7 @@ version = "0.0.1" anyhow = "1.0.86" async-channel = "2.3.1" async-stream = "0.3" -http = "0.2" -http-body = "0.4.2" -hyper-util = { version = "0.1.4"} +hyper-util = { version = "0.1"} tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros"]} tokio-stream = "0.1" tokio-vsock = "*" diff --git a/common/Cargo.toml b/common/Cargo.toml index 529dde3..d87d3c0 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -9,8 +9,6 @@ version = "0.0.1" [dependencies] anyhow = "1.0.86" async-stream = "0.3" -http = "0.2" -http-body = "0.4.2" prost = "0.13" tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros"]} tokio-stream = "0.1" From cfc55ef0fca41b7db0c8229496e30c656d1c449d Mon Sep 17 00:00:00 2001 From: Santtu Lakkala Date: Mon, 28 Oct 2024 16:37:30 +0200 Subject: [PATCH 2/3] Remove usage of deprecated method Signed-off-by: Santtu Lakkala --- common/build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/build.rs b/common/build.rs index f76b44f..5f76ade 100644 --- a/common/build.rs +++ b/common/build.rs @@ -5,16 +5,16 @@ fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); tonic_build::configure() .file_descriptor_set_path(out_dir.join("admin_descriptor.bin")) - .compile(&["api/admin/admin.proto"], &["admin"]) + .compile_protos(&["api/admin/admin.proto"], &["admin"]) .unwrap(); tonic_build::configure() .file_descriptor_set_path(out_dir.join("locale_descriptor.bin")) - .compile(&["api/locale/locale.proto"], &["locale"]) + .compile_protos(&["api/locale/locale.proto"], &["locale"]) .unwrap(); tonic_build::configure() .file_descriptor_set_path(out_dir.join("systemd_descriptor.bin")) - .compile(&["api/systemd/systemd.proto"], &["systemd"]) + .compile_protos(&["api/systemd/systemd.proto"], &["systemd"]) .unwrap(); } From d37e55720b93ba77491b80e7afe9f1a75a80a475 Mon Sep 17 00:00:00 2001 From: Santtu Lakkala Date: Mon, 28 Oct 2024 17:41:33 +0200 Subject: [PATCH 3/3] Miscellany cleanups Signed-off-by: Santtu Lakkala --- client/src/client.rs | 15 ++++++++--- src/admin/server.rs | 63 +++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index cbe1727..1dd875b 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -77,10 +77,10 @@ impl AdminClient { .register_service(request) .await? .into_inner(); - if let Some(err) = response.error { - bail!("{err}"); - } - Ok(()) + response + .error + .map(|e| Err(anyhow::Error::msg(e))) + .unwrap_or(Ok(())) } pub async fn start( @@ -97,6 +97,7 @@ impl AdminClient { let _response = self.connect_to().await?.start_application(request).await?; Ok(()) } + pub async fn stop(&self, app_name: String) -> anyhow::Result<()> { let request = pb::admin::ApplicationRequest { app_name, @@ -106,6 +107,7 @@ impl AdminClient { let _response = self.connect_to().await?.stop_application(request).await?; Ok(()) } + pub async fn pause(&self, app_name: String) -> anyhow::Result<()> { let request = pb::admin::ApplicationRequest { app_name, @@ -115,6 +117,7 @@ impl AdminClient { let _response = self.connect_to().await?.pause_application(request).await?; Ok(()) } + pub async fn resume(&self, app_name: String) -> anyhow::Result<()> { let request = pb::admin::ApplicationRequest { app_name, @@ -124,21 +127,25 @@ impl AdminClient { let _response = self.connect_to().await?.resume_application(request).await?; Ok(()) } + pub async fn reboot(&self) -> anyhow::Result<()> { let request = pb::admin::Empty {}; let _response = self.connect_to().await?.reboot(request).await?; Ok(()) } + pub async fn poweroff(&self) -> anyhow::Result<()> { let request = pb::admin::Empty {}; let _response = self.connect_to().await?.poweroff(request).await?; Ok(()) } + pub async fn suspend(&self) -> anyhow::Result<()> { let request = pb::admin::Empty {}; let _response = self.connect_to().await?.suspend(request).await?; Ok(()) } + pub async fn wakeup(&self) -> anyhow::Result<()> { let request = pb::admin::Empty {}; let _response = self.connect_to().await?.wakeup(request).await?; diff --git a/src/admin/server.rs b/src/admin/server.rs index 02d5c73..3b8fd0a 100644 --- a/src/admin/server.rs +++ b/src/admin/server.rs @@ -1,6 +1,6 @@ use super::entry::*; use crate::pb::{self, *}; -use anyhow::{bail, Context}; +use anyhow::{anyhow, bail, Context}; use async_stream::try_stream; use givc_common::query::Event; use regex::Regex; @@ -110,7 +110,7 @@ impl AdminServiceImpl { pub fn endpoint(&self, entry: &RegistryEntry) -> anyhow::Result { let transport = match &entry.placement { Placement::Managed(parent) => { - let parent = self.registry.by_name(&parent)?; + let parent = self.registry.by_name(parent)?; parent .agent() .with_context(|| "When get_remote_status()")? @@ -166,24 +166,23 @@ impl AdminServiceImpl { /* Check status of the unit */ match client.get_remote_status(unit.into()).await { - Ok(status) => { - if status.load_state == "loaded" { - /* No action, if the unit is loaded and already running. */ - if status.active_state == "active" && status.sub_state == "running" { - info!("Service {unit} is already in running state!"); - } else { - /* Start the unit if it is loaded and not running. */ - client.start_remote(unit.into()).await?; - } - return Ok(()); + Ok(status) if status.load_state == "loaded" => { + /* No action, if the unit is loaded and already running. */ + if status.active_state == "active" && status.sub_state == "running" { + info!("Service {unit} is already in running state!"); } else { - /* Error, if the unit is not loaded. */ - bail!("Service {unit} is not loaded!"); + /* Start the unit if it is loaded and not running. */ + client.start_remote(unit.into()).await?; } + Ok(()) + } + Ok(_) => { + /* Error, if the unit is not loaded. */ + Err(anyhow!("Service {unit} is not loaded!")) } Err(e) => { - eprintln!("Error retrieving unit status: {}", e); - return Err(e.into()); + eprintln!("Error retrieving unit status: {e}"); + Err(e) } } } @@ -236,21 +235,17 @@ impl AdminServiceImpl { .with_context(|| format!("handing error, by restart VM {}", entry.name))?; Ok(()) // FIXME: should use `?` from line above, why it didn't work? } - (x, y) => bail!( - "Don't known how to handle_error for VM type: {:?}:{:?}", - x, - y - ), + (x, y) => bail!("Don't known how to handle_error for VM type: {x:?}:{y:?}"), } } async fn monitor_routine(&self) -> anyhow::Result<()> { let watch_list = self.registry.watch_list(); for entry in watch_list { - debug!("Monitoring {}...", &entry.name); + debug!("Monitoring {}...", entry.name); match self.get_remote_status(&entry).await { Err(err) => { - error!("could not get status of unit {}: {}", &entry.name, err); + error!("could not get status of unit {}: {}", entry.name, err); self.handle_error(entry) .await .context("during handle error")? @@ -261,11 +256,11 @@ impl AdminServiceImpl { if inactive { error!( "Status of {} is {}, instead of active. Recovering.", - &entry.name, status.active_state + entry.name, status.active_state ) }; - debug!("Status of {} is {:#?} (updated)", &entry.name, status); + debug!("Status of {} is {:#?} (updated)", entry.name, status); // We have immutable copy of entry here, but need update _in registry_ copy self.registry.update_state(&entry.name, status)?; @@ -286,7 +281,7 @@ impl AdminServiceImpl { loop { watch.tick().await; if let Err(err) = self.monitor_routine().await { - error!("Error during watch: {}", err); + error!("Error during watch: {err}"); } } } @@ -509,17 +504,15 @@ impl pb::admin_service_server::AdminService for AdminService { request: tonic::Request, ) -> Result, tonic::Status> { escalate(request, |_| async { - // Kludge - let list: Vec = self + let list = self .inner .registry .contents() .into_iter() - .map(|item| item.into()) + .map(QueryResult::from) + .map(From::from) .collect(); - Ok(QueryListResponse { - list: list.into_iter().map(|item| item.into()).collect(), // Kludge - }) + Ok(QueryListResponse { list }) }) .await } @@ -540,14 +533,12 @@ impl pb::admin_service_server::AdminService for AdminService { }); let locale = req.locale.clone(); tokio::spawn(async move { + let localemsg = pb::locale::LocaleMessage { locale }; for ec in managers { if let Ok(conn) = ec.connect().await { let mut client = pb::locale::locale_client_client::LocaleClientClient::new(conn); - let localemsg = pb::locale::LocaleMessage { - locale: locale.clone(), - }; - let _ = client.locale_set(localemsg).await; + let _ = client.locale_set(localemsg.clone()).await; } } });