Skip to main content

canic_backup/restore/plan/
mod.rs

1//! Module: restore::plan
2//!
3//! Responsibility: build no-mutation restore plans from backup manifests.
4//! Does not own: artifact verification, command rendering, or restore execution.
5//! Boundary: maps manifest members and optional target mappings into ordered restore plans.
6
7mod error;
8mod mapping;
9mod members;
10mod ordering;
11mod summary;
12mod types;
13
14pub use error::RestorePlanError;
15pub use types::*;
16
17use crate::manifest::DeploymentBackupManifest;
18
19use mapping::{validate_mapping, validate_mapping_sources};
20use members::resolve_members;
21use ordering::{order_members, restore_ordering_summary};
22use summary::{
23    restore_identity_summary, restore_operation_summary, restore_readiness_summary,
24    restore_snapshot_summary, restore_verification_summary,
25};
26
27///
28/// RestorePlanner
29///
30/// Stateless planner for restore dry-run and apply workflows.
31/// Owned by restore planning and used by restore apply and runner callers.
32///
33
34pub struct RestorePlanner;
35
36impl RestorePlanner {
37    /// Build a no-mutation restore plan from the manifest and optional target mapping.
38    pub fn plan(
39        manifest: &DeploymentBackupManifest,
40        mapping: Option<&RestoreMapping>,
41    ) -> Result<RestorePlan, RestorePlanError> {
42        manifest.validate()?;
43        if let Some(mapping) = mapping {
44            validate_mapping(mapping)?;
45            validate_mapping_sources(manifest, mapping)?;
46        }
47
48        let members = resolve_members(manifest, mapping)?;
49        let identity_summary = restore_identity_summary(&members, mapping.is_some());
50        let snapshot_summary = restore_snapshot_summary(&members);
51        let verification_summary = restore_verification_summary(manifest, &members);
52        let readiness_summary = restore_readiness_summary(&snapshot_summary, &verification_summary);
53        let members = order_members(members)?;
54        let ordering_summary = restore_ordering_summary(&members);
55        let operation_summary =
56            restore_operation_summary(manifest.deployment.members.len(), &verification_summary);
57
58        Ok(RestorePlan {
59            backup_id: manifest.backup_id.clone(),
60            source_environment: manifest.source.environment.clone(),
61            source_root_canister: manifest.source.root_canister.clone(),
62            topology_hash: manifest.deployment.topology_hash.clone(),
63            member_count: manifest.deployment.members.len(),
64            identity_summary,
65            snapshot_summary,
66            verification_summary,
67            readiness_summary,
68            operation_summary,
69            ordering_summary,
70            deployment_verification_checks: manifest.verification.deployment_checks.clone(),
71            members,
72        })
73    }
74}