Skip to main content

witchcraft_server/health/api/objects/
health_state.rs

1#![allow(deprecated)]
2use std::fmt;
3use std::str;
4#[derive(
5    Debug,
6    Clone,
7    PartialEq,
8    Eq,
9    PartialOrd,
10    Ord,
11    Hash,
12    conjure_object::serde::Deserialize,
13    conjure_object::serde::Serialize,
14)]
15#[serde(crate = "conjure_object::serde")]
16pub enum HealthState {
17    /// The service node is fully operational with no issues.
18    #[serde(rename = "HEALTHY")]
19    Healthy,
20    /// The service node is fully operational with no issues; however, it is requesting to defer shutdown or restart. A deferring node should not accept "new" jobs but should allow polling of existing jobs.
21    #[serde(rename = "DEFERRING")]
22    Deferring,
23    /// The service node is no longer serving requests and is ready to be shut down. Nodes in a deferring state are expected to change to a suspended state once they have completed any pending work. A suspended node must also indicate in its readiness probe that it should not receive incoming requests.
24    #[serde(rename = "SUSPENDED")]
25    Suspended,
26    /// The service node is operating in a degraded state, but is capable of automatically recovering. If any of the nodes in the service were to be restarted, it may result in correctness or consistency issues with the service. Ex: When a cassandra node decides it is not up-to-date and needs to repair, the node is operating in a degraded state. Restarting the node prior to the repair being complete might result in the service being unable to correctly respond to requests.
27    #[serde(rename = "REPAIRING")]
28    Repairing,
29    /// The service node is in a state that is trending towards an error. If no corrective action is taken, the health is expected to become an error.
30    #[serde(rename = "WARNING")]
31    Warning,
32    /// The service node is operationally unhealthy.
33    #[serde(rename = "ERROR")]
34    Error,
35    /// The service node has entered an unrecoverable state. All nodes of the service should be stopped and no automated attempt to restart the node should be made. Ex: a service fails to migrate to a new schema and is left in an unrecoverable state.
36    #[serde(rename = "TERMINAL")]
37    Terminal,
38}
39impl HealthState {
40    /// Returns the string representation of the enum.
41    #[inline]
42    pub fn as_str(&self) -> &str {
43        match self {
44            HealthState::Healthy => "HEALTHY",
45            HealthState::Deferring => "DEFERRING",
46            HealthState::Suspended => "SUSPENDED",
47            HealthState::Repairing => "REPAIRING",
48            HealthState::Warning => "WARNING",
49            HealthState::Error => "ERROR",
50            HealthState::Terminal => "TERMINAL",
51        }
52    }
53}
54impl fmt::Display for HealthState {
55    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
56        fmt::Display::fmt(self.as_str(), fmt)
57    }
58}
59impl conjure_object::Plain for HealthState {
60    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
61        conjure_object::Plain::fmt(self.as_str(), fmt)
62    }
63}
64impl str::FromStr for HealthState {
65    type Err = conjure_object::plain::ParseEnumError;
66    #[inline]
67    fn from_str(v: &str) -> Result<HealthState, conjure_object::plain::ParseEnumError> {
68        match v {
69            "HEALTHY" => Ok(HealthState::Healthy),
70            "DEFERRING" => Ok(HealthState::Deferring),
71            "SUSPENDED" => Ok(HealthState::Suspended),
72            "REPAIRING" => Ok(HealthState::Repairing),
73            "WARNING" => Ok(HealthState::Warning),
74            "ERROR" => Ok(HealthState::Error),
75            "TERMINAL" => Ok(HealthState::Terminal),
76            _ => Err(conjure_object::plain::ParseEnumError::new()),
77        }
78    }
79}
80impl conjure_object::FromPlain for HealthState {
81    type Err = conjure_object::plain::ParseEnumError;
82    #[inline]
83    fn from_plain(
84        v: &str,
85    ) -> Result<HealthState, conjure_object::plain::ParseEnumError> {
86        v.parse()
87    }
88}