Skip to main content

llm_optimizer_processor/actuator/
traits.rs

1//! Actuator core traits
2
3use async_trait::async_trait;
4
5use super::error::{ActuatorError, ActuatorResult, ActuatorState};
6use super::types::{
7    ActuatorStats, DeploymentRequest, DeploymentStatus, HealthCheckResult, RollbackRequest,
8    RollbackResult, SystemMetrics,
9};
10use crate::decision::Decision;
11
12/// Core trait for the Actuator
13#[async_trait]
14pub trait Actuator: Send + Sync {
15    /// Get the name of this actuator
16    fn name(&self) -> &str;
17
18    /// Get the current state
19    fn state(&self) -> ActuatorState;
20
21    /// Start the actuator
22    async fn start(&mut self) -> ActuatorResult<()>;
23
24    /// Stop the actuator
25    async fn stop(&mut self) -> ActuatorResult<()>;
26
27    /// Execute a deployment
28    ///
29    /// # Arguments
30    /// * `request` - Deployment request with decision and strategy
31    ///
32    /// # Returns
33    /// Deployment status
34    async fn deploy(&mut self, request: DeploymentRequest) -> ActuatorResult<DeploymentStatus>;
35
36    /// Get deployment status
37    async fn get_deployment_status(&self, deployment_id: &str) -> ActuatorResult<DeploymentStatus>;
38
39    /// Rollback a deployment
40    async fn rollback(&mut self, request: RollbackRequest) -> ActuatorResult<RollbackResult>;
41
42    /// Health check
43    async fn health_check(&self) -> ActuatorResult<Vec<HealthCheckResult>>;
44
45    /// Get statistics
46    fn get_stats(&self) -> ActuatorStats;
47
48    /// Reset the actuator
49    async fn reset(&mut self) -> ActuatorResult<()>;
50}
51
52/// Trait for canary deployment
53#[async_trait]
54pub trait CanaryDeployment: Send + Sync {
55    /// Start a canary deployment
56    async fn start_canary(
57        &mut self,
58        request: DeploymentRequest,
59    ) -> ActuatorResult<DeploymentStatus>;
60
61    /// Promote to next canary phase
62    async fn promote(&mut self, deployment_id: &str) -> ActuatorResult<DeploymentStatus>;
63
64    /// Complete canary deployment (promote to 100%)
65    async fn complete(&mut self, deployment_id: &str) -> ActuatorResult<DeploymentStatus>;
66
67    /// Abort canary deployment
68    async fn abort(&mut self, deployment_id: &str) -> ActuatorResult<RollbackResult>;
69
70    /// Get current canary status
71    async fn get_status(&self, deployment_id: &str) -> ActuatorResult<DeploymentStatus>;
72
73    /// Check if phase can be promoted
74    async fn can_promote(&self, deployment_id: &str) -> ActuatorResult<bool>;
75}
76
77/// Trait for health monitoring
78#[async_trait]
79pub trait HealthMonitor: Send + Sync {
80    /// Perform health checks
81    async fn check_health(
82        &self,
83        deployment_id: &str,
84        metrics: &SystemMetrics,
85    ) -> ActuatorResult<Vec<HealthCheckResult>>;
86
87    /// Check if deployment should be rolled back
88    async fn should_rollback(
89        &self,
90        deployment_id: &str,
91        status: &DeploymentStatus,
92    ) -> ActuatorResult<bool>;
93
94    /// Get health status summary
95    async fn get_health_summary(
96        &self,
97        deployment_id: &str,
98    ) -> ActuatorResult<super::types::HealthStatus>;
99}
100
101/// Trait for configuration management
102#[async_trait]
103pub trait ConfigurationManager: Send + Sync {
104    /// Apply configuration changes
105    async fn apply_config(
106        &mut self,
107        changes: &[crate::decision::ConfigChange],
108    ) -> ActuatorResult<()>;
109
110    /// Revert configuration changes
111    async fn revert_config(
112        &mut self,
113        changes: &[crate::decision::ConfigChange],
114    ) -> ActuatorResult<()>;
115
116    /// Create configuration snapshot
117    async fn create_snapshot(&mut self) -> ActuatorResult<super::types::ConfigurationSnapshot>;
118
119    /// Restore from snapshot
120    async fn restore_snapshot(&mut self, snapshot_id: &str) -> ActuatorResult<()>;
121
122    /// Get current configuration
123    async fn get_config(&self) -> ActuatorResult<std::collections::HashMap<String, serde_json::Value>>;
124
125    /// Validate configuration
126    async fn validate_config(
127        &self,
128        changes: &[crate::decision::ConfigChange],
129    ) -> ActuatorResult<()>;
130}
131
132/// Trait for traffic splitting
133#[async_trait]
134pub trait TrafficSplitter: Send + Sync {
135    /// Route request to canary or control
136    async fn route_request(&self, request_id: &str, canary_percent: f64) -> ActuatorResult<bool>;
137
138    /// Get current routing statistics
139    fn get_routing_stats(&self) -> std::collections::HashMap<String, u64>;
140}