From 6621cf1af206aaa67c22cf617df188d3d65839a2 Mon Sep 17 00:00:00 2001
From: coulbeck <coulbeck@localhost>
Date: Mon, 30 Apr 2007 18:38:13 +0000
Subject: [PATCH] Fix for issue #1464: Getting errors exporting non-userRoot backend IDs. This change fixes export-ldif on the schema backend, but disables it for the config and monitor backends.

---
 opendj-sdk/opends/src/server/org/opends/server/backends/MonitorBackend.java      |   67 ++++++++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java |    5 +
 opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java       |   82 ++++++++++++++++++--------
 3 files changed, 126 insertions(+), 28 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/MonitorBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/MonitorBackend.java
index a9d414d..3dd69e2 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/MonitorBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/MonitorBackend.java
@@ -941,7 +941,9 @@
   public boolean supportsLDIFExport()
   {
     // We can export all the monitor entries as a point-in-time snapshot.
-    return true;
+    // TODO implementation of export is incomplete
+    // TODO export-ldif reports nonsense for upTime etc.
+    return false;
   }
 
 
@@ -953,6 +955,68 @@
                          LDIFExportConfig exportConfig)
          throws DirectoryException
   {
+    // TODO export-ldif reports nonsense for upTime etc.
+
+    configEntryDN = configEntry.getDN();
+
+
+    // Get the set of user-defined attributes for the configuration entry.  Any
+    // attributes that we don't recognize will be included directly in the base
+    // monitor entry.
+    userDefinedAttributes = new ArrayList<Attribute>();
+    for (List<Attribute> attrs :
+         configEntry.getEntry().getUserAttributes().values())
+    {
+      for (Attribute a : attrs)
+      {
+        if (! isMonitorConfigAttribute(a))
+        {
+          userDefinedAttributes.add(a);
+        }
+      }
+    }
+    for (List<Attribute> attrs :
+         configEntry.getEntry().getOperationalAttributes().values())
+    {
+      for (Attribute a : attrs)
+      {
+        if (! isMonitorConfigAttribute(a))
+        {
+          userDefinedAttributes.add(a);
+        }
+      }
+    }
+
+
+    // Create the set of base DNs that we will handle.  In this case, it's just
+    // the DN of the base monitor entry.
+    try
+    {
+      baseMonitorDN = DN.decode(DN_MONITOR_ROOT);
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        debugCaught(DebugLogLevel.ERROR, e);
+      }
+
+      int msgID = MSGID_MONITOR_CANNOT_DECODE_MONITOR_ROOT_DN;
+      String message = getMessage(msgID, getExceptionMessage(e));
+      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                   message, msgID, e);
+    }
+
+    // Construct the set of objectclasses to include in the base monitor entry.
+    monitorObjectClasses = new LinkedHashMap<ObjectClass,String>(2);
+    ObjectClass topOC = DirectoryServer.getObjectClass(OC_TOP, true);
+    monitorObjectClasses.put(topOC, OC_TOP);
+
+    ObjectClass monitorOC = DirectoryServer.getObjectClass(OC_MONITOR_ENTRY,
+                                                           true);
+    monitorObjectClasses.put(monitorOC, OC_MONITOR_ENTRY);
+
+
     // Create the LDIF writer.
     LDIFWriter ldifWriter;
     try
