use crate::id::types::{ChildId, SupervisorPath};
use crate::shutdown::coordinator::ShutdownResult;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct CommandId {
pub value: Uuid,
}
impl CommandId {
pub fn new() -> Self {
Self {
value: Uuid::new_v4(),
}
}
}
impl Default for CommandId {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CommandMeta {
pub command_id: CommandId,
pub requested_by: String,
pub reason: String,
}
impl CommandMeta {
pub fn new(requested_by: impl Into<String>, reason: impl Into<String>) -> Self {
Self {
command_id: CommandId::new(),
requested_by: requested_by.into(),
reason: reason.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ControlCommand {
AddChild {
meta: CommandMeta,
target: SupervisorPath,
child_manifest: String,
},
RemoveChild {
meta: CommandMeta,
child_id: ChildId,
},
RestartChild {
meta: CommandMeta,
child_id: ChildId,
},
PauseChild {
meta: CommandMeta,
child_id: ChildId,
},
ResumeChild {
meta: CommandMeta,
child_id: ChildId,
},
QuarantineChild {
meta: CommandMeta,
child_id: ChildId,
},
ShutdownTree {
meta: CommandMeta,
},
CurrentState {
meta: CommandMeta,
},
}
impl ControlCommand {
pub fn meta(&self) -> &CommandMeta {
match self {
Self::AddChild { meta, .. }
| Self::RemoveChild { meta, .. }
| Self::RestartChild { meta, .. }
| Self::PauseChild { meta, .. }
| Self::ResumeChild { meta, .. }
| Self::QuarantineChild { meta, .. }
| Self::ShutdownTree { meta }
| Self::CurrentState { meta } => meta,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ManagedChildState {
Running,
Paused,
Quarantined,
Removed,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CurrentState {
pub child_count: usize,
pub shutdown_completed: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum CommandResult {
ChildAdded {
child_manifest: String,
},
ChildState {
child_id: ChildId,
state: ManagedChildState,
idempotent: bool,
},
CurrentState {
state: CurrentState,
},
Shutdown {
result: ShutdownResult,
},
}