harn_cli/commands/orchestrator/harness/
config.rs1use std::net::SocketAddr;
4use std::path::PathBuf;
5use std::sync::Arc;
6use std::time::Duration;
7
8use harn_vm::clock::{Clock, RealClock};
9
10use super::super::errors::OrchestratorError;
11use super::super::role::OrchestratorRole;
12use super::super::tls::TlsFiles;
13
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
18pub struct DrainConfig {
19 pub max_items: usize,
20 pub deadline: Duration,
21}
22
23impl Default for DrainConfig {
24 fn default() -> Self {
25 Self {
26 max_items: crate::package::default_orchestrator_drain_max_items(),
27 deadline: Duration::from_secs(
28 crate::package::default_orchestrator_drain_deadline_seconds(),
29 ),
30 }
31 }
32}
33
34#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub struct PumpConfig {
37 pub max_outstanding: usize,
38}
39
40impl Default for PumpConfig {
41 fn default() -> Self {
42 Self {
43 max_outstanding: crate::package::default_orchestrator_pump_max_outstanding(),
44 }
45 }
46}
47
48#[derive(Clone, Debug)]
50pub struct OrchestratorConfig {
51 pub manifest_path: PathBuf,
52 pub state_dir: PathBuf,
53 pub bind: SocketAddr,
54 pub role: OrchestratorRole,
55 pub watch_manifest: bool,
56 pub mcp: bool,
57 pub mcp_path: String,
58 pub tls: Option<TlsFiles>,
59 pub shutdown_timeout: Duration,
60 pub drain: DrainConfig,
61 pub pump: PumpConfig,
62 pub log_format: Option<harn_vm::observability::otel::LogFormat>,
65 pub clock: Arc<dyn Clock>,
68 pub public_metrics: bool,
74}
75
76impl OrchestratorConfig {
77 pub fn for_test(manifest_path: PathBuf, state_dir: PathBuf) -> Self {
79 Self {
80 manifest_path,
81 state_dir,
82 bind: "127.0.0.1:0".parse().unwrap(),
83 role: OrchestratorRole::SingleTenant,
84 watch_manifest: false,
85 mcp: false,
86 mcp_path: "/mcp".to_string(),
87 tls: None,
88 shutdown_timeout: Duration::from_secs(5),
89 drain: DrainConfig::default(),
90 pump: PumpConfig::default(),
91 log_format: None,
92 clock: RealClock::arc(),
93 public_metrics: false,
94 }
95 }
96
97 pub fn with_clock(mut self, clock: Arc<dyn Clock>) -> Self {
102 self.clock = clock;
103 self
104 }
105}
106
107#[derive(Debug)]
111pub struct ShutdownReport {
112 #[allow(dead_code)]
113 pub timed_out: bool,
114}
115
116#[derive(Debug)]
118pub struct HarnessError(pub String);
119
120impl std::fmt::Display for HarnessError {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 f.write_str(&self.0)
123 }
124}
125
126impl From<OrchestratorError> for HarnessError {
127 fn from(error: OrchestratorError) -> Self {
128 HarnessError(error.to_string())
129 }
130}
131
132impl From<String> for HarnessError {
133 fn from(s: String) -> Self {
134 HarnessError(s)
135 }
136}