DBTest.java revision 0fd845d18cfaf23fc9f54e92775c735955e4e859
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/**
* This program provides a utility that may be used to debug a JE backend. This
* tool provides the ability list various containers in the backend as well as
* dump the contents of database containers. This will be
* a process that is intended to run separate from Directory Server and not
* internally within the server process (e.g., via the tasks interface).
*/
public class DBTest
{
/** The error stream which this application should use. */
private final PrintStream err;
/** The output stream which this application should use. */
private final PrintStream out;
/**
* Flag indicating whether or not the global arguments have already been
* initialized.
*/
private boolean globalArgumentsInitialized;
/** The command-line argument parser. */
private final SubCommandArgumentParser parser;
/** The argument which should be used to request usage information. */
private BooleanArgument showUsageArgument;
/** The argument which should be used to specify the config class. */
private StringArgument configClass;
/** THe argument which should be used to specify the config file. */
private StringArgument configFile;
/**
* Flag indicating whether or not the sub-commands have already been
* initialized.
*/
private boolean subCommandsInitialized;
/**
* Provides the command-line arguments to the main application for
* processing.
*
* @param args
* The set of command-line arguments provided to this
* program.
*/
if (exitCode != 0) {
}
}
/**
* Provides the command-line arguments to the main application for
* processing and returns the exit code as an integer.
*
* @param args
* The set of command-line arguments provided to this
* program.
* @param initializeServer
* Indicates whether to perform basic initialization (which
* should not be done if the tool is running in the same
* JVM as the server).
* @param outStream
* The output stream for standard output.
* @param errStream
* The output stream for standard error.
* @return Zero to indicate that the program completed successfully,
* or non-zero to indicate that an error occurred.
*/
// Run the application.
}
/**
* Creates a new dsconfig application instance.
*
* @param out
* The application output stream.
* @param err
* The application error stream.
*/
{
}
/**
* Registers the global arguments with the argument parser.
*
* @throws ArgumentException
* If a global argument could not be registered.
*/
private void initializeGlobalArguments() throws ArgumentException {
if (!globalArgumentsInitialized) {
OPTION_LONG_CONFIG_CLASS, true, false,
true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
configClass.setHidden(true);
null,
configFile.setHidden(true);
// Register the global arguments.
globalArgumentsInitialized = true;
}
}
/**
* Registers the sub-commands with the argument parser.
*
* @throws ArgumentException
* If a sub-command could not be created.
*/
private void initializeSubCommands() throws ArgumentException {
if (!subCommandsInitialized) {
baseDN =
null,
baseDN =
null,
false, true, INFO_DATABASE_NAME_PLACEHOLDER.get(),
false, true,
false, true,
null,
null,
false, false, true,
-1,
null,
false, false, true,
-1,
null,
baseDN =
null,
subCommandsInitialized = true;
}
}
/**
* Parses the provided command-line arguments and makes the
* appropriate changes to the Directory Server configuration.
*
* @param args
* The command-line arguments provided to this program.
* @param initializeServer
* Indicates whether to perform basic initialization (which
* should not be done if the tool is running in the same
* JVM as the server).
* @return The exit code from the configuration processing. A
* nonzero value indicates that there was some kind of
* problem during the configuration processing.
*/
// Register global arguments and sub-commands.
try {
} catch (ArgumentException e) {
return 1;
}
// Parse the command-line arguments provided to this program.
try {
} catch (ArgumentException ae) {
return 1;
}
// to do anything else.
if (parser.usageOrVersionDisplayed()) {
return 0;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
return 1;
}
// Only initialize the server when run as a standalone
// application.
if (initializeServer) {
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
try
{
}
catch (Exception e)
{
return 1;
}
try
{
configFile.getValue());
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server schema elements.
try
{
}
catch (ConfigException | InitializationException e)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server core configuration.
try
{
}
catch (ConfigException | InitializationException e)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server crypto manager.
try
{
}
catch (ConfigException | InitializationException e)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
// Make sure that we have a sub-command.
{
return 1;
}
// Retrieve the sub-command implementation and run it.
try {
{
return listRootContainers();
}
{
}
{
}
{
}
{
}
return 0;
} catch (Exception e) {
return 1;
}
}
private int listRootContainers()
{
int count = 0;
// Create a table of their properties.
{
count++;
}
return 0;
}
{
{
return 1;
}
// Acquire an shared lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
return 1;
}
try
{
}
catch(Exception e)
{
err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e)));
return 1;
}
try
{
// Create a table of their properties.
int count = 0;
{
count++;
}
return 0;
}
catch(DatabaseException de)
{
return 1;
}
finally
{
}
}
{
{
return 1;
}
{
try
{
}
catch(DirectoryException de)
{
return 1;
}
}
// Acquire an shared lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
return 1;
}
try
{
}
catch(Exception e)
{
err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e)));
return 1;
}
try
{
// Create a table of their properties.
int count = 0;
{
{
printWrappedText(err, ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID()));
return 1;
}
}
else
{
{
}
}
return 0;
}
catch(DatabaseException de)
{
return 1;
}
finally
{
}
}
{
{
count++;
}
return count;
}
{
try
{
}
catch(DatabaseException ignored)
{
// Ignore.
}
}
{
try
{
{
printWrappedText(err, WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason));
}
}
catch (Exception e)
{
printWrappedText(err, WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
}
}
{
{
{
return b;
}
}
for (Backend<?> b : otherBackends)
{
{
return null;
}
}
return null;
}
{
{
return 1;
}
{
try
{
}
catch(DirectoryException de)
{
return 1;
}
}
// Acquire an shared lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
return 1;
}
try
{
}
catch(Exception e)
{
err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e)));
return 1;
}
try
{
// Create a table of their properties.
int count = 0;
{
printWrappedText(err, ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID()));
return 1;
}
{
{
{
{
{
// Entry limit has exceeded and there is no encoded
// undefined set size.
undefined ++;
{
keyList = new StringBuilder();
}
else
{
}
{
}
else
{
}
}
else
{
// Seems like entry limit has not been exceeded and the bytes
// is a list of entry IDs.
double percentFull =
if(percentFull >= .8)
{
if(percentFull < .9)
{
eighty++;
}
else if(percentFull < .95)
{
ninety++;
}
else
{
ninetyFive++;
}
}
}
}
}
else
{
}
count++;
}
}
{
}
return 0;
}
catch(DatabaseException de)
{
return 1;
}
finally
{
}
}
{
{
return 1;
}
try
{
}
catch(DirectoryException de)
{
return 1;
}
// Acquire an shared lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_LOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
return 1;
}
try
{
}
catch(Exception e)
{
err, ERR_DBTEST_ERROR_INITIALIZING_BACKEND.get(backend.getBackendID(), stackTraceToSingleLineString(e)));
return 1;
}
try
{
{
printWrappedText(err, ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID()));
return 1;
}
{
{
break;
}
}
if(databaseContainer == null)
{
err, ERR_DBTEST_NO_DATABASE_CONTAINERS_FOR_NAME.get(databaseName.getValue(), base, backend.getBackendID()));
return 1;
}
int count = 0;
long totalKeySize = 0;
long totalDataSize = 0;
int indent = 4;
try
{
int minSize = -1;
int maxSize = -1;
if(maxDataSize.isPresent())
{
try
{
}
catch(Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_SIZE.get(maxDataSize.getValue(), getExceptionMessage(e)));
return 1;
}
}
if(minDataSize.isPresent())
{
try
{
}
catch(Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_SIZE.get(minDataSize.getValue(), getExceptionMessage(e)));
return 1;
}
}
// Parse the min value if given
if(minKeyValue.isPresent())
{
try
{
}
catch(Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_KEY.get(minKeyValue.getValue(), getExceptionMessage(e)));
return 1;
}
}
// Parse the max value if given
if(maxKeyValue.isPresent())
{
try
{
}
catch(Exception e)
{
printWrappedText(err, ERR_DBTEST_CANNOT_DECODE_KEY.get(maxKeyValue.getValue(), getExceptionMessage(e)));
return 1;
}
}
{
}
else
{
}
{
// Make sure this record is within the value size params
{
continue;
}
// Make sure we haven't gone pass the max value yet
{
break;
}
{
if(!skipDecode.isPresent())
{
if(databaseContainer instanceof DN2ID)
{
try
{
}
catch(Exception e)
{
}
}
else if(databaseContainer instanceof ID2Entry)
{
try
{
formatedData = lineSep +
}
catch(Exception e)
{
}
}
else if(databaseContainer instanceof DN2URI)
{
try
{
}
catch(Exception e)
{
}
}
else if(databaseContainer instanceof Index)
{
{
int lineCount = 0;
{
if(lineCount == 10)
{
lineCount = 0;
}
else
{
lineCount++;
}
}
}
else
{
}
}
else if(databaseContainer instanceof VLVIndex)
{
int pos = 0;
{
// Decode the attribute values
{
{
int numLengthBytes = valueLength;
valueLength = 0;
{
}
}
byte[] valueBytes = new byte[valueLength];
{
}
else
{
}
pos += valueLength;
}
byte[] entryIDBytes = new byte[8];
}
else
{
formatedKey = "UNBOUNDED";
}
try
{
index);
{
{
{
}
{
}
else
{
}
}
}
}
catch(Exception e)
{
}
}
}
if(formatedKey == null)
{
}
if(formatedData == null)
{
}
}
count++;
}
}
finally
{
}
if(count > 0)
{
}
return 0;
}
catch(DatabaseException de)
{
return 1;
}
finally
{
}
}
throws ParseException, DirectoryException
{
{
}
else if(databaseContainer instanceof DN2ID
|| databaseContainer instanceof DN2URI)
{
// Encode the value as a DN
}
else if(databaseContainer instanceof ID2Entry)
{
// Encode the value as an entryID
return JebFormat.entryIDToDatabase(
}
else if(databaseContainer instanceof VLVIndex)
{
return builder.toByteArray();
}
else
{
}
}
{
if(databaseContainer instanceof Index)
{
}
else if(databaseContainer instanceof VLVIndex)
{
}
else
{ // default comparator
return ByteSequence.BYTE_ARRAY_COMPARATOR;
}
}
private static Map<LocalDBBackendCfg, BackendImpl> getJEBackends(Collection<Backend<?>> otherBackends)
{
{
if(backend instanceof BackendImpl)
{
}
else if (otherBackends != null)
{
}
}
return jeBackends;
}
}