Skip to main content

edge_computing/
models.rs

1//! Edge Computing models
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7/// Edge node status
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9pub enum NodeStatus {
10    Online,
11    Offline,
12    Maintenance,
13    Overloaded,
14}
15
16/// Edge node
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct EdgeNode {
19    pub id: Uuid,
20    pub name: String,
21    pub location: String,
22    pub endpoint: String,
23    pub status: NodeStatus,
24    pub capacity: NodeCapacity,
25    pub last_heartbeat: DateTime<Utc>,
26    pub metadata: serde_json::Value,
27}
28
29/// Node capacity
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct NodeCapacity {
32    pub cpu_cores: u32,
33    pub memory_mb: u64,
34    pub storage_gb: u64,
35    pub available_cpu: f64,
36    pub available_memory_mb: u64,
37    pub available_storage_gb: u64,
38}
39
40/// Edge task
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct EdgeTask {
43    pub id: Uuid,
44    pub task_type: TaskType,
45    pub payload: serde_json::Value,
46    pub priority: TaskPriority,
47    pub assigned_node: Option<Uuid>,
48    pub status: TaskStatus,
49    pub created_at: DateTime<Utc>,
50    pub started_at: Option<DateTime<Utc>>,
51    pub completed_at: Option<DateTime<Utc>>,
52    pub result: Option<serde_json::Value>,
53}
54
55/// Task type
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
57pub enum TaskType {
58    DataProcessing,
59    Analytics,
60    CacheUpdate,
61    Synchronization,
62    IotDataCollection,
63    RealTimeProcessing,
64}
65
66/// Task priority
67#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
68pub enum TaskPriority {
69    Low = 1,
70    Normal = 2,
71    High = 3,
72    Critical = 4,
73}
74
75/// Task status
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
77pub enum TaskStatus {
78    Pending,
79    Assigned,
80    Running,
81    Completed,
82    Failed,
83    Cancelled,
84}
85
86/// Sync operation
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct SyncOperation {
89    pub id: Uuid,
90    pub source_node: Uuid,
91    pub target_node: Uuid,
92    pub data_type: String,
93    pub data: serde_json::Value,
94    pub status: SyncStatus,
95    pub created_at: DateTime<Utc>,
96    pub completed_at: Option<DateTime<Utc>>,
97}
98
99/// Sync status
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
101pub enum SyncStatus {
102    Pending,
103    InProgress,
104    Completed,
105    Failed,
106}