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

neil_a_wilson
13.43.2007 c3502b5d887989e12d6b653568ee0c20a90b6dd9
Update the config file handler so that it will do something with the
ConfigChangeResult objects that are returned from attempting to apply
configuration changes. It will perform the following (in order of precedence):

- For any method that returns a null ConfigChangeResult, it will be logged as
such using a SEVERE_ERROR level.

- For any method that returns a result with a result code other than success,
it will be logged at a SEVERE_ERROR level.

- For any method that returns a result with admin action required, it will be
logged at a SEVERE_WARNING level.

- For any method that returns a result with messages, it will be logged at an
INFORMATIONAL level.

OpenDS Issue Number: 1367
2 files modified
169 ■■■■■ changed files
opends/src/server/org/opends/server/extensions/ConfigFileHandler.java 106 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ConfigMessages.java 63 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
@@ -42,6 +42,7 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;
import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;
@@ -1148,8 +1149,9 @@
      // Notify all the add listeners that the entry has been added.
      for (ConfigAddListener l : addListeners)
      {
        // FIXME -- Do something with the result.
        ConfigChangeResult result =  l.applyConfigurationAdd(newEntry);
        handleConfigChangeResult(l.applyConfigurationAdd(newEntry),
                                 newEntry.getDN(), l.getClass().getName(),
                                 "applyConfigurationAdd");
      }
    }
    finally
@@ -1295,8 +1297,9 @@
      // Notify all the delete listeners that the entry has been removed.
      for (ConfigDeleteListener l : deleteListeners)
      {
        // FIXME -- Do something with the result.
        ConfigChangeResult result = l.applyConfigurationDelete(entry);
        handleConfigChangeResult(l.applyConfigurationDelete(entry),
                                 entry.getDN(), l.getClass().getName(),
                                 "applyConfigurationDelete");
      }
    }
    finally
@@ -1469,8 +1472,9 @@
      // Notify all the change listeners of the update.
      for (ConfigChangeListener l : changeListeners)
      {
        // FIXME -- Do something with the result.
        ConfigChangeResult result = l.applyConfigurationChange(currentEntry);
        handleConfigChangeResult(l.applyConfigurationChange(currentEntry),
                                 currentEntry.getDN(), l.getClass().getName(),
                                 "applyConfigurationChange");
      }
@@ -1479,9 +1483,10 @@
      {
        for (ConfigurableComponent c : configurableComponents)
        {
          // FIXME -- Do something with the result.
          ConfigChangeResult result = c.applyNewConfiguration(currentEntry,
                                           DynamicConstants.DEBUG_BUILD);
          handleConfigChangeResult(c.applyNewConfiguration(currentEntry,
                                          DynamicConstants.DEBUG_BUILD),
                                   currentEntry.getDN(), c.getClass().getName(),
                                   "applyNewConfiguration");
        }
      }
    }
