mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

abobrov
23.04.2009 a608d0372f24771ac4f40df9980b35140008cabd
- fix regression introduced by the fix for issue 3773 in revision 5243.
- fix task scheduler completed tasks cleanup.
- fix task scheduler retention time calculation.
- fix task scheduler to no longer throw alerts if recurring task is not found when scheduling next iteration and remove related alert messages.
- fix recurring task unit test to be less prone to timing issues by scheduling test tasks way ahead.
4 files modified
93 ■■■■ changed files
opends/src/messages/messages/backend.properties 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/task/TaskScheduler.java 44 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/ServerConstants.java 23 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/backends/task/TaskBackendTestCase.java 22 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/backend.properties
@@ -410,10 +410,6 @@
 the same ID
SEVERE_ERR_TASKSCHED_DUPLICATE_TASK_ID_134=Unable to schedule task %s because \
 another task already exists with the same ID
SEVERE_ERR_TASKSCHED_CANNOT_FIND_RECURRING_TASK_135=Task %s has completed \
 processing and indicates that it is associated with recurring task %s but no \
 recurring task with that ID is currently defined so it is not possible to \
 schedule the next iteration
SEVERE_ERR_TASKSCHED_ERROR_SCHEDULING_RECURRING_ITERATION_136=An error \
 occurred while attempting to schedule the next iteration of recurring task \
 %s:  %s
opends/src/server/org/opends/server/backends/task/TaskScheduler.java
@@ -44,6 +44,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -294,19 +295,18 @@
    try
    {
      RecurringTask recurringTask = recurringTasks.remove(recurringTaskID);
      writeState();
      for (Task t : tasks.values())
      {
        if ((t.getRecurringTaskID() != null) &&
            (t.getRecurringTaskID().equals(recurringTaskID)) &&
            (!TaskState.isDone(t.getTaskState())))
            !TaskState.isDone(t.getTaskState()))
        {
          cancelTask(t.getTaskID());
        }
        removeCompletedTask(t.getTaskID());
      }
      writeState();
      return recurringTask;
    }
    finally
@@ -617,25 +617,13 @@
        return false;
      }
      // See if the task is part of a recurring task.  If so, then schedule the
      // next iteration.
      String recurringTaskID = completedTask.getRecurringTaskID();
      if (recurringTaskID != null)
      {
        RecurringTask recurringTask = recurringTasks.get(recurringTaskID);
        if (recurringTask == null)
        {
          // This shouldn't happen, but handle it anyway.
          Message message = ERR_TASKSCHED_CANNOT_FIND_RECURRING_TASK.get(
              String.valueOf(taskID), String.valueOf(recurringTaskID));
          logError(message);
          DirectoryServer.sendAlertNotification(this,
                               ALERT_TYPE_CANNOT_FIND_RECURRING_TASK,
                  message);
        }
        else
        if (recurringTask != null)
        {
          Task newIteration = null;
          try {
@@ -645,8 +633,6 @@
          }
          if (newIteration != null)
          {
            // FIXME -- What to do if new iteration is null?
            try
            {
              scheduleTask(newIteration, false);
@@ -671,10 +657,8 @@
        }
      }
      writeState();
      if (isRunning)
      {
        idleThreads.add(taskThread);
@@ -929,8 +913,10 @@
          // Clean up any completed tasks that have been around long enough.
          long retentionTimeMillis =
            TimeUnit.SECONDS.toMillis(taskBackend.getRetentionTime());
          long oldestRetainedCompletionTime =
                    TimeThread.getTime() - taskBackend.getRetentionTime();
                    TimeThread.getTime() - retentionTimeMillis;
          iterator = completedTasks.iterator();
          while (iterator.hasNext())
          {
@@ -938,19 +924,11 @@
            if (t.getCompletionTime() < oldestRetainedCompletionTime)
            {
              iterator.remove();
              tasks.remove(t.getTaskID());
              writeState = true;
            }
            // FIXME -- If the completed tasks list is sorted, can we break out
            //          of the iterator as soon as we hit one that's not old
            //          enough to be expired?
          }
          // FIXME -- Should we check to see if any of the running jobs have
          //          logged any messages?
          // If anything changed, then make sure that the on-disk state gets
          // updated.
          if (writeState)
@@ -970,9 +948,7 @@
          {
            Thread.sleep(sleepTime);
          }
        } catch (InterruptedException ie){}
        // Clean up any completed tasks that have been around long enough.
        } catch (InterruptedException ie) {}
      }
    }
    finally
