public FileSystemDTO removeFileSystem(String dirPath) throws Exception {
   FileSystemDTO fsDTO = fileSystemMgt().removeFileSystem(getFileSystemGroupID(), dirPath);
   if (storageFileSystem != null && storageFileSystem.getPk() == fsDTO.getPk()) {
     selectStorageFileSystem();
   }
   return fsDTO;
 }
 protected FileSystemDTO addRWFileSystem(FileSystemDTO fsDTO) throws Exception {
   FileSystemDTO dto = fileSystemMgt().addAndLinkFileSystem(fsDTO);
   if (dto.getStatus() == FileSystemStatus.DEF_RW) {
     storageFileSystem = dto;
   }
   return dto;
 }
Пример #3
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 String adjustExpectedDataVolumePerDay(FileSystemMgt2 fsMgt, FileSystemDTO[] fss)
     throws Exception {
   Calendar cal = Calendar.getInstance();
   cal.roll(Calendar.DAY_OF_MONTH, false);
   long after = cal.getTimeInMillis();
   long sum = 0L;
   for (FileSystemDTO fs : fss) {
     sum += fsMgt.sizeOfFilesCreatedAfter(fs.getPk(), after);
   }
   String size = FileUtils.formatSize(sum);
   if (sum > expectedDataVolumePerDay) {
     server.setAttribute(super.serviceName, new Attribute("ExpectedDataVolumePerDay", size));
   }
   return size;
 }
 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 FileSystemDTO mkFileSystemDTO(String dirPath, int status) {
   FileSystemDTO fs = new FileSystemDTO();
   fs.setDirectoryPath(dirPath);
   fs.setGroupID(getFileSystemGroupID());
   fs.setRetrieveAET(defRetrieveAET);
   fs.setAvailability(defAvailability);
   fs.setUserInfo(defUserInfo);
   fs.setStatus(status);
   return fs;
 }
 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);
 }
 private boolean updateStorageFileSystem(FileSystemMgt2 fsMgt)
     throws FinderException, RemoteException {
   if (storageFileSystem == null) return false;
   try {
     storageFileSystem = fsMgt.getFileSystem(storageFileSystem.getPk());
     return true;
   } catch (ObjectNotFoundException ignore) {
     log.warn(
         "Current storage file system: " + storageFileSystem + " was removed from configuration");
     storageFileSystem = null;
     return false;
   }
 }
Пример #9
0
  public long getUsableDiskSpaceOnDest() {
    try {
      if (destFsGroup == null) return -1;
      if (destFsGroup.indexOf('@') == -1)
        return (Long)
            server.getAttribute(
                new ObjectName(getFileSystemMgtServiceNamePrefix() + destFsGroup),
                "UsableDiskSpace");
      FileSystemDTO fsDTO = getDestinationFilesystem(fileSystemMgt());
      if (fsDTO == null) return -2;
      String dirPath = fsDTO.getDirectoryPath();
      if (dirPath.startsWith("tar:")) dirPath = dirPath.substring(4);
      File dir = FileUtils.toFile(dirPath);
      return dir.isDirectory()
          ? FileSystemUtils.freeSpace(dir.getPath()) - getMinFreeDiskSpaceOnDestFS()
          : hsmModuleServicename == null ? -1 : Long.MAX_VALUE;

    } catch (Exception x) {
      log.error("Failed to get UsableDiskSpaceOnDest!", x);
      return -3;
    }
  }
Пример #10
0
  public String getUsableDiskSpaceStringOnDest() {
    try {
      if (destFsGroup == null) return NOT_APPLICABLE;
      if (destFsGroup.indexOf('@') == -1)
        return (String)
            server.getAttribute(
                new ObjectName(getFileSystemMgtServiceNamePrefix() + destFsGroup),
                "UsableDiskSpaceString");
      FileSystemDTO fsDTO = getDestinationFilesystem(fileSystemMgt());
      if (fsDTO == null) return "Dest FS not found!";
      String dirPath = fsDTO.getDirectoryPath();
      if (dirPath.startsWith("tar:")) dirPath = dirPath.substring(4);
      File dir = FileUtils.toFile(dirPath);
      return dir.isDirectory()
          ? FileUtils.formatSize(
              FileSystemUtils.freeSpace(dir.getPath()) - getMinFreeDiskSpaceOnDestFS())
          : hsmModuleServicename == null ? "UNKNOWN (destination path not found)" : "n.a. (HSM)";

    } catch (Exception x) {
      log.error("Failed to get UsableDiskSpaceStringOnDest!", x);
      return ERROR;
    }
  }
 private File checkFS(FileSystemDTO fsDTO, String msgPostfix) {
   File dir = FileUtils.toFile(fsDTO.getDirectoryPath());
   if (!dir.exists()) {
     if (!makeStorageDirectory) {
       log.warn("No such directory " + dir + msgPostfix);
       return null;
     }
     log.info("M-WRITE " + dir);
     if (!dir.mkdirs()) {
       log.warn("Failed to create directory " + dir + msgPostfix);
       return null;
     }
   }
   File nomount = new File(dir, mountFailedCheckFile);
   if (nomount.exists()) {
     log.warn("Mount on " + dir + " seems broken" + msgPostfix);
     return null;
   }
   return dir;
 }
 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;
   }
 }
 public File selectStorageDirectory() throws Exception {
   FileSystemDTO dto = selectStorageFileSystem();
   return dto != null ? FileUtils.toFile(dto.getDirectoryPath()) : null;
 }
 public long getFreeDiskSpaceOnCurFS() throws IOException {
   if (storageFileSystem == null) return -1L;
   File dir = FileUtils.toFile(storageFileSystem.getDirectoryPath());
   return dir.isDirectory() ? FileSystemUtils.freeSpace(dir.getPath()) : -1L;
 }
