@@ -40,6 +40,8 @@ class WorkspaceProvisioner(
4040 WorkspaceIncrementalLoad
4141 )
4242
43+ upstream_group : list [CatalogWorkspace ]
44+
4345 def __init__ (self , * args : str , ** kwargs : str ) -> None :
4446 """Creates an instance of the WorkspaceProvisioner.
4547
@@ -97,10 +99,11 @@ def _create_or_update_panther_workspaces(
9799 workspace_ids_to_update : set [str ],
98100 child_to_parent_map : dict [str , str ],
99101 workspace_id_to_wdf_map : dict [str , dict [str , list [str ]]],
102+ source_group : list [WorkspaceFullLoad ] | list [WorkspaceIncrementalLoad ],
100103 ) -> None :
101104 action : Literal ["CREATE" , "UPDATE" ]
102105
103- for source_workspace in self . source_group_full :
106+ for source_workspace in source_group :
104107 if source_workspace .workspace_id in workspace_ids_to_update :
105108 action = "UPDATE"
106109 elif source_workspace .workspace_id in workspace_ids_to_create :
@@ -205,8 +208,8 @@ def _provision_full_load(self) -> None:
205208 )
206209
207210 # Get upstream children of all parent workspaces.
208- self .upstream_group : list [ CatalogWorkspace ] = (
209- self ._api . get_panther_children_workspaces ( self . maps .parent_ids )
211+ self .upstream_group = self . _api . get_panther_children_workspaces (
212+ self .maps .parent_ids
210213 )
211214
212215 # Set maps that require upstream data.
@@ -240,6 +243,7 @@ def _provision_full_load(self) -> None:
240243 self .ids_to_update ,
241244 self .maps .child_to_parent_id_map ,
242245 self .maps .workspace_id_to_wdf_map ,
246+ self .source_group_full ,
243247 )
244248
245249 # Check WDF settings of ignored workspaces.
@@ -265,5 +269,42 @@ def _provision_full_load(self) -> None:
265269
266270 def _provision_incremental_load (self ) -> None :
267271 """Incremental workspace provisioning."""
272+ # Set the maps based on the source data.
273+ self .maps = self .parser .set_maps_based_on_source (
274+ self .maps , self .source_group_incremental
275+ )
276+
277+ # Get upstream children of all parent workspaces.
278+ self .upstream_group = self ._api .get_panther_children_workspaces (
279+ self .maps .parent_ids
280+ )
268281
269- raise NotImplementedError ("Not implemented yet." )
282+ # Set maps that require upstream data.
283+ self .maps = self .parser .set_maps_with_upstream_data (
284+ self .maps , self .source_group_incremental , self .upstream_group
285+ )
286+
287+ # Create an instance of WDF manager with the created maps.
288+ self .wdf_manager = WorkspaceDataFilterManager (self ._api , self .maps )
289+
290+ # Iterate through the source data and sort workspace ID to groups
291+ ids_to_update : set [str ] = set ()
292+ ids_to_delete : set [str ] = set ()
293+
294+ for workspace in self .source_group_incremental :
295+ if workspace .is_active :
296+ ids_to_update .add (workspace .workspace_id )
297+ else :
298+ ids_to_delete .add (workspace .workspace_id )
299+
300+ self ._create_or_update_panther_workspaces (
301+ set (),
302+ ids_to_update ,
303+ self .maps .child_to_parent_id_map ,
304+ self .maps .workspace_id_to_wdf_map ,
305+ self .source_group_incremental ,
306+ )
307+
308+ self .delete_panther_workspaces (
309+ ids_to_delete , self .maps .workspace_id_to_name_map
310+ )
0 commit comments