Skip to main content

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