1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! The words for what a run is doing and where it stands, shared by the API, the record and the
//! event stream.
use std::fmt;
use serde::{Deserialize, Serialize};
/// An operation on a run.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Op {
/// Start the run.
Up,
/// Remove everything the run created.
Down,
/// Stop the run, keeping what it created.
Park,
/// Start a parked run again.
Resume,
/// Run the lab's checks.
Check,
/// Run the set-up again on running machines.
Provision,
}
impl Op {
/// The operation as written in events (`up`).
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Op::Up => "up",
Op::Down => "down",
Op::Park => "park",
Op::Resume => "resume",
Op::Check => "check",
Op::Provision => "provision",
}
}
/// The state a run is in while this operation runs.
pub(crate) fn during(self) -> Option<RunState> {
match self {
Op::Up => Some(RunState::Starting),
Op::Down => Some(RunState::Stopping),
Op::Park => Some(RunState::Parking),
Op::Resume => Some(RunState::Resuming),
Op::Check | Op::Provision => None,
}
}
}
impl fmt::Display for Op {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
/// Where a run stands.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum RunState {
/// Being started.
Starting,
/// Up, every target machine running.
Ready,
/// Something of it exists, but not every target machine runs (a failed start, a machine down).
Failed,
/// Being parked.
Parking,
/// Parked: stopped, what it created kept.
Parked,
/// Being resumed.
Resuming,
/// Being removed.
Stopping,
/// Nothing of it exists.
Absent,
}
impl RunState {
/// The state as written in events (`ready`).
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
RunState::Starting => "starting",
RunState::Ready => "ready",
RunState::Failed => "failed",
RunState::Parking => "parking",
RunState::Parked => "parked",
RunState::Resuming => "resuming",
RunState::Stopping => "stopping",
RunState::Absent => "absent",
}
}
}
impl fmt::Display for RunState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
/// How a run is parked: the manifest's `lifecycle.park.pause` or `.shutdown` steps.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Park {
/// Suspended, memory kept where the target can (Docker: stopped).
Pause,
/// Shut down.
Shutdown,
}
impl Park {
/// The mode as the manifest names it.
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Park::Pause => "pause",
Park::Shutdown => "shutdown",
}
}
}
impl fmt::Display for Park {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}