コード例 #1
0
 /**
  * Return nominal time or Action Creation Time.
  *
  * <p>
  *
  * @return coordinator action creation or materialization date time
  * @throws Exception if unable to format the Date object to String
  */
 public static String ph2_coord_nominalTime() throws Exception {
   ELEvaluator eval = ELEvaluator.getCurrent();
   SyncCoordAction action =
       ParamChecker.notNull(
           (SyncCoordAction) eval.getVariable(COORD_ACTION), "Coordinator Action");
   return DateUtils.formatDateUTC(action.getNominalTime());
 }
コード例 #2
0
 /**
  * Returns the a date string while given a base date in 'strBaseDate', offset and unit (e.g. DAY,
  * MONTH, HOUR, MINUTE, MONTH).
  *
  * @param strBaseDate -- base date
  * @param offset -- any number
  * @param unit -- DAY, MONTH, HOUR, MINUTE, MONTH
  * @return date string
  * @throws Exception
  */
 public static String ph2_coord_dateOffset(String strBaseDate, int offset, String unit)
     throws Exception {
   Calendar baseCalDate = DateUtils.getCalendar(strBaseDate);
   StringBuilder buffer = new StringBuilder();
   baseCalDate.add(TimeUnit.valueOf(unit).getCalendarUnit(), offset);
   buffer.append(DateUtils.formatDateUTC(baseCalDate));
   return buffer.toString();
 }
コード例 #3
0
 /**
  * Return Action Start time.
  *
  * <p>
  *
  * @return coordinator action start time
  * @throws Exception if unable to format the Date object to String
  */
 public static String ph2_coord_actualTime() throws Exception {
   ELEvaluator eval = ELEvaluator.getCurrent();
   SyncCoordAction coordAction = (SyncCoordAction) eval.getVariable(COORD_ACTION);
   if (coordAction == null) {
     throw new RuntimeException(
         "Associated Application instance should be defined with key " + COORD_ACTION);
   }
   return DateUtils.formatDateUTC(coordAction.getActualTime());
 }
コード例 #4
0
  /**
   * @param n
   * @return n-th instance Date-Time from current instance for data-set
   *     <p>return empty string ("") if the Action_Creation_time or the n-th instance
   *     <p>is earlier than the Initial_Instance of dataset.
   * @throws Exception
   */
  private static String coord_current_sync(int n) throws Exception {
    int datasetFrequency = getDSFrequency(); // in minutes
    TimeUnit dsTimeUnit = getDSTimeUnit();
    int[] instCount = new int[1]; // used as pass by ref
    Calendar nominalInstanceCal = getCurrentInstance(getActionCreationtime(), instCount);
    if (nominalInstanceCal == null) {
      return "";
    }
    nominalInstanceCal = getInitialInstanceCal();
    int absInstanceCount = instCount[0] + n;
    nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), datasetFrequency * absInstanceCount);

    if (nominalInstanceCal.getTime().compareTo(getInitialInstance()) < 0) {
      return "";
    }
    String str = DateUtils.formatDateUTC(nominalInstanceCal);
    return str;
  }
コード例 #5
0
  /**
   * @param offset
   * @return n-th available latest instance Date-Time for SYNC data-set
   * @throws Exception
   */
  private static String coord_latest_sync(int offset) throws Exception {
    if (offset > 0) {
      throw new RuntimeException(
          "For latest there is no meaning " + "of positive instance. n should be <=0" + offset);
    }
    ELEvaluator eval = ELEvaluator.getCurrent();
    String retVal = "";
    int datasetFrequency = (int) getDSFrequency(); // in minutes
    TimeUnit dsTimeUnit = getDSTimeUnit();
    int[] instCount = new int[1];
    Calendar nominalInstanceCal = getCurrentInstance(getActualTime(), instCount);
    if (nominalInstanceCal != null) {
      Calendar initInstance = getInitialInstanceCal();
      SyncCoordDataset ds = (SyncCoordDataset) eval.getVariable(DATASET);
      if (ds == null) {
        throw new RuntimeException("Associated Dataset should be defined with key " + DATASET);
      }
      String uriTemplate = ds.getUriTemplate();
      Configuration conf = (Configuration) eval.getVariable(CONFIGURATION);
      if (conf == null) {
        throw new RuntimeException(
            "Associated Configuration should be defined with key " + CONFIGURATION);
      }
      int available = 0;
      boolean resolved = false;
      String user =
          ParamChecker.notEmpty(
              (String) eval.getVariable(OozieClient.USER_NAME), OozieClient.USER_NAME);
      String group =
          ParamChecker.notEmpty(
              (String) eval.getVariable(OozieClient.GROUP_NAME), OozieClient.GROUP_NAME);
      String doneFlag = ds.getDoneFlag();
      while (nominalInstanceCal.compareTo(initInstance) >= 0) {
        ELEvaluator uriEval = getUriEvaluator(nominalInstanceCal);
        String uriPath = uriEval.evaluate(uriTemplate, String.class);
        String pathWithDoneFlag = uriPath;
        if (doneFlag.length() > 0) {
          pathWithDoneFlag += "/" + doneFlag;
        }
        if (isPathAvailable(pathWithDoneFlag, user, group, conf)) {
          XLog.getLog(CoordELFunctions.class)
              .debug("Found latest(" + available + "): " + pathWithDoneFlag);
          if (available == offset) {
            XLog.getLog(CoordELFunctions.class).debug("Found Latest File: " + pathWithDoneFlag);
            resolved = true;
            retVal = DateUtils.formatDateUTC(nominalInstanceCal);
            eval.setVariable("resolved_path", uriPath);
            break;
          }

          available--;
        }
        // nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(),
        // -datasetFrequency);
        nominalInstanceCal = (Calendar) initInstance.clone();
        instCount[0]--;
        nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), instCount[0] * datasetFrequency);
        // DateUtils.moveToEnd(nominalInstanceCal, getDSEndOfFlag());
      }
      if (!resolved) {
        // return unchanged latest function with variable 'is_resolved'
        // to 'false'
        eval.setVariable("is_resolved", Boolean.FALSE);
        retVal = "${coord:latest(" + offset + ")}";
      } else {
        eval.setVariable("is_resolved", Boolean.TRUE);
      }
    } else { // No feasible nominal time
      eval.setVariable("is_resolved", Boolean.FALSE);
    }
    return retVal;
  }