use super::*;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Link {
Live,
Retrying {
attempt: u32,
},
Lost {
at_local: String,
why: String,
},
}
#[derive(Debug, Clone)]
pub struct Row {
pub info: ProcessInfo,
pub anchor: Instant,
}
impl Row {
#[must_use]
pub(crate) fn reported(&self) -> Reported {
if self.info.dog.is_none() {
return Reported::Live(self.info.status);
}
Reported::of(self.info.status, self.info.handshook)
}
}
#[derive(Debug, Clone)]
pub struct GroupTotals {
pub count: usize,
pub restarts: u32,
pub cpu: Option<f32>,
pub memory: Option<u64>,
pub uptime_ms: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Sent {
Lambs {
id: u32,
},
Action {
verb: ActionVerb,
target: RowKey,
name: String,
},
Dog {
name: String,
enable: bool,
source: DogSource,
ticket: u64,
},
SheepConfig {
name: String,
},
ApplyField {
name: String,
ticket: u64,
key: String,
value: FieldValue,
authority: WriteAuthority,
},
DogSection {
name: String,
},
SetDogSection {
name: String,
ticket: u64,
toml: DogSectionToml,
authority: WriteAuthority,
},
SetEnv {
name: String,
ticket: u64,
key: String,
value: Option<EnvValue>,
authority: WriteAuthority,
},
}
impl Sent {
#[must_use]
pub fn request(&self) -> Request {
match self {
Self::Lambs { id } => Request::Describe {
selector: SelectorSpec::Id(*id),
},
Self::Action { verb, target, .. } => {
let selector = match target {
RowKey::Sheep(id) => SelectorSpec::Id(*id),
RowKey::Group(name) => SelectorSpec::Name(name.clone()),
RowKey::Fold(name) => SelectorSpec::Fold(name.clone()),
RowKey::Section(_) => unreachable!("a header is never an action target"),
};
match verb {
ActionVerb::Stop => Request::Stop { selector },
ActionVerb::Restart => Request::Restart { selector },
ActionVerb::Reload => Request::Reload { selector },
}
}
Self::Dog {
name,
enable: true,
source,
..
} => Request::EnableDog {
name: name.clone(),
source: source.clone(),
},
Self::Dog {
name,
enable: false,
..
} => Request::DisableDog { name: name.clone() },
Self::SheepConfig { name } => Request::SheepConfig { name: name.clone() },
Self::ApplyField {
name, key, value, ..
} => Request::SetSheepField {
name: name.clone(),
key: key.clone(),
value: value.as_value().clone(),
},
Self::DogSection { name } => Request::DogConfig { name: name.clone() },
Self::SetDogSection { name, toml, .. } => Request::SetDogConfig {
name: name.clone(),
toml: toml.clone(),
},
Self::SetEnv {
name, key, value, ..
} => Request::SetSheepEnv {
name: name.clone(),
key: key.clone(),
value: value.clone(),
},
}
}
pub(super) fn ticket(&self) -> Option<u64> {
match self {
Self::ApplyField { ticket, .. }
| Self::SetDogSection { ticket, .. }
| Self::SetEnv { ticket, .. } => Some(*ticket),
Self::Lambs { .. }
| Self::Action { .. }
| Self::Dog { .. }
| Self::SheepConfig { .. }
| Self::DogSection { .. } => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DogEdit {
pub name: String,
pub enable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DogProbe {
pub name: String,
pub adopted_path: Option<PathBuf>,
pub schema: serde_json::Value,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum RowKey {
Group(String),
Sheep(u32),
Section(&'static str),
Fold(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Grouping {
#[default]
Flat,
ByFold,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LambWalk {
Walked(Vec<Lamb>),
NotWalked,
Failed,
}
#[derive(Debug, Clone, Copy)]
pub struct LogSize {
pub(super) id: u32,
pub(super) total_bytes: Option<u64>,
}
#[derive(Debug, Clone)]
pub struct LambReading {
pub(super) id: u32,
pub(super) at: Instant,
pub(super) walk: LambWalk,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Notice {
pub(super) text: String,
pub(super) grave: bool,
}
impl Notice {
#[must_use]
pub fn is_grave(&self) -> bool {
self.grave
}
}
impl fmt::Display for Notice {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.text)
}
}