public FileSystemDTO removeFileSystem(String dirPath) throws Exception {
   FileSystemDTO fsDTO = fileSystemMgt().removeFileSystem(getFileSystemGroupID(), dirPath);
   if (storageFileSystem != null && storageFileSystem.getPk() == fsDTO.getPk()) {
     selectStorageFileSystem();
   }
   return fsDTO;
 }
 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;
   }
 }
 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;
   }
 }
 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;
 }
Exemplo n.º 6
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());
    }
  }