83 lines
1.9 KiB
Rust
83 lines
1.9 KiB
Rust
#![allow(non_camel_case_types, unused)]
|
|
|
|
use std::str::FromStr;
|
|
|
|
#[derive(Debug, serde::Serialize)]
|
|
pub enum DataStatus {
|
|
OK,
|
|
/// An Error while looking up a hash
|
|
HASH_ERR,
|
|
/// Timeout Error
|
|
TIMEOUT_ERR,
|
|
}
|
|
|
|
#[derive(Debug, serde::Serialize)]
|
|
pub enum NodeStatusLogin {
|
|
/// Accepted Login
|
|
ACCEPTED,
|
|
/// Rejected Login
|
|
REJECTED,
|
|
}
|
|
|
|
#[derive(Debug, serde::Serialize)]
|
|
pub enum NodeStatusLogout {
|
|
/// Head-Node ACKs the Logout request from compute node
|
|
ACK,
|
|
/// Head-Node restructured and rebalanced Task-Queue, allowing the compute node to log out
|
|
OK,
|
|
/// Head-Node failed to restructure and rebalance Task-Queue, preventing compute node to log out
|
|
ERR,
|
|
}
|
|
|
|
#[derive(Debug, serde::Serialize)]
|
|
pub enum ProtocolId {
|
|
/// Identifier indicating one node pushing data to another
|
|
DATA_PUSH,
|
|
/// Identifier indicating one node pulling to another
|
|
DATA_PULL,
|
|
/// Identifier indicating the success of a `DATA_PUSH` or `DATA_PULL`
|
|
DATA_RESP,
|
|
HASH_PUSH,
|
|
HASH_PULL,
|
|
HASH_RESP,
|
|
/// Identifier indicating a node wants to join the cluster
|
|
NODE_LOGIN,
|
|
/// Identifier indicating a node being online
|
|
NODE_ALIVE,
|
|
/// Identifier indicating a node wants to leave the cluster
|
|
NODE_LOGOUT,
|
|
}
|
|
|
|
pub struct Login {
|
|
protocol_id: ProtocolId,
|
|
node_id: String,
|
|
transaction_uuid: uuid::Uuid,
|
|
status: NodeStatusLogin,
|
|
}
|
|
|
|
pub struct AliveCheck {
|
|
protocol_id: ProtocolId,
|
|
node_id: String,
|
|
transaction_uuid: uuid::Uuid,
|
|
}
|
|
|
|
pub struct Logout {
|
|
protocol_id: ProtocolId,
|
|
node_id: String,
|
|
transaction_uuid: uuid::Uuid,
|
|
status: NodeStatusLogout,
|
|
}
|
|
|
|
fn str_to_uuid(uuid: String) -> uuid::Uuid {
|
|
uuid::Uuid::from_str(&uuid).unwrap()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
#[test]
|
|
fn uuid() {
|
|
let res = str_to_uuid("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_string());
|
|
assert_eq!(uuid::uuid!("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"), res);
|
|
}
|
|
}
|