From 325b2ee4a27d0c24aa0a539f7bd0a8cf24905ff7 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Tue, 10 Apr 2007 20:41:27 +0000
Subject: [PATCH] Added the following capabilities to OpenDS: - Index rebuilding capabilities. All indexes including system and attribute indexes can  be rebuilt. Each index will be rebuilt by a seperate thread to increase performance. A  max number of rebuild threads could be set to limit the resources used by large rebuild  jobs. Partial rebuilds of attribute indexes could also be done by specifying the  attribute index type after the attribute type (ie. sn.approximate). - Index rebuilding standalone tool. Rebuilding of attribute indexes could be done with  the backend online. However, rebuilds including system indexes must be done with the  backend offline. - Index rebuilding task. Rebuilding of attribute indexes are done with the backend  online. Rebuilds that include system indexes will be performed after bring the backend  offline. The user must have index-rebuild privilages to rebuild indexes. - Approxitae indexing capability. The value of the attribute will be normalized using  the approximate maching rule of that attribute type. This is used as the key for the  index. Approximate indexes are fully supported by the index verify, rebuild, and import  jobs. - Fixed bug in build.xml where weave is enabled even if a test.* property is set. - Consolidated some common tool messages. - Consolidated some JE backend methods common to all tools. - Added unit tests for rebuild job and approximate indexes.

---
 opends/src/server/org/opends/server/tools/ImportLDIF.java |  266 +++-------------------------------------------------
 1 files changed, 18 insertions(+), 248 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/ImportLDIF.java b/opends/src/server/org/opends/server/tools/ImportLDIF.java
index 8dc717a..41883d2 100644
--- a/opends/src/server/org/opends/server/tools/ImportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -38,8 +38,6 @@
 import org.opends.server.api.plugin.PluginType;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
-import org.opends.server.config.DNConfigAttribute;
-import org.opends.server.config.StringConfigAttribute;
 import org.opends.server.core.CoreConfigManager;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.LockFileManager;
@@ -63,7 +61,6 @@
 
 import static org.opends.server.config.ConfigConstants.*;
 import static org.opends.server.loggers.Error.*;
-import static org.opends.server.messages.ConfigMessages.*;
 import static org.opends.server.messages.MessageHandler.*;
 import static org.opends.server.messages.ToolMessages.*;
 import static org.opends.server.util.ServerConstants.*;
@@ -167,7 +164,7 @@
                               OPTION_LONG_CONFIG_CLASS, true, false,
                               true, OPTION_VALUE_CONFIG_CLASS,
                               ConfigFileHandler.class.getName(), null,
-                              MSGID_LDIFIMPORT_DESCRIPTION_CONFIG_CLASS);
+                              MSGID_DESCRIPTION_CONFIG_CLASS);
       configClass.setHidden(true);
       argParser.addArgument(configClass);
 
@@ -175,7 +172,7 @@
       configFile =
            new StringArgument("configfile", 'f', "configFile", true, false,
                               true, "{configFile}", null, null,
-                              MSGID_LDIFIMPORT_DESCRIPTION_CONFIG_FILE);
+                              MSGID_DESCRIPTION_CONFIG_FILE);
       configFile.setHidden(true);
       argParser.addArgument(configFile);
 
@@ -303,13 +300,13 @@
 
       displayUsage =
            new BooleanArgument("help", OPTION_SHORT_HELP, OPTION_LONG_HELP,
-                               MSGID_LDIFIMPORT_DESCRIPTION_USAGE);
+                               MSGID_DESCRIPTION_USAGE);
       argParser.addArgument(displayUsage);
       argParser.setUsageArgument(displayUsage);
     }
     catch (ArgumentException ae)
     {
-      int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_ARGS;
+      int    msgID   = MSGID_CANNOT_INITIALIZE_ARGS;
       String message = getMessage(msgID, ae.getMessage());
 
       System.err.println(wrapText(message, MAX_LINE_WIDTH));
@@ -324,7 +321,7 @@
     }
     catch (ArgumentException ae)
     {
-      int    msgID   = MSGID_LDIFIMPORT_ERROR_PARSING_ARGS;
+      int    msgID   = MSGID_ERROR_PARSING_ARGS;
       String message = getMessage(msgID, ae.getMessage());
 
       System.err.println(wrapText(message, MAX_LINE_WIDTH));
@@ -375,7 +372,7 @@
       }
       catch (Exception e)
       {
-        int    msgID   = MSGID_LDIFIMPORT_SERVER_BOOTSTRAP_ERROR;
+        int    msgID   = MSGID_SERVER_BOOTSTRAP_ERROR;
         String message = getMessage(msgID, stackTraceToSingleLineString(e));
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
@@ -388,14 +385,14 @@
       }
       catch (InitializationException ie)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_LOAD_CONFIG;
