@@ -441,30 +441,44 @@ private Optional<StackGresBackup> getReplicationInitializationBackupToCreate(
441441 labelFactory .replicationInitializationBackupLabels (cluster )))
442442 .filter (backup -> backup .getSpec ().getSgCluster ().equals (
443443 cluster .getMetadata ().getName ()))
444- .filter (backup -> Optional .ofNullable (backup .getStatus ())
445- .map (StackGresBackupStatus ::getSgBackupConfig )
446- .map (StackGresBackupConfigSpec ::getStorage )
447- .equals (backupObjectStorage .map (StackGresObjectStorage ::getSpec )))
448- .filter (backup -> Optional .ofNullable (backup .getStatus ())
449- .map (StackGresBackupStatus ::getBackupPath )
450- .equals (Optional
451- .ofNullable (cluster .getSpec ().getConfigurations ().getBackups ())
452- .map (Collection ::stream )
453- .flatMap (Stream ::findFirst )
454- .map (StackGresClusterBackupConfiguration ::getPath )))
455- .filter (backup -> Optional .ofNullable (backup .getStatus ())
444+ .filter (backup -> backup .getStatus () == null
445+ || Optional .ofNullable (backup .getStatus ())
446+ .filter (status -> Optional .of (status )
447+ .map (StackGresBackupStatus ::getProcess )
448+ .map (StackGresBackupProcess ::getStatus )
449+ .filter (Predicate .not (BackupStatus .COMPLETED .toString ()::equals )
450+ .and (Predicate .not (BackupStatus .FAILED .toString ()::equals )))
451+ .isPresent ())
452+ .isPresent ()
453+ || Optional .ofNullable (backup .getStatus ())
454+ .filter (status -> Optional .of (status )
455+ .map (StackGresBackupStatus ::getSgBackupConfig )
456+ .map (StackGresBackupConfigSpec ::getStorage )
457+ .equals (backupObjectStorage .map (StackGresObjectStorage ::getSpec )))
458+ .filter (status -> Optional .of (status )
459+ .map (StackGresBackupStatus ::getBackupPath )
460+ .equals (Optional
461+ .ofNullable (cluster .getSpec ().getConfigurations ().getBackups ())
462+ .map (Collection ::stream )
463+ .flatMap (Stream ::findFirst )
464+ .map (StackGresClusterBackupConfiguration ::getPath )))
465+ .filter (status -> Optional .of (status )
466+ .map (StackGresBackupStatus ::getBackupInformation )
467+ .map (StackGresBackupInformation ::getPostgresMajorVersion )
468+ .filter (postgresMajorVersion ::equals )
469+ .isPresent ())
470+ .filter (status -> Optional .of (status )
471+ .map (StackGresBackupStatus ::getProcess )
472+ .map (StackGresBackupProcess ::getStatus )
473+ .filter (BackupStatus .COMPLETED .toString ()::equals )
474+ .isPresent ())
456475 .map (StackGresBackupStatus ::getProcess )
457476 .map (StackGresBackupProcess ::getTiming )
458477 .map (StackGresBackupTiming ::getEnd )
459478 .map (Instant ::parse )
460479 .or (() -> Optional .of (now ))
461480 .filter (end -> backupNewerThan .map (end ::isAfter ).orElse (true ))
462481 .isPresent ())
463- .filter (backup -> Optional .ofNullable (backup .getStatus ())
464- .map (StackGresBackupStatus ::getBackupInformation )
465- .map (StackGresBackupInformation ::getPostgresMajorVersion )
466- .filter (postgresMajorVersion ::equals )
467- .isPresent ())
468482 .findFirst ();
469483 }
470484
0 commit comments