@@ -3172,5 +3177,88 @@
    return alerts;
  }
  /**
   * Examines the provided result and logs a message if appropriate.  If the
   * result code is anything other than {@code SUCCESS}, then it will log an
   * error message.  If the operation was successful but admin action is
   * required, then it will log a warning message.  If no action is required but
   * messages were generated, then it will log an informational message.
   *
   * @param  result      The config change result object that
   * @param  entryDN     The DN of the entry that was added, deleted, or
   *                     modified.
   * @param  className   The name of the class for the object that generated the
   *                     provided result.
   * @param  methodName  The name of the method that generated the provided
   *                     result.
   */
  public void handleConfigChangeResult(ConfigChangeResult result, DN entryDN,
                                       String className, String methodName)
  {
    if (result == null)
    {
      int    msgID   = MSGID_CONFIG_CHANGE_NO_RESULT;
      String message = getMessage(msgID, String.valueOf(className),
                                  String.valueOf(methodName),
                                  String.valueOf(entryDN));
      logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_ERROR,
               message, msgID);
      return;
    }
    ResultCode   resultCode          = result.getResultCode();
    boolean      adminActionRequired = result.adminActionRequired();
    List<String> messages            = result.getMessages();
    StringBuilder messageBuffer = new StringBuilder();
    if (messages != null)
    {
      for (String s : messages)
      {
        if (messageBuffer.length() > 0)
        {
          messageBuffer.append("  ");
        }
        messageBuffer.append(s);
      }
    }
    if (resultCode != ResultCode.SUCCESS)
    {
      int    msgID   = MSGID_CONFIG_CHANGE_RESULT_ERROR;
      String message = getMessage(msgID, String.valueOf(className),
                                  String.valueOf(methodName),
                                  String.valueOf(entryDN),
                                  String.valueOf(resultCode),
                                  adminActionRequired,
                                  messageBuffer.toString());
      logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_ERROR,
               message, msgID);
    }
    else if (adminActionRequired)
    {
      int    msgID   = MSGID_CONFIG_CHANGE_RESULT_ACTION_REQUIRED;
      String message = getMessage(msgID, String.valueOf(className),
                                  String.valueOf(methodName),
                                  String.valueOf(entryDN),
                                  messageBuffer.toString());
      logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_WARNING,
               message, msgID);
    }
    else if (messageBuffer.length() > 0)
    {
      int    msgID   = MSGID_CONFIG_CHANGE_RESULT_MESSAGES;
      String message = getMessage(msgID, String.valueOf(className),
                                  String.valueOf(methodName),
                                  String.valueOf(entryDN),
                                  messageBuffer.toString());
      logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.INFORMATIONAL,
               message, msgID);
    }
  }
}
opends/src/server/org/opends/server/messages/ConfigMessages.java
@@ -6478,6 +6478,56 @@
  /**
   * The message ID for the message that will be used if a configuration add,
   * delete, or change listener or a configurable component return a result of
   * {@code null} instead of a valid config change result.  This takes three
   * arguments, which are the class name of the object, the name of the method
   * that was invoked, and the DN of the target entry.
   */
  public static final int MSGID_CONFIG_CHANGE_NO_RESULT =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_ERROR | 645;
  /**
   * The message ID for the message that will be used if an error occurs while
   * attempting to update the configuration as a result of an added, deleted,
   * or modified configuration entry.  This takes six arguments, which are the
   * class name of the object that generated the error, the name of the method
   * that was invoked, the DN of the target entry, the result code generated,
   * whether administrative action is required to apply the change, and any
   * messages generated.
   */
  public static final int MSGID_CONFIG_CHANGE_RESULT_ERROR =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_ERROR | 646;
  /**
   * The message ID for the message that will be used if a configuration change
   * requires some kind of administrative action before it will take effect.
   * This takes four arguments, which are the class name of the object that
   * indicated the action was required, the name of the method that was invoked,
   * the DN of the target entry, and any messages generated.
   */
  public static final int MSGID_CONFIG_CHANGE_RESULT_ACTION_REQUIRED =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_WARNING | 647;
  /**
   * The message ID for the message that will be used if a configuration change
   * was successful and no administrative action is required, but there were
   * messages generated.  This takes four arguments, which are the name of the
   * object that performed the processing, the name of the method that was
   * invoked, the DN of the target entry, and the messages generated.
   */
  public static final int MSGID_CONFIG_CHANGE_RESULT_MESSAGES =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_INFORMATIONAL | 648;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
   */
@@ -9320,6 +9370,19 @@
                    "configuration attribute " +
                    ATTR_REJECT_UNAUTHENTICATED_REQ + "(the value should " +
                    "be either true or false)");
    registerMessage(MSGID_CONFIG_CHANGE_NO_RESULT,
                    "%s.%s returned a result of null for entry %s.");
    registerMessage(MSGID_CONFIG_CHANGE_RESULT_ERROR,
                    "%s.%s failed for entry %s:  result code=%s, admin " +
                    "action required=%b, messages=\"%s\".");
    registerMessage(MSGID_CONFIG_CHANGE_RESULT_ACTION_REQUIRED,
                    "%s.%s indicated that administrative action is required " +
                    "for entry %s:  messages=\"%s\".");
    registerMessage(MSGID_CONFIG_CHANGE_RESULT_MESSAGES,
                    "%s.%s succeeded but generated the following messages " +
                    "for entry %s:  %s.");
  }
}