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 hw_inventory_utils;
27mod pin_unpin;
28mod scoring;
29
30/// LCM (Least Common Multiple) used to normalise memory capacity values.
31/// Memory DIMMs come in multiples of 16 GiB (16384 MiB).
32pub(in crate::service::hw_cluster) const MEMORY_CAPACITY_LCM: u64 = 16384;
33
34/// Maximum number of concurrent hardware component queries.
35pub(in crate::service::hw_cluster) const HW_COMPONENT_CONCURRENCY_LIMIT: usize =
36  5;
37
38// ── Public types ────────────────────────────────────────────────────────────
39
40pub use manta_shared::types::api::hw_cluster::HwClusterMode;
41
42/// A list of nodes paired with their per-component counts.
43pub type NodeHwCountVec = Vec<(String, HashMap<String, usize>)>;
44
45/// Result of an `add hw-component` operation.
46pub struct AddHwResult {
47  /// Xnames moved from the parent group into the target group as
48  /// part of this operation.
49  pub nodes_moved: Vec<String>,
50  /// Final membership of the target group after the move.
51  pub target_nodes: Vec<String>,
52  /// Final membership of the parent group after the move.
53  pub parent_nodes: Vec<String>,
54}
55
56/// Result of a `delete hw-component` operation.
57pub struct DeleteHwResult {
58  /// Xnames moved out of the target group and returned to the
59  /// parent group as part of this operation.
60  pub nodes_moved: Vec<String>,
61  /// Final membership of the target group after the move.
62  pub target_nodes: Vec<String>,
63  /// Final membership of the parent group after the move.
64  pub parent_nodes: Vec<String>,
65}
66
67/// Result of an `apply hw-configuration` (pin/unpin) operation.
68pub struct ApplyHwResult {
69  /// Final membership of the target group after pin/unpin completes.
70  pub target_nodes: Vec<String>,
71  /// Final membership of the parent group after pin/unpin completes.
72  pub parent_nodes: Vec<String>,
73}
74
75// ── External API (re-exported from sub-modules) ─────────────────────────────
76
77pub use apply::{
78  ApplyHwConfigurationParams, add_hw_component, apply_hw_configuration,
79  delete_hw_component,
80};
81
82#[cfg(test)]
83mod tests;