manta_server/service/hw_cluster/mod.rs
1//! Hardware cluster pin/unpin and hw-component add/delete service logic.
2//!
3//! Split into three (private) sub-modules:
4//!
5//! - `scoring` — pure-computation functions for component scarcity,
6//! per-node scoring, candidate selection, pattern parsing, and the
7//! parallel hw-inventory fetcher. Also hosts
8//! `resolve_hw_description_to_xnames`, which dispatches between
9//! pin and unpin.
10//! - `pin_unpin` — the `calculate_target_hsm_pin` / `_unpin` node
11//! selection algorithms plus the shared coordination helpers used
12//! by `apply_hw_configuration` (pattern parsing, target-group
13//! existence check, resource-sufficiency validation, group-update
14//! orchestration).
15//! - `apply` — high-level coordinators called by the server
16//! handlers: `apply_hw_configuration`, `add_hw_component`,
17//! `delete_hw_component`.
18//!
19//! Public types (`AddHwResult`, `DeleteHwResult`, `ApplyHwResult`,
20//! `NodeHwCountVec`, `HwClusterMode`) and shared constants live here
21//! so all three sub-modules can use them.
22
23use std::collections::HashMap;
24
25mod apply;
26mod pin_unpin;
27mod scoring;
28
29/// LCM (Least Common Multiple) used to normalise memory capacity values.
30/// Memory DIMMs come in multiples of 16 GiB (16384 MiB).
31pub(in crate::service::hw_cluster) const MEMORY_CAPACITY_LCM: u64 = 16384;
32
33/// Maximum number of concurrent hardware component queries.
34pub(in crate::service::hw_cluster) const HW_COMPONENT_CONCURRENCY_LIMIT: usize =
35 5;
36
37// ── Public types ────────────────────────────────────────────────────────────
38
39pub use manta_shared::shared::params::hw_cluster::HwClusterMode;
40
41/// A list of nodes paired with their per-component counts.
42pub type NodeHwCountVec = Vec<(String, HashMap<String, usize>)>;
43
44/// Result of an `add hw-component` operation.
45pub struct AddHwResult {
46 /// Xnames moved from the parent group into the target group as
47 /// part of this operation.
48 pub nodes_moved: Vec<String>,
49 /// Final membership of the target group after the move.
50 pub target_nodes: Vec<String>,
51 /// Final membership of the parent group after the move.
52 pub parent_nodes: Vec<String>,
53}
54
55/// Result of a `delete hw-component` operation.
56pub struct DeleteHwResult {
57 /// Xnames moved out of the target group and returned to the
58 /// parent group as part of this operation.
59 pub nodes_moved: Vec<String>,
60 /// Final membership of the target group after the move.
61 pub target_nodes: Vec<String>,
62 /// Final membership of the parent group after the move.
63 pub parent_nodes: Vec<String>,
64}
65
66/// Result of an `apply hw-configuration` (pin/unpin) operation.
67pub struct ApplyHwResult {
68 /// Final membership of the target group after pin/unpin completes.
69 pub target_nodes: Vec<String>,
70 /// Final membership of the parent group after pin/unpin completes.
71 pub parent_nodes: Vec<String>,
72}
73
74// ── External API (re-exported from sub-modules) ─────────────────────────────
75
76pub use apply::{
77 add_hw_component, apply_hw_configuration, delete_hw_component,
78};
79
80#[cfg(test)]
81mod tests;