Skip to main content

canic_backup/plan/preflight/
requests.rs

1//! Module: plan::preflight::requests
2//!
3//! Responsibility: project backup plans into typed execution preflight requests.
4//! Does not own: request execution, receipt validation, or plan construction.
5//! Boundary: exposes immutable request views for external preflight providers.
6
7use crate::plan::{
8    BackupPlan, ControlAuthorityPreflightRequest, ControlAuthorityPreflightTarget,
9    QuiescencePreflightRequest, QuiescencePreflightTarget, SnapshotReadAuthorityPreflightRequest,
10    SnapshotReadAuthorityPreflightTarget, TopologyPreflightRequest, TopologyPreflightTarget,
11};
12
13impl BackupPlan {
14    /// Build the typed control-authority preflight request for this plan.
15    #[must_use]
16    pub fn control_authority_preflight_request(&self) -> ControlAuthorityPreflightRequest {
17        ControlAuthorityPreflightRequest {
18            plan_id: self.plan_id.clone(),
19            run_id: self.run_id.clone(),
20            fleet: self.fleet.clone(),
21            network: self.network.clone(),
22            root_canister_id: self.root_canister_id.clone(),
23            requires_root_controller: self.requires_root_controller,
24            targets: self
25                .targets
26                .iter()
27                .map(ControlAuthorityPreflightTarget::from)
28                .collect(),
29        }
30    }
31
32    /// Build the typed snapshot-read preflight request for this plan.
33    #[must_use]
34    pub fn snapshot_read_authority_preflight_request(
35        &self,
36    ) -> SnapshotReadAuthorityPreflightRequest {
37        SnapshotReadAuthorityPreflightRequest {
38            plan_id: self.plan_id.clone(),
39            run_id: self.run_id.clone(),
40            fleet: self.fleet.clone(),
41            network: self.network.clone(),
42            root_canister_id: self.root_canister_id.clone(),
43            targets: self
44                .targets
45                .iter()
46                .map(SnapshotReadAuthorityPreflightTarget::from)
47                .collect(),
48        }
49    }
50
51    /// Build the typed topology preflight request for this plan.
52    #[must_use]
53    pub fn topology_preflight_request(&self) -> TopologyPreflightRequest {
54        TopologyPreflightRequest {
55            plan_id: self.plan_id.clone(),
56            run_id: self.run_id.clone(),
57            fleet: self.fleet.clone(),
58            network: self.network.clone(),
59            root_canister_id: self.root_canister_id.clone(),
60            selected_subtree_root: self.selected_subtree_root.clone(),
61            selected_scope_kind: self.selected_scope_kind.clone(),
62            topology_hash_before_quiesce: self.topology_hash_before_quiesce.clone(),
63            targets: self
64                .targets
65                .iter()
66                .map(TopologyPreflightTarget::from)
67                .collect(),
68        }
69    }
70
71    /// Build the typed quiescence preflight request for this plan.
72    #[must_use]
73    pub fn quiescence_preflight_request(&self) -> QuiescencePreflightRequest {
74        QuiescencePreflightRequest {
75            plan_id: self.plan_id.clone(),
76            run_id: self.run_id.clone(),
77            fleet: self.fleet.clone(),
78            network: self.network.clone(),
79            root_canister_id: self.root_canister_id.clone(),
80            selected_subtree_root: self.selected_subtree_root.clone(),
81            quiescence_policy: self.quiescence_policy.clone(),
82            targets: self
83                .targets
84                .iter()
85                .map(QuiescencePreflightTarget::from)
86                .collect(),
87        }
88    }
89}