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