| 1 |
//! Regional Resource Balancer |
| 2 |
//! |
| 3 |
//! Balances resource allocation across geographic regions based on contribution and demand |
| 4 |
|
| 5 |
use anyhow::Result; |
| 6 |
use serde::{Deserialize, Serialize}; |
| 7 |
use std::collections::HashMap; |
| 8 |
use chrono::{DateTime, Utc}; |
| 9 |
|
| 10 |
/// Regional resource balancer for geographic distribution |
| 11 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 12 |
pub struct RegionalResourceBalancer { |
| 13 |
pub regional_allocations: HashMap<String, RegionalAllocation>, |
| 14 |
pub regional_metrics: HashMap<String, RegionalMetrics>, |
| 15 |
pub balancing_policies: Vec<RegionalPolicy>, |
| 16 |
} |
| 17 |
|
| 18 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 19 |
pub struct RegionalAllocation { |
| 20 |
pub region: String, |
| 21 |
pub total_capacity_gb: u64, |
| 22 |
pub allocated_capacity_gb: u64, |
| 23 |
pub active_nodes: u32, |
| 24 |
pub utilization_percent: f64, |
| 25 |
pub last_updated: DateTime<Utc>, |
| 26 |
} |
| 27 |
|
| 28 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 29 |
pub struct RegionalMetrics { |
| 30 |
pub region: String, |
| 31 |
pub average_latency_ms: u32, |
| 32 |
pub throughput_gbps: f64, |
| 33 |
pub reliability_score: f64, |
| 34 |
pub cost_efficiency: f64, |
| 35 |
} |
| 36 |
|
| 37 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 38 |
pub struct GeographicDistribution { |
| 39 |
pub optimal_regions: Vec<String>, |
| 40 |
pub current_distribution: HashMap<String, f64>, |
| 41 |
pub rebalancing_needed: bool, |
| 42 |
} |
| 43 |
|
| 44 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 45 |
pub struct RegionalPolicy { |
| 46 |
pub name: String, |
| 47 |
pub description: String, |
| 48 |
pub enabled: bool, |
| 49 |
} |
| 50 |
|
| 51 |
impl RegionalResourceBalancer { |
| 52 |
pub fn new() -> Self { |
| 53 |
Self { |
| 54 |
regional_allocations: HashMap::new(), |
| 55 |
regional_metrics: HashMap::new(), |
| 56 |
balancing_policies: Vec::new(), |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
impl Default for RegionalResourceBalancer { |
| 62 |
fn default() -> Self { |
| 63 |
Self::new() |
| 64 |
} |
| 65 |
} |