| | |
| | | import org.opends.server.backends.jeb.VerifyConfig; |
| | | 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; |
| | |
| | | import java.util.List; |
| | | |
| | | import static org.opends.server.messages.ToolMessages.*; |
| | | 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.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | |
| | | OPTION_LONG_CONFIG_CLASS, true, false, |
| | | true, OPTION_VALUE_CONFIG_CLASS, |
| | | ConfigFileHandler.class.getName(), null, |
| | | MSGID_VERIFYINDEX_DESCRIPTION_CONFIG_CLASS); |
| | | MSGID_DESCRIPTION_CONFIG_CLASS); |
| | | configClass.setHidden(true); |
| | | argParser.addArgument(configClass); |
| | | |
| | |
| | | configFile = |
| | | new StringArgument("configfile", 'f', "configFile", true, false, |
| | | true, "{configFile}", null, null, |
| | | MSGID_VERIFYINDEX_DESCRIPTION_CONFIG_FILE); |
| | | MSGID_DESCRIPTION_CONFIG_FILE); |
| | | configFile.setHidden(true); |
| | | argParser.addArgument(configFile); |
| | | |
| | |
| | | |
| | | displayUsage = |
| | | new BooleanArgument("help", OPTION_SHORT_HELP, OPTION_LONG_HELP, |
| | | MSGID_VERIFYINDEX_DESCRIPTION_USAGE); |
| | | MSGID_DESCRIPTION_USAGE); |
| | | argParser.addArgument(displayUsage); |
| | | argParser.setUsageArgument(displayUsage); |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_INITIALIZE_ARGS; |
| | | int msgID = MSGID_CANNOT_INITIALIZE_ARGS; |
| | | String message = getMessage(msgID, ae.getMessage()); |
| | | |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | |
| | | } |
| | | catch (ArgumentException ae) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_ERROR_PARSING_ARGS; |
| | | int msgID = MSGID_ERROR_PARSING_ARGS; |
| | | String message = getMessage(msgID, ae.getMessage()); |
| | | |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_SERVER_BOOTSTRAP_ERROR; |
| | | int msgID = MSGID_SERVER_BOOTSTRAP_ERROR; |
| | | String message = getMessage(msgID, stackTraceToSingleLineString(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.exit(1); |
| | |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_LOAD_CONFIG; |
| | | int msgID = MSGID_CANNOT_LOAD_CONFIG; |
| | | String message = getMessage(msgID, ie.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.exit(1); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_LOAD_CONFIG; |
| | | int msgID = MSGID_CANNOT_LOAD_CONFIG; |
| | | String message = getMessage(msgID, stackTraceToSingleLineString(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.exit(1); |
| | |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_LOAD_SCHEMA; |
| | | int msgID = MSGID_CANNOT_LOAD_SCHEMA; |
| | | String message = getMessage(msgID, ce.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.exit(1); |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_LOAD_SCHEMA; |
| | | int msgID = MSGID_CANNOT_LOAD_SCHEMA; |
| | | String message = getMessage(msgID, ie.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.exit(1); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_LOAD_SCHEMA; |
| | | int msgID = MSGID_CANNOT_LOAD_SCHEMA; |
| | | String message = getMessage(msgID, stackTraceToSingleLineString(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.exit(1); |
| | |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_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)); |
| | | System.exit(1); |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_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)); |
| | | System.exit(1); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_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)); |
| | | System.exit(1); |
| | |
| | | } |
| | | 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)); |
| | | System.exit(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)); |
| | | System.exit(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)); |
| | | System.exit(1); |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_DECODE_BASE_DN; |
| | | int msgID = MSGID_CANNOT_DECODE_BASE_DN; |
| | | String message = getMessage(msgID, baseDNString.getValue(), |
| | | de.getErrorMessage()); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_DECODE_BASE_DN; |
| | | int msgID = MSGID_CANNOT_DECODE_BASE_DN; |
| | | String message = getMessage(msgID, baseDNString.getValue(), |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | |
| | | ArrayList<Backend> backendList = new ArrayList<Backend>(); |
| | | ArrayList<ConfigEntry> entryList = new ArrayList<ConfigEntry>(); |
| | | ArrayList<List<DN>> dnList = new ArrayList<List<DN>>(); |
| | | getBackends(backendList, entryList, dnList); |
| | | BackendToolUtils.getBackends(backendList, entryList, dnList); |
| | | |
| | | int numBackends = backendList.size(); |
| | | for (int i=0; i < numBackends; i++) |
| | |
| | | } |
| | | else |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_MULTIPLE_BACKENDS_FOR_BASE; |
| | | int msgID = MSGID_MULTIPLE_BACKENDS_FOR_BASE; |
| | | String message = getMessage(msgID, baseDNString.getValue()); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | |
| | | |
| | | if (backend == null) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_NO_BACKENDS_FOR_BASE; |
| | | int msgID = MSGID_NO_BACKENDS_FOR_BASE; |
| | | String message = getMessage(msgID, baseDNString.getValue()); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | |
| | | |
| | | if (!(backend instanceof BackendImpl)) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_WRONG_BACKEND_TYPE; |
| | | int msgID = MSGID_BACKEND_NO_INDEXING_SUPPORT; |
| | | String message = getMessage(msgID); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | |
| | | message, msgID); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | */ |
| | | private static void 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_VERIFYINDEX_CANNOT_DECODE_BACKEND_BASE_DN; |
| | | String message = getMessage(msgID, DN_BACKEND_BASE, de.getErrorMessage()); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | | System.exit(1); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_DECODE_BACKEND_BASE_DN; |
| | | String message = getMessage(msgID, DN_BACKEND_BASE, |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | | System.exit(1); |
| | | } |
| | | |
| | | ConfigEntry baseEntry = null; |
| | | try |
| | | { |
| | | baseEntry = DirectoryServer.getConfigEntry(backendBaseDN); |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY; |
| | | String message = getMessage(msgID, DN_BACKEND_BASE, ce.getMessage()); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | | System.exit(1); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_RETRIEVE_BACKEND_BASE_ENTRY; |
| | | String message = getMessage(msgID, DN_BACKEND_BASE, |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | | System.exit(1); |
| | | } |
| | | |
| | | |
| | | // Iterate through the immediate children, attempting to parse them as |
| | | // backends. |
| | | for (ConfigEntry configEntry : baseEntry.getChildren().values()) |
| | | { |
| | | // Get the backend class name attribute from the entry. If there isn't |
| | | // one, then just skip this 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_VERIFYINDEX_CANNOT_DETERMINE_BACKEND_CLASS; |
| | | String message = getMessage(msgID, String.valueOf(configEntry.getDN()), |
| | | ce.getMessage()); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | System.exit(1); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_DETERMINE_BACKEND_CLASS; |
| | | String message = getMessage(msgID, String.valueOf(configEntry.getDN()), |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | System.exit(1); |
| | | } |
| | | |
| | | Class backendClass = null; |
| | | try |
| | | { |
| | | backendClass = Class.forName(backendClassName); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_LOAD_BACKEND_CLASS; |
| | | String message = getMessage(msgID, backendClassName, |
| | | String.valueOf(configEntry.getDN()), |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | System.exit(1); |
| | | } |
| | | |
| | | Backend backend = null; |
| | | try |
| | | { |
| | | backend = (Backend) backendClass.newInstance(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_VERIFYINDEX_CANNOT_INSTANTIATE_BACKEND_CLASS; |
| | | String message = getMessage(msgID, backendClassName, |
| | | String.valueOf(configEntry.getDN()), |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | System.exit(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_VERIFYINDEX_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_VERIFYINDEX_CANNOT_DETERMINE_BASES_FOR_BACKEND; |
| | | String message = getMessage(msgID, String.valueOf(configEntry.getDN()), |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | System.exit(1); |
| | | } |
| | | |
| | | |
| | | backendList.add(backend); |
| | | entryList.add(configEntry); |
| | | dnList.add(baseDNs); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |