-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: streaming and pty setup --------- Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr>
- Loading branch information
1 parent
b547afa
commit 64a5996
Showing
21 changed files
with
319 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod client; | ||
pub mod services; | ||
pub mod service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::client::{ | ||
vmmorchestrator::{ExecuteResponse, RunVmmRequest}, | ||
VmmClient, | ||
}; | ||
use actix_web::{post, web, HttpResponse, Responder}; | ||
use actix_web_lab::sse; | ||
use async_stream::stream; | ||
use serde::Serialize; | ||
use shared_models::CloudletDtoRequest; | ||
use tokio_stream::StreamExt; | ||
use tonic::Streaming; | ||
|
||
#[post("/run")] | ||
pub async fn run(req_body: web::Json<CloudletDtoRequest>) -> impl Responder { | ||
let req = req_body.into_inner(); | ||
|
||
let mut client = VmmClient::new().await.unwrap(); | ||
|
||
let vmm_request = RunVmmRequest { | ||
code: req.code, | ||
env: req.env, | ||
language: req.language as i32, | ||
log_level: req.log_level as i32, | ||
}; | ||
|
||
println!("Request: {:?}", vmm_request); | ||
|
||
println!("Successfully connected to VMM service"); | ||
|
||
let mut response_stream: Streaming<ExecuteResponse> = | ||
client.run_vmm(vmm_request).await.unwrap(); | ||
println!("Response stream: {:?}", response_stream); | ||
|
||
let stream = stream! { | ||
while let Some(Ok(exec_response)) = response_stream.next().await { | ||
let json: ExecuteJsonResponse = exec_response.into(); | ||
yield sse::Event::Data(sse::Data::new_json(json).unwrap()); | ||
} | ||
}; | ||
|
||
sse::Sse::from_infallible_stream(stream) | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct ExecuteJsonResponse { | ||
pub stdout: String, | ||
pub stderr: String, | ||
pub exit_code: i32, | ||
} | ||
|
||
impl From<ExecuteResponse> for ExecuteJsonResponse { | ||
fn from(value: ExecuteResponse) -> Self { | ||
Self { | ||
stdout: value.stdout, | ||
stderr: value.stderr, | ||
exit_code: value.exit_code, | ||
} | ||
} | ||
} | ||
|
||
#[post("/shutdown")] | ||
pub async fn shutdown(req_body: String) -> impl Responder { | ||
// TODO: Get the id from the body and shutdown the vm | ||
HttpResponse::Ok().body(req_body) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: rust | ||
env_path: /home/thomas/Desktop/fork/cloudlet/src/cli/config/example.env | ||
code_path: /home/thomas/Desktop/fork/cloudlet/src/cli/src/main.rs | ||
log_level: debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,63 @@ | ||
use crate::utils::ConfigFileHandler; | ||
use reqwest::Client; | ||
use shared_models::{CloudletDtoRequest, YamlClientConfigFile}; | ||
use std::error::Error; | ||
use serde::Deserialize; | ||
use shared_models::{CloudletDtoRequest, Language}; | ||
use std::{error::Error, path::PathBuf}; | ||
|
||
#[derive(Deserialize)] | ||
struct TomlConfig { | ||
#[serde(rename = "workload-name")] | ||
_workload_name: String, | ||
language: Language, | ||
_action: String, | ||
_server: ServerConfig, | ||
build: BuildConfig, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct ServerConfig { | ||
_address: String, | ||
_port: u16, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct BuildConfig { | ||
#[serde(rename = "source-code-path")] | ||
source_code_path: PathBuf, | ||
_release: bool, | ||
} | ||
|
||
pub struct CloudletClient {} | ||
|
||
impl CloudletClient { | ||
pub fn new_cloudlet_config(config: YamlClientConfigFile) -> CloudletDtoRequest { | ||
let code: String = ConfigFileHandler::read_file(&config.code_path) | ||
pub fn new_cloudlet_config(config: String) -> CloudletDtoRequest { | ||
let config: TomlConfig = | ||
toml::from_str(&config).expect("Error while parsing the config file"); | ||
|
||
let code: String = ConfigFileHandler::read_file(&config.build.source_code_path) | ||
.expect("Error while reading the code file"); | ||
let env = ConfigFileHandler::read_file(&config.env_path) | ||
.expect("Error while reading the environment file"); | ||
let env = ""; | ||
|
||
let language = config.language; | ||
let log_level = config.log_level; | ||
CloudletDtoRequest { | ||
language, | ||
env, | ||
code, | ||
log_level, | ||
env: env.to_string(), | ||
log_level: shared_models::LogLevel::INFO, | ||
} | ||
} | ||
|
||
pub async fn run(request: CloudletDtoRequest) -> Result<(), Box<dyn Error>> { | ||
let client = Client::new(); | ||
let json = serde_json::to_string(&request)?; | ||
println!("REQUEST : {:?}", request); | ||
let res = client | ||
.post("http://127.0.0.1:3000/run") | ||
.header(reqwest::header::CONTENT_TYPE, "application/json") | ||
.body(json) | ||
.send() | ||
.await?; | ||
|
||
match res.status().as_u16() { | ||
200 => Ok(()), | ||
_ => Err("Error while making the request".into()), | ||
} | ||
println!("Response: {:?}", res.text().await?); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::compile_protos("../../proto/vmm.proto")?; | ||
tonic_build::compile_protos("../../proto/agent.proto")?; | ||
Ok(()) | ||
} |
Oops, something went wrong.