+        int    msgID   = MSGID_CANNOT_LOAD_CONFIG;
         String message = getMessage(msgID, ie.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (Exception e)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_LOAD_CONFIG;
+        int    msgID   = MSGID_CANNOT_LOAD_CONFIG;
         String message = getMessage(msgID, stackTraceToSingleLineString(e));
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
@@ -410,21 +407,21 @@
       }
       catch (ConfigException ce)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_LOAD_SCHEMA;
+        int    msgID   = MSGID_CANNOT_LOAD_SCHEMA;
         String message = getMessage(msgID, ce.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (InitializationException ie)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_LOAD_SCHEMA;
+        int    msgID   = MSGID_CANNOT_LOAD_SCHEMA;
         String message = getMessage(msgID, ie.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (Exception e)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_LOAD_SCHEMA;
+        int    msgID   = MSGID_CANNOT_LOAD_SCHEMA;
         String message = getMessage(msgID, stackTraceToSingleLineString(e));
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
@@ -439,21 +436,21 @@
       }
       catch (ConfigException ce)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_CORE_CONFIG;
+        int    msgID   = MSGID_CANNOT_INITIALIZE_CORE_CONFIG;
         String message = getMessage(msgID, ce.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (InitializationException ie)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_CORE_CONFIG;
+        int    msgID   = MSGID_CANNOT_INITIALIZE_CORE_CONFIG;
         String message = getMessage(msgID, ie.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (Exception e)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_CORE_CONFIG;
+        int    msgID   = MSGID_CANNOT_INITIALIZE_CORE_CONFIG;
         String message = getMessage(msgID, stackTraceToSingleLineString(e));
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
@@ -467,21 +464,21 @@
       }
       catch (ConfigException ce)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_CRYPTO_MANAGER;
+        int    msgID   = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER;
         String message = getMessage(msgID, ce.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (InitializationException ie)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_CRYPTO_MANAGER;
+        int    msgID   = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER;
         String message = getMessage(msgID, ie.getMessage());
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
       }
       catch (Exception e)
       {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_CRYPTO_MANAGER;
+        int    msgID   = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER;
         String message = getMessage(msgID, stackTraceToSingleLineString(e));
         System.err.println(wrapText(message, MAX_LINE_WIDTH));
         return 1;
@@ -710,7 +707,7 @@
     ArrayList<Backend>     backendList = new ArrayList<Backend>();
     ArrayList<ConfigEntry> entryList   = new ArrayList<ConfigEntry>();
     ArrayList<List<DN>> dnList = new ArrayList<List<DN>>();
-    int code = getBackends(backendList, entryList, dnList);
+    int code = BackendToolUtils.getBackends(backendList, entryList, dnList);
     if (code != 0)
     {
       return code;
@@ -1045,232 +1042,5 @@
     importConfig.close();
     return retCode;
   }
-
-
-
-  /**
-   * Retrieves information about the backends defined in the Directory Server
-   * configuration.
-   *
-   * @param  backendList  A list into which instantiated (but not initialized)
-   *                      backend instances will be placed.
-   * @param  entryList    A list into which the config entries associated with
-   *                      the backends will be placed.
-   * @param  dnList       A list into which the set of base DNs for each backend
-   *                      will be placed.
-   *
-   * @return 0 if everything went fine. 1 if an error occurred.
-   *
-   */
-  private static int getBackends(ArrayList<Backend> backendList,
-                                  ArrayList<ConfigEntry> entryList,
-                                  ArrayList<List<DN>> dnList)
-  {
-    // Get the base entry for all backend configuration.
-    DN backendBaseDN = null;
-    try
-    {
-      backendBaseDN = DN.decode(DN_BACKEND_BASE);
-    }
-    catch (DirectoryException de)
-    {
-      int    msgID   = MSGID_LDIFIMPORT_CANNOT_DECODE_BACKEND_BASE_DN;
-      String message = getMessage(msgID, DN_BACKEND_BASE, de.getErrorMessage());
-      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
-               msgID);
-      return 1;
-    }
-    catch (Exception e)
-    {
-      int    msgID   = MSGID_LDIFIMPORT_CANNOT_DECODE_BACKEND_BASE_DN;
-      String message = getMessage(msgID, DN_BACKEND_BASE,
-                                  stackTraceToSingleLineString(e));
-      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
-               msgID);
-      return 1;
-    }
-
-    ConfigEntry baseEntry = null;
-    try
-    {
-      baseEntry = DirectoryServer.getConfigEntry(backendBaseDN);
-    }
-    catch (ConfigException ce)
-    {
-      int    msgID   = MSGID_LDIFIMPORT_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY;
-      String message = getMessage(msgID, DN_BACKEND_BASE, ce.getMessage());
-      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
-               msgID);
-      return 1;
-    }
-    catch (Exception e)
-    {
-      int    msgID   = MSGID_LDIFIMPORT_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY;
-      String message = getMessage(msgID, DN_BACKEND_BASE,
-                                  stackTraceToSingleLineString(e));
-      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
-               msgID);
-      return 1;
-    }
-
-
-    // Iterate through the immediate children, attempting to parse them as
-    // backends.
-    for (ConfigEntry configEntry : baseEntry.getChildren().values())
-    {
-      // Get the backend ID attribute from the entry.  If there isn't one, then
-      // skip the entry.
-      String backendID = null;
-      try
-      {
-        int msgID = MSGID_CONFIG_BACKEND_ATTR_DESCRIPTION_BACKEND_ID;
-        StringConfigAttribute idStub =
-             new StringConfigAttribute(ATTR_BACKEND_ID, getMessage(msgID),
-                                       true, false, true);
-        StringConfigAttribute idAttr =
-             (StringConfigAttribute) configEntry.getConfigAttribute(idStub);
-        if (idAttr == null)
-        {
-          continue;
-        }
-        else
-        {
-          backendID = idAttr.activeValue();
-        }
-      }
-      catch (ConfigException ce)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_DETERMINE_BACKEND_ID;
-        String message = getMessage(msgID, String.valueOf(configEntry.getDN()),
-                                    ce.getMessage());
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_DETERMINE_BACKEND_ID;
-        String message = getMessage(msgID, String.valueOf(configEntry.getDN()),
-                                    stackTraceToSingleLineString(e));
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-
-
-      // Get the backend class name attribute from the entry.  If there isn't
-      // one, then just skip the entry.
-      String backendClassName = null;
-      try
-      {
-        int msgID = MSGID_CONFIG_BACKEND_ATTR_DESCRIPTION_CLASS;
-        StringConfigAttribute classStub =
-             new StringConfigAttribute(ATTR_BACKEND_CLASS, getMessage(msgID),
-                                       true, false, false);
-        StringConfigAttribute classAttr =
-             (StringConfigAttribute) configEntry.getConfigAttribute(classStub);
-        if (classAttr == null)
-        {
-          continue;
-        }
-        else
-        {
-          backendClassName = classAttr.activeValue();
-        }
-      }
-      catch (ConfigException ce)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_DETERMINE_BACKEND_CLASS;
-        String message = getMessage(msgID, String.valueOf(configEntry.getDN()),
-                                    ce.getMessage());
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_DETERMINE_BACKEND_CLASS;
-        String message = getMessage(msgID, String.valueOf(configEntry.getDN()),
-                                    stackTraceToSingleLineString(e));
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-
-      Class backendClass = null;
-      try
-      {
-        backendClass = Class.forName(backendClassName);
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_LOAD_BACKEND_CLASS;
-        String message = getMessage(msgID, backendClassName,
-                                    String.valueOf(configEntry.getDN()),
-                                    stackTraceToSingleLineString(e));
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-
-      Backend backend = null;
-      try
-      {
-        backend = (Backend) backendClass.newInstance();
-        backend.setBackendID(backendID);
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_INSTANTIATE_BACKEND_CLASS;
-        String message = getMessage(msgID, backendClassName,
-                                    String.valueOf(configEntry.getDN()),
-                                    stackTraceToSingleLineString(e));
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-
-
-      // Get the base DN attribute from the entry.  If there isn't one, then
-      // just skip this entry.
-      List<DN> baseDNs = null;
-      try
-      {
-        int msgID = MSGID_CONFIG_BACKEND_ATTR_DESCRIPTION_BASE_DNS;
-        DNConfigAttribute baseDNStub =
-             new DNConfigAttribute(ATTR_BACKEND_BASE_DN, getMessage(msgID),
-                                   true, true, true);
-        DNConfigAttribute baseDNAttr =
-             (DNConfigAttribute) configEntry.getConfigAttribute(baseDNStub);
-        if (baseDNAttr == null)
-        {
-          msgID = MSGID_LDIFIMPORT_NO_BASES_FOR_BACKEND;
-          String message = getMessage(msgID,
-                                      String.valueOf(configEntry.getDN()));
-          logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                   message, msgID);
-        }
-        else
-        {
-          baseDNs = baseDNAttr.activeValues();
-        }
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFIMPORT_CANNOT_DETERMINE_BASES_FOR_BACKEND;
-        String message = getMessage(msgID, String.valueOf(configEntry.getDN()),
-                                    stackTraceToSingleLineString(e));
-        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
-                 message, msgID);
-        return 1;
-      }
-
-
-      backendList.add(backend);
-      entryList.add(configEntry);
-      dnList.add(baseDNs);
-    }
-    return 0;
-  }
 }
 

--
Gitblit v1.10.0