From 2811274062184e78e27d610a38b4edb84f15b837 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 02 Mar 2007 21:51:18 +0000
Subject: [PATCH] Make the import-ldif, export-ldif, backup, and restore tools easier to invoke programmatically from within the same JVM as the server. This will make it much easier to call them from unit tests.
---
opends/src/server/org/opends/server/tools/ExportLDIF.java | 302 +++++++-------
opends/src/server/org/opends/server/tools/RestoreDB.java | 248 ++++++-----
opends/src/server/org/opends/server/tools/BackUpDB.java | 248 ++++++-----
opends/src/server/org/opends/server/tools/ImportLDIF.java | 362 +++++++++--------
4 files changed, 612 insertions(+), 548 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/BackUpDB.java b/opends/src/server/org/opends/server/tools/BackUpDB.java
index 3ab90fc..b1a2f53 100644
--- a/opends/src/server/org/opends/server/tools/BackUpDB.java
+++ b/opends/src/server/org/opends/server/tools/BackUpDB.java
@@ -103,6 +103,20 @@
*/
public static int mainBackUpDB(String[] args)
{
+ return mainBackUpDB(args, true);
+ }
+
+ /**
+ * Processes the command-line arguments and invokes the backup process.
+ *
+ * @param args The command-line arguments provided to this
+ * program.
+ * @param initializeServer Indicates whether to initialize the server.
+ *
+ * @return The error code.
+ */
+ public static int mainBackUpDB(String[] args, boolean initializeServer)
+ {
// Define the command-line arguments that may be used with this program.
BooleanArgument backUpAll = null;
BooleanArgument compress = null;
@@ -339,132 +353,134 @@
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
DirectoryServer directoryServer = DirectoryServer.getInstance();
+ if (initializeServer)
+ {
+ try
+ {
+ directoryServer.bootstrapClient();
+ directoryServer.initializeJMX();
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_BACKUPDB_SERVER_BOOTSTRAP_ERROR;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- try
- {
- directoryServer.bootstrapClient();
- directoryServer.initializeJMX();
- }
- catch (Exception e)
- {
- int msgID = MSGID_BACKUPDB_SERVER_BOOTSTRAP_ERROR;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
-
- try
- {
- directoryServer.initializeConfiguration(configClass.getValue(),
- configFile.getValue());
- }
- catch (InitializationException ie)
- {
- int msgID = MSGID_BACKUPDB_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_BACKUPDB_CANNOT_LOAD_CONFIG;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ try
+ {
+ directoryServer.initializeConfiguration(configClass.getValue(),
+ configFile.getValue());
+ }
+ catch (InitializationException ie)
+ {
+ int msgID = MSGID_BACKUPDB_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_BACKUPDB_CANNOT_LOAD_CONFIG;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server schema elements.
- try
- {
- directoryServer.initializeSchema();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_BACKUPDB_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_BACKUPDB_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_BACKUPDB_CANNOT_LOAD_SCHEMA;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server schema elements.
+ try
+ {
+ directoryServer.initializeSchema();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_BACKUPDB_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_BACKUPDB_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_BACKUPDB_CANNOT_LOAD_SCHEMA;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server core configuration.
- try
- {
- CoreConfigManager coreConfigManager = new CoreConfigManager();
- coreConfigManager.initializeCoreConfig();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_BACKUPDB_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_BACKUPDB_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_BACKUPDB_CANNOT_INITIALIZE_CORE_CONFIG;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server core configuration.
+ try
+ {
+ CoreConfigManager coreConfigManager = new CoreConfigManager();
+ coreConfigManager.initializeCoreConfig();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_BACKUPDB_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_BACKUPDB_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_BACKUPDB_CANNOT_INITIALIZE_CORE_CONFIG;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server crypto manager.
- try
- {
- directoryServer.initializeCryptoManager();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_BACKUPDB_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_BACKUPDB_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_BACKUPDB_CANNOT_INITIALIZE_CRYPTO_MANAGER;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server crypto manager.
+ try
+ {
+ directoryServer.initializeCryptoManager();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_BACKUPDB_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_BACKUPDB_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_BACKUPDB_CANNOT_INITIALIZE_CRYPTO_MANAGER;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // FIXME -- Install a custom logger to capture information about the state
- // of the export.
- StartupErrorLogger startupLogger = new StartupErrorLogger();
- startupLogger.initializeErrorLogger(null);
- addErrorLogger(startupLogger);
+ // FIXME -- Install a custom logger to capture information about the state
+ // of the export.
+ StartupErrorLogger startupLogger = new StartupErrorLogger();
+ startupLogger.initializeErrorLogger(null);
+ addErrorLogger(startupLogger);
+ }
// Get information about the backends defined in the server, and determine
diff --git a/opends/src/server/org/opends/server/tools/ExportLDIF.java b/opends/src/server/org/opends/server/tools/ExportLDIF.java
index 1caaea9..0e7add0 100644
--- a/opends/src/server/org/opends/server/tools/ExportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ExportLDIF.java
@@ -101,6 +101,20 @@
*/
public static int mainExportLDIF(String[] args)
{
+ return mainExportLDIF(args, true);
+ }
+
+ /**
+ * Processes the command-line arguments and invokes the export process.
+ *
+ * @param args The command-line arguments provided to this
+ * program.
+ * @param initializeServer Indicates whether to initialize the server.
+ *
+ * @return The error code.
+ */
+ public static int mainExportLDIF(String[] args, boolean initializeServer)
+ {
// Define the command-line arguments that may be used with this program.
BooleanArgument appendToLDIF = null;
BooleanArgument compressLDIF = null;
@@ -284,161 +298,163 @@
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
DirectoryServer directoryServer = DirectoryServer.getInstance();
+ if (initializeServer)
+ {
+ try
+ {
+ directoryServer.bootstrapClient();
+ directoryServer.initializeJMX();
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_LDIFEXPORT_SERVER_BOOTSTRAP_ERROR;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- try
- {
- directoryServer.bootstrapClient();
- directoryServer.initializeJMX();
- }
- catch (Exception e)
- {
- int msgID = MSGID_LDIFEXPORT_SERVER_BOOTSTRAP_ERROR;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
-
- try
- {
- directoryServer.initializeConfiguration(configClass.getValue(),
- configFile.getValue());
- }
- catch (InitializationException ie)
- {
- int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_CANNOT_LOAD_CONFIG;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ try
+ {
+ directoryServer.initializeConfiguration(configClass.getValue(),
+ configFile.getValue());
+ }
+ catch (InitializationException ie)
+ {
+ int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_CANNOT_LOAD_CONFIG;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server schema elements.
- try
- {
- directoryServer.initializeSchema();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_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_LDIFEXPORT_CANNOT_LOAD_SCHEMA;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server schema elements.
+ try
+ {
+ directoryServer.initializeSchema();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_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_LDIFEXPORT_CANNOT_LOAD_SCHEMA;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server core configuration.
- try
- {
- CoreConfigManager coreConfigManager = new CoreConfigManager();
- coreConfigManager.initializeCoreConfig();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_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_LDIFEXPORT_CANNOT_INITIALIZE_CORE_CONFIG;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server core configuration.
+ try
+ {
+ CoreConfigManager coreConfigManager = new CoreConfigManager();
+ coreConfigManager.initializeCoreConfig();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_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_LDIFEXPORT_CANNOT_INITIALIZE_CORE_CONFIG;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server crypto manager.
- try
- {
- directoryServer.initializeCryptoManager();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_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_LDIFEXPORT_CANNOT_INITIALIZE_CRYPTO_MANAGER;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server crypto manager.
+ try
+ {
+ directoryServer.initializeCryptoManager();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFEXPORT_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_LDIFEXPORT_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_LDIFEXPORT_CANNOT_INITIALIZE_CRYPTO_MANAGER;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // FIXME -- Install a custom logger to capture information about the state
- // of the export.
- StartupErrorLogger startupLogger = new StartupErrorLogger();
- startupLogger.initializeErrorLogger(null);
- addErrorLogger(startupLogger);
+ // FIXME -- Install a custom logger to capture information about the state
+ // of the export.
+ StartupErrorLogger startupLogger = new StartupErrorLogger();
+ startupLogger.initializeErrorLogger(null);
+ addErrorLogger(startupLogger);
- // Make sure that the Directory Server plugin initialization is performed.
- try
- {
- HashSet<PluginType> pluginTypes = new HashSet<PluginType>(1);
- pluginTypes.add(PluginType.LDIF_EXPORT);
- directoryServer.initializePlugins(pluginTypes);
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFEXPORT_CANNOT_INITIALIZE_PLUGINS;
- String message = getMessage(msgID, ce.getMessage());
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
- catch (InitializationException ie)
- {
- int msgID = MSGID_LDIFEXPORT_CANNOT_INITIALIZE_PLUGINS;
- String message = getMessage(msgID, ie.getMessage());
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
- catch (Exception e)
- {
- int msgID = MSGID_LDIFEXPORT_CANNOT_INITIALIZE_PLUGINS;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
+ // Make sure that the Directory Server plugin initialization is performed.
+ try
+ {
+ HashSet<PluginType> pluginTypes = new HashSet<PluginType>(1);
+ pluginTypes.add(PluginType.LDIF_EXPORT);
+ directoryServer.initializePlugins(pluginTypes);
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFEXPORT_CANNOT_INITIALIZE_PLUGINS;
+ String message = getMessage(msgID, ce.getMessage());
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
+ catch (InitializationException ie)
+ {
+ int msgID = MSGID_LDIFEXPORT_CANNOT_INITIALIZE_PLUGINS;
+ String message = getMessage(msgID, ie.getMessage());
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_LDIFEXPORT_CANNOT_INITIALIZE_PLUGINS;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
}
diff --git a/opends/src/server/org/opends/server/tools/ImportLDIF.java b/opends/src/server/org/opends/server/tools/ImportLDIF.java
index e39d51f..2d334f2 100644
--- a/opends/src/server/org/opends/server/tools/ImportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -104,12 +104,26 @@
/**
* Processes the command-line arguments and invokes the import process.
*
- * @param args The command-line arguments provided to this program.
+ * @param args The command-line arguments provided to thisprogram.
*
* @return The error code.
*/
public static int mainImportLDIF(String[] args)
{
+ return mainImportLDIF(args, true);
+ }
+
+ /**
+ * Processes the command-line arguments and invokes the import process.
+ *
+ * @param args The command-line arguments provided to this
+ * program.
+ * @param initializeServer Indicates whether to initialize the server.
+ *
+ * @return The error code.
+ */
+ public static int mainImportLDIF(String[] args, boolean initializeServer)
+ {
// FIXME -- Need to add a mechanism for verifying the file signature.
// Define the command-line arguments that may be used with this program.
@@ -347,192 +361,194 @@
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
DirectoryServer directoryServer = DirectoryServer.getInstance();
+ if (initializeServer)
+ {
+ try
+ {
+ DirectoryServer.bootstrapClient();
+ DirectoryServer.initializeJMX();
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_LDIFIMPORT_SERVER_BOOTSTRAP_ERROR;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- try
- {
- DirectoryServer.bootstrapClient();
- DirectoryServer.initializeJMX();
- }
- catch (Exception e)
- {
- int msgID = MSGID_LDIFIMPORT_SERVER_BOOTSTRAP_ERROR;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
-
- try
- {
- directoryServer.initializeConfiguration(configClass.getValue(),
- configFile.getValue());
- }
- catch (InitializationException ie)
- {
- int msgID = MSGID_LDIFIMPORT_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;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ try
+ {
+ directoryServer.initializeConfiguration(configClass.getValue(),
+ configFile.getValue());
+ }
+ catch (InitializationException ie)
+ {
+ int msgID = MSGID_LDIFIMPORT_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;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server schema elements.
- try
- {
- directoryServer.initializeSchema();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFIMPORT_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;
- 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;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server schema elements.
+ try
+ {
+ directoryServer.initializeSchema();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFIMPORT_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;
+ 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;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server core configuration.
- try
- {
- CoreConfigManager coreConfigManager = new CoreConfigManager();
- coreConfigManager.initializeCoreConfig();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFIMPORT_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;
- 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;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server core configuration.
+ try
+ {
+ CoreConfigManager coreConfigManager = new CoreConfigManager();
+ coreConfigManager.initializeCoreConfig();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFIMPORT_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;
+ 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;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server crypto manager.
- try
- {
- directoryServer.initializeCryptoManager();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFIMPORT_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;
- 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;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server crypto manager.
+ try
+ {
+ directoryServer.initializeCryptoManager();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFIMPORT_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;
+ 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;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- if (! quietMode.isPresent())
- {
- // FIXME -- Install a custom logger to capture information about the state
- // of the import.
- StartupErrorLogger startupLogger = new StartupErrorLogger();
- startupLogger.initializeErrorLogger(null);
- addErrorLogger(startupLogger);
- }
+ if (! quietMode.isPresent())
+ {
+ // FIXME -- Install a custom logger to capture information about the
+ // state of the import.
+ StartupErrorLogger startupLogger = new StartupErrorLogger();
+ startupLogger.initializeErrorLogger(null);
+ addErrorLogger(startupLogger);
+ }
- // Initialize all the password policy information.
- try
- {
- directoryServer.initializePasswordPolicyComponents();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_PWPOLICY;
- 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_PWPOLICY;
- 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_PWPOLICY;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize all the password policy information.
+ try
+ {
+ directoryServer.initializePasswordPolicyComponents();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_PWPOLICY;
+ 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_PWPOLICY;
+ 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_PWPOLICY;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Make sure that the Directory Server plugin initialization is performed.
- try
- {
- HashSet<PluginType> pluginTypes = new HashSet<PluginType>(1);
- pluginTypes.add(PluginType.LDIF_IMPORT);
- directoryServer.initializePlugins(pluginTypes);
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_PLUGINS;
- 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_PLUGINS;
- 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_PLUGINS;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
+ // Make sure that the Directory Server plugin initialization is performed.
+ try
+ {
+ HashSet<PluginType> pluginTypes = new HashSet<PluginType>(1);
+ pluginTypes.add(PluginType.LDIF_IMPORT);
+ directoryServer.initializePlugins(pluginTypes);
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_INITIALIZE_PLUGINS;
+ 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_PLUGINS;
+ 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_PLUGINS;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
}
diff --git a/opends/src/server/org/opends/server/tools/RestoreDB.java b/opends/src/server/org/opends/server/tools/RestoreDB.java
index a92f10a..9835366 100644
--- a/opends/src/server/org/opends/server/tools/RestoreDB.java
+++ b/opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -101,6 +101,20 @@
*/
public static int mainRestoreDB(String[] args)
{
+ return mainRestoreDB(args, true);
+ }
+
+ /**
+ * Processes the command-line arguments and invokes the restore process.
+ *
+ * @param args The command-line arguments provided to this
+ * program.
+ * @param initializeServer Indicates whether to initialize the server.
+ *
+ * @return The error code.
+ */
+ public static int mainRestoreDB(String[] args, boolean initializeServer)
+ {
// Define the command-line arguments that may be used with this program.
BooleanArgument displayUsage = null;
BooleanArgument listBackups = null;
@@ -205,132 +219,134 @@
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
DirectoryServer directoryServer = DirectoryServer.getInstance();
+ if (initializeServer)
+ {
+ try
+ {
+ directoryServer.bootstrapClient();
+ directoryServer.initializeJMX();
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_RESTOREDB_SERVER_BOOTSTRAP_ERROR;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- try
- {
- directoryServer.bootstrapClient();
- directoryServer.initializeJMX();
- }
- catch (Exception e)
- {
- int msgID = MSGID_RESTOREDB_SERVER_BOOTSTRAP_ERROR;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
-
- try
- {
- directoryServer.initializeConfiguration(configClass.getValue(),
- configFile.getValue());
- }
- catch (InitializationException ie)
- {
- int msgID = MSGID_RESTOREDB_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_RESTOREDB_CANNOT_LOAD_CONFIG;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ try
+ {
+ directoryServer.initializeConfiguration(configClass.getValue(),
+ configFile.getValue());
+ }
+ catch (InitializationException ie)
+ {
+ int msgID = MSGID_RESTOREDB_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_RESTOREDB_CANNOT_LOAD_CONFIG;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server schema elements.
- try
- {
- directoryServer.initializeSchema();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_RESTOREDB_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_RESTOREDB_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_RESTOREDB_CANNOT_LOAD_SCHEMA;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server schema elements.
+ try
+ {
+ directoryServer.initializeSchema();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_RESTOREDB_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_RESTOREDB_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_RESTOREDB_CANNOT_LOAD_SCHEMA;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server core configuration.
- try
- {
- CoreConfigManager coreConfigManager = new CoreConfigManager();
- coreConfigManager.initializeCoreConfig();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_RESTOREDB_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_RESTOREDB_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_RESTOREDB_CANNOT_INITIALIZE_CORE_CONFIG;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server core configuration.
+ try
+ {
+ CoreConfigManager coreConfigManager = new CoreConfigManager();
+ coreConfigManager.initializeCoreConfig();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_RESTOREDB_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_RESTOREDB_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_RESTOREDB_CANNOT_INITIALIZE_CORE_CONFIG;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // Initialize the Directory Server crypto manager.
- try
- {
- directoryServer.initializeCryptoManager();
- }
- catch (ConfigException ce)
- {
- int msgID = MSGID_RESTOREDB_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_RESTOREDB_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_RESTOREDB_CANNOT_INITIALIZE_CRYPTO_MANAGER;
- String message = getMessage(msgID, stackTraceToSingleLineString(e));
- System.err.println(wrapText(message, MAX_LINE_WIDTH));
- return 1;
- }
+ // Initialize the Directory Server crypto manager.
+ try
+ {
+ directoryServer.initializeCryptoManager();
+ }
+ catch (ConfigException ce)
+ {
+ int msgID = MSGID_RESTOREDB_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_RESTOREDB_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_RESTOREDB_CANNOT_INITIALIZE_CRYPTO_MANAGER;
+ String message = getMessage(msgID, stackTraceToSingleLineString(e));
+ System.err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
- // FIXME -- Install a custom logger to capture information about the state
- // of the export.
- StartupErrorLogger startupLogger = new StartupErrorLogger();
- startupLogger.initializeErrorLogger(null);
- addErrorLogger(startupLogger);
+ // FIXME -- Install a custom logger to capture information about the state
+ // of the export.
+ StartupErrorLogger startupLogger = new StartupErrorLogger();
+ startupLogger.initializeErrorLogger(null);
+ addErrorLogger(startupLogger);
+ }
// Open the backup directory and make sure it is valid.
--
Gitblit v1.10.0