| | |
| | | */ |
| | | package org.opends.server.backends.jeb; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.text.ParseException; |
| | |
| | | this.parser.setVersionHandler(new DirectoryServerVersionHandler()); |
| | | } |
| | | |
| | | /** Displays the provided message followed by a help usage reference. */ |
| | | private void displayMessageAndUsageReference(LocalizableMessage message) { |
| | | printErrorMessage(message); |
| | | printErrorMessage(LocalizableMessage.EMPTY); |
| | | printErrorMessage(parser.getHelpUsageReference()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers the global arguments with the argument parser. |
| | | * |
| | |
| | | initializeGlobalArguments(); |
| | | initializeSubCommands(); |
| | | } catch (ArgumentException e) { |
| | | LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(e.getMessage()); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_INITIALIZE_ARGS.get(e.getMessage())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | try { |
| | | parser.parseArguments(args); |
| | | } catch (ArgumentException ae) { |
| | | LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage()); |
| | | displayMessageAndUsageReference(message); |
| | | printWrappedText(err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); |
| | | err.println(parser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (InitializationException e) |
| | | { |
| | | printErrorMessage(e.getMessageObject()); |
| | | printWrappedText(err, e.getMessageObject()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_SERVER_BOOTSTRAP_ERROR.get( |
| | | getExceptionMessage(e)); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_SERVER_BOOTSTRAP_ERROR.get(getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_LOAD_CONFIG.get( |
| | | ie.getMessage()); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_LOAD_CONFIG.get(ie.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_LOAD_CONFIG.get( |
| | | getExceptionMessage(e)); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_LOAD_CONFIG.get(getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ConfigException | InitializationException e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_LOAD_SCHEMA.get(e.getMessage()); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_LOAD_SCHEMA.get(e.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_LOAD_SCHEMA.get(getExceptionMessage(e)); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_LOAD_SCHEMA.get(getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ConfigException | InitializationException e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_INITIALIZE_CORE_CONFIG.get(e.getMessage()); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_INITIALIZE_CORE_CONFIG.get(e.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_INITIALIZE_CORE_CONFIG.get(getExceptionMessage(e)); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_INITIALIZE_CORE_CONFIG.get(getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (ConfigException | InitializationException e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_INITIALIZE_CRYPTO_MANAGER.get(e.getMessage()); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_INITIALIZE_CRYPTO_MANAGER.get(e.getMessage())); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_CANNOT_INITIALIZE_CRYPTO_MANAGER.get(getExceptionMessage(e)); |
| | | printErrorMessage(message); |
| | | printWrappedText(err, ERR_CANNOT_INITIALIZE_CRYPTO_MANAGER.get(getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | // Make sure that we have a sub-command. |
| | | if (parser.getSubCommand() == null) |
| | | { |
| | | LocalizableMessage message = ERR_DBTEST_MISSING_SUBCOMMAND.get(); |
| | | displayMessageAndUsageReference(message); |
| | | printWrappedText(err, ERR_DBTEST_MISSING_SUBCOMMAND.get()); |
| | | err.println(parser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | return 0; |
| | | } catch (Exception e) { |
| | | printErrorMessage(LocalizableMessage.raw(StaticUtils.stackTraceToString(e))); |
| | | printWrappedText(err, LocalizableMessage.raw(StaticUtils.stackTraceToString(e))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.acquireSharedLock(lockFile, failureReason)) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | return 1; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get( |
| | | backend.getBackendID(), |
| | | StaticUtils.stackTraceToSingleLineString(e))); |
| | | printWrappedText( |
| | | err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(DatabaseException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_READING_DATABASE.get( |
| | | StaticUtils.stackTraceToSingleLineString(de))); |
| | | printWrappedText(err, ERR_DBTEST_ERROR_READING_DATABASE.get(stackTraceToSingleLineString(de))); |
| | | return 1; |
| | | } |
| | | finally |
| | |
| | | } |
| | | catch(DirectoryException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_BASE_DN.get(baseDN.getValue(), |
| | | getExceptionMessage(de))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_BASE_DN.get(baseDN.getValue(), getExceptionMessage(de))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.acquireSharedLock(lockFile, failureReason)) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | return 1; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get( |
| | | backend.getBackendID(), |
| | | StaticUtils.stackTraceToSingleLineString(e))); |
| | | printWrappedText( |
| | | err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | EntryContainer ec = rc.getEntryContainer(base); |
| | | if(ec == null) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get( |
| | | base, backend.getBackendID())); |
| | | printWrappedText(err, ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(DatabaseException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_READING_DATABASE.get( |
| | | StaticUtils.stackTraceToSingleLineString(de))); |
| | | printWrappedText(err, ERR_DBTEST_ERROR_READING_DATABASE.get(stackTraceToSingleLineString(de))); |
| | | return 1; |
| | | } |
| | | finally |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (!LockFileManager.releaseLock(lockFile, failureReason)) |
| | | { |
| | | printErrorMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | printWrappedText(err, WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | printErrorMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | printWrappedText(err, WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | if (b.getBackendID().equalsIgnoreCase(backendID)) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_NOT_JE_BACKEND.get(backendID)); |
| | | printWrappedText(err, ERR_DBTEST_NOT_JE_BACKEND.get(backendID)); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | printErrorMessage(ERR_DBTEST_NO_BACKENDS_FOR_ID.get(backendID)); |
| | | printWrappedText(err, ERR_DBTEST_NO_BACKENDS_FOR_ID.get(backendID)); |
| | | return null; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(DirectoryException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_BASE_DN.get(baseDN.getValue(), |
| | | getExceptionMessage(de))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_BASE_DN.get(baseDN.getValue(), getExceptionMessage(de))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.acquireSharedLock(lockFile, failureReason)) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | return 1; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get( |
| | | backend.getBackendID(), |
| | | StaticUtils.stackTraceToSingleLineString(e))); |
| | | printWrappedText( |
| | | err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | EntryContainer ec = rc.getEntryContainer(base); |
| | | if(ec == null) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID())); |
| | | printWrappedText(err, ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(DatabaseException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_READING_DATABASE.get( |
| | | StaticUtils.stackTraceToSingleLineString(de))); |
| | | printWrappedText(err, ERR_DBTEST_ERROR_READING_DATABASE.get(stackTraceToSingleLineString(de))); |
| | | return 1; |
| | | } |
| | | finally |
| | |
| | | } |
| | | catch(DirectoryException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_BASE_DN.get(baseDN.getValue(), |
| | | getExceptionMessage(de))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_BASE_DN.get(baseDN.getValue(), getExceptionMessage(de))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.acquireSharedLock(lockFile, failureReason)) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), failureReason)); |
| | | return 1; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get( |
| | | backend.getBackendID(), |
| | | StaticUtils.stackTraceToSingleLineString(e))); |
| | | printWrappedText( |
| | | err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e))); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | EntryContainer ec = rc.getEntryContainer(base); |
| | | if(ec == null) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID())); |
| | | printWrappedText(err, ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | |
| | | if(databaseContainer == null) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_NO_DATABASE_CONTAINERS_FOR_NAME.get( |
| | | databaseName.getValue(), base, backend.getBackendID())); |
| | | printWrappedText( |
| | | err, ERR_DBTEST_NO_DATABASE_CONTAINERS_FOR_NAME.get(databaseName.getValue(), base, backend.getBackendID())); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_DECODE_SIZE.get( |
| | | maxDataSize.getValue(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_SIZE.get(maxDataSize.getValue(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_DECODE_SIZE.get( |
| | | minDataSize.getValue(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_SIZE.get(minDataSize.getValue(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_DECODE_KEY.get( |
| | | minKeyValue.getValue(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_KEY.get(minKeyValue.getValue(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_CANNOT_DECODE_KEY.get( |
| | | maxKeyValue.getValue(), getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_KEY.get(maxKeyValue.getValue(), getExceptionMessage(e))); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | } |
| | | formatedData = String.valueOf( |
| | | JebFormat.entryIDFromDatabase(data.getData())); |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | } |
| | | } |
| | | else if(databaseContainer instanceof DN2URI) |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | } |
| | | formatedData = new String(key.getData()); |
| | | dataLabel = INFO_LABEL_DBTEST_URI.get(); |
| | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | printWrappedText(err, ERR_DBTEST_DECODE_FAIL.get(getExceptionMessage(e))); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | catch(DatabaseException de) |
| | | { |
| | | printErrorMessage(ERR_DBTEST_ERROR_READING_DATABASE.get( |
| | | StaticUtils.stackTraceToSingleLineString(de))); |
| | | printWrappedText(err, ERR_DBTEST_ERROR_READING_DATABASE.get(stackTraceToSingleLineString(de))); |
| | | return 1; |
| | | } |
| | | finally |
| | |
| | | } |
| | | return jeBackends; |
| | | } |
| | | |
| | | private final void printErrorMessage(LocalizableMessage msg) { |
| | | err.println(wrapText(msg.toString(), MAX_LINE_WIDTH)); |
| | | } |
| | | } |