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