Placeholder client logic; State Machine data structures
All checks were successful
/ build (push) Successful in 1m43s
/ clippy (push) Successful in 1m43s

This commit is contained in:
xqtc 2024-09-09 18:19:19 +02:00
parent 0216989438
commit 6e3b797dd1
5 changed files with 51 additions and 12 deletions

1
Cargo.lock generated
View file

@ -1474,6 +1474,7 @@ dependencies = [
"tonic",
"tonic-build",
"tonic-reflection",
"uuid",
]
[[package]]

View file

@ -12,6 +12,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
lz4_flex = "0.11.3"
uuid = "1.10"
toml = "0.8.19"
lazy_static = "1.5.0"
log = "0.4.22"

View file

@ -4,7 +4,7 @@ mod grpc;
mod config;
use crate::config::CONFIG;
use log::info;
use log::{debug, info};
pub mod sched {
tonic::include_proto!("sched");
@ -14,14 +14,16 @@ pub mod sched {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("RUST_LOG", CONFIG.log.level.clone());
pretty_env_logger::init();
let url: SocketAddr = "[::1]:50051".parse()?;
// let mut data_client = sched::data_client::DataClient::connect(url.clone()).await?;
// let mut auth_client = sched::auth_client::AuthClient::connect(url.clone()).await?;
alive_check_serve(url).await?;
let server_addr = "http://[::1]:50051";
let addr: SocketAddr = "[::1]:50052".parse()?;
let mut data_client = sched::data_client::DataClient::connect(server_addr.clone()).await?;
debug!("{:#?}", &data_client);
// let mut auth_client = sched::auth_client::AuthClient::connect(server_addr.clone()).await?;
alive_check_serve(addr).await?;
Ok(())
}
async fn alive_check_serve(url: SocketAddr) -> Result<(), Box<dyn std::error::Error>> {
async fn alive_check_serve(addr: SocketAddr) -> Result<(), Box<dyn std::error::Error>> {
use grpc::AliveCheckService;
use sched::alive_check_server::AliveCheckServer;
use tokio::sync::mpsc;
@ -30,12 +32,16 @@ async fn alive_check_serve(url: SocketAddr) -> Result<(), Box<dyn std::error::Er
let (tx, mut rx) = mpsc::channel::<Server>(100);
// Spawn gRPC server in own async task
task::spawn(async move {
info!("Starting Alive Check gRPC server");
info!(
"Starting Alive Check gRPC server on: http://{}",
addr.to_string()
);
let alive_check_service = AliveCheckService::default();
Server::builder()
.add_service(AliveCheckServer::new(alive_check_service))
.serve(url)
.serve(addr)
.await
.unwrap();
});

View file

@ -1,7 +1,6 @@
use crate::sched::{
alive_check_client::{AliveCheckClient},
alive_check_server, auth_server, data_server, AliveCheckRequest, AliveCheckResponse,
DataRequest, DataResponse, LoginRequest, LoginResponse,
alive_check_client::AliveCheckClient, alive_check_server, auth_server, data_server,
AliveCheckRequest, AliveCheckResponse, DataRequest, DataResponse, LoginRequest, LoginResponse,
};
use log::{debug, info};
@ -30,6 +29,10 @@ impl data_server::Data for DataService {
}
}
async fn data_client() {
todo!()
}
#[derive(Debug, Default)]
pub struct AuthService {}
@ -49,6 +52,10 @@ impl auth_server::Auth for AuthService {
}
}
async fn auth_client() {
todo!()
}
#[derive(Debug, Default, Clone)]
pub struct AliveCheckService {}

View file

@ -1,13 +1,14 @@
mod config;
mod grpc;
use std::collections::HashMap;
use crate::config::CONFIG;
use clap::{Parser, Subcommand};
use log::{debug, info};
use tonic::transport::Server;
// Import generated protobuf
mod sched {
tonic::include_proto!("sched");
@ -15,6 +16,29 @@ mod sched {
// tonic::include_file_descriptor_set!("protocol_descriptor").into();
}
struct Node {
id: String,
specs: NodeSpecs,
curr_job: Job,
job_queue: Vec<Job>,
}
struct Job {
id: uuid::Uuid,
data: Vec<u8>,
}
struct NodeSpecs {
threads: u64,
mem: u64,
net_speed: f64,
}
struct State {
nodes: Vec<Node>,
delegation_efficiency: f32,
tasks: HashMap<uuid::Uuid, Job>,
}
#[derive(Parser)]
#[command(author, version, about)]
#[command(propagate_version = true)]