use bytes::Bytes;
use std::collections::HashMap;
use crate::wit::WitInterface;
#[derive(Debug, Clone, PartialEq)]
pub struct Workload {
pub namespace: String,
pub name: String,
pub annotations: HashMap<String, String>,
pub service: Option<Service>,
pub components: Vec<Component>,
pub host_interfaces: Vec<WitInterface>,
pub volumes: Vec<Volume>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WorkloadState {
Unspecified,
Starting,
Running,
Completed,
Stopping,
Error,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Service {
pub bytes: Bytes,
pub local_resources: LocalResources,
pub max_restarts: u64,
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Component {
pub bytes: Bytes,
pub local_resources: LocalResources,
pub pool_size: i32,
pub max_invocations: i32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalResources {
pub memory_limit_mb: i32,
pub cpu_limit: i32,
pub config: HashMap<String, String>,
pub environment: HashMap<String, String>,
pub volume_mounts: Vec<VolumeMount>,
pub allowed_hosts: Vec<String>,
}
impl Default for LocalResources {
fn default() -> Self {
Self {
memory_limit_mb: -1,
cpu_limit: -1,
config: HashMap::new(),
environment: HashMap::new(),
volume_mounts: Vec::new(),
allowed_hosts: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Volume {
pub name: String,
pub volume_type: VolumeType,
}
#[derive(Debug, Clone, PartialEq)]
pub enum VolumeType {
HostPath(HostPathVolume),
EmptyDir(EmptyDirVolume),
}
#[derive(Debug, Clone, PartialEq)]
pub struct VolumeMount {
pub name: String,
pub mount_path: String,
pub read_only: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EmptyDirVolume {}
#[derive(Debug, Clone, PartialEq)]
pub struct HostPathVolume {
pub local_path: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HostHeartbeat {
pub id: String,
pub hostname: String,
pub friendly_name: String,
pub version: String,
pub labels: HashMap<String, String>,
pub started_at: chrono::DateTime<chrono::Utc>,
pub os_arch: String,
pub os_name: String,
pub os_kernel: String,
pub system_cpu_usage: f32,
pub system_memory_total: u64,
pub system_memory_free: u64,
pub component_count: u64,
pub workload_count: u64,
pub imports: Vec<WitInterface>,
pub exports: Vec<WitInterface>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStatus {
pub workload_id: String,
pub workload_state: WorkloadState,
pub message: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStartRequest {
pub workload: Workload,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStartResponse {
pub workload_status: WorkloadStatus,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStatusRequest {
pub workload_id: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStatusResponse {
pub workload_status: WorkloadStatus,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStopRequest {
pub workload_id: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WorkloadStopResponse {
pub workload_status: WorkloadStatus,
}