Example #1
0
 public void onMessage(Message message) {
   ObjectMessage om = (ObjectMessage) message;
   try {
     DeleteStudyOrder order = (DeleteStudyOrder) om.getObject();
     log.info("Start processing " + order);
     try {
       process(order);
       log.info("Finished processing " + order);
     } catch (Exception e) {
       order.setThrowable(e);
       final int failureCount = order.getFailureCount() + 1;
       order.setFailureCount(failureCount);
       final long delay = retryIntervalls.getIntervall(failureCount);
       if (delay == -1L) {
         log.error("Give up to process " + order, e);
         jmsDelegate.fail(moveFilesOfStudyQueueName, order);
       } else {
         log.warn("Failed to process " + order + ". Scheduling retry.", e);
         jmsDelegate.queue(
             moveFilesOfStudyQueueName, order, 0, System.currentTimeMillis() + delay);
       }
     }
   } catch (JMSException e) {
     log.error("jms error during processing message: " + message, e);
   } catch (Throwable e) {
     log.error("unexpected error during processing message: " + message, e);
   }
 }
Example #2
0
 protected void schedule(DeleteStudyOrder order, long scheduledTime) throws Exception {
   if (srcFsGroup == null || destFsGroup == null) {
     String msg =
         "FileMove service is disabled! Set SourceFileSystemGroupID and DestinationFileSystemGroupID to enable it.";
     log.info(msg);
     throw new RuntimeException(msg);
   } else if ("ERROR".equals(getUsableDiskSpaceStringOnDest())) {
     String msg =
         "UsableDiskSpaceStringOnDest reports an error! Scheduling Move Order cancelled! Please check DestinationFileSystemGroupID configuration!";
     log.error(msg);
     throw new RuntimeException(msg);
   } else {
     if (log.isInfoEnabled()) {
       String scheduledTimeStr = scheduledTime > 0 ? new Date(scheduledTime).toString() : "now";
       log.info(
           "Scheduling job ["
               + order
               + "] at "
               + scheduledTimeStr
               + ". Retry times: "
               + order.getFailureCount());
     }
     jmsDelegate.queue(moveFilesOfStudyQueueName, order, Message.DEFAULT_PRIORITY, scheduledTime);
   }
 }
Example #3
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());
    }
  }