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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Hardware-cluster pin/unpin and hw-component add/delete service logic.
//!
//! # Model
//!
//! CSM groups nodes into HSM groups. A *parent* group holds the
//! shared pool; a *target* group represents a sub-pool reserved for a
//! particular workload. "Pinning" moves nodes from the parent into
//! the target so that the target satisfies a user-supplied hardware
//! pattern (e.g. `a100:8,milan:2` — eight A100s and two Milan CPUs).
//! "Unpinning" is the reverse: nodes are released back to the parent.
//!
//! Both operations are framed as a search over candidate moves where
//! each candidate is scored by how *useful* a node is for the target
//! workload, with a scarcity weighting that prefers giving up common
//! components and keeping rare ones. See `scoring` for the rubric.
//!
//! # Layout
//!
//! Split into four (private) sub-modules plus shared types:
//!
//! - `scoring` — pure-computation functions for component scarcity,
//! per-node scoring, candidate selection, pattern parsing, and the
//! parallel hw-inventory fetcher. Also hosts
//! `resolve_hw_description_to_xnames`, which dispatches between
//! pin and unpin.
//! - `pin_unpin` — the `calculate_target_group_pin` / `_unpin` node
//! selection algorithms plus the shared coordination helpers used
//! by `apply_hw_configuration` (pattern parsing, target-group
//! existence check, resource-sufficiency validation, group-update
//! orchestration).
//! - `apply` — high-level coordinators called by the server
//! handlers: `apply_hw_configuration`, `add_hw_component`,
//! `delete_hw_component`.
//! - `hw_inventory_utils` — JSON-pointer helpers that extract memory,
//! processor, and accelerator data from raw HSM inventory payloads.
//!
//! Public types (`AddHwResult`, `DeleteHwResult`, `ApplyHwResult`,
//! `NodeHwCountVec`, `HwClusterMode`) and shared constants live here
//! so all sub-modules can use them. The public surface is re-exported
//! at the bottom of this file; callers (the `hw_cluster` handlers
//! under `crate::server::handlers`) should depend only on those
//! re-exports.
use HashMap;
/// LCM (Least Common Multiple) used to normalise memory capacity values.
/// Memory DIMMs come in multiples of 16 GiB (16384 MiB).
pub const MEMORY_CAPACITY_LCM: u64 = 16384;
/// Maximum number of concurrent hardware component queries.
pub const HW_COMPONENT_CONCURRENCY_LIMIT: usize =
5;
// ── Public types ────────────────────────────────────────────────────────────
pub use HwClusterMode;
/// A list of nodes paired with their per-component counts.
pub type NodeHwCountVec = ;
/// Result of an `add hw-component` operation.
/// Result of a `delete hw-component` operation.
/// Result of an `apply hw-configuration` (pin/unpin) operation.
// ── External API (re-exported from sub-modules) ─────────────────────────────
pub use ;