示例#1
0
 /**
  * Saves the state of the batch for revision runs usage If the current batch is 1000 and revision
  * is 1 then the file would be saved as '1000_1.savepoint'
  *
  * @param batchContext The job batchContext of the batch
  * @throws BatchException Any exception occurred during the serialization process
  */
 public static synchronized void saveBatchState(BatchContext batchContext) throws BatchException {
   BatchInfo toSaveBatchInfo = batchContext.getBatchInfo();
   toSaveBatchInfo.setProgressLevelAtLastSavePoint(
       (ProgressLevel)
           ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo())
               .clone()); // clone is necessary as ProgresLevel is static
   if (logger.isDebugEnabled()) {
     logger.debug(
         "Saving Current Batch progress level as ==>"
             + ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo()).toString());
   }
   String savepointFilePath =
       Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY");
   ObjectOutputStream oos = null;
   try {
     oos =
         new ObjectOutputStream(
             new FileOutputStream(
                 FilenameUtils.concat(
                     savepointFilePath,
                     toSaveBatchInfo.getBatchNo()
                         + "_"
                         + toSaveBatchInfo.getBatchRevNo()
                         + ".savepoint")));
     oos.writeObject(toSaveBatchInfo);
     oos.flush();
     batchContext.setBatchStateSaved(true);
   } catch (FileNotFoundException e) {
     batchContext.setBatchStateSaved(false);
     logger.error(e);
     throw new BatchException(e.getMessage(), e);
   } catch (IOException e) {
     batchContext.setBatchStateSaved(false);
     logger.error(e);
     throw new BatchException(e.getMessage(), e);
   } finally {
     IOUtils.closeQuietly(oos);
   }
 }
示例#2
0
  /**
   * Reads the saved state of the batch for revision runs If the current batch number it 1000 and
   * revision is 5, then this method would look for saved state of batch 1000 with revision (5 - 1)
   * i.e. '1000_4.savepoint'
   *
   * @param batchContext The context for the batch
   * @throws BatchException Any exception thrown during reading of the serialized file
   */
  public static synchronized void updateBatchState(BatchContext batchContext)
      throws BatchException {
    BatchInfo newBatchInfo = batchContext.getBatchInfo();
    String savepointFilePath =
        Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY");
    String savePointFile =
        FilenameUtils.concat(
            savepointFilePath,
            newBatchInfo.getBatchNo() + "_" + (newBatchInfo.getBatchRevNo() - 1) + ".savepoint");
    if (logger.isDebugEnabled()) {
      logger.debug("Reading the saved state from file : " + savePointFile);
    }
    FileInputStream fis = null;
    try {

      // Check whether the file exists
      File f = new File(savePointFile);
      if (!f.exists())
        throw new BatchException("Cannot locate the the save point file named :" + savePointFile);

      fis = new FileInputStream(f);
      ObjectInputStream ois = new ObjectInputStream(fis);
      BatchInfo savedBatchInfo = (BatchInfo) ois.readObject();
      newBatchInfo.setOrderedMap(savedBatchInfo.getOrderedMap());
      newBatchInfo.setProgressLevelAtLastSavePoint(
          (ProgressLevel)
              savedBatchInfo
                  .getProgressLevelAtLastSavePoint()); // This object is different but still cloned.
      newBatchInfo.setBatchRunDate(savedBatchInfo.getBatchRunDate());
      newBatchInfo.setDateRun(savedBatchInfo.isDateRun());

      if (logger.isDebugEnabled()) {
        logger.debug(
            "Last batch saved state is "
                + savedBatchInfo.getProgressLevelAtLastSavePoint().toString());
      }
      // Set the ExecutionStatus in the ProgressLevel
      ExecutionStatus savedExecutionStatus =
          newBatchInfo.getProgressLevelAtLastSavePoint().getExecutionStatus();
      ProgressLevel.getProgressLevel(newBatchInfo.getBatchNo())
          .setExecutionStatus(
              savedExecutionStatus.getEntity(), savedExecutionStatus.getStageCode());
      fis.close();
      fis = null;
      ois.close();
      ois = null;
    } catch (FileNotFoundException e) {
      logger.error(e);
      throw new BatchException(e.getMessage(), e);
    } catch (IOException e) {
      logger.error(e);
      throw new BatchException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      logger.error(e);
      throw new BatchException(e.getMessage(), e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
        }
      }
    }
  }