Skip to content

Commit

Permalink
fix: fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Font Vincent <[email protected]>
  • Loading branch information
Hunh0w committed May 2, 2024
1 parent 1906dd0 commit 0b16dde
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
8 changes: 3 additions & 5 deletions src/api/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
}
Expand All @@ -97,7 +95,7 @@ pub struct ShutdownJsonResponse {
impl From<ShutdownVmResponse> for ShutdownJsonResponse {
fn from(value: ShutdownVmResponse) -> Self {
Self {
success: value.success
success: value.success,
}
}
}
11 changes: 7 additions & 4 deletions src/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/cli/src/services.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -53,12 +55,14 @@ impl CloudletClient {

pub async fn shutdown() -> Result<bool, ()> {
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::<CloudletShutdownResponse>().await.unwrap();
let shutdown_response: CloudletShutdownResponse = response
.unwrap()
.json::<CloudletShutdownResponse>()
.await
.unwrap();

Ok(shutdown_response.success)
}
}
}
2 changes: 1 addition & 1 deletion src/shared-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct CloudletDtoRequest {

#[derive(Debug, Deserialize)]
pub struct CloudletShutdownResponse {
pub success: bool
pub success: bool,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
12 changes: 4 additions & 8 deletions src/vmm/src/grpc/client.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -35,7 +35,7 @@ impl WorkloadClient {
) -> Result<Streaming<agent::ExecuteResponse>, tonic::Status> {
let request = tonic::Request::new(request);
let response_stream = self.client.execute(request).await?.into_inner();

Ok(response_stream)
}

Expand All @@ -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 })
}
}
7 changes: 5 additions & 2 deletions src/vmm/src/grpc/server.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 0b16dde

Please sign in to comment.