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

neil_a_wilson
08.29.2007 36f277e76984f6184f2694507aeb7a3c8d856fda
Update the config file handler so that it will report back to clients if a
problem occurs while applying a configuration add, delete, or modify after the
new configuration has been written to disk.

This is the first part of the fix for issue #1861.
2 files modified
164 ■■■■■ changed files
opends/src/server/org/opends/server/extensions/ConfigFileHandler.java 109 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ConfigMessages.java 55 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
@@ -39,6 +39,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -1357,12 +1358,44 @@
      // Notify all the add listeners that the entry has been added.
      ResultCode         resultCode = ResultCode.SUCCESS;
      LinkedList<String> messages   = new LinkedList<String>();
      for (ConfigAddListener l : addListeners)
      {
        handleConfigChangeResult(l.applyConfigurationAdd(newEntry),
                                 newEntry.getDN(), l.getClass().getName(),
        ConfigChangeResult result = l.applyConfigurationAdd(newEntry);
        if (result.getResultCode() != ResultCode.SUCCESS)
        {
          if (resultCode == ResultCode.SUCCESS)
          {
            resultCode = result.getResultCode();
          }
          messages.addAll(result.getMessages());
        }
        handleConfigChangeResult(result, newEntry.getDN(),
                                 l.getClass().getName(),
                                 "applyConfigurationAdd");
      }
      if (resultCode != ResultCode.SUCCESS)
      {
        StringBuilder buffer = new StringBuilder();
        if (! messages.isEmpty())
        {
          Iterator<String> iterator = messages.iterator();
          buffer.append(iterator.next());
          while (iterator.hasNext())
          {
            buffer.append(".  ");
            buffer.append(iterator.next());
          }
        }
        int    msgID   = MSGID_CONFIG_FILE_ADD_APPLY_FAILED;
        String message = getMessage(msgID, String.valueOf(buffer));
        throw new DirectoryException(resultCode, message, msgID);
      }
    }
    finally
    {
@@ -1505,12 +1538,44 @@
      // Notify all the delete listeners that the entry has been removed.
      ResultCode         resultCode = ResultCode.SUCCESS;
      LinkedList<String> messages   = new LinkedList<String>();
      for (ConfigDeleteListener l : deleteListeners)
      {
        handleConfigChangeResult(l.applyConfigurationDelete(entry),
                                 entry.getDN(), l.getClass().getName(),
        ConfigChangeResult result = l.applyConfigurationDelete(entry);
        if (result.getResultCode() != ResultCode.SUCCESS)
        {
          if (resultCode == ResultCode.SUCCESS)
          {
            resultCode = result.getResultCode();
          }
          messages.addAll(result.getMessages());
        }
        handleConfigChangeResult(result, entry.getDN(),
                                 l.getClass().getName(),
                                 "applyConfigurationDelete");
      }
      if (resultCode != ResultCode.SUCCESS)
      {
        StringBuilder buffer = new StringBuilder();
        if (! messages.isEmpty())
        {
          Iterator<String> iterator = messages.iterator();
          buffer.append(iterator.next());
          while (iterator.hasNext())
          {
            buffer.append(".  ");
            buffer.append(iterator.next());
          }
        }
        int    msgID   = MSGID_CONFIG_FILE_DELETE_APPLY_FAILED;
        String message = getMessage(msgID, String.valueOf(buffer));
        throw new DirectoryException(resultCode, message, msgID);
      }
    }
    finally
    {
@@ -1658,12 +1723,44 @@
      // Notify all the change listeners of the update.
      ResultCode         resultCode = ResultCode.SUCCESS;
      LinkedList<String> messages   = new LinkedList<String>();
      for (ConfigChangeListener l : changeListeners)
      {
        handleConfigChangeResult(l.applyConfigurationChange(currentEntry),
                                 currentEntry.getDN(), l.getClass().getName(),
        ConfigChangeResult result = l.applyConfigurationChange(newEntry);
        if (result.getResultCode() != ResultCode.SUCCESS)
        {
          if (resultCode == ResultCode.SUCCESS)
          {
            resultCode = result.getResultCode();
          }
          messages.addAll(result.getMessages());
        }
        handleConfigChangeResult(result, newEntry.getDN(),
                                 l.getClass().getName(),
                                 "applyConfigurationChange");
      }
      if (resultCode != ResultCode.SUCCESS)
      {
        StringBuilder buffer = new StringBuilder();
        if (! messages.isEmpty())
        {
          Iterator<String> iterator = messages.iterator();
          buffer.append(iterator.next());
          while (iterator.hasNext())
          {
            buffer.append(".  ");
            buffer.append(iterator.next());
          }
        }
        int    msgID   = MSGID_CONFIG_FILE_MODIFY_APPLY_FAILED;
        String message = getMessage(msgID, String.valueOf(buffer));
        throw new DirectoryException(resultCode, message, msgID);
      }
    }
    finally
    {
opends/src/server/org/opends/server/messages/ConfigMessages.java
@@ -6824,6 +6824,39 @@
  /**
   * The message ID for the message that will be used if an error occurred when
   * attempting to apply configuration changes after an entry had been added to
   * the server configuration.  This takes a single argument, which is a message
   * explaining the problem(s) that occurred.
   */
  public static final int MSGID_CONFIG_FILE_ADD_APPLY_FAILED =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_ERROR | 676;
  /**
   * The message ID for the message that will be used if an error occurred when
   * attempting to apply configuration changes after an entry had been removed
   * from the server configuration.  This takes a single argument, which is a
   * message explaining the problem(s) that occurred.
   */
  public static final int MSGID_CONFIG_FILE_DELETE_APPLY_FAILED =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_ERROR | 677;
  /**
   * The message ID for the message that will be used if an error occurred when
   * attempting to apply configuration changes after an entry had been updated
   * in the server configuration.  This takes a single argument, which is a
   * message explaining the problem(s) that occurred.
   */
  public static final int MSGID_CONFIG_FILE_MODIFY_APPLY_FAILED =
       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_ERROR | 678;
  /**
   * Associates a set of generic messages with the message IDs defined in this
@@ -9731,6 +9764,28 @@
                    "An error occurred while attempting create a text writer " +
                    "for a Directory Server logger from the information " +
                    "in configuration entry %s:  %s");
    registerMessage(MSGID_CONFIG_FILE_ADD_APPLY_FAILED,
                    "The attempt to apply the configuration add failed.  The " +
                    "preliminary checks were all successful and the entry " +
                    "was added to the server configuration, but at least one " +
                    "of the configuration add listeners reported an error " +
                    "when attempting to apply the change:  %s");
    registerMessage(MSGID_CONFIG_FILE_DELETE_APPLY_FAILED,
                    "The attempt to apply the configuration delete failed.  " +
                    "The preliminary checks were all successful and the " +
                    "entry was removed from the server configuration, but at " +
                    "least one of the configuration delete listeners " +
                    "reported an error when attempting to apply the change:  " +
                    "%s");
    registerMessage(MSGID_CONFIG_FILE_MODIFY_APPLY_FAILED,
                    "The attempt to apply the configuration modification " +
                    "failed.  The preliminary checks were all successful and " +
                    "the modified entry was written to the server " +
                    "configuration, but at least one of the configuration " +
                    "change listeners reported an error when attempting to " +
                    "apply the change:  %s");
  }
}