11use crate :: prelude:: * ;
22
33use super :: spec:: { GraphDeclaration , GraphElementMapping , NodeFromFieldsSpec , TargetFieldMapping } ;
4- use crate :: setup:: components:: { self , State } ;
4+ use crate :: setup:: components:: { self , apply_component_changes , State } ;
55use crate :: setup:: { ResourceSetupStatus , SetupChangeType } ;
66use crate :: { ops:: sdk:: * , setup:: CombinedState } ;
77
@@ -688,7 +688,7 @@ impl ComponentKind {
688688 }
689689}
690690#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
691- struct ComponentKey {
691+ pub struct ComponentKey {
692692 kind : ComponentKind ,
693693 name : String ,
694694}
@@ -754,13 +754,13 @@ impl components::State<ComponentKey> for ComponentState {
754754 }
755755}
756756
757- struct SetupComponentOperator {
757+ pub struct SetupComponentOperator {
758758 graph_pool : Arc < GraphPool > ,
759759 conn_spec : ConnectionSpec ,
760760}
761761
762762#[ async_trait]
763- impl components:: Operator for SetupComponentOperator {
763+ impl components:: SetupOperator for SetupComponentOperator {
764764 type Key = ComponentKey ;
765765 type State = ComponentState ;
766766 type SetupState = SetupState ;
@@ -855,7 +855,7 @@ fn build_composite_field_names(qualifier: &str, field_names: &[String]) -> Strin
855855}
856856#[ derive( Derivative ) ]
857857#[ derivative( Debug ) ]
858- struct SetupStatus {
858+ pub struct GraphElementDataSetupStatus {
859859 key : GraphElement ,
860860 #[ derivative( Debug = "ignore" ) ]
861861 graph_pool : Arc < GraphPool > ,
@@ -864,7 +864,7 @@ struct SetupStatus {
864864 change_type : SetupChangeType ,
865865}
866866
867- impl SetupStatus {
867+ impl GraphElementDataSetupStatus {
868868 fn new (
869869 key : GraphElement ,
870870 graph_pool : Arc < GraphPool > ,
@@ -907,8 +907,7 @@ impl SetupStatus {
907907 }
908908}
909909
910- #[ async_trait]
911- impl ResourceSetupStatus for SetupStatus {
910+ impl ResourceSetupStatus for GraphElementDataSetupStatus {
912911 fn describe_changes ( & self ) -> Vec < String > {
913912 let mut result = vec ! [ ] ;
914913 if let Some ( data_clear) = & self . data_clear {
@@ -934,6 +933,12 @@ impl ResourceSetupStatus for SetupStatus {
934933 self . change_type
935934 }
936935
936+ fn as_any ( & self ) -> & dyn Any {
937+ self
938+ }
939+ }
940+
941+ impl GraphElementDataSetupStatus {
937942 async fn apply_change ( & self ) -> Result < ( ) > {
938943 let graph = self . graph_pool . get_graph ( & self . conn_spec ) . await ?;
939944 if let Some ( data_clear) = & self . data_clear {
@@ -1077,6 +1082,10 @@ impl StorageFactoryBase for Factory {
10771082 type Spec = Spec ;
10781083 type DeclarationSpec = Declaration ;
10791084 type SetupState = SetupState ;
1085+ type SetupStatus = (
1086+ GraphElementDataSetupStatus ,
1087+ components:: SetupStatus < SetupComponentOperator > ,
1088+ ) ;
10801089 type Key = GraphElement ;
10811090 type ExportContext = ExportContext ;
10821091
@@ -1255,24 +1264,24 @@ impl StorageFactoryBase for Factory {
12551264 desired : Option < SetupState > ,
12561265 existing : CombinedState < SetupState > ,
12571266 auth_registry : & Arc < AuthRegistry > ,
1258- ) -> Result < impl ResourceSetupStatus + ' static > {
1267+ ) -> Result < Self :: SetupStatus > {
12591268 let conn_spec = auth_registry. get :: < ConnectionSpec > ( & key. connection ) ?;
1260- let base = SetupStatus :: new (
1269+ let data_status = GraphElementDataSetupStatus :: new (
12611270 key,
12621271 self . graph_pool . clone ( ) ,
12631272 conn_spec. clone ( ) ,
12641273 desired. as_ref ( ) ,
12651274 & existing,
12661275 ) ;
1267- let comp = components:: Status :: create (
1276+ let components = components:: SetupStatus :: create (
12681277 SetupComponentOperator {
12691278 graph_pool : self . graph_pool . clone ( ) ,
12701279 conn_spec : conn_spec. clone ( ) ,
12711280 } ,
12721281 desired,
12731282 existing,
12741283 ) ?;
1275- Ok ( components :: combine_setup_statuss ( base , comp ) )
1284+ Ok ( ( data_status , components ) )
12761285 }
12771286
12781287 fn check_state_compatibility (
@@ -1328,4 +1337,15 @@ impl StorageFactoryBase for Factory {
13281337 }
13291338 Ok ( ( ) )
13301339 }
1340+
1341+ async fn apply_setup_changes (
1342+ & self ,
1343+ changes : Vec < & ' async_trait Self :: SetupStatus > ,
1344+ ) -> Result < ( ) > {
1345+ for change in changes. iter ( ) {
1346+ change. 0 . apply_change ( ) . await ?;
1347+ }
1348+ apply_component_changes ( changes. iter ( ) . map ( |c| & c. 1 ) . collect ( ) ) . await ?;
1349+ Ok ( ( ) )
1350+ }
13311351}
0 commit comments