llm_optimizer_processor/actuator/
error.rs1use thiserror::Error;
4
5pub type ActuatorResult<T> = Result<T, ActuatorError>;
7
8#[derive(Error, Debug, Clone, PartialEq)]
10pub enum ActuatorError {
11 #[error("Configuration error: {0}")]
13 ConfigError(String),
14
15 #[error("Deployment failed: {0}")]
17 DeploymentFailed(String),
18
19 #[error("Rollback failed: {0}")]
21 RollbackFailed(String),
22
23 #[error("Health check failed: {0}")]
25 HealthCheckFailed(String),
26
27 #[error("Validation failed: {0}")]
29 ValidationFailed(String),
30
31 #[error("Traffic splitting error: {0}")]
33 TrafficSplitError(String),
34
35 #[error("State error: {0}")]
37 StateError(String),
38
39 #[error("Actuator is not running")]
41 NotRunning,
42
43 #[error("Invalid state transition from {from:?} to {to:?}")]
45 InvalidStateTransition {
46 from: ActuatorState,
47 to: ActuatorState,
48 },
49
50 #[error("Operation timeout after {0}ms")]
52 Timeout(u64),
53
54 #[error("Internal error: {0}")]
56 Internal(String),
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
61pub enum ActuatorState {
62 Initialized,
64 Starting,
66 Running,
68 Deploying,
70 RollingBack,
72 Draining,
74 Stopped,
76 Failed,
78}
79
80impl ActuatorState {
81 pub fn can_deploy(&self) -> bool {
83 matches!(self, ActuatorState::Running)
84 }
85
86 pub fn can_rollback(&self) -> bool {
88 matches!(self, ActuatorState::Running | ActuatorState::Deploying)
89 }
90
91 pub fn can_transition_to(&self, to: ActuatorState) -> bool {
93 use ActuatorState::*;
94 matches!(
95 (self, to),
96 (Initialized, Starting)
97 | (Starting, Running)
98 | (Starting, Failed)
99 | (Running, Deploying)
100 | (Running, RollingBack)
101 | (Running, Draining)
102 | (Running, Failed)
103 | (Deploying, Running)
104 | (Deploying, RollingBack)
105 | (Deploying, Failed)
106 | (RollingBack, Running)
107 | (RollingBack, Failed)
108 | (Draining, Stopped)
109 | (Draining, Failed)
110 | (Failed, Initialized)
111 )
112 }
113}
114
115#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
117pub enum DeploymentState {
118 Pending,
120 Validating,
122 RollingOut,
124 Monitoring,
126 Completed,
128 RollingBack,
130 RolledBack,
132 Failed,
134}
135
136impl DeploymentState {
137 pub fn is_terminal(&self) -> bool {
139 matches!(
140 self,
141 DeploymentState::Completed
142 | DeploymentState::RolledBack
143 | DeploymentState::Failed
144 )
145 }
146
147 pub fn can_rollback(&self) -> bool {
149 matches!(
150 self,
151 DeploymentState::RollingOut | DeploymentState::Monitoring
152 )
153 }
154}
155
156impl std::fmt::Display for DeploymentState {
157 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
158 match self {
159 DeploymentState::Pending => write!(f, "Pending"),
160 DeploymentState::Validating => write!(f, "Validating"),
161 DeploymentState::RollingOut => write!(f, "RollingOut"),
162 DeploymentState::Monitoring => write!(f, "Monitoring"),
163 DeploymentState::Completed => write!(f, "Completed"),
164 DeploymentState::RollingBack => write!(f, "RollingBack"),
165 DeploymentState::RolledBack => write!(f, "RolledBack"),
166 DeploymentState::Failed => write!(f, "Failed"),
167 }
168 }
169}