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",
"tonic-build", "tonic-build",
"tonic-reflection", "tonic-reflection",
"uuid",
] ]
[[package]] [[package]]

View file

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

View file

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

View file

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

View file

@ -1,6 +1,8 @@
mod config; mod config;
mod grpc; mod grpc;
use std::collections::HashMap;
use crate::config::CONFIG; use crate::config::CONFIG;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use log::{debug, info}; use log::{debug, info};
@ -8,13 +10,35 @@ use tonic::transport::Server;
// Import generated protobuf // Import generated protobuf
mod sched { mod sched {
tonic::include_proto!("sched"); tonic::include_proto!("sched");
// pub(crate) const FILE_DESCRIPTOR_SET: FileDescriptorSet = // pub(crate) const FILE_DESCRIPTOR_SET: FileDescriptorSet =
// tonic::include_file_descriptor_set!("protocol_descriptor").into(); // 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)] #[derive(Parser)]
#[command(author, version, about)] #[command(author, version, about)]
#[command(propagate_version = true)] #[command(propagate_version = true)]