Skip to main content

rc_core/admin/
cluster.rs

1//! Cluster management type definitions
2//!
3//! This module contains data structures for cluster management operations
4//! including server information, disk status, and heal operations.
5
6use serde::{Deserialize, Serialize};
7use std::collections::{BTreeMap, HashMap};
8
9/// Server information representing a RustFS node
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct ServerInfo {
13    /// Server state (online, offline, initializing)
14    #[serde(default)]
15    pub state: String,
16
17    /// Server endpoint URL
18    #[serde(default)]
19    pub endpoint: String,
20
21    /// Connection scheme (http/https)
22    #[serde(default)]
23    pub scheme: String,
24
25    /// Uptime in seconds
26    #[serde(default)]
27    pub uptime: u64,
28
29    /// Server version
30    #[serde(default)]
31    pub version: String,
32
33    /// Git commit ID
34    #[serde(default, rename = "commitID")]
35    pub commit_id: String,
36
37    /// Network interfaces
38    #[serde(default)]
39    pub network: HashMap<String, String>,
40
41    /// Attached drives
42    #[serde(default, rename = "drives")]
43    pub disks: Vec<DiskInfo>,
44
45    /// Pool number
46    #[serde(default, rename = "poolNumber")]
47    pub pool_number: i32,
48
49    /// Memory statistics
50    #[serde(default, rename = "mem_stats")]
51    pub mem_stats: MemStats,
52}
53
54/// Disk information
55#[derive(Debug, Clone, Serialize, Deserialize, Default)]
56#[serde(rename_all = "camelCase")]
57pub struct DiskInfo {
58    /// Disk endpoint
59    #[serde(default)]
60    pub endpoint: String,
61
62    /// Whether this is a root disk
63    #[serde(default, rename = "rootDisk")]
64    pub root_disk: bool,
65
66    /// Drive path
67    #[serde(default, rename = "path")]
68    pub drive_path: String,
69
70    /// Whether healing is in progress
71    #[serde(default)]
72    pub healing: bool,
73
74    /// Whether scanning is in progress
75    #[serde(default)]
76    pub scanning: bool,
77
78    /// Disk state (online, offline)
79    #[serde(default)]
80    pub state: String,
81
82    /// Disk UUID
83    #[serde(default)]
84    pub uuid: String,
85
86    /// Total space in bytes
87    #[serde(default, rename = "totalspace")]
88    pub total_space: u64,
89
90    /// Used space in bytes
91    #[serde(default, rename = "usedspace")]
92    pub used_space: u64,
93
94    /// Available space in bytes
95    #[serde(default, rename = "availspace")]
96    pub available_space: u64,
97
98    /// Pool index
99    #[serde(default, alias = "pool_index")]
100    pub pool_index: i32,
101
102    /// Set index
103    #[serde(default, alias = "set_index")]
104    pub set_index: i32,
105
106    /// Disk index within set
107    #[serde(default, alias = "disk_index")]
108    pub disk_index: i32,
109
110    /// Healing info if disk is being healed
111    #[serde(default, skip_serializing_if = "Option::is_none")]
112    pub heal_info: Option<HealingDiskInfo>,
113}
114
115/// Healing disk information
116#[derive(Debug, Clone, Serialize, Deserialize, Default)]
117#[serde(rename_all = "camelCase")]
118pub struct HealingDiskInfo {
119    /// Heal ID
120    #[serde(default)]
121    pub id: String,
122
123    /// Heal session ID
124    #[serde(default)]
125    pub heal_id: String,
126
127    /// Pool index
128    #[serde(default)]
129    pub pool_index: Option<usize>,
130
131    /// Set index
132    #[serde(default)]
133    pub set_index: Option<usize>,
134
135    /// Disk index
136    #[serde(default)]
137    pub disk_index: Option<usize>,
138
139    /// Endpoint being healed
140    #[serde(default)]
141    pub endpoint: String,
142
143    /// Path being healed
144    #[serde(default)]
145    pub path: String,
146
147    /// Objects total count
148    #[serde(default)]
149    pub objects_total_count: u64,
150
151    /// Objects total size
152    #[serde(default)]
153    pub objects_total_size: u64,
154
155    /// Items healed count
156    #[serde(default)]
157    pub items_healed: u64,
158
159    /// Items failed count
160    #[serde(default)]
161    pub items_failed: u64,
162
163    /// Bytes done
164    #[serde(default)]
165    pub bytes_done: u64,
166
167    /// Whether healing is finished
168    #[serde(default)]
169    pub finished: bool,
170
171    /// Current bucket being healed
172    #[serde(default)]
173    pub bucket: String,
174
175    /// Current object being healed
176    #[serde(default)]
177    pub object: String,
178}
179
180/// Memory statistics
181#[derive(Debug, Clone, Serialize, Deserialize, Default)]
182pub struct MemStats {
183    /// Current allocated memory
184    #[serde(default)]
185    pub alloc: u64,
186
187    /// Total allocated memory over lifetime
188    #[serde(default)]
189    pub total_alloc: u64,
190
191    /// Heap allocated memory
192    #[serde(default)]
193    pub heap_alloc: u64,
194}
195
196/// Storage backend type
197#[derive(Debug, Clone, Serialize, Deserialize, Default)]
198#[serde(rename_all = "lowercase")]
199pub enum BackendType {
200    /// Filesystem backend (single drive)
201    #[default]
202    #[serde(rename = "FS")]
203    Fs,
204    /// Erasure coding backend (distributed)
205    #[serde(rename = "Erasure")]
206    Erasure,
207}
208
209impl std::fmt::Display for BackendType {
210    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
211        match self {
212            BackendType::Fs => write!(f, "FS"),
213            BackendType::Erasure => write!(f, "Erasure"),
214        }
215    }
216}
217
218/// Backend information
219#[derive(Debug, Clone, Serialize, Deserialize, Default)]
220#[serde(rename_all = "camelCase")]
221pub struct BackendInfo {
222    /// Backend type
223    #[serde(default, rename = "backendType")]
224    pub backend_type: BackendType,
225
226    /// Number of online disks
227    #[serde(default, rename = "onlineDisks")]
228    pub online_disks: usize,
229
230    /// Number of offline disks
231    #[serde(default, rename = "offlineDisks")]
232    pub offline_disks: usize,
233
234    /// Standard storage class parity
235    #[serde(default, rename = "standardSCParity")]
236    pub standard_sc_parity: Option<usize>,
237
238    /// Reduced redundancy storage class parity
239    #[serde(default, rename = "rrSCParity")]
240    pub rr_sc_parity: Option<usize>,
241
242    /// Total erasure sets
243    #[serde(default, rename = "totalSets")]
244    pub total_sets: Vec<usize>,
245
246    /// Drives per erasure set
247    #[serde(default, rename = "totalDrivesPerSet")]
248    pub drives_per_set: Vec<usize>,
249}
250
251/// Cluster usage statistics
252#[derive(Debug, Clone, Serialize, Deserialize, Default)]
253pub struct UsageInfo {
254    /// Total storage size in bytes
255    #[serde(default)]
256    pub size: u64,
257
258    /// Error message if any
259    #[serde(default, skip_serializing_if = "Option::is_none")]
260    pub error: Option<String>,
261}
262
263/// Bucket count information
264#[derive(Debug, Clone, Serialize, Deserialize, Default)]
265pub struct BucketsInfo {
266    /// Number of buckets
267    #[serde(default)]
268    pub count: u64,
269
270    /// Error message if any
271    #[serde(default, skip_serializing_if = "Option::is_none")]
272    pub error: Option<String>,
273}
274
275/// Object count information
276#[derive(Debug, Clone, Serialize, Deserialize, Default)]
277pub struct ObjectsInfo {
278    /// Number of objects
279    #[serde(default)]
280    pub count: u64,
281
282    /// Error message if any
283    #[serde(default, skip_serializing_if = "Option::is_none")]
284    pub error: Option<String>,
285}
286
287/// Pool erasure set metrics returned by cluster information.
288#[derive(Debug, Clone, Serialize, Deserialize, Default)]
289#[serde(rename_all = "camelCase")]
290pub struct PoolErasureSetInfo {
291    /// Erasure set ID within the pool.
292    #[serde(default)]
293    pub id: i32,
294
295    /// Raw used capacity in bytes.
296    #[serde(default, rename = "rawUsage")]
297    pub raw_usage: u64,
298
299    /// Raw total capacity in bytes.
300    #[serde(default, rename = "rawCapacity")]
301    pub raw_capacity: u64,
302
303    /// Object data usage in bytes.
304    #[serde(default)]
305    pub usage: u64,
306
307    /// Number of objects in the set.
308    #[serde(default, rename = "objectsCount")]
309    pub objects_count: u64,
310
311    /// Number of versions in the set.
312    #[serde(default, rename = "versionsCount")]
313    pub versions_count: u64,
314
315    /// Number of delete markers in the set.
316    #[serde(default, rename = "deleteMarkersCount")]
317    pub delete_markers_count: u64,
318
319    /// Number of healing disks in the set.
320    #[serde(default, rename = "healDisks")]
321    pub heal_disks: i32,
322}
323
324/// Complete cluster information response
325#[derive(Debug, Clone, Serialize, Deserialize, Default)]
326#[serde(rename_all = "camelCase")]
327pub struct ClusterInfo {
328    /// Deployment mode (distributed, standalone)
329    #[serde(default)]
330    pub mode: Option<String>,
331
332    /// Domain names
333    #[serde(default)]
334    pub domain: Option<Vec<String>>,
335
336    /// Region
337    #[serde(default)]
338    pub region: Option<String>,
339
340    /// Deployment ID
341    #[serde(default, rename = "deploymentID")]
342    pub deployment_id: Option<String>,
343
344    /// Bucket information
345    #[serde(default)]
346    pub buckets: Option<BucketsInfo>,
347
348    /// Object information
349    #[serde(default)]
350    pub objects: Option<ObjectsInfo>,
351
352    /// Storage usage
353    #[serde(default)]
354    pub usage: Option<UsageInfo>,
355
356    /// Backend information
357    #[serde(default)]
358    pub backend: Option<BackendInfo>,
359
360    /// Server information
361    #[serde(default)]
362    pub servers: Option<Vec<ServerInfo>>,
363
364    /// Pool metrics keyed by pool and erasure set index.
365    #[serde(default)]
366    pub pools: Option<BTreeMap<i32, BTreeMap<i32, PoolErasureSetInfo>>>,
367}
368
369impl ClusterInfo {
370    /// Get the total number of online disks across all servers
371    pub fn online_disks(&self) -> usize {
372        self.servers
373            .as_ref()
374            .map(|servers| {
375                servers
376                    .iter()
377                    .flat_map(|s| &s.disks)
378                    .filter(|d| d.state == "online" || d.state == "ok")
379                    .count()
380            })
381            .unwrap_or(0)
382    }
383
384    /// Get the total number of offline disks across all servers
385    pub fn offline_disks(&self) -> usize {
386        self.servers
387            .as_ref()
388            .map(|servers| {
389                servers
390                    .iter()
391                    .flat_map(|s| &s.disks)
392                    .filter(|d| d.state == "offline")
393                    .count()
394            })
395            .unwrap_or(0)
396    }
397
398    /// Get total storage capacity in bytes
399    pub fn total_capacity(&self) -> u64 {
400        self.servers
401            .as_ref()
402            .map(|servers| {
403                servers
404                    .iter()
405                    .flat_map(|s| &s.disks)
406                    .map(|d| d.total_space)
407                    .sum()
408            })
409            .unwrap_or(0)
410    }
411
412    /// Get used storage in bytes
413    pub fn used_capacity(&self) -> u64 {
414        self.servers
415            .as_ref()
416            .map(|servers| {
417                servers
418                    .iter()
419                    .flat_map(|s| &s.disks)
420                    .map(|d| d.used_space)
421                    .sum()
422            })
423            .unwrap_or(0)
424    }
425}
426
427/// Heal operation mode
428#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
429#[serde(rename_all = "lowercase")]
430pub enum HealScanMode {
431    /// Normal scan (default)
432    #[default]
433    Normal,
434    /// Deep scan (slower but more thorough)
435    Deep,
436}
437
438impl std::fmt::Display for HealScanMode {
439    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
440        match self {
441            HealScanMode::Normal => write!(f, "normal"),
442            HealScanMode::Deep => write!(f, "deep"),
443        }
444    }
445}
446
447impl std::str::FromStr for HealScanMode {
448    type Err = String;
449
450    fn from_str(s: &str) -> Result<Self, Self::Err> {
451        match s.to_lowercase().as_str() {
452            "normal" => Ok(HealScanMode::Normal),
453            "deep" => Ok(HealScanMode::Deep),
454            _ => Err(format!("Invalid heal scan mode: {s}")),
455        }
456    }
457}
458
459/// Request to start a heal operation
460#[derive(Debug, Clone, Serialize, Deserialize, Default)]
461#[serde(rename_all = "camelCase")]
462pub struct HealStartRequest {
463    /// Bucket to heal (empty for all buckets)
464    #[serde(default, skip_serializing_if = "Option::is_none")]
465    pub bucket: Option<String>,
466
467    /// Object prefix to heal
468    #[serde(default, skip_serializing_if = "Option::is_none")]
469    pub prefix: Option<String>,
470
471    /// Scan mode
472    #[serde(default)]
473    pub scan_mode: HealScanMode,
474
475    /// Whether to remove dangling objects
476    #[serde(default)]
477    pub remove: bool,
478
479    /// Whether to recreate missing data
480    #[serde(default)]
481    pub recreate: bool,
482
483    /// Dry run mode (don't actually heal)
484    #[serde(default)]
485    pub dry_run: bool,
486}
487
488/// Information about a single heal drive
489#[derive(Debug, Clone, Serialize, Deserialize, Default)]
490pub struct HealDriveInfo {
491    /// Drive UUID
492    #[serde(default)]
493    pub uuid: String,
494
495    /// Drive endpoint
496    #[serde(default)]
497    pub endpoint: String,
498
499    /// Drive state
500    #[serde(default)]
501    pub state: String,
502}
503
504/// Result of a heal operation on a single item
505#[derive(Debug, Clone, Serialize, Deserialize, Default)]
506#[serde(rename_all = "camelCase")]
507pub struct HealResultItem {
508    /// Result index
509    #[serde(default, rename = "resultId")]
510    pub result_index: usize,
511
512    /// Type of item healed (bucket, object, metadata)
513    #[serde(default, rename = "type")]
514    pub item_type: String,
515
516    /// Bucket name
517    #[serde(default)]
518    pub bucket: String,
519
520    /// Object key
521    #[serde(default)]
522    pub object: String,
523
524    /// Version ID
525    #[serde(default, rename = "versionId")]
526    pub version_id: String,
527
528    /// Detail message
529    #[serde(default)]
530    pub detail: String,
531
532    /// Number of parity blocks
533    #[serde(default, rename = "parityBlocks")]
534    pub parity_blocks: usize,
535
536    /// Number of data blocks
537    #[serde(default, rename = "dataBlocks")]
538    pub data_blocks: usize,
539
540    /// Object size
541    #[serde(default, rename = "objectSize")]
542    pub object_size: u64,
543
544    /// Drive info before healing
545    #[serde(default)]
546    pub before: HealDriveInfos,
547
548    /// Drive info after healing
549    #[serde(default)]
550    pub after: HealDriveInfos,
551}
552
553/// Collection of heal drive infos
554#[derive(Debug, Clone, Serialize, Deserialize, Default)]
555pub struct HealDriveInfos {
556    /// Drive information
557    #[serde(default)]
558    pub drives: Vec<HealDriveInfo>,
559}
560
561/// Status of a heal operation
562#[derive(Debug, Clone, Serialize, Deserialize, Default)]
563#[serde(rename_all = "camelCase")]
564pub struct HealStatus {
565    /// Heal ID
566    #[serde(default)]
567    pub heal_id: String,
568
569    /// Whether healing is in progress
570    #[serde(default)]
571    pub healing: bool,
572
573    /// Current bucket being healed
574    #[serde(default)]
575    pub bucket: String,
576
577    /// Current object being healed
578    #[serde(default)]
579    pub object: String,
580
581    /// Current scan mode reported by background healing
582    #[serde(default, skip_serializing_if = "Option::is_none")]
583    pub scan_mode: Option<HealScanMode>,
584
585    /// Background heal scan cycle
586    #[serde(default)]
587    pub scan_cycle: u64,
588
589    /// Number of queued heal tasks
590    #[serde(default)]
591    pub heal_queue_length: u64,
592
593    /// Number of active heal tasks
594    #[serde(default)]
595    pub heal_active_tasks: u64,
596
597    /// Number of items scanned
598    #[serde(default)]
599    pub items_scanned: u64,
600
601    /// Number of items healed
602    #[serde(default)]
603    pub items_healed: u64,
604
605    /// Number of items failed
606    #[serde(default)]
607    pub items_failed: u64,
608
609    /// Bytes scanned
610    #[serde(default)]
611    pub bytes_scanned: u64,
612
613    /// Bytes healed
614    #[serde(default)]
615    pub bytes_healed: u64,
616
617    /// Start time
618    #[serde(default)]
619    pub started: Option<String>,
620
621    /// Last update time
622    #[serde(default)]
623    pub last_update: Option<String>,
624}
625
626/// Request targeting a storage pool by command line or numeric ID.
627#[derive(Debug, Clone, Serialize, Deserialize, Default)]
628#[serde(rename_all = "camelCase")]
629pub struct PoolTarget {
630    /// Pool command line, or zero-based pool ID when `by_id` is true.
631    pub pool: String,
632
633    /// Interpret `pool` as a zero-based pool ID.
634    #[serde(default)]
635    pub by_id: bool,
636}
637
638/// Status of a server pool.
639#[derive(Debug, Clone, Serialize, Deserialize, Default)]
640pub struct PoolStatus {
641    /// Zero-based pool ID.
642    #[serde(default)]
643    pub id: usize,
644
645    /// Pool command line used by the server process.
646    #[serde(default, rename = "cmdline")]
647    pub cmd_line: String,
648
649    /// Last pool metadata update timestamp.
650    #[serde(default, rename = "lastUpdate")]
651    pub last_update: String,
652
653    /// Pool lifecycle status.
654    #[serde(default)]
655    pub status: String,
656
657    /// Decommission operation status for this pool.
658    #[serde(default, rename = "decommissionStatus")]
659    pub decommission_status: String,
660
661    /// Rebalance operation status for this pool.
662    #[serde(default, rename = "rebalanceStatus")]
663    pub rebalance_status: String,
664
665    /// Total pool size in bytes.
666    #[serde(default, rename = "totalSize")]
667    pub total_size: u64,
668
669    /// Current free size in bytes.
670    #[serde(default, rename = "currentSize")]
671    pub current_size: u64,
672
673    /// Used pool size in bytes.
674    #[serde(default, rename = "usedSize")]
675    pub used_size: u64,
676
677    /// Used capacity ratio in the range 0.0..=1.0.
678    #[serde(default)]
679    pub used: f64,
680
681    /// Decommission status and progress for this pool.
682    #[serde(default, rename = "decommissionInfo")]
683    pub decommission: Option<PoolDecommissionInfo>,
684}
685
686/// Decommission status response.
687#[derive(Debug, Clone, Serialize, Deserialize, Default)]
688pub struct DecommissionStatus {
689    /// Per-pool decommission status.
690    #[serde(default)]
691    pub pools: Vec<DecommissionPoolStatus>,
692}
693
694/// Decommission operation status for a single pool.
695#[derive(Debug, Clone, Serialize, Deserialize, Default)]
696pub struct DecommissionPoolStatus {
697    /// Zero-based pool ID.
698    #[serde(default)]
699    pub id: usize,
700
701    /// Pool command line used by the server process.
702    #[serde(default, rename = "cmdline")]
703    pub cmd_line: String,
704
705    /// Decommission operation status for this pool.
706    #[serde(default)]
707    pub status: String,
708
709    /// Pool lifecycle status.
710    #[serde(default, rename = "poolStatus")]
711    pub pool_status: String,
712
713    /// Decommission state and progress for this pool.
714    #[serde(default, rename = "decommissionInfo")]
715    pub decommission: Option<PoolDecommissionInfo>,
716}
717
718/// Decommission state and progress for a server pool.
719#[derive(Debug, Clone, Serialize, Deserialize, Default)]
720pub struct PoolDecommissionInfo {
721    /// Decommission start timestamp.
722    #[serde(default, rename = "startTime")]
723    pub start_time: Option<String>,
724
725    /// Free bytes when decommission started.
726    #[serde(default, rename = "startSize")]
727    pub start_size: u64,
728
729    /// Total pool size in bytes.
730    #[serde(default, rename = "totalSize")]
731    pub total_size: u64,
732
733    /// Current free size in bytes.
734    #[serde(default, rename = "currentSize")]
735    pub current_size: u64,
736
737    /// Whether decommission completed.
738    #[serde(default)]
739    pub complete: bool,
740
741    /// Whether decommission failed.
742    #[serde(default)]
743    pub failed: bool,
744
745    /// Whether decommission was canceled.
746    #[serde(default)]
747    pub canceled: bool,
748
749    /// Whether decommission is queued.
750    #[serde(default)]
751    pub queued: bool,
752
753    /// Buckets waiting to be decommissioned.
754    #[serde(default, rename = "queuedBuckets")]
755    pub queued_buckets: Vec<String>,
756
757    /// Buckets already decommissioned.
758    #[serde(default, rename = "decommissionedBuckets")]
759    pub decommissioned_buckets: Vec<String>,
760
761    /// Current bucket.
762    #[serde(default)]
763    pub bucket: String,
764
765    /// Current prefix.
766    #[serde(default)]
767    pub prefix: String,
768
769    /// Current object.
770    #[serde(default)]
771    pub object: String,
772
773    /// Current decommission stage.
774    #[serde(default)]
775    pub stage: String,
776
777    /// Number of successfully decommissioned objects.
778    #[serde(default, rename = "objectsDecommissioned")]
779    pub objects_decommissioned: u64,
780
781    /// Number of objects that failed to decommission.
782    #[serde(default, rename = "objectsDecommissionedFailed")]
783    pub objects_decommissioned_failed: u64,
784
785    /// Bytes successfully moved off the pool.
786    #[serde(default, rename = "bytesDecommissioned")]
787    pub bytes_decommissioned: u64,
788
789    /// Bytes that failed to move off the pool.
790    #[serde(default, rename = "bytesDecommissionedFailed")]
791    pub bytes_decommissioned_failed: u64,
792
793    /// Reason why decommission is waiting.
794    #[serde(default, rename = "waitingReason")]
795    pub waiting_reason: Option<String>,
796}
797
798/// Response from starting a rebalance operation.
799#[derive(Debug, Clone, Serialize, Deserialize, Default)]
800pub struct RebalanceStartResult {
801    /// Rebalance operation ID.
802    #[serde(default)]
803    pub id: String,
804}
805
806/// Cluster-wide rebalance status.
807#[derive(Debug, Clone, Serialize, Deserialize, Default)]
808pub struct RebalanceStatus {
809    /// Rebalance operation ID.
810    #[serde(default)]
811    pub id: String,
812
813    /// Per-pool rebalance status.
814    #[serde(default)]
815    pub pools: Vec<RebalancePoolStatus>,
816
817    /// Timestamp when rebalance was stopped.
818    #[serde(default, rename = "stoppedAt")]
819    pub stopped_at: Option<String>,
820}
821
822/// Rebalance status for a single pool.
823#[derive(Debug, Clone, Serialize, Deserialize, Default)]
824pub struct RebalancePoolStatus {
825    /// Zero-based pool ID.
826    #[serde(default)]
827    pub id: usize,
828
829    /// Rebalance status for this pool.
830    #[serde(default)]
831    pub status: String,
832
833    /// Used capacity ratio in the range 0.0..=1.0.
834    #[serde(default)]
835    pub used: f64,
836
837    /// Last rebalance error, if any.
838    #[serde(default, rename = "lastError")]
839    pub last_error: Option<String>,
840
841    /// Cleanup warnings observed after this pool finishes rebalance.
842    #[serde(default, rename = "cleanupWarnings")]
843    pub cleanup_warnings: RebalanceCleanupWarnings,
844
845    /// Rebalance progress, if this pool is active.
846    #[serde(default)]
847    pub progress: Option<RebalancePoolProgress>,
848}
849
850/// Cleanup warnings recorded for a rebalanced pool.
851#[derive(Debug, Clone, Serialize, Deserialize, Default)]
852pub struct RebalanceCleanupWarnings {
853    /// Number of cleanup warnings observed.
854    #[serde(default)]
855    pub count: u64,
856
857    /// Last cleanup warning message.
858    #[serde(default, rename = "lastMsg")]
859    pub last_message: Option<String>,
860
861    /// Bucket associated with the last cleanup warning.
862    #[serde(default, rename = "lastBucket")]
863    pub last_bucket: Option<String>,
864
865    /// Object associated with the last cleanup warning.
866    #[serde(default, rename = "lastObject")]
867    pub last_object: Option<String>,
868
869    /// Timestamp of the last cleanup warning.
870    #[serde(default, rename = "lastAt")]
871    pub last_at: Option<String>,
872}
873
874/// Rebalance progress for a single pool.
875#[derive(Debug, Clone, Serialize, Deserialize, Default)]
876pub struct RebalancePoolProgress {
877    /// Number of objects moved.
878    #[serde(default, rename = "objects")]
879    pub num_objects: u64,
880
881    /// Number of object versions moved.
882    #[serde(default, rename = "versions")]
883    pub num_versions: u64,
884
885    /// Number of bytes moved.
886    #[serde(default)]
887    pub bytes: u64,
888
889    /// Number of buckets remaining.
890    #[serde(default, rename = "remainingBuckets")]
891    pub remaining_buckets: usize,
892
893    /// Current bucket.
894    #[serde(default)]
895    pub bucket: String,
896
897    /// Current object.
898    #[serde(default)]
899    pub object: String,
900
901    /// Elapsed seconds.
902    #[serde(default)]
903    pub elapsed: u64,
904
905    /// Estimated seconds remaining.
906    #[serde(default)]
907    pub eta: u64,
908}
909
910#[cfg(test)]
911mod tests {
912    use super::*;
913
914    #[test]
915    fn test_backend_type_display() {
916        assert_eq!(BackendType::Fs.to_string(), "FS");
917        assert_eq!(BackendType::Erasure.to_string(), "Erasure");
918    }
919
920    #[test]
921    fn test_heal_scan_mode_display() {
922        assert_eq!(HealScanMode::Normal.to_string(), "normal");
923        assert_eq!(HealScanMode::Deep.to_string(), "deep");
924    }
925
926    #[test]
927    fn test_heal_scan_mode_from_str() {
928        assert_eq!(
929            "normal".parse::<HealScanMode>().unwrap(),
930            HealScanMode::Normal
931        );
932        assert_eq!("deep".parse::<HealScanMode>().unwrap(), HealScanMode::Deep);
933        assert!("invalid".parse::<HealScanMode>().is_err());
934    }
935
936    #[test]
937    fn test_cluster_info_default() {
938        let info = ClusterInfo::default();
939        assert!(info.mode.is_none());
940        assert!(info.servers.is_none());
941        assert_eq!(info.online_disks(), 0);
942        assert_eq!(info.offline_disks(), 0);
943    }
944
945    #[test]
946    fn test_cluster_info_disk_counts() {
947        let info = ClusterInfo {
948            servers: Some(vec![ServerInfo {
949                disks: vec![
950                    DiskInfo {
951                        state: "online".to_string(),
952                        ..Default::default()
953                    },
954                    DiskInfo {
955                        state: "online".to_string(),
956                        ..Default::default()
957                    },
958                    DiskInfo {
959                        state: "offline".to_string(),
960                        ..Default::default()
961                    },
962                ],
963                ..Default::default()
964            }]),
965            ..Default::default()
966        };
967
968        assert_eq!(info.online_disks(), 2);
969        assert_eq!(info.offline_disks(), 1);
970    }
971
972    #[test]
973    fn test_cluster_info_capacity() {
974        let info = ClusterInfo {
975            servers: Some(vec![ServerInfo {
976                disks: vec![
977                    DiskInfo {
978                        total_space: 1000,
979                        used_space: 300,
980                        ..Default::default()
981                    },
982                    DiskInfo {
983                        total_space: 2000,
984                        used_space: 500,
985                        ..Default::default()
986                    },
987                ],
988                ..Default::default()
989            }]),
990            ..Default::default()
991        };
992
993        assert_eq!(info.total_capacity(), 3000);
994        assert_eq!(info.used_capacity(), 800);
995    }
996
997    #[test]
998    fn test_disk_info_default() {
999        let disk = DiskInfo::default();
1000        assert!(disk.endpoint.is_empty());
1001        assert!(!disk.healing);
1002        assert!(!disk.scanning);
1003        assert_eq!(disk.total_space, 0);
1004    }
1005
1006    #[test]
1007    fn test_disk_info_deserializes_snake_case_location_indexes() {
1008        let json = r#"{"pool_index":1,"set_index":2,"disk_index":3}"#;
1009
1010        let disk: DiskInfo = serde_json::from_str(json).unwrap();
1011
1012        assert_eq!(disk.pool_index, 1);
1013        assert_eq!(disk.set_index, 2);
1014        assert_eq!(disk.disk_index, 3);
1015    }
1016
1017    #[test]
1018    fn test_server_info_default() {
1019        let server = ServerInfo::default();
1020        assert!(server.state.is_empty());
1021        assert!(server.endpoint.is_empty());
1022        assert_eq!(server.uptime, 0);
1023    }
1024
1025    #[test]
1026    fn test_heal_start_request_default() {
1027        let req = HealStartRequest::default();
1028        assert!(req.bucket.is_none());
1029        assert!(req.prefix.is_none());
1030        assert_eq!(req.scan_mode, HealScanMode::Normal);
1031        assert!(!req.remove);
1032        assert!(!req.dry_run);
1033    }
1034
1035    #[test]
1036    fn test_heal_status_default() {
1037        let status = HealStatus::default();
1038        assert!(status.heal_id.is_empty());
1039        assert!(!status.healing);
1040        assert!(status.scan_mode.is_none());
1041        assert_eq!(status.scan_cycle, 0);
1042        assert_eq!(status.heal_queue_length, 0);
1043        assert_eq!(status.heal_active_tasks, 0);
1044        assert_eq!(status.items_scanned, 0);
1045    }
1046
1047    #[test]
1048    fn test_pool_status_deserialization() {
1049        let json = r#"{"id":1,"cmdline":"/data/pool1/disk{1...4}","lastUpdate":"2026-05-06T00:00:00Z","status":"decommissioning","decommissionStatus":"running","rebalanceStatus":"none","totalSize":1000,"currentSize":600,"usedSize":400,"used":0.4,"decommissionInfo":{"startTime":"2026-05-06T00:00:01Z","startSize":100,"totalSize":1000,"currentSize":600,"complete":false,"failed":false,"canceled":false,"queued":true,"queuedBuckets":["bucket-a"],"decommissionedBuckets":["bucket-b"],"bucket":"bucket-a","prefix":"","object":"object.txt","stage":"migrate_object","objectsDecommissioned":2,"objectsDecommissionedFailed":1,"bytesDecommissioned":128,"bytesDecommissionedFailed":64,"waitingReason":"queued"}}"#;
1050
1051        let status: PoolStatus = serde_json::from_str(json).unwrap();
1052
1053        assert_eq!(status.id, 1);
1054        assert_eq!(status.cmd_line, "/data/pool1/disk{1...4}");
1055        assert_eq!(status.status, "decommissioning");
1056        assert_eq!(status.decommission_status, "running");
1057        assert_eq!(status.rebalance_status, "none");
1058        assert_eq!(status.used_size, 400);
1059        let info = status.decommission.expect("decommission info exists");
1060        assert!(info.queued);
1061        assert_eq!(info.queued_buckets, vec!["bucket-a"]);
1062        assert_eq!(info.bucket, "bucket-a");
1063        assert_eq!(info.object, "object.txt");
1064        assert_eq!(info.waiting_reason.as_deref(), Some("queued"));
1065        assert_eq!(info.objects_decommissioned, 2);
1066        assert_eq!(info.bytes_decommissioned_failed, 64);
1067    }
1068
1069    #[test]
1070    fn test_decommission_status_deserialization() {
1071        let json = r#"{"pools":[{"id":2,"cmdline":"/data/pool2/disk{1...4}","status":"failed","poolStatus":"blocked","decommissionInfo":{"failed":true,"totalSize":1000,"currentSize":900}}]}"#;
1072
1073        let status: DecommissionStatus = serde_json::from_str(json).unwrap();
1074
1075        assert_eq!(status.pools.len(), 1);
1076        assert_eq!(status.pools[0].id, 2);
1077        assert_eq!(status.pools[0].status, "failed");
1078        assert_eq!(status.pools[0].pool_status, "blocked");
1079        assert!(
1080            status.pools[0]
1081                .decommission
1082                .as_ref()
1083                .is_some_and(|info| info.failed)
1084        );
1085    }
1086
1087    #[test]
1088    fn test_rebalance_status_deserialization() {
1089        let json = r#"{"id":"rebalance-1","pools":[{"id":0,"status":"Started","used":0.5,"lastError":null,"cleanupWarnings":{"count":1,"lastMsg":"cleanup warning","lastBucket":"bucket","lastObject":"object","lastAt":"2026-06-12T00:00:00Z"},"progress":{"objects":3,"versions":4,"bytes":1024,"remainingBuckets":2,"bucket":"bucket","object":"object","elapsed":10,"eta":20}}],"stoppedAt":null}"#;
1090
1091        let status: RebalanceStatus = serde_json::from_str(json).unwrap();
1092
1093        assert_eq!(status.id, "rebalance-1");
1094        assert_eq!(status.pools.len(), 1);
1095        assert_eq!(status.pools[0].used, 0.5);
1096        assert_eq!(status.pools[0].cleanup_warnings.count, 1);
1097        assert_eq!(
1098            status.pools[0].cleanup_warnings.last_message.as_deref(),
1099            Some("cleanup warning")
1100        );
1101        let progress = status.pools[0]
1102            .progress
1103            .as_ref()
1104            .expect("progress should exist");
1105        assert_eq!(progress.num_objects, 3);
1106        assert_eq!(progress.remaining_buckets, 2);
1107    }
1108
1109    #[test]
1110    fn test_rebalance_status_defaults_cleanup_warnings() {
1111        let json = r#"{"id":"rebalance-1","pools":[{"id":0,"status":"Completed","used":0.5,"lastError":null,"progress":null}],"stoppedAt":null}"#;
1112
1113        let status: RebalanceStatus = serde_json::from_str(json).unwrap();
1114
1115        assert_eq!(status.pools[0].cleanup_warnings.count, 0);
1116        assert_eq!(status.pools[0].cleanup_warnings.last_message, None);
1117    }
1118
1119    #[test]
1120    fn test_serialization() {
1121        let info = ClusterInfo {
1122            mode: Some("distributed".to_string()),
1123            deployment_id: Some("test-123".to_string()),
1124            ..Default::default()
1125        };
1126
1127        let json = serde_json::to_string(&info).unwrap();
1128        assert!(json.contains("distributed"));
1129        assert!(json.contains("test-123"));
1130
1131        let deserialized: ClusterInfo = serde_json::from_str(&json).unwrap();
1132        assert_eq!(deserialized.mode, Some("distributed".to_string()));
1133    }
1134}