fakecloud_dms/state.rs
1//! Account-partitioned, serializable state for AWS Database Migration
2//! Service's (`dms`) control plane.
3//!
4//! Every DMS resource is stored as an already-output-valid JSON object
5//! (`serde_json::Value`) keyed by its ARN or identifier. Storing the wire
6//! shape directly keeps per-engine endpoint settings and other nested
7//! configuration objects round-tripping verbatim and guarantees the
8//! `Describe` responses echo exactly what was persisted.
9
10use std::collections::BTreeMap;
11use std::sync::Arc;
12
13use parking_lot::RwLock;
14use serde::{Deserialize, Serialize};
15use serde_json::Value;
16
17use fakecloud_core::multi_account::{AccountState, MultiAccountState};
18
19pub const DMS_SNAPSHOT_SCHEMA_VERSION: u32 = 1;
20
21/// Per-account DMS state. Each map is keyed by the resource's ARN (or, for
22/// resources without an ARN in their describe shape, their identifier) and
23/// holds the resource's already-output-valid JSON object.
24#[derive(Debug, Clone, Default, Serialize, Deserialize)]
25pub struct DmsData {
26 /// Replication instances keyed by `ReplicationInstanceArn`.
27 #[serde(default)]
28 pub replication_instances: BTreeMap<String, Value>,
29 /// Endpoints keyed by `EndpointArn`.
30 #[serde(default)]
31 pub endpoints: BTreeMap<String, Value>,
32 /// Replication tasks keyed by `ReplicationTaskArn`.
33 #[serde(default)]
34 pub replication_tasks: BTreeMap<String, Value>,
35 /// Replication subnet groups keyed by `ReplicationSubnetGroupIdentifier`.
36 #[serde(default)]
37 pub subnet_groups: BTreeMap<String, Value>,
38 /// Event subscriptions keyed by `CustSubscriptionId` (subscription name).
39 #[serde(default)]
40 pub event_subscriptions: BTreeMap<String, Value>,
41 /// Certificates keyed by `CertificateArn`.
42 #[serde(default)]
43 pub certificates: BTreeMap<String, Value>,
44 /// Serverless replication configs keyed by `ReplicationConfigArn`.
45 #[serde(default)]
46 pub replication_configs: BTreeMap<String, Value>,
47 /// Serverless replications keyed by `ReplicationConfigArn`.
48 #[serde(default)]
49 pub replications: BTreeMap<String, Value>,
50 /// Data providers keyed by `DataProviderArn`.
51 #[serde(default)]
52 pub data_providers: BTreeMap<String, Value>,
53 /// Instance profiles keyed by `InstanceProfileArn`.
54 #[serde(default)]
55 pub instance_profiles: BTreeMap<String, Value>,
56 /// Migration projects keyed by `MigrationProjectArn`.
57 #[serde(default)]
58 pub migration_projects: BTreeMap<String, Value>,
59 /// Data migrations keyed by `DataMigrationArn`.
60 #[serde(default)]
61 pub data_migrations: BTreeMap<String, Value>,
62 /// Replication-task assessment runs keyed by
63 /// `ReplicationTaskAssessmentRunArn`.
64 #[serde(default)]
65 pub assessment_runs: BTreeMap<String, Value>,
66 /// Endpoint/replication-instance connections keyed by
67 /// `"{endpoint_arn}|{instance_arn}"`.
68 #[serde(default)]
69 pub connections: BTreeMap<String, Value>,
70 /// Fleet Advisor collectors keyed by `CollectorReferencedId`.
71 #[serde(default)]
72 pub fleet_advisor_collectors: BTreeMap<String, Value>,
73 /// Schema-conversion / metadata-model requests keyed by `RequestIdentifier`.
74 #[serde(default)]
75 pub schema_conversion_requests: BTreeMap<String, Value>,
76 /// Fleet-advisor / target recommendations keyed by `DatabaseId`.
77 #[serde(default)]
78 pub recommendations: BTreeMap<String, Value>,
79 /// Per-migration-project schema-conversion configuration JSON, keyed by
80 /// `MigrationProjectArn`.
81 #[serde(default)]
82 pub conversion_configs: BTreeMap<String, String>,
83 /// Refresh-schemas status keyed by `EndpointArn`.
84 #[serde(default)]
85 pub refresh_schemas_status: BTreeMap<String, Value>,
86 /// Resource tags keyed by `ResourceArn` -> (key -> value).
87 #[serde(default)]
88 pub tags: BTreeMap<String, BTreeMap<String, String>>,
89}
90
91impl AccountState for DmsData {
92 fn new_for_account(_account_id: &str, _region: &str, _endpoint: &str) -> Self {
93 Self::default()
94 }
95}
96
97pub type SharedDmsState = Arc<RwLock<MultiAccountState<DmsData>>>;
98
99#[derive(Debug, Serialize, Deserialize)]
100pub struct DmsSnapshot {
101 pub schema_version: u32,
102 pub accounts: MultiAccountState<DmsData>,
103}