@Test public void getLatestBackupMetadata() throws Exception { prepare(); List<BackupMetadata> list = backupStatusMgr.getLatestBackupMetadata( BackupVersion.SNAPSHOT_BACKUP, new DateRange(backupDate + "," + "201812031000")); list.forEach(System.out::println); }
public List<BackupMetadata> getLatestBackupMetadata( BackupVersion backupVersion, DateUtil.DateRange dateRange) { Instant startDay = dateRange.getStartTime().truncatedTo(ChronoUnit.DAYS); Instant endDay = dateRange.getEndTime().truncatedTo(ChronoUnit.DAYS); List<BackupMetadata> allBackups = new ArrayList<>(); Instant previousDay = endDay; do { logger.info( "Will try to find snapshot for : {}", DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, previousDay)); List<BackupMetadata> backupsForDate = locate(new Date(previousDay.toEpochMilli())); if (backupsForDate != null) allBackups.addAll(backupsForDate); previousDay = previousDay.minus(1, ChronoUnit.DAYS); } while (!previousDay.isBefore(startDay)); return allBackups .stream() .filter(Objects::nonNull) .filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED) .filter(backupMetadata -> backupMetadata.getBackupVersion().equals(backupVersion)) .filter( backupMetadata -> backupMetadata .getStart() .toInstant() .compareTo(dateRange.getStartTime()) >= 0 && backupMetadata .getStart() .toInstant() .compareTo(dateRange.getEndTime()) <= 0) .sorted(Comparator.comparing(BackupMetadata::getStart).reversed()) .collect(Collectors.toList()); }
BackupStatusMgr implements IBackupStatusMgr { public List<BackupMetadata> getLatestBackupMetadata( BackupVersion backupVersion, DateUtil.DateRange dateRange) { Instant startDay = dateRange.getStartTime().truncatedTo(ChronoUnit.DAYS); Instant endDay = dateRange.getEndTime().truncatedTo(ChronoUnit.DAYS); List<BackupMetadata> allBackups = new ArrayList<>(); Instant previousDay = endDay; do { logger.info( "Will try to find snapshot for : {}", DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, previousDay)); List<BackupMetadata> backupsForDate = locate(new Date(previousDay.toEpochMilli())); if (backupsForDate != null) allBackups.addAll(backupsForDate); previousDay = previousDay.minus(1, ChronoUnit.DAYS); } while (!previousDay.isBefore(startDay)); return allBackups .stream() .filter(Objects::nonNull) .filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED) .filter(backupMetadata -> backupMetadata.getBackupVersion().equals(backupVersion)) .filter( backupMetadata -> backupMetadata .getStart() .toInstant() .compareTo(dateRange.getStartTime()) >= 0 && backupMetadata .getStart() .toInstant() .compareTo(dateRange.getEndTime()) <= 0) .sorted(Comparator.comparing(BackupMetadata::getStart).reversed()) .collect(Collectors.toList()); } }
BackupStatusMgr implements IBackupStatusMgr { public List<BackupMetadata> getLatestBackupMetadata( BackupVersion backupVersion, DateUtil.DateRange dateRange) { Instant startDay = dateRange.getStartTime().truncatedTo(ChronoUnit.DAYS); Instant endDay = dateRange.getEndTime().truncatedTo(ChronoUnit.DAYS); List<BackupMetadata> allBackups = new ArrayList<>(); Instant previousDay = endDay; do { logger.info( "Will try to find snapshot for : {}", DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, previousDay)); List<BackupMetadata> backupsForDate = locate(new Date(previousDay.toEpochMilli())); if (backupsForDate != null) allBackups.addAll(backupsForDate); previousDay = previousDay.minus(1, ChronoUnit.DAYS); } while (!previousDay.isBefore(startDay)); return allBackups .stream() .filter(Objects::nonNull) .filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED) .filter(backupMetadata -> backupMetadata.getBackupVersion().equals(backupVersion)) .filter( backupMetadata -> backupMetadata .getStart() .toInstant() .compareTo(dateRange.getStartTime()) >= 0 && backupMetadata .getStart() .toInstant() .compareTo(dateRange.getEndTime()) <= 0) .sorted(Comparator.comparing(BackupMetadata::getStart).reversed()) .collect(Collectors.toList()); } @Inject  BackupStatusMgr(int capacity, InstanceState instanceState); }
BackupStatusMgr implements IBackupStatusMgr { public List<BackupMetadata> getLatestBackupMetadata( BackupVersion backupVersion, DateUtil.DateRange dateRange) { Instant startDay = dateRange.getStartTime().truncatedTo(ChronoUnit.DAYS); Instant endDay = dateRange.getEndTime().truncatedTo(ChronoUnit.DAYS); List<BackupMetadata> allBackups = new ArrayList<>(); Instant previousDay = endDay; do { logger.info( "Will try to find snapshot for : {}", DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, previousDay)); List<BackupMetadata> backupsForDate = locate(new Date(previousDay.toEpochMilli())); if (backupsForDate != null) allBackups.addAll(backupsForDate); previousDay = previousDay.minus(1, ChronoUnit.DAYS); } while (!previousDay.isBefore(startDay)); return allBackups .stream() .filter(Objects::nonNull) .filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED) .filter(backupMetadata -> backupMetadata.getBackupVersion().equals(backupVersion)) .filter( backupMetadata -> backupMetadata .getStart() .toInstant() .compareTo(dateRange.getStartTime()) >= 0 && backupMetadata .getStart() .toInstant() .compareTo(dateRange.getEndTime()) <= 0) .sorted(Comparator.comparing(BackupMetadata::getStart).reversed()) .collect(Collectors.toList()); } @Inject  BackupStatusMgr(int capacity, InstanceState instanceState); @Override int getCapacity(); @Override Map<String, LinkedList<BackupMetadata>> getAllSnapshotStatus(); @Override LinkedList<BackupMetadata> locate(Date snapshotDate); @Override LinkedList<BackupMetadata> locate(String snapshotDate); @Override void start(BackupMetadata backupMetadata); @Override void finish(BackupMetadata backupMetadata); @Override void update(BackupMetadata backupMetadata); @Override void failed(BackupMetadata backupMetadata); List<BackupMetadata> getLatestBackupMetadata(
            BackupVersion backupVersion, DateUtil.DateRange dateRange); @Override String toString(); }
BackupStatusMgr implements IBackupStatusMgr { public List<BackupMetadata> getLatestBackupMetadata( BackupVersion backupVersion, DateUtil.DateRange dateRange) { Instant startDay = dateRange.getStartTime().truncatedTo(ChronoUnit.DAYS); Instant endDay = dateRange.getEndTime().truncatedTo(ChronoUnit.DAYS); List<BackupMetadata> allBackups = new ArrayList<>(); Instant previousDay = endDay; do { logger.info( "Will try to find snapshot for : {}", DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, previousDay)); List<BackupMetadata> backupsForDate = locate(new Date(previousDay.toEpochMilli())); if (backupsForDate != null) allBackups.addAll(backupsForDate); previousDay = previousDay.minus(1, ChronoUnit.DAYS); } while (!previousDay.isBefore(startDay)); return allBackups .stream() .filter(Objects::nonNull) .filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED) .filter(backupMetadata -> backupMetadata.getBackupVersion().equals(backupVersion)) .filter( backupMetadata -> backupMetadata .getStart() .toInstant() .compareTo(dateRange.getStartTime()) >= 0 && backupMetadata .getStart() .toInstant() .compareTo(dateRange.getEndTime()) <= 0) .sorted(Comparator.comparing(BackupMetadata::getStart).reversed()) .collect(Collectors.toList()); } @Inject  BackupStatusMgr(int capacity, InstanceState instanceState); @Override int getCapacity(); @Override Map<String, LinkedList<BackupMetadata>> getAllSnapshotStatus(); @Override LinkedList<BackupMetadata> locate(Date snapshotDate); @Override LinkedList<BackupMetadata> locate(String snapshotDate); @Override void start(BackupMetadata backupMetadata); @Override void finish(BackupMetadata backupMetadata); @Override void update(BackupMetadata backupMetadata); @Override void failed(BackupMetadata backupMetadata); List<BackupMetadata> getLatestBackupMetadata(
            BackupVersion backupVersion, DateUtil.DateRange dateRange); @Override String toString();  }