Skip to content

Commit

Permalink
feat(proto): update proto to keep the 'stage' field
Browse files Browse the repository at this point in the history
Signed-off-by: Mateo Fernandez <[email protected]>
  • Loading branch information
mfernd committed May 30, 2024
1 parent e787188 commit 8b115e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
8 changes: 4 additions & 4 deletions proto/vmm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -41,7 +42,6 @@ message RunVmmRequest {
Language language = 2;
string code = 3;
LogLevel log_level = 4;

}

message RunVmmResponse {
Expand Down
33 changes: 29 additions & 4 deletions src/api/src/service.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -49,14 +49,39 @@ pub async fn run(req_body: web::Json<CloudletDtoRequest>) -> impl Responder {

#[derive(Debug, Serialize)]
pub struct ExecuteJsonResponse {
pub stdout: String,
pub stderr: String,
pub exit_code: i32,
pub stage: StageJson,
pub stdout: Option<String>,
pub stderr: Option<String>,
pub exit_code: Option<i32>,
}

#[derive(Debug, Serialize)]
pub enum StageJson {
Pending,
Building,
Running,
Done,
Failed,
Debug,
}

impl From<Stage> 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<ExecuteResponse> 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,
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8b115e8

Please sign in to comment.