From 0b16dde35d89c54589b2240fc250556f5f91b932 Mon Sep 17 00:00:00 2001 From: Font Vincent Date: Thu, 2 May 2024 17:06:51 +0200 Subject: [PATCH] fix: fmt Signed-off-by: Font Vincent --- src/api/src/service.rs | 8 +++----- src/cli/src/main.rs | 11 +++++++---- src/cli/src/services.rs | 16 ++++++++++------ src/shared-models/src/lib.rs | 2 +- src/vmm/src/grpc/client.rs | 12 ++++-------- src/vmm/src/grpc/server.rs | 7 +++++-- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/api/src/service.rs b/src/api/src/service.rs index 0c1da7a..badd3b8 100644 --- a/src/api/src/service.rs +++ b/src/api/src/service.rs @@ -72,7 +72,7 @@ pub async fn shutdown(request: HttpRequest) -> impl Responder { println!("Request: {:?}", req); - let shutdown_request = ShutdownVmRequest{}; + let shutdown_request = ShutdownVmRequest {}; let response_result = client.shutdown_vm(shutdown_request).await; match response_result { @@ -81,9 +81,7 @@ pub async fn shutdown(request: HttpRequest) -> impl Responder { HttpResponse::Ok().body(serde_json::to_string(&json_response).unwrap()) } Err(_) => { - let json_response: ShutdownJsonResponse = ShutdownJsonResponse { - success: false - }; + let json_response: ShutdownJsonResponse = ShutdownJsonResponse { success: false }; return HttpResponse::Ok().body(serde_json::to_string(&json_response).unwrap()); } } @@ -97,7 +95,7 @@ pub struct ShutdownJsonResponse { impl From for ShutdownJsonResponse { fn from(value: ShutdownVmResponse) -> Self { Self { - success: value.success + success: value.success, } } } diff --git a/src/cli/src/main.rs b/src/cli/src/main.rs index 1e80599..35f10cc 100644 --- a/src/cli/src/main.rs +++ b/src/cli/src/main.rs @@ -29,14 +29,17 @@ async fn main() -> io::Result<()> { Ok(_) => println!("Request successful {:?}", response), Err(e) => eprintln!("Error while making the request: {}", e), } - }, + } Commands::Shutdown {} => { let response = CloudletClient::shutdown().await; match response { Ok(bool) => { - if bool { println!("Shutdown Request successful !")} - else { println!("Shutdown Request Failed")} - }, + if bool { + println!("Shutdown Request successful !") + } else { + println!("Shutdown Request Failed") + } + } Err(()) => println!("Cannot send shutdown Request"), } } diff --git a/src/cli/src/services.rs b/src/cli/src/services.rs index 6a38332..4749ee9 100644 --- a/src/cli/src/services.rs +++ b/src/cli/src/services.rs @@ -1,7 +1,9 @@ use crate::utils::ConfigFileHandler; use reqwest::Client; use serde::Deserialize; -use shared_models::{BuildConfig, CloudletDtoRequest, Language, ServerConfig, CloudletShutdownResponse}; +use shared_models::{ + BuildConfig, CloudletDtoRequest, CloudletShutdownResponse, Language, ServerConfig, +}; use std::error::Error; #[derive(Deserialize, Debug)] @@ -53,12 +55,14 @@ impl CloudletClient { pub async fn shutdown() -> Result { let client = Client::new(); - let response = client.post("http://127.0.0.1:3000/shutdown") - .send() - .await; + let response = client.post("http://127.0.0.1:3000/shutdown").send().await; - let shutdown_response: CloudletShutdownResponse = response.unwrap().json::().await.unwrap(); + let shutdown_response: CloudletShutdownResponse = response + .unwrap() + .json::() + .await + .unwrap(); Ok(shutdown_response.success) } -} \ No newline at end of file +} diff --git a/src/shared-models/src/lib.rs b/src/shared-models/src/lib.rs index 2a54e87..b2c4e7e 100644 --- a/src/shared-models/src/lib.rs +++ b/src/shared-models/src/lib.rs @@ -41,7 +41,7 @@ pub struct CloudletDtoRequest { #[derive(Debug, Deserialize)] pub struct CloudletShutdownResponse { - pub success: bool + pub success: bool, } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/vmm/src/grpc/client.rs b/src/vmm/src/grpc/client.rs index 564305f..9c0ad5a 100644 --- a/src/vmm/src/grpc/client.rs +++ b/src/vmm/src/grpc/client.rs @@ -1,8 +1,8 @@ use self::agent::{workload_runner_client::WorkloadRunnerClient, ExecuteRequest, SignalRequest}; +use super::server::vmmorchestrator::{ShutdownVmRequest, ShutdownVmResponse}; use log::error; use std::{error::Error, net::Ipv4Addr, time::Duration}; use tonic::{transport::Channel, Streaming}; -use super::server::vmmorchestrator::{ShutdownVmRequest, ShutdownVmResponse}; pub mod agent { tonic::include_proto!("cloudlet.agent"); @@ -35,7 +35,7 @@ impl WorkloadClient { ) -> Result, tonic::Status> { let request = tonic::Request::new(request); let response_stream = self.client.execute(request).await?.into_inner(); - + Ok(response_stream) } @@ -51,14 +51,10 @@ impl WorkloadClient { if let Err(status) = response { let error = status.source().unwrap().source().unwrap().source().unwrap(); if error.to_string().as_str().eq(BROKEN_PIPE_ERROR) { - return Ok(ShutdownVmResponse { - success: true - }); + return Ok(ShutdownVmResponse { success: true }); } } - Ok(ShutdownVmResponse { - success: false - }) + Ok(ShutdownVmResponse { success: false }) } } diff --git a/src/vmm/src/grpc/server.rs b/src/vmm/src/grpc/server.rs index 6ce44d8..d8cc28f 100644 --- a/src/vmm/src/grpc/server.rs +++ b/src/vmm/src/grpc/server.rs @@ -1,4 +1,7 @@ -use self::vmmorchestrator::{vmm_service_server::VmmService as VmmServiceTrait, Language, RunVmmRequest, ShutdownVmRequest, ShutdownVmResponse}; +use self::vmmorchestrator::{ + vmm_service_server::VmmService as VmmServiceTrait, Language, RunVmmRequest, ShutdownVmRequest, + ShutdownVmResponse, +}; use crate::grpc::client::agent::ExecuteRequest; use crate::VmmErrors; use crate::{core::vmm::VMM, grpc::client::WorkloadClient}; @@ -63,7 +66,7 @@ impl VmmServiceTrait for VmmService { let response = client.shutdown(request.into_inner()).await.unwrap(); return Ok(Response::new(response)); - }else if let Err(e) = grpc_client { + } else if let Err(e) = grpc_client { error!("ERROR {:?}", e); } return Err(Status::internal("Failed to shutdown the VM"));