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

kenneth_suter
15.34.2007 80c58327faaa4873369f6bb949e62792c2f708e0
opends/src/server/org/opends/server/backends/task/Task.java
@@ -25,6 +25,7 @@
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.backends.task;
import org.opends.messages.Message;
@@ -37,6 +38,7 @@
import java.util.List;
import java.util.TimeZone;
import java.util.UUID;
import java.util.Collections;
import java.util.concurrent.locks.Lock;
import javax.mail.MessagingException;
@@ -51,8 +53,8 @@
import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Operation;
import org.opends.server.util.EMailMessage;
@@ -60,8 +62,8 @@
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.messages.BackendMessages.*;
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.messages.BackendMessages.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -98,6 +100,11 @@
  private LinkedList<String> dependencyIDs;
  // A set of log messages generated by this task.
  // TODO: convert from String to Message objects.
  // Since these are stored in an entry we would need
  // to adopt some way for writing message to string in such
  // a way that the information could be reparsed from its
  // string value.
  private LinkedList<String> logMessages;
  // The set of e-mail addresses of the users to notify when the task is done
@@ -170,10 +177,9 @@
    {
      if (recurringTaskID == null)
      {
        int    msgID   = MSGID_TASK_MISSING_ATTR;
        String message = getMessage(msgID, String.valueOf(taskEntry.getDN()),
                                    ATTR_TASK_ID);
        throw new InitializationException(msgID, message);
        Message message = ERR_TASK_MISSING_ATTR.get(
            String.valueOf(taskEntry.getDN()), ATTR_TASK_ID);
        throw new InitializationException(message);
      }
      else
      {
@@ -194,9 +200,8 @@
      taskState = TaskState.fromString(stateString);
      if (taskState == null)
      {
        int    msgID   = MSGID_TASK_INVALID_STATE;
        String message = getMessage(msgID, taskDN, stateString);
        throw new InitializationException(msgID, message);
        Message message = ERR_TASK_INVALID_STATE.get(taskDN, stateString);
        throw new InitializationException(message);
      }
    }
@@ -231,9 +236,9 @@
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }
        int    msgID   = MSGID_TASK_CANNOT_PARSE_SCHEDULED_START_TIME;
        String message = getMessage(msgID, timeString, taskDN);
        throw new InitializationException(msgID, message, e);
        Message message =
            ERR_TASK_CANNOT_PARSE_SCHEDULED_START_TIME.get(timeString, taskDN);
        throw new InitializationException(message, e);
      }
    }
@@ -265,9 +270,9 @@
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }
        int    msgID   = MSGID_TASK_CANNOT_PARSE_ACTUAL_START_TIME;
        String message = getMessage(msgID, timeString, taskDN);
        throw new InitializationException(msgID, message, e);
        Message message =
            ERR_TASK_CANNOT_PARSE_ACTUAL_START_TIME.get(timeString, taskDN);
        throw new InitializationException(message, e);
      }
    }
@@ -299,9 +304,9 @@
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }
        int    msgID   = MSGID_TASK_CANNOT_PARSE_COMPLETION_TIME;
        String message = getMessage(msgID, timeString, taskDN);
        throw new InitializationException(msgID, message, e);
        Message message =
            ERR_TASK_CANNOT_PARSE_COMPLETION_TIME.get(timeString, taskDN);
        throw new InitializationException(message, e);
      }
    }
