Search in sources :

Example 1 with DiskBackupStatus

use of org.apache.geode.management.DiskBackupStatus in project geode by apache.

the class DistributedSystemBridge method backupAllMembers.

/**
   *
   * @param targetDirPath path of the directory where the back up files should be placed.
   * @param baselineDirPath path of the directory for baseline backup.
   * @return open type DiskBackupStatus containing each member wise disk back up status
   */
public DiskBackupStatus backupAllMembers(String targetDirPath, String baselineDirPath) throws Exception {
    if (BackupDataStoreHelper.obtainLock(dm)) {
        try {
            if (targetDirPath == null || targetDirPath.isEmpty()) {
                throw new Exception(ManagementStrings.TARGET_DIR_CANT_BE_NULL_OR_EMPTY.toLocalizedString());
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
            File targetDir = new File(targetDirPath);
            targetDir = new File(targetDir, format.format(new Date()));
            File baselineDir = null;
            if (baselineDirPath != null) {
                baselineDir = new File(baselineDirPath);
            }
            DM dm = cache.getDistributionManager();
            Set<PersistentID> missingMembers = MissingPersistentIDsRequest.send(dm);
            Set recipients = dm.getOtherDistributionManagerIds();
            BackupDataStoreResult result = BackupDataStoreHelper.backupAllMembers(dm, recipients, targetDir, baselineDir);
            Iterator<DistributedMember> it = result.getSuccessfulMembers().keySet().iterator();
            Map<String, String[]> backedUpDiskStores = new HashMap<>();
            while (it.hasNext()) {
                DistributedMember member = it.next();
                Set<PersistentID> setOfDisk = result.getSuccessfulMembers().get(member);
                String[] setOfDiskStr = new String[setOfDisk.size()];
                int j = 0;
                for (PersistentID id : setOfDisk) {
                    setOfDiskStr[j] = id.getDirectory();
                    j++;
                }
                backedUpDiskStores.put(member.getId(), setOfDiskStr);
            }
            // should override the previous missingMembers
            for (Set<PersistentID> onlineMembersIds : result.getSuccessfulMembers().values()) {
                missingMembers.removeAll(onlineMembersIds);
            }
            result.getExistingDataStores().keySet().removeAll(result.getSuccessfulMembers().keySet());
            String[] setOfMissingDiskStr = null;
            if (result.getExistingDataStores().size() > 0) {
                setOfMissingDiskStr = new String[result.getExistingDataStores().size()];
                int j = 0;
                for (Set<PersistentID> lostMembersIds : result.getExistingDataStores().values()) {
                    for (PersistentID id : lostMembersIds) {
                        setOfMissingDiskStr[j] = id.getDirectory();
                        j++;
                    }
                }
            }
            DiskBackupStatus diskBackupStatus = new DiskBackupStatus();
            diskBackupStatus.setBackedUpDiskStores(backedUpDiskStores);
            diskBackupStatus.setOfflineDiskStores(setOfMissingDiskStr);
            return diskBackupStatus;
        } finally {
            BackupDataStoreHelper.releaseLock(dm);
        }
    } else {
        throw new Exception(LocalizedStrings.DistributedSystem_BACKUP_ALREADY_IN_PROGRESS.toLocalizedString());
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BackupDataStoreResult(org.apache.geode.admin.internal.BackupDataStoreResult) DM(org.apache.geode.distributed.internal.DM) ManagementException(org.apache.geode.management.ManagementException) ListenerNotFoundException(javax.management.ListenerNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) Date(java.util.Date) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) PersistentID(org.apache.geode.cache.persistence.PersistentID) DiskBackupStatus(org.apache.geode.management.DiskBackupStatus)

Aggregations

File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 BackupDataStoreResult (org.apache.geode.admin.internal.BackupDataStoreResult)1 PersistentID (org.apache.geode.cache.persistence.PersistentID)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DM (org.apache.geode.distributed.internal.DM)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DiskBackupStatus (org.apache.geode.management.DiskBackupStatus)1 ManagementException (org.apache.geode.management.ManagementException)1