ic_query/cloud_engine/model.rs
1//! Module: cloud_engine::model
2//!
3//! Responsibility: define stable CloudEngine report and source-data models.
4//! Does not own: live transport, source validation, CLI parsing, or text rendering.
5//! Boundary: preserves raw control-plane identities, prices, timestamps, and authority limits.
6
7#[cfg(feature = "cloud-engine-host")]
8use crate::report::CollectionSourceRequest;
9use serde::{Deserialize, Serialize};
10use std::fmt;
11
12#[cfg(all(feature = "cloud-engine-host", feature = "subnet-catalog-host"))]
13use crate::subnet_catalog::{
14 CacheDisposition, CatalogAssurance, ClassificationSource, GeographicScope, SubnetKind,
15 SubnetSpecialization,
16};
17
18///
19/// CloudEngineReportContext
20///
21/// Provenance shared by direct CloudEngine control-plane reports.
22///
23
24#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
25pub struct CloudEngineReportContext {
26 /// Report schema version.
27 pub schema_version: u32,
28 /// Queried network identity.
29 pub network: String,
30 /// Authority represented by the report.
31 pub authority: String,
32 /// CloudEngine control-plane registry canister principal.
33 pub engine_canister_id: String,
34 /// UTC collection timestamp.
35 pub fetched_at: String,
36 /// Replica endpoint used for the queries.
37 pub source_endpoint: String,
38 /// Collector identity.
39 pub fetched_by: String,
40 /// Whether the application data was cryptographically certified.
41 pub certified: bool,
42 /// Whether sequential calls form one point-in-time view.
43 pub point_in_time_guaranteed: bool,
44 /// Number of native canister query calls represented by the report.
45 pub query_call_count: usize,
46}
47
48///
49/// CloudEngineOperatorReport
50///
51/// Public operator binding and settings for one CloudEngine Subnet.
52///
53
54#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
55pub struct CloudEngineOperatorReport {
56 /// Query and authority provenance.
57 #[serde(flatten)]
58 pub context: CloudEngineReportContext,
59 /// Canonical requested Subnet principal.
60 pub subnet_id: String,
61 /// Per-engine operator canister principal when registered.
62 pub operator_canister_id: Option<String>,
63 /// Public engine-owner principal returned by the operator.
64 pub engine_owner: Option<String>,
65 /// Public platform-administrator principal returned by the operator.
66 pub platform_admin: Option<String>,
67 /// Public Caffeine integration setting; `None` means the setting is absent.
68 pub caffeine_enabled: Option<bool>,
69 /// Canonically ordered claimed custom-domain names.
70 pub claimed_domains: Option<Vec<String>>,
71}
72
73///
74/// CloudEngineNodeType
75///
76/// CloudEngine marketplace node class.
77///
78
79#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
80pub enum CloudEngineNodeType {
81 /// Type 4.1 node class.
82 #[serde(rename = "type4_1")]
83 Type4_1,
84 /// Type 4.2 node class.
85 #[serde(rename = "type4_2")]
86 Type4_2,
87 /// Type 4.3 node class.
88 #[serde(rename = "type4_3")]
89 Type4_3,
90 /// Type 4.4 node class.
91 #[serde(rename = "type4_4")]
92 Type4_4,
93 /// Type 4.5 node class.
94 #[serde(rename = "type4_5")]
95 Type4_5,
96}
97
98impl CloudEngineNodeType {
99 /// Stable CloudEngine marketplace label.
100 #[must_use]
101 pub const fn as_str(self) -> &'static str {
102 match self {
103 Self::Type4_1 => "type4.1",
104 Self::Type4_2 => "type4.2",
105 Self::Type4_3 => "type4.3",
106 Self::Type4_4 => "type4.4",
107 Self::Type4_5 => "type4.5",
108 }
109 }
110}
111
112impl fmt::Display for CloudEngineNodeType {
113 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
114 formatter.write_str(self.as_str())
115 }
116}
117
118///
119/// CloudEnginePriceRow
120///
121/// One public CloudEngine marketplace price override.
122///
123
124#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
125pub struct CloudEnginePriceRow {
126 /// Canonical flattened marketplace key.
127 pub key: String,
128 /// Node class priced by this row.
129 pub node_type: CloudEngineNodeType,
130 /// Optional Registry data-center identifier for a location-specific override.
131 pub data_center_id: Option<String>,
132 /// Optional provider principal for a provider-specific override.
133 pub provider_id: Option<String>,
134 /// Provider share in raw cycles per month.
135 pub net_cycles_per_month: String,
136 /// Customer charge in raw cycles per month, including the network fee.
137 pub gross_cycles_per_month: String,
138 /// Raw control-plane update timestamp in Unix nanoseconds.
139 pub updated_at_unix_nanos: i64,
140}
141
142///
143/// CloudEnginePricesReport
144///
145/// Bounded public CloudEngine marketplace fee and price report.
146///
147
148#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
149pub struct CloudEnginePricesReport {
150 /// Query and authority provenance.
151 #[serde(flatten)]
152 pub context: CloudEngineReportContext,
153 /// Network-fee fraction added to provider net prices.
154 pub network_fee: f64,
155 /// Canonically ordered marketplace prices.
156 pub prices: Vec<CloudEnginePriceRow>,
157}
158
159///
160/// CloudEngineListRow
161///
162/// One Registry-classified CloudEngine Subnet and its separate operator-binding observation.
163///
164
165#[cfg(all(feature = "cloud-engine-host", feature = "subnet-catalog-host"))]
166#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
167pub struct CloudEngineListRow {
168 /// Canonical Registry Subnet principal.
169 pub subnet_id: String,
170 /// Human-facing catalog label.
171 pub subnet_label: String,
172 /// Provenance for the catalog label.
173 pub subnet_label_source: ClassificationSource,
174 /// Registry Subnet type discriminant.
175 pub registry_subnet_type: i32,
176 /// Current catalog classification; always `cloud_engine` in this report.
177 pub subnet_kind: SubnetKind,
178 /// Provenance for the Subnet kind.
179 pub subnet_kind_source: ClassificationSource,
180 /// Current catalog specialization.
181 pub subnet_specialization: SubnetSpecialization,
182 /// Provenance for the specialization.
183 pub subnet_specialization_source: ClassificationSource,
184 /// Current catalog geographic scope.
185 pub geographic_scope: GeographicScope,
186 /// Provenance for the geographic scope.
187 pub geographic_scope_source: ClassificationSource,
188 /// Registry node count when present.
189 pub node_count: Option<u32>,
190 /// Whether application charges normally apply for this classification.
191 pub charges_apply_by_default: bool,
192 /// Number of routing ranges assigned to the Subnet in the catalog snapshot.
193 pub range_count: usize,
194 /// Exact control-plane lookup: a registered principal, successful absence, or bounded error.
195 pub operator: Result<Option<ic_platform::candid::contract::Principal>, String>,
196}
197
198///
199/// CloudEngineListReport
200///
201/// Registry CloudEngine inventory joined to bounded public operator-binding observations.
202///
203
204#[cfg(all(feature = "cloud-engine-host", feature = "subnet-catalog-host"))]
205#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
206pub struct CloudEngineListReport {
207 /// Report schema version.
208 pub schema_version: u32,
209 /// Queried network identity.
210 pub network: String,
211
212 /// Registry authority represented by the inventory side of the report.
213 pub registry_authority: String,
214 /// Registry canister principal represented by the catalog snapshot.
215 pub registry_canister_id: String,
216 /// Exact Registry version represented by the catalog snapshot.
217 pub registry_version: u64,
218 /// Assurance established for the Registry snapshot.
219 pub registry_assurance: CatalogAssurance,
220 /// Endpoints contributing to the Registry snapshot.
221 pub registry_source_endpoints: Vec<String>,
222 /// Endpoint-agreement digest when established by collection policy.
223 pub registry_agreement_digest: Option<String>,
224 /// Registry calls made when the represented catalog was collected.
225 pub registry_query_call_count: u64,
226
227 /// Local path supplying the catalog snapshot.
228 pub catalog_path: String,
229 /// Current catalog schema version.
230 pub catalog_schema_version: u32,
231 /// Canonical catalog payload digest.
232 pub catalog_digest: String,
233 /// Cache action supplying this report.
234 pub catalog_cache_disposition: CacheDisposition,
235 /// Catalog collection timestamp.
236 pub catalog_fetched_at: String,
237 /// Whether the catalog exceeds the display freshness threshold.
238 pub catalog_stale: bool,
239 /// Human-readable stale determination.
240 pub catalog_stale_reason: String,
241 /// Collector package version recorded by the catalog.
242 pub catalog_collector_version: String,
243 /// Classification contract version used by the catalog.
244 pub classification_schema_version: u32,
245 /// Digest of the classification policy used by the catalog.
246 pub classification_policy_digest: String,
247 /// Resolver backend recorded by the catalog.
248 pub resolver_backend: String,
249 /// Resolver contract version used by the catalog.
250 pub resolver_schema_version: u32,
251
252 /// Control-plane authority represented by binding observations.
253 pub control_plane_authority: String,
254 /// Fixed CloudEngine control-plane canister principal.
255 pub control_plane_canister_id: String,
256 /// Replica endpoint used for operator-binding lookups.
257 pub control_plane_source_endpoint: String,
258 /// Collection timestamp for the binding observations.
259 pub control_plane_fetched_at: String,
260 /// Collector identity for the binding observations.
261 pub control_plane_fetched_by: String,
262 /// Whether the control-plane application data was cryptographically certified.
263 pub control_plane_certified: bool,
264 /// Whether the per-row calls form one point-in-time view.
265 pub control_plane_point_in_time_guaranteed: bool,
266 /// Number of exact per-Subnet control-plane lookups attempted.
267 pub control_plane_lookup_attempt_count: usize,
268
269 /// Number of CloudEngine Subnets supplied by the Registry catalog.
270 pub registry_cloud_engine_subnet_count: usize,
271 /// Number of Subnets with a resolved operator binding.
272 pub operator_binding_count: usize,
273 /// Number of successful lookups that returned no binding.
274 pub missing_operator_binding_count: usize,
275 /// Number of per-row control-plane lookup failures.
276 pub operator_lookup_failure_count: usize,
277 /// Canonically ordered Registry inventory with separate binding results.
278 pub cloud_engines: Vec<CloudEngineListRow>,
279}
280
281///
282/// CloudEngineOperatorSourceData
283///
284/// Untrusted source result for one Subnet-to-operator lookup and public detail follow-up.
285///
286
287#[cfg(feature = "cloud-engine-host")]
288#[derive(Clone, Debug, Eq, PartialEq)]
289pub struct CloudEngineOperatorSourceData {
290 /// Source provenance echoed by the adapter.
291 pub source: CollectionSourceRequest,
292 /// Canonical Subnet principal looked up by the source.
293 pub subnet_id: String,
294 /// Per-engine operator canister principal when registered.
295 pub operator_canister_id: Option<String>,
296 /// Public engine-owner principal returned by the operator.
297 pub engine_owner: Option<String>,
298 /// Public platform-administrator principal returned by the operator.
299 pub platform_admin: Option<String>,
300 /// Public Caffeine setting returned by the operator.
301 pub caffeine_enabled: Option<bool>,
302 /// Claimed custom-domain names, or `None` when the field was absent.
303 pub claimed_domains: Option<Vec<String>>,
304 /// Exact number of native query calls made by the source.
305 pub query_call_count: usize,
306}
307
308///
309/// CloudEngineOperatorBindingSourceData
310///
311/// Untrusted source result for one exact Subnet-to-operator lookup without detail calls.
312///
313
314#[cfg(feature = "cloud-engine-host")]
315#[derive(Clone, Debug, Eq, PartialEq)]
316pub struct CloudEngineOperatorBindingSourceData {
317 /// Source provenance echoed by the adapter.
318 pub source: CollectionSourceRequest,
319 /// Canonical Subnet principal looked up by the source.
320 pub subnet_id: String,
321 /// Per-engine operator canister principal when registered.
322 pub operator_canister_id: Option<String>,
323 /// Exact number of native query calls made by the source.
324 pub query_call_count: usize,
325}
326
327///
328/// CloudEnginePricesSourceData
329///
330/// Untrusted source result for the public CloudEngine marketplace.
331///
332
333#[cfg(feature = "cloud-engine-host")]
334#[derive(Clone, Debug, PartialEq)]
335pub struct CloudEnginePricesSourceData {
336 /// Source provenance echoed by the adapter.
337 pub source: CollectionSourceRequest,
338 /// Raw network-fee fraction returned by the control-plane canister.
339 pub network_fee: f64,
340 /// Raw public marketplace rows.
341 pub prices: Vec<CloudEnginePriceRow>,
342 /// Exact number of native query calls made by the source.
343 pub query_call_count: usize,
344}