protected FileSystemDTO addRWFileSystem(FileSystemDTO fsDTO) throws Exception {
   FileSystemDTO dto = fileSystemMgt().addAndLinkFileSystem(fsDTO);
   if (dto.getStatus() == FileSystemStatus.DEF_RW) {
     storageFileSystem = dto;
   }
   return dto;
 }
Exemple #2
0
 public long updateMinFreeDiskSpaceFromSrcFSGroup() throws Exception {
   String mfd =
       (String)
           server.getAttribute(
               new ObjectName(getFileSystemMgtServiceNamePrefix() + srcFsGroup),
               "MinimumFreeDiskSpace");
   log.info("getMinFreeDiskSpaceFromSrcFS group:" + srcFsGroup + " minFree:" + mfd);
   if (mfd.equalsIgnoreCase(NONE)) return 0;
   if (mfd.endsWith("%")) {
     float ratio = Float.parseFloat(mfd.substring(0, mfd.length() - 1));
     FileSystemDTO[] fsDTOs = fileSystemMgt().getFileSystemsOfGroup(srcFsGroup);
     long total = 0L;
     for (FileSystemDTO fsDTO : fsDTOs) {
       int status = fsDTO.getStatus();
       if (status == FileSystemStatus.RW || status == FileSystemStatus.DEF_RW) {
         File dir = FileUtils.toFile(fsDTO.getDirectoryPath());
         if (dir.isDirectory()) {
           total += FileSystemUtils.totalSpace(dir.getPath());
         }
       }
     }
     minFree = (long) (total * ratio / 100);
   } else {
     minFree = FileUtils.parseSize(mfd, MIN_FREE_DISK_SPACE);
   }
   return minFree;
 }
 private void checkStorageFileSystemStatus(FileSystemMgt2 fsMgt)
     throws FinderException, RemoteException {
   try {
     FileSystemDTO tmpFS = fsMgt.getFileSystem(storageFileSystem.getPk());
     if (tmpFS.getStatus() == FileSystemStatus.DEF_RW) {
       return;
     }
     log.info("Status of previous storage file system changed: " + storageFileSystem);
   } catch (ObjectNotFoundException onfe) {
     log.info(
         "Previous storage file system: " + storageFileSystem + " was removed from configuration");
   }
   storageFileSystem = fsMgt.getDefRWFileSystemsOfGroup(getFileSystemGroupID());
   if (storageFileSystem != null) {
     log.info("New storage file system: " + storageFileSystem);
   }
   if (minFreeDiskSpaceRatio > 0) {
     minFreeDiskSpace = calcFreeDiskSpace(storageFileSystem);
   }
   checkFreeDiskSpaceTime = 0;
 }
 private boolean switchFileSystem(FileSystemMgt2 fsMgt, FileSystemDTO fsDTO) throws Exception {
   synchronized (switchFileSystemMonitor) {
     if (!updateStorageFileSystem(fsMgt)) {
       return selectStorageFileSystem() != null;
     }
     if (storageFileSystem == null || fsDTO == null) {
       log.info("Storage filesystem not set! No RW filesystem configured or no space left!");
       return false;
     } else if (storageFileSystem.getPk() != fsDTO.getPk()) {
       log.info(
           "Storage file system has already been switched from "
               + fsDTO
               + " to "
               + storageFileSystem
               + " by another thread.");
       return true;
     }
     FileSystemDTO tmp = storageFileSystem;
     String next;
     while ((next = tmp.getNext()) != null && !next.equals(storageFileSystem.getDirectoryPath())) {
       tmp = fsMgt.getFileSystemOfGroup(getFileSystemGroupID(), next);
       if (minFreeDiskSpaceRatio > 0) {
         minFreeDiskSpace = calcFreeDiskSpace(tmp);
       }
       if (tmp.getStatus() == FileSystemStatus.RW
           && tmp.getAvailability() == Availability.toInt(getDefAvailability())
           && checkFreeDiskSpace(tmp)) {
         storageFileSystem = fsMgt.updateFileSystemStatus(tmp.getPk(), FileSystemStatus.DEF_RW);
         log.info("Switch storage file system from " + fsDTO + " to " + storageFileSystem);
         sendJMXNotification(new StorageFileSystemSwitched(fsDTO, storageFileSystem));
         return true;
       }
     }
     return false;
   }
 }