Esempio n. 1
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 long calcFreeDiskSpace(FileSystemDTO fs) {
   if (fs == null) {
     return -1;
   }
   File dir = checkFS(fs, " - can not calculate minimum free disc space!");
   if (dir == null) {
     return -1;
   }
   long total = FileSystemUtils.totalSpace(dir.getAbsolutePath());
   log.info("Total space of " + fs.getDirectoryPath() + " :" + FileUtils.formatSize(total));
   return (long) (total * minFreeDiskSpaceRatio / 100);
 }