auth stuff
This commit is contained in:
parent
733e09fc96
commit
0af37a6a4f
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -340,6 +340,12 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorful"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffb474a9c3219a8254ead020421ecf1b90427f29b55f6aae9a2471fa62c126ef"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.3.11"
|
version = "0.3.11"
|
||||||
|
@ -1454,13 +1460,14 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uwusched-head-node"
|
name = "uwusched"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bincode",
|
"bincode",
|
||||||
"bson",
|
"bson",
|
||||||
"clap",
|
"clap",
|
||||||
|
"colorful",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"lz4_flex",
|
"lz4_flex",
|
||||||
|
|
|
@ -20,7 +20,8 @@ message DataResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
service Auth {
|
service Auth {
|
||||||
rpc Auth (LoginRequest) returns (LoginResponse);
|
rpc Login (LoginRequest) returns (LoginResponse);
|
||||||
|
rpc Logout (LogoutRequest) returns (LogoutResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
message LoginRequest {
|
message LoginRequest {
|
||||||
|
@ -41,6 +42,14 @@ message LoginResponse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message LogoutRequest {
|
||||||
|
string node_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LogoutResponse {
|
||||||
|
string node_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
service AliveCheck {
|
service AliveCheck {
|
||||||
rpc AliveCheck (AliveCheckRequest) returns (AliveCheckResponse);
|
rpc AliveCheck (AliveCheckRequest) returns (AliveCheckResponse);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["xqtc"]
|
authors = ["xqtc"]
|
||||||
description = "Distributed computing with abstract data"
|
description = "Distributed computing with abstract data"
|
||||||
name = "uwusched-head-node"
|
name = "uwusched"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ tonic = "0.12.2"
|
||||||
tonic-reflection = "0.12.2"
|
tonic-reflection = "0.12.2"
|
||||||
prost = "0.13.2"
|
prost = "0.13.2"
|
||||||
prost-types = "0.13.2"
|
prost-types = "0.13.2"
|
||||||
|
colorful = "0.3.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = "0.12.2"
|
tonic-build = "0.12.2"
|
||||||
|
|
|
@ -5,6 +5,7 @@ mod config;
|
||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
|
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
use sched::LoginRequest;
|
||||||
|
|
||||||
pub mod sched {
|
pub mod sched {
|
||||||
tonic::include_proto!("sched");
|
tonic::include_proto!("sched");
|
||||||
|
@ -14,12 +15,34 @@ 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();
|
||||||
|
use colorful::Colorful;
|
||||||
|
use colorful::HSL;
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
"
|
||||||
|
,--. ,--. ,--. ,--. ,--. ,--.
|
||||||
|
| | | | ,--. ,--. | | | | ,---. ,---. | ,---. ,---. ,-| |
|
||||||
|
| | | | | |.'.| | | | | | ( .-' | .--' | .-. | | .-. : ' .-. |
|
||||||
|
' '-' ' | .'. | ' '-' ' .-' `) \\ `--. | | | | \\ --. \\ `-' |
|
||||||
|
`-----' '--' '--' `-----' `----' `---' `--' `--' `----' `---'
|
||||||
|
Compute Node
|
||||||
|
"
|
||||||
|
.gradient_with_color(HSL::new(0.0, 1.0, 0.5), HSL::new(0.833, 1.0, 0.5))
|
||||||
|
);
|
||||||
let server_addr = "http://[::1]:50051";
|
let server_addr = "http://[::1]:50051";
|
||||||
let addr: SocketAddr = "[::1]:50052".parse()?;
|
let addr: SocketAddr = "[::1]:50052".parse()?;
|
||||||
let data_client = sched::data_client::DataClient::connect(server_addr).await?;
|
let mut data = sched::data_client::DataClient::connect(server_addr).await?;
|
||||||
debug!("{:#?}", &data_client);
|
let mut auth = sched::auth_client::AuthClient::connect(server_addr).await?;
|
||||||
// let mut auth_client = sched::auth_client::AuthClient::connect(server_addr.clone()).await?;
|
debug!("{:#?}", &data);
|
||||||
alive_check_serve(addr).await?;
|
debug!("{:#?}", &auth);
|
||||||
|
// alive_check_serve(addr).await?;
|
||||||
|
debug!(
|
||||||
|
"{:#?}",
|
||||||
|
auth.login(tonic::Request::new(LoginRequest {
|
||||||
|
node_id: "compute-1".to_string(),
|
||||||
|
}))
|
||||||
|
.await?
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +55,6 @@ async fn alive_check_serve(addr: SocketAddr) -> Result<(), Box<dyn std::error::E
|
||||||
|
|
||||||
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!(
|
info!(
|
||||||
"Starting Alive Check gRPC server on: http://{}",
|
"Starting Alive Check gRPC server on: http://{}",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::sched::{
|
use crate::sched::{
|
||||||
alive_check_client::AliveCheckClient, alive_check_server, auth_server, data_server,
|
alive_check_client::AliveCheckClient, alive_check_server, auth_server, data_server,
|
||||||
AliveCheckRequest, AliveCheckResponse, DataRequest, DataResponse, LoginRequest, LoginResponse,
|
AliveCheckRequest, AliveCheckResponse, DataRequest, DataResponse, LoginRequest, LoginResponse,
|
||||||
|
LogoutRequest, LogoutResponse,
|
||||||
};
|
};
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ pub struct AuthService {}
|
||||||
|
|
||||||
#[tonic::async_trait]
|
#[tonic::async_trait]
|
||||||
impl auth_server::Auth for AuthService {
|
impl auth_server::Auth for AuthService {
|
||||||
async fn auth(
|
async fn login(
|
||||||
&self,
|
&self,
|
||||||
request: tonic::Request<LoginRequest>,
|
request: tonic::Request<LoginRequest>,
|
||||||
) -> Result<tonic::Response<LoginResponse>, tonic::Status> {
|
) -> Result<tonic::Response<LoginResponse>, tonic::Status> {
|
||||||
|
@ -50,12 +51,26 @@ impl auth_server::Auth for AuthService {
|
||||||
|
|
||||||
Ok(tonic::Response::new(res))
|
Ok(tonic::Response::new(res))
|
||||||
}
|
}
|
||||||
|
async fn logout(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<LogoutRequest>,
|
||||||
|
) -> Result<tonic::Response<LogoutResponse>, tonic::Status> {
|
||||||
|
info!("Got a logout request: {:#?}", request);
|
||||||
|
let input = request.get_ref();
|
||||||
|
let res = LogoutResponse {
|
||||||
|
node_id: input.node_id.clone(),
|
||||||
|
};
|
||||||
|
Ok(tonic::Response::new(res))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn auth_client() {
|
async fn login(node_id: String) -> tonic::Request<LoginRequest> {
|
||||||
todo!()
|
let req = LoginRequest { node_id };
|
||||||
|
tonic::Request::new(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async fn logout(node_id: String) -> tonic::Request<LoginRequest> {}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct AliveCheckService {}
|
pub struct AliveCheckService {}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct Node {
|
||||||
id: String,
|
id: String,
|
||||||
specs: NodeSpecs,
|
specs: NodeSpecs,
|
||||||
curr_job: Job,
|
curr_job: Job,
|
||||||
job_queue: Vec<Job>,
|
job_queue: JobQueue,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Job {
|
struct Job {
|
||||||
|
@ -28,6 +28,11 @@ struct Job {
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct JobQueue {
|
||||||
|
jobs: Vec<Job>,
|
||||||
|
size: u128,
|
||||||
|
}
|
||||||
|
|
||||||
struct NodeSpecs {
|
struct NodeSpecs {
|
||||||
threads: u64,
|
threads: u64,
|
||||||
mem: u64,
|
mem: u64,
|
||||||
|
@ -65,25 +70,22 @@ fn get_type_of<T>(_: &T) -> &'static str {
|
||||||
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 cli = Cli::parse();
|
||||||
|
match &cli.command {
|
||||||
|
Some(Commands::Start { role }) => {
|
||||||
|
debug!("{:#?}", role)
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
let addr = "[::1]:50051".parse()?;
|
let addr = "[::1]:50051".parse()?;
|
||||||
info!("Starting gRPC server on {}", addr);
|
info!("Starting gRPC server on {}", addr);
|
||||||
let data = grpc::DataService::default();
|
let data = grpc::DataService::default();
|
||||||
let auth = grpc::AuthService::default();
|
let auth = grpc::AuthService::default();
|
||||||
// let reflection = tonic_reflection::server::Builder::configure()
|
|
||||||
// .register_file_descriptor_set(sched::FILE_DESCRIPTOR_SET)
|
|
||||||
// .build_v1()?;
|
|
||||||
Server::builder()
|
Server::builder()
|
||||||
.add_service(sched::data_server::DataServer::new(data))
|
.add_service(sched::data_server::DataServer::new(data))
|
||||||
.add_service(sched::auth_server::AuthServer::new(auth))
|
.add_service(sched::auth_server::AuthServer::new(auth))
|
||||||
.serve(addr)
|
.serve(addr)
|
||||||
.await?;
|
.await?;
|
||||||
debug!("{:?}", CONFIG.node);
|
debug!("{:?}", CONFIG.node);
|
||||||
// let cli = Cli::parse();
|
|
||||||
// match &cli.command {
|
|
||||||
// Some(Commands::Start { role }) => {
|
|
||||||
// debug!("{:#?}", role)
|
|
||||||
// }
|
|
||||||
// None => {}
|
|
||||||
// }
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue