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

boli
03.55.2007 d755882f59202fe62b2ad5a141b3c044c1898aa6
opends/src/server/org/opends/server/tools/RebuildIndex.java
@@ -36,12 +36,14 @@
import static org.opends.server.messages.ToolMessages.*;
import org.opends.server.config.ConfigException;
import org.opends.server.config.ConfigEntry;
import static org.opends.server.loggers.Error.*;
import static org.opends.server.loggers.Error.logError;
import org.opends.server.loggers.StartupErrorLogger;
import static org.opends.server.loggers.ErrorLogger.logError;
import org.opends.server.loggers.ThreadFilterTextErrorLogPublisher;
import org.opends.server.loggers.TextWriter;
import org.opends.server.loggers.ErrorLogger;
import static org.opends.server.messages.MessageHandler.getMessage;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import org.opends.server.util.StaticUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.CoreConfigManager;
import org.opends.server.core.LockFileManager;
@@ -62,6 +64,8 @@
 */
public class RebuildIndex
{
  private static DN publisherDN = null;
  /**
   * Processes the command-line arguments and invokes the rebuild process.
   *
@@ -69,6 +73,28 @@
   */
  public static void main(String[] args)
  {
    int retCode = mainRebuildIndex(args);
    if(publisherDN != null)
    {
      ErrorLogger.removeErrorLogPublisher(publisherDN);
    }
    if(retCode != 0)
    {
      System.exit(retCode);
    }
  }
  /**
   * Processes the command-line arguments and invokes the rebuild process.
   *
   * @param  args  The command-line arguments provided to this program.
   *
   * @return The error code.
   */
  public static int mainRebuildIndex(String[] args)
  {
    // Define the command-line arguments that may be used with this program.
    StringArgument  configClass             = null;
    StringArgument  configFile              = null;
@@ -132,7 +158,7 @@
      String message = getMessage(msgID, ae.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
@@ -148,14 +174,14 @@
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.err.println(argParser.getUsage());
      System.exit(1);
      return 1;
    }
    // If we should just display usage information, then print it and exit.
    if (argParser.usageDisplayed())
    {
      System.exit(0);
      return 0;
    }
@@ -166,7 +192,7 @@
    if (numArgs == 0)
    {
      System.out.println(argParser.getUsage());
      System.exit(1);
      return 1;
    }
@@ -177,7 +203,7 @@
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.out.println(argParser.getUsage());
      System.exit(1);
      return 1;
    }
    // Perform the initial bootstrap of the Directory Server and process the
@@ -194,7 +220,7 @@
      int    msgID   = MSGID_SERVER_BOOTSTRAP_ERROR;
      String message = getMessage(msgID, getExceptionMessage(e));
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    try
@@ -207,14 +233,14 @@
      int    msgID   = MSGID_CANNOT_LOAD_CONFIG;
      String message = getMessage(msgID, ie.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (Exception e)
    {
      int    msgID   = MSGID_CANNOT_LOAD_CONFIG;
      String message = getMessage(msgID, getExceptionMessage(e));
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
@@ -229,21 +255,21 @@
      int    msgID   = MSGID_CANNOT_LOAD_SCHEMA;
      String message = getMessage(msgID, ce.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (InitializationException ie)
    {
      int    msgID   = MSGID_CANNOT_LOAD_SCHEMA;
      String message = getMessage(msgID, ie.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (Exception e)
    {
      int    msgID   = MSGID_CANNOT_LOAD_SCHEMA;
      String message = getMessage(msgID, getExceptionMessage(e));
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
@@ -258,21 +284,21 @@
      int    msgID   = MSGID_CANNOT_INITIALIZE_CORE_CONFIG;
      String message = getMessage(msgID, ce.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (InitializationException ie)
    {
      int    msgID   = MSGID_CANNOT_INITIALIZE_CORE_CONFIG;
      String message = getMessage(msgID, ie.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (Exception e)
    {
      int    msgID   = MSGID_CANNOT_INITIALIZE_CORE_CONFIG;
      String message = getMessage(msgID, getExceptionMessage(e));
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
@@ -286,30 +312,41 @@
      int    msgID   = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER;
      String message = getMessage(msgID, ce.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (InitializationException ie)
    {
      int    msgID   = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER;
      String message = getMessage(msgID, ie.getMessage());
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    catch (Exception e)
    {
      int    msgID   = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER;
      String message = getMessage(msgID, getExceptionMessage(e));
      System.err.println(wrapText(message, MAX_LINE_WIDTH));
      System.exit(1);
      return 1;
    }
    // FIXME -- Install a custom logger to capture information about the state
    // of the verify process.
    StartupErrorLogger startupLogger = new StartupErrorLogger();
    startupLogger.initializeErrorLogger(null);
    addErrorLogger(startupLogger);
    try
    {
      publisherDN = DN.decode("cn=Custom Logger for RebuildIndex");
      ThreadFilterTextErrorLogPublisher publisher =
          new ThreadFilterTextErrorLogPublisher(Thread.currentThread(),
                                                new TextWriter.STDOUT());
      ErrorLogger.addErrorLogPublisher(publisherDN, publisher);
    }
    catch(Exception e)
    {
      System.err.println("Error installing the custom error logger: " +
          StaticUtils.stackTraceToSingleLineString(e));
    }
    // Decode the base DN provided by the user.
    DN rebuildBaseDN = null;
@@ -324,7 +361,7 @@
                                  de.getErrorMessage());
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
               msgID);
      System.exit(1);
      return 1;
    }
    catch (Exception e)
    {
@@ -333,7 +370,7 @@
                                  getExceptionMessage(e));
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
               msgID);
      System.exit(1);
      return 1;
    }
    // Get information about the backends defined in the server.
@@ -370,7 +407,7 @@
            String message = getMessage(msgID, baseDNString.getValue());
            logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                     message, msgID);
            System.exit(1);
            return 1;
          }
          break;
        }
@@ -383,7 +420,7 @@
      String message = getMessage(msgID, baseDNString.getValue());
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
               msgID);
      System.exit(1);
      return 1;
    }
    if (!(backend instanceof BackendImpl))
@@ -392,7 +429,7 @@
      String message = getMessage(msgID);
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
               msgID);
      System.exit(1);
      return 1;
    }
    // Initialize the rebuild configuration.
@@ -416,7 +453,7 @@
                                    String.valueOf(failureReason));
        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                 message, msgID);
        return;
        return 1;
      }
    }
    catch (Exception e)
@@ -426,7 +463,7 @@
                                  getExceptionMessage(e));
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
               message, msgID);
      return;
      return 1;
    }
    // Launch the rebuild process.
@@ -467,5 +504,7 @@
                 message, msgID);
      }
    }
    return 0;
  }
}