@@ -2156,8 +2132,6 @@
  {
    LinkedHashMap<String,String> alerts = new LinkedHashMap<String,String>();
    alerts.put(ALERT_TYPE_CANNOT_FIND_RECURRING_TASK,
               ALERT_DESCRIPTION_CANNOT_FIND_RECURRING_TASK);
    alerts.put(ALERT_TYPE_CANNOT_SCHEDULE_RECURRING_ITERATION,
               ALERT_DESCRIPTION_CANNOT_SCHEDULE_RECURRING_ITERATION);
    alerts.put(ALERT_TYPE_CANNOT_RENAME_CURRENT_TASK_FILE,
opends/src/server/org/opends/server/util/ServerConstants.java
@@ -1288,29 +1288,6 @@
  /**
   * The description for the alert type that will be used for the alert
   * notification generated if a recurring task cannot be found to schedule the
   * next iteration after the previous iteration has completed.
   */
  public static final String ALERT_DESCRIPTION_CANNOT_FIND_RECURRING_TASK =
      "This alert type will be used to notify administrators if the " +
      "Directory Server is unable to locate a recurring task definition in " +
      "order to schedule the next iteration once the previous iteration has " +
      "completed.";
  /**
   * The alert type string that will be used for the alert notification
   * generated if a recurring task cannot be found to schedule the next
   * iteration after the previous iteration has completed.
   */
  public static final String ALERT_TYPE_CANNOT_FIND_RECURRING_TASK =
       "org.opends.server.CannotFindRecurringTask";
  /**
   * The description for the alert type that will be used for the alert
   * notification generated if an error occurs while attempting to rename the
   * current tasks backing file.
   */
opends/tests/unit-tests-testng/src/server/org/opends/server/backends/task/TaskBackendTestCase.java
@@ -479,20 +479,25 @@
  @Test
  public void testRecurringTask() throws Exception
  {
    String taskID = "testRecurringTask";
    String taskDN =
        "ds-recurring-task-id=" + taskID
            + ",cn=Recurring Tasks,cn=tasks";
    String taskSchedule = "00 * * * *";
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setFirstDayOfWeek(GregorianCalendar.SUNDAY);
    calendar.setLenient(false);
    calendar.add(GregorianCalendar.MONTH, 1);
    calendar.add(GregorianCalendar.HOUR_OF_DAY, 1);
    calendar.set(GregorianCalendar.MINUTE, 0);
    calendar.set(GregorianCalendar.SECOND, 0);
    Date scheduledDate = calendar.getTime();
    int scheduledMonth =
      calendar.get(GregorianCalendar.MONTH) + 1;
    String taskID = "testRecurringTask";
    String taskDN =
        "ds-recurring-task-id=" + taskID
            + ",cn=Recurring Tasks,cn=tasks";
    String taskSchedule = "00 * * " +
      Integer.toString(scheduledMonth) + " *";
    String scheduledTaskID = taskID + " - " + scheduledDate.toString();
    String scheduledTaskDN =
        "ds-task-id=" + scheduledTaskID
@@ -519,8 +524,9 @@
    assertEquals(resultCode, 0);
    assertFalse(DirectoryServer.entryExists(DN.decode(taskDN)));
    // Make sure scheduled task iteration got canceled and removed.
    assertFalse(DirectoryServer.entryExists(DN.decode(scheduledTaskDN)));
    // Make sure recurring task iteration got canceled.
    scheduledTask = TasksTestCase.getTask(DN.decode(scheduledTaskDN));
    assertTrue(TaskState.isCancelled(scheduledTask.getTaskState()));
  }