1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//!
//! # Resource Master
//!
//! This module act as the global controller, all resoures are under its management.
//!

use crate::model::{Env, EnvId, Vm, VmId};
use lazy_static::lazy_static;
use parking_lot::RwLock;
use std::{
    collections::{HashMap, HashSet},
    sync::Arc,
};

lazy_static! {
    /// Global entrypoint.
    pub static ref SERV: Arc<Service> = Arc::new(Service::default());
}

/// Alias of client ID.
pub type UserId = String;

/// Service is a global data collection.
#[derive(Default)]
pub struct Service {
    #[allow(missing_docs)]
    pub user_to_env: Arc<RwLock<HashMap<UserId, HashSet<EnvId>>>>,
    #[allow(missing_docs)]
    pub all_env: Arc<RwLock<HashMap<EnvId, Env>>>,
    #[allow(missing_docs)]
    pub all_vm: Arc<RwLock<HashMap<VmId, Vm>>>,
}