@@ -219,21 +219,6 @@ def restore_snapshot(snapshot_id):
219219 log .error (f"Failed to restore { snapshot_id } : { r .text } " )
220220
221221
222- # Fetch all snapshots and restore all of them
223- def restore ():
224- log .info ("Starting to restore snapshots..." )
225-
226- snapshot_ids = fetch_snapshots ()
227-
228- # For each snapshot, restore it
229- for snapshot in snapshot_ids :
230- restore_snapshot (snapshot )
231- time .sleep (3 )
232-
233- # Delete restored snapshots
234- delete_snapshots (snapshot_ids )
235-
236-
237222# Check if the cluster is ready to receive requests
238223# Return a boolean based on Monitoring API status code
239224def check_cluster_ready ():
@@ -257,6 +242,40 @@ def wait_ready_cluster():
257242 time .sleep (10 )
258243
259244
245+ # Fetch all snapshots and restore all of them
246+ def restore ():
247+ log .info ("Starting to restore snapshots..." )
248+
249+ snapshot_ids = fetch_snapshots ()
250+
251+ # Move enonic cms snapshot to the end
252+ for i , snapshot in enumerate (snapshot_ids ):
253+ if "com.enonic.cms" in snapshot :
254+ snapshot_ids .append (snapshot_ids .pop (i ))
255+ break
256+
257+ # Move auditlog snapshot to the end
258+ for i , snapshot in enumerate (snapshot_ids ):
259+ if "system.auditlog" in snapshot :
260+ snapshot_ids .append (snapshot_ids .pop (i ))
261+ break
262+
263+ # Move repo snapshot to the beggining
264+ for i , snapshot in enumerate (snapshot_ids ):
265+ if "system-repo" in snapshot :
266+ snapshot_ids .insert (0 , snapshot_ids .pop (i ))
267+ break
268+
269+ # For each snapshot, restore it
270+ for snapshot in snapshot_ids :
271+ restore_snapshot (snapshot )
272+ time .sleep (5 )
273+ wait_ready_cluster ()
274+
275+ # Delete restored snapshots
276+ delete_snapshots (snapshot_ids )
277+
278+
260279# Define all tasks to be performed just on the application startup
261280def post_start ():
262281 log .debug ("post_start function starting" )
@@ -278,6 +297,8 @@ def post_start():
278297 # If is master then restore the snapshots
279298 if is_master :
280299 restore ()
300+ time .sleep (5 )
301+ wait_ready_cluster ()
281302 take_snapshot ()
282303 else :
283304 log .info ("No need to restore snapshots." )
0 commit comments