1use bytes::Bytes;
18use std::collections::HashMap;
19
20use crate::wit::WitInterface;
21
22#[derive(Debug, Clone, PartialEq)]
26pub struct Workload {
27 pub namespace: String,
28 pub name: String,
29 pub annotations: HashMap<String, String>,
30 pub service: Option<Service>,
31 pub components: Vec<Component>,
32 pub host_interfaces: Vec<WitInterface>,
33 pub volumes: Vec<Volume>,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
38pub enum WorkloadState {
39 Unspecified,
40 Starting,
41 Running,
42 Completed,
43 Stopping,
44 Error,
45}
46
47#[derive(Debug, Clone, PartialEq)]
50pub struct Service {
51 pub bytes: Bytes,
52 pub local_resources: LocalResources,
53 pub max_restarts: u64,
54}
55
56#[derive(Debug, Default, Clone, PartialEq)]
59pub struct Component {
60 pub bytes: Bytes,
61 pub local_resources: LocalResources,
62 pub pool_size: i32,
63 pub max_invocations: i32,
64}
65
66#[derive(Debug, Clone, PartialEq)]
69pub struct LocalResources {
70 pub memory_limit_mb: i32,
71 pub cpu_limit: i32,
72 pub config: HashMap<String, String>,
76 pub environment: HashMap<String, String>,
78 pub volume_mounts: Vec<VolumeMount>,
79 pub allowed_hosts: Vec<String>,
80}
81
82impl Default for LocalResources {
83 fn default() -> Self {
84 Self {
85 memory_limit_mb: -1,
86 cpu_limit: -1,
87 config: HashMap::new(),
88 environment: HashMap::new(),
89 volume_mounts: Vec::new(),
90 allowed_hosts: Vec::new(),
91 }
92 }
93}
94
95#[derive(Debug, Clone, PartialEq)]
97pub struct Volume {
98 pub name: String,
99 pub volume_type: VolumeType,
100}
101
102#[derive(Debug, Clone, PartialEq)]
104pub enum VolumeType {
105 HostPath(HostPathVolume),
106 EmptyDir(EmptyDirVolume),
107}
108
109#[derive(Debug, Clone, PartialEq)]
111pub struct VolumeMount {
112 pub name: String,
113 pub mount_path: String,
114 pub read_only: bool,
115}
116
117#[derive(Debug, Clone, PartialEq)]
119pub struct EmptyDirVolume {}
120
121#[derive(Debug, Clone, PartialEq)]
123pub struct HostPathVolume {
124 pub local_path: String,
125}
126
127#[derive(Debug, Clone, PartialEq)]
130pub struct HostHeartbeat {
131 pub id: String,
132 pub hostname: String,
133 pub friendly_name: String,
134 pub version: String,
135 pub labels: HashMap<String, String>,
136 pub started_at: chrono::DateTime<chrono::Utc>,
137 pub os_arch: String,
138 pub os_name: String,
139 pub os_kernel: String,
140 pub system_cpu_usage: f32,
142 pub system_memory_total: u64,
144 pub system_memory_free: u64,
146 pub component_count: u64,
147 pub workload_count: u64,
148 pub imports: Vec<WitInterface>,
149 pub exports: Vec<WitInterface>,
150}
151
152#[derive(Debug, Clone, PartialEq)]
154pub struct WorkloadStatus {
155 pub workload_id: String,
156 pub workload_state: WorkloadState,
157 pub message: String,
158}
159
160#[derive(Debug, Clone, PartialEq)]
162pub struct WorkloadStartRequest {
163 pub workload: Workload,
164}
165
166#[derive(Debug, Clone, PartialEq)]
168pub struct WorkloadStartResponse {
169 pub workload_status: WorkloadStatus,
170}
171
172#[derive(Debug, Clone, PartialEq)]
174pub struct WorkloadStatusRequest {
175 pub workload_id: String,
176}
177
178#[derive(Debug, Clone, PartialEq)]
180pub struct WorkloadStatusResponse {
181 pub workload_status: WorkloadStatus,
182}
183
184#[derive(Debug, Clone, PartialEq)]
186pub struct WorkloadStopRequest {
187 pub workload_id: String,
188}
189
190#[derive(Debug, Clone, PartialEq)]
192pub struct WorkloadStopResponse {
193 pub workload_status: WorkloadStatus,
194}