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