use crate::cluster::peer::{Peer, PeerEndpoint, PeerState};
use crate::cluster::Datacenter;
use crate::hashkit::DynToken;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PeerSnapshot {
pub idx: u32,
pub host: String,
pub port: u16,
pub dc: String,
pub rack: String,
pub state: PeerState,
pub tokens: Vec<DynToken>,
pub is_local: bool,
}
impl From<&Peer> for PeerSnapshot {
fn from(p: &Peer) -> Self {
Self {
idx: p.idx(),
host: p.endpoint().host().to_string(),
port: p.endpoint().port(),
dc: p.dc().to_string(),
rack: p.rack().to_string(),
state: p.state(),
tokens: p.tokens().to_vec(),
is_local: p.is_local(),
}
}
}
impl PeerSnapshot {
#[must_use]
pub fn to_peer(&self) -> Peer {
Peer::new(
self.idx,
PeerEndpoint::tcp(self.host.clone(), self.port),
self.rack.clone(),
self.dc.clone(),
self.tokens.clone(),
self.is_local,
true,
false,
)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RackSnapshot {
pub name: String,
pub continuum_len: usize,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DatacenterSnapshot {
pub name: String,
pub racks: Vec<RackSnapshot>,
}
impl From<&Datacenter> for DatacenterSnapshot {
fn from(dc: &Datacenter) -> Self {
Self {
name: dc.name().to_string(),
racks: dc
.racks()
.iter()
.map(|r| RackSnapshot {
name: r.name().to_string(),
continuum_len: r.continuums().len(),
})
.collect(),
}
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct RingSnapshot {
pub entries: Vec<(DynToken, u32)>,
pub generation: u64,
}