Пример #15
0
  private void process(DeleteStudyOrder order) throws Exception {
    try {
      if (destFsGroup == null) throw new RuntimeException("No destination file system configured!");
      FileSystemMgt2 mgt = fileSystemMgt();
      FileSystemDTO fsDTO = getDestinationFilesystem(mgt);
      if (fsDTO == null) {
        throw new RuntimeException("No destination file system (with free disk space) available!");
      }
      long availOnDest = getUsableDiskSpaceOnDest();
      log.debug("Available disk space on destination FS:" + availOnDest);
      FileDTO[][] files = null;
      if (availOnDest > 0) {
        files = mgt.getFilesOfStudy(order);
        for (int i = 0; i < files.length && availOnDest > 0; i++) {
          for (int j = 0; j < files[i].length && availOnDest > 0; j++) {
            availOnDest -= files[i][j].getFileSize();
          }
        }
      }
      log.debug("Expected available disk space on destination FS after move:" + availOnDest);
      if (availOnDest < 0) {
        log.error(
            "Not enough space left on destination filesystem to move study ("
                + order.getStudyIUID()
                + ")!");
        throw new RuntimeException("Not enough space left on destination filesystem!");
      }
      File[] srcFiles = null;
      log.info(
          "Move "
              + files.length
              + " files of study "
              + order.getStudyIUID()
              + " to Filesystem:"
              + fsDTO);
      if (files.length > 0) {
        String destPath = fsDTO.getDirectoryPath();
        if (destPath.startsWith("tar:")) {
          for (int i = 0; i < files.length; i++) {
            srcFiles = copyTar(files[i], destPath, fsDTO.getPk());
          }
          List<FileDTO> failed = mgt.moveFiles(order, files, destFileStatus, keepSrcFiles, false);
        } else {
          srcFiles = copyFiles(files, destPath, fsDTO.getPk());
          List<FileDTO> failed =
              mgt.moveFiles(order, files, destFileStatus, keepSrcFiles, keepMovedFilesOnError);
          log.info("moveFiles done! failed:" + failed);
          if (failed != null) {
            if (keepSrcFiles) {
              FileDTO dto;
              for (int i = 0; i < failed.size(); i++) {
                dto = failed.get(i);
                deleteFile(FileUtils.toFile(dto.getDirectoryPath() + '/' + dto.getFilePath()));
              }

            } else {
              int k = 0, s = 0;
              FileDTO failedDto = failed.get(k);
              for (int i = 0; i < files.length; i++) {
                for (int j = 0; j < files[i].length; j++) {
                  if (failedDto != null && files[i][j].getPk() == failedDto.getPk()) {
                    deleteFile(
                        FileUtils.toFile(
                            failedDto.getDirectoryPath() + '/' + failedDto.getFilePath()));
                    failedDto = ++k < failed.size() ? failed.get(k) : null;
                  } else {
                    deleteFile(srcFiles[s]);
                  }
                  s++;
                }
              }
            }
            throw (Exception) order.getThrowable();
          }
        }
        if (!keepSrcFiles) {
          for (int i = 0; i < srcFiles.length; i++) {
            deleteFile(srcFiles[i]);
          }
          try {
            mgt.removeStudyOnFSRecord(order);
          } catch (Exception x) {
            log.warn("Remove StudyOnFS record failed for " + order, x);
          }
        }
      }
    } catch (ConcurrentStudyStorageException x) {
      log.info(x.getMessage());
    }
  }