From 8086404e92e575ef9dfc1947613be994a2fdc96c Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sun, 08 Jul 2007 21:29:59 +0000
Subject: [PATCH] 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.
---
opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java | 55 ++++++++++++++++++
opendj-sdk/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java | 109 ++++++++++++++++++++++++++++++++++--
2 files changed, 158 insertions(+), 6 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
index 1d896c2..e878102 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
+++ b/opendj-sdk/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
{
diff --git a/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java b/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
index 1b91fad..8e73f83 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
+++ b/opendj-sdk/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");
}
}
--
Gitblit v1.10.0