diff --git a/proto/vmm.proto b/proto/vmm.proto index 8244446..34ec802 100644 --- a/proto/vmm.proto +++ b/proto/vmm.proto @@ -26,9 +26,10 @@ message ExecuteResponse { DEBUG = 5; } - string stdout = 1; - string stderr = 2; - int32 exit_code = 3; + Stage stage = 1; + optional string stdout = 2; + optional string stderr = 3; + optional int32 exit_code = 4; } service VmmService { @@ -41,7 +42,6 @@ message RunVmmRequest { Language language = 2; string code = 3; LogLevel log_level = 4; - } message RunVmmResponse { diff --git a/src/api/src/service.rs b/src/api/src/service.rs index 243c287..9d4a2a4 100644 --- a/src/api/src/service.rs +++ b/src/api/src/service.rs @@ -1,5 +1,5 @@ use crate::client::{ - vmmorchestrator::{ExecuteResponse, RunVmmRequest, ShutdownVmRequest, ShutdownVmResponse}, + vmmorchestrator::{execute_response::Stage, ExecuteResponse, RunVmmRequest, ShutdownVmRequest, ShutdownVmResponse}, VmmClient, }; use actix_web::{post, web, HttpRequest, HttpResponse, Responder}; @@ -49,14 +49,39 @@ pub async fn run(req_body: web::Json) -> impl Responder { #[derive(Debug, Serialize)] pub struct ExecuteJsonResponse { - pub stdout: String, - pub stderr: String, - pub exit_code: i32, + pub stage: StageJson, + pub stdout: Option, + pub stderr: Option, + pub exit_code: Option, +} + +#[derive(Debug, Serialize)] +pub enum StageJson { + Pending, + Building, + Running, + Done, + Failed, + Debug, +} + +impl From for StageJson { + fn from(value: Stage) -> Self { + match value { + Stage::Pending => StageJson::Pending, + Stage::Building => StageJson::Building, + Stage::Running => StageJson::Running, + Stage::Done => StageJson::Done, + Stage::Failed => StageJson::Failed, + Stage::Debug => StageJson::Debug, + } + } } impl From for ExecuteJsonResponse { fn from(value: ExecuteResponse) -> Self { Self { + stage: Stage::from_i32(value.stage).unwrap().into(), stdout: value.stdout, stderr: value.stderr, exit_code: value.exit_code, diff --git a/src/vmm/src/grpc/server.rs b/src/vmm/src/grpc/server.rs index 898a60f..9bac2ad 100644 --- a/src/vmm/src/grpc/server.rs +++ b/src/vmm/src/grpc/server.rs @@ -250,6 +250,7 @@ impl VmmServiceTrait for VmmService { // Process each message as it arrives while let Some(response) = response_stream.message().await? { let vmm_response = vmmorchestrator::ExecuteResponse { + stage: response.stage, stdout: response.stdout, stderr: response.stderr, exit_code: response.exit_code,