@@ -361,10 +366,9 @@
    {
      if (isRequired)
      {
        int    msgID   = MSGID_TASK_MISSING_ATTR;
        String message = getMessage(msgID, String.valueOf(taskEntry.getDN()),
                                    attributeName);
        throw new InitializationException(msgID, message);
        Message message = ERR_TASK_MISSING_ATTR.get(
            String.valueOf(taskEntry.getDN()), attributeName);
        throw new InitializationException(message);
      }
      else
      {
@@ -374,10 +378,9 @@
    if (attrList.size() > 1)
    {
      int    msgID   = MSGID_TASK_MULTIPLE_ATTRS_FOR_TYPE;
      String message = getMessage(msgID, attributeName,
                                  String.valueOf(taskEntry.getDN()));
      throw new InitializationException(msgID, message);
      Message message = ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get(
          attributeName, String.valueOf(taskEntry.getDN()));
      throw new InitializationException(message);
    }
    Iterator<AttributeValue> iterator = attrList.get(0).getValues().iterator();
@@ -385,10 +388,9 @@
    {
      if (isRequired)
      {
        int    msgID   = MSGID_TASK_NO_VALUES_FOR_ATTR;
        String message = getMessage(msgID, attributeName,
                                    String.valueOf(taskEntry.getDN()));
        throw new InitializationException(msgID, message);
        Message message = ERR_TASK_NO_VALUES_FOR_ATTR.get(
            attributeName, String.valueOf(taskEntry.getDN()));
        throw new InitializationException(message);
      }
      else
      {
@@ -399,10 +401,9 @@
    AttributeValue value = iterator.next();
    if (iterator.hasNext())
    {
      int    msgID   = MSGID_TASK_MULTIPLE_VALUES_FOR_ATTR;
      String message = getMessage(msgID, attributeName,
                                  String.valueOf(taskEntry.getDN()));
      throw new InitializationException(msgID, message);
      Message message = ERR_TASK_MULTIPLE_VALUES_FOR_ATTR.get(
          attributeName, String.valueOf(taskEntry.getDN()));
      throw new InitializationException(message);
    }
    return value.getStringValue();
@@ -437,9 +438,9 @@
    if (attrList.size() > 1)
    {
      int    msgID   = MSGID_TASK_MULTIPLE_ATTRS_FOR_TYPE;
      String message = getMessage(msgID, attributeName);
      throw new InitializationException(msgID, message);
      Message message = ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get(
          attributeName, String.valueOf(taskEntry.getDN()));
      throw new InitializationException(message);
    }
    Iterator<AttributeValue> iterator = attrList.get(0).getValues().iterator();
@@ -817,9 +818,14 @@
   *
   * @return  The set of messages that were logged by this task.
   */
  public final LinkedList<String> getLogMessages()
  public final List<Message> getLogMessages()
  {
    return logMessages;
    List<Message> msgList = new ArrayList<Message>();
    for(String logString : logMessages) {
      // TODO: a better job or recreating the message
      msgList.add(Message.raw(logString));
    }
    return Collections.unmodifiableList(msgList);
  }
@@ -830,68 +836,13 @@
   * the one in <code>org.opends.server.loggers.Error</code> to ensure the
   * messages are included in the ds-task-log-message attribute.
   *
   * @param  category  The category that may be used to determine whether to
   *                   actually log this message.
   * @param  severity  The severity that may be used to determine whether to
   *                   actually log this message.
   * @param  errorID   The error ID that uniquely identifies the provided format
   *                   string.
   */
  protected void logError(ErrorLogCategory category, ErrorLogSeverity severity,
                          int errorID)
  {
    // Simply pass this on to the server error logger, and it will call back
    // to the addLogMessage method for this task.
    ErrorLogger.logError(category, severity, errorID);
  }
  /**
   * Writes a message to the error log using the provided information.
   * Tasks should use this method to log messages to the error log instead of
   * the one in <code>org.opends.server.loggers.Error</code> to ensure the
   * messages are included in the ds-task-log-message attribute.
   *
   * @param  category  The category that may be used to determine whether to
   *                   actually log this message.
   * @param  severity  The severity that may be used to determine whether to
   *                   actually log this message.
   * @param  errorID   The error ID that uniquely identifies the provided format
   *                   string.
   * @param  args      The set of arguments to use for the provided format
   *                   string.
   */
  protected void logError(ErrorLogCategory category, ErrorLogSeverity severity,
                          int errorID, Object... args)
  {
    // Simply pass this on to the server error logger, and it will call back
    // to the addLogMessage method for this task.
    ErrorLogger.logError(category, severity, errorID, args);
  }
  /**
   * Writes a message to the error log using the provided information.
   * Tasks should use this method to log messages to the error log instead of
   * the one in <code>org.opends.server.loggers.Error</code> to ensure the
   * messages are included in the ds-task-log-message attribute.
   *
   * @param  category  The category that may be used to determine whether to
   *                   actually log this message.
   * @param  severity  The severity that may be used to determine whether to
   *                   actually log this message.
   * @param  message   The message to be logged.
   * @param  errorID   The error ID that uniquely identifies the format string
   *                   used to generate the provided message.
   */
  protected void logError(ErrorLogCategory category, ErrorLogSeverity severity,
                          String message, int errorID)
  protected void logError(Message message)
  {
    // Simply pass this on to the server error logger, and it will call back
    // to the addLogMessage method for this task.
    ErrorLogger.logError(category, severity, message, errorID);
    ErrorLogger.logError(message);
  }
@@ -902,12 +853,9 @@
   * indirectly through the {@code ErrorLog.logError} methods. It does not
   * automatically persist the updated task information to disk.
   *
   * @param  severity       The severity level for the log message.
   * @param  messageID      The ID that uniquely identifies the log message.
   * @param  messageString  The text of the log message
   * @param  message  he log message
   */
  public void addLogMessage(ErrorLogSeverity severity, int messageID,
                            String messageString)
  public void addLogMessage(Message message)
  {
    // We only need to grab the entry-level lock if we don't already hold the
    // broader scheduler lock.
@@ -924,17 +872,17 @@
      buffer.append("[");
      buffer.append(TimeThread.getLocalTime());
      buffer.append("] severity=\"");
      buffer.append(severity.getSeverityName());
      buffer.append(message.getDescriptor().getSeverity().name());
      buffer.append("\" msgCount=");
      buffer.append(logMessageCounter++);
      buffer.append(" msgID=");
      buffer.append(messageID);
      buffer.append(message.getDescriptor().getOrdinal());
      buffer.append(" message=\"");
      buffer.append(messageString);
      buffer.append(message.toString());
      buffer.append("\"");
      String message = buffer.toString();
      logMessages.add(message);
      String messageString = buffer.toString();
      logMessages.add(messageString);
      AttributeType type = DirectoryServer.getAttributeType(
@@ -1109,11 +1057,9 @@
      setTaskState(TaskState.STOPPED_BY_ERROR);
      int    msgID   = MSGID_TASK_EXECUTE_FAILED;
      String message = getMessage(msgID, String.valueOf(taskEntry.getDN()),
                                  stackTraceToSingleLineString(e));
      ErrorLogger.logError(ErrorLogCategory.TASK, ErrorLogSeverity.SEVERE_ERROR,
                           message, msgID);
      Message message = ERR_TASK_EXECUTE_FAILED.get(
          String.valueOf(taskEntry.getDN()), stackTraceToSingleLineString(e));
      logError(message);
    }
    finally
    {
@@ -1177,7 +1123,7 @@
        String actualStartDate = new Date(actualStartTime).toString();
        String completionDate  = new Date(completionTime).toString();
        message.setBody(getMessage(MSGID_TASK_COMPLETION_BODY, taskID,
        message.setBody(INFO_TASK_COMPLETION_BODY.get(taskID,
                                   String.valueOf(taskState),
                                   scheduledStartDate, actualStartDate,
                                   completionDate));
@@ -1233,7 +1179,7 @@
   *                          successfully interrupted.
   * @param  interruptReason  A human-readable explanation for the cancellation.
   */
  public void interruptTask(TaskState interruptState, String interruptReason)
  public void interruptTask(TaskState interruptState, Message interruptReason)
  {
    // No action is performed by default.
  }