canic_host/installed_fleet/
mod.rs1use crate::{
2 fleet_catalog::{FleetCatalogEntryV1, FleetCatalogError, read_fleet_catalog_entry_from_root},
3 registry::RegistryEntry,
4};
5use std::{collections::BTreeMap, path::Path};
6use thiserror::Error as ThisError;
7
8#[derive(Clone, Debug, Eq, PartialEq)]
13pub struct InstalledFleetRequest {
14 pub fleet: String,
15 pub environment: String,
16}
17
18#[derive(Clone, Debug, Eq, PartialEq)]
23pub struct InstalledFleetResolution {
24 pub source: InstalledFleetSource,
25 pub fleet: FleetCatalogEntryV1,
26 pub registry: InstalledFleetRegistry,
27 pub topology: ResolvedFleetTopology,
28}
29
30#[derive(Clone, Copy, Debug, Eq, PartialEq)]
35pub enum InstalledFleetSource {
36 LocalReplica,
37 IcpCli,
38}
39
40#[derive(Clone, Debug, Eq, PartialEq)]
45pub struct InstalledFleetRegistry {
46 pub root_canister_id: String,
47 pub entries: Vec<RegistryEntry>,
48}
49
50#[derive(Clone, Debug, Eq, PartialEq)]
55pub struct ResolvedFleetTopology {
56 pub root_canister_id: String,
57 pub children_by_parent: BTreeMap<Option<String>, Vec<String>>,
58 pub roles_by_canister: BTreeMap<String, String>,
59}
60
61#[derive(Debug, ThisError)]
66pub enum InstalledFleetError {
67 #[error("Fleet {fleet} is not installed on environment {environment}")]
68 NoInstalledFleet { environment: String, fleet: String },
69
70 #[error("failed to read the canonical-network Fleet catalog: {0}")]
71 FleetCatalog(#[from] FleetCatalogError),
72
73 #[error(
74 "Fleet {fleet} is Coordinator-anchored at {coordinator}; the removed single-root topology resolver cannot serve this operation"
75 )]
76 CoordinatorAnchoredTopologyUnavailable { fleet: String, coordinator: String },
77}
78
79pub fn resolve_installed_fleet_from_root(
80 request: &InstalledFleetRequest,
81 icp_root: &Path,
82) -> Result<InstalledFleetResolution, InstalledFleetError> {
83 let fleet = read_installed_fleet_from_root(&request.environment, &request.fleet, icp_root)?;
84 Err(
85 InstalledFleetError::CoordinatorAnchoredTopologyUnavailable {
86 fleet: fleet.fleet_name.to_string(),
87 coordinator: fleet.coordinator_principal,
88 },
89 )
90}
91
92pub fn read_installed_fleet_from_root(
93 environment: &str,
94 fleet: &str,
95 icp_root: &Path,
96) -> Result<FleetCatalogEntryV1, InstalledFleetError> {
97 read_fleet_catalog_entry_from_root(icp_root, environment, fleet)
98 .map_err(InstalledFleetError::FleetCatalog)?
99 .ok_or_else(|| InstalledFleetError::NoInstalledFleet {
100 environment: environment.to_string(),
101 fleet: fleet.to_string(),
102 })
103}
104
105#[cfg(test)]
106mod tests;