@@ -1011,6 +1075,7 @@
     {
       try
       {
+        // TODO implementation of export is incomplete
       }
       catch (Exception e)
       {
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
index 102c583..4c6c56b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -246,12 +246,19 @@
   }
 
 
-
   /**
-   * {@inheritDoc}
+   * Initialization shared by multiple backend methods.
+   * @param  configEntry  The configuration entry that contains the
+   *                      information to use to initialize this
+   *                      backend.
+   * @param  baseDNs      The set of base DNs that have been
+   *                      configured for this backend.
+   * @throws  ConfigException  If an unrecoverable problem arises in
+   *                           the process of performing the
+   *                           initialization.
    */
-  public void initializeBackend(ConfigEntry configEntry, DN[] baseDNs)
-         throws ConfigException, InitializationException
+  private void initializeCommon(ConfigEntry configEntry, DN[] baseDNs)
+       throws ConfigException
   {
     // Make sure that a configuration entry was provided.  If not, then we will
     // not be able to complete initialization.
@@ -262,8 +269,8 @@
       throw new ConfigException(msgID, message);
     }
 
-    configEntryDN = configEntry.getDN();
     SchemaBackendCfg cfg = getSchemaBackendCfg(configEntry);
+    configEntryDN = configEntry.getDN();
 
     // Get all of the attribute types that we will use for schema elements.
     attributeTypesType =
@@ -295,6 +302,27 @@
     modifyTimestampType =
          DirectoryServer.getAttributeType(OP_ATTR_MODIFY_TIMESTAMP_LC, true);
 
+    // Construct the set of objectclasses to include in the schema entry.
+    schemaObjectClasses = new LinkedHashMap<ObjectClass,String>(3);
+    schemaObjectClasses.put(DirectoryServer.getTopObjectClass(), OC_TOP);
+
+    ObjectClass subentryOC = DirectoryServer.getObjectClass(OC_LDAP_SUBENTRY_LC,
+                                                            true);
+    schemaObjectClasses.put(subentryOC, OC_LDAP_SUBENTRY);
+
+    ObjectClass subschemaOC = DirectoryServer.getObjectClass(OC_SUBSCHEMA,
+                                                             true);
+    schemaObjectClasses.put(subschemaOC, OC_SUBSCHEMA);
+
+
+    // Define empty sets for the supported controls and features.
+    supportedControls = new HashSet<String>(0);
+    supportedFeatures = new HashSet<String>(0);
+
+
+    configEntryDN = configEntry.getDN();
+    this.baseDNs = baseDNs;
+
     creatorsName  = new AttributeValue(creatorsNameType, baseDNs[0].toString());
     modifiersName =
          new AttributeValue(modifiersNameType, baseDNs[0].toString());
@@ -340,9 +368,20 @@
     showAllAttributes = cfg.isShowAllAttributes();
 
 
+    currentConfig = cfg;
+  }
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public void initializeBackend(ConfigEntry configEntry, DN[] baseDNs)
+         throws ConfigException, InitializationException
+  {
+    initializeCommon(configEntry, baseDNs);
+
     // Register each of the suffixes with the Directory Server.  Also, register
     // the first one as the schema base.
-    this.baseDNs = baseDNs;
     DirectoryServer.setSchemaDN(baseDNs[0]);
     for (int i=0; i < baseDNs.length; i++)
     {
@@ -365,24 +404,6 @@
     }
 
 
-    // Construct the set of objectclasses to include in the schema entry.
-    schemaObjectClasses = new LinkedHashMap<ObjectClass,String>(3);
-    schemaObjectClasses.put(DirectoryServer.getTopObjectClass(), OC_TOP);
-
-    ObjectClass subentryOC = DirectoryServer.getObjectClass(OC_LDAP_SUBENTRY_LC,
-                                                            true);
-    schemaObjectClasses.put(subentryOC, OC_LDAP_SUBENTRY);
-
-    ObjectClass subschemaOC = DirectoryServer.getObjectClass(OC_SUBSCHEMA,
-                                                             true);
-    schemaObjectClasses.put(subschemaOC, OC_SUBSCHEMA);
-
-
-    // Define an empty sets for the supported controls and features.
-    supportedControls = new HashSet<String>(0);
-    supportedFeatures = new HashSet<String>(0);
-
-
     // Identify any differences that may exist between the concatenated schema
     // file from the last online modification and the current schema files.  If
     // there are any differences, then they should be from making changes to the
@@ -494,8 +515,7 @@
 
 
     // Register with the Directory Server as a configurable component.
-    currentConfig = cfg;
-    cfg.addSchemaChangeListener(this);
+    currentConfig.addSchemaChangeListener(this);
   }
 
 
@@ -4134,6 +4154,16 @@
                          LDIFExportConfig exportConfig)
          throws DirectoryException
   {
+    try
+    {
+      initializeCommon(configEntry, baseDNs);
+    }
+    catch (ConfigException e)
+    {
+      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                   e.getMessage(), e.getMessageID());
+    }
+
     // Create the LDIF writer.
     LDIFWriter ldifWriter;
     try
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 2e50169..a9a19b2 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
@@ -1970,7 +1970,8 @@
    */
   public boolean supportsLDIFExport()
   {
-    return true;
+    // TODO We would need export-ldif to initialize this backend.
+    return false;
   }
 
 
@@ -1992,6 +1993,8 @@
                          LDIFExportConfig exportConfig)
          throws DirectoryException
   {
+    // TODO We would need export-ldif to initialize this backend.
+
     LDIFWriter writer;
     try
     {

--
Gitblit v1.10.0