/*
* 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-2009 Sun Microsystems, Inc.
* Portions Copyright 2011-2013 ForgeRock AS
*/
/**
* This program provides a utility to rebuild the contents of the indexes of a
* Directory Server backend. 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).
*/
{
"org.opends.server.tools.RebuildIndex",
/**
* Processes the command-line arguments and invokes the rebuild process.
*
* @param args
* The command-line arguments provided to this program.
*/
{
final int retCode =
if (retCode != 0)
{
}
}
/**
* Processes the command-line arguments and invokes the rebuild process.
*
* @param args
* The command-line arguments provided to this program.
* @param initializeServer
* Indicates whether to initialize the server.
* @param outStream
* The output stream to use for standard output, or {@code null} if
* standard output is not needed.
* @param errStream
* The output stream to use for standard error, or {@code null} if
* standard error is not needed.
* @return The error code.
*/
final OutputStream errStream)
{
}
{
// Initialize all the command-line argument types and register them with the
// parser.
try
{
initializeArguments(false);
}
catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// If no arguments were provided, then display usage information and exit.
if (numArgs == 0)
{
return 1;
}
&& !rebuildDegraded.isPresent())
{
return 1;
}
{
return 1;
}
{
return 1;
}
{
return 1;
}
{
return 1;
}
{
return 1;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
return 1;
}
}
/**
* Initializes the arguments for the rebuild index tool.
*
* @param isMultipleBackends
* {@code true} if the tool is used as internal.
* @throws ArgumentException
* If the initialization fails.
*/
throws ArgumentException
{
configClass.setHidden(true);
configFile.setHidden(true);
}
/**
* {@inheritDoc}
*/
{
// Performs the initial bootstrap of the Directory Server and processes the
// configuration.
if (initializeServer)
{
if (init != 0)
{
return init;
}
}
{
return 1;
}
}
/**
* Configures the rebuild index process. i.e.: decodes the selected DN and
* retrieves the backend which holds it. Finally, initializes and sets the
* rebuild configuration.
*
* @param dn
* User selected base DN.
* @return A boolean representing the result of the process.
*/
// Decodes the base DN provided by the user.
try
{
}
catch (Exception e)
{
getExceptionMessage(e));
return false;
}
// Retrieves the backend which holds the selected base DN.
try
{
}
catch (Exception e)
{
return false;
}
return true;
}
/**
* Defines the error and the debug log publisher used in this tool.
*
* @param out
* The output stream to use for standard output, or {@code null} if
* standard output is not needed.
* @param err
* The output stream to use for standard error, or {@code null} if
* standard error is not needed.
*/
final PrintStream err)
{
try
{
final ErrorLogPublisher<?> errorLogPublisher =
final DebugLogPublisher<?> debugLogPublisher =
}
catch (Exception e)
{
+ stackTraceToSingleLineString(e));
}
}
/**
* Initializes the directory server.<br />
* Processes to :
* - bootstrapClient
* - initializeJMX
* - initializeConfiguration
* - initializeSchema
* - coreConfigManager.initializeCoreConfig()
* - initializeCryptoManager
*
* @param directoryServer
* The current instance.
* @param out
* The output stream to use for standard output, or {@code null} if
* standard output is not needed.
* @param err
* The output stream to use for standard error, or {@code null} if
* standard error is not needed.
* @return The result code.
*/
{
try
{
}
catch (Exception e)
{
return 1;
}
try
{
configFile.getValue());
}
{
if (ex instanceof InitializationException)
{
}
else
{
}
return 1;
}
// Initializes the Directory Server schema elements.
try
{
}
catch (Exception e)
{
if (e instanceof ConfigException || e instanceof InitializationException)
{
}
else
{
}
return 1;
}
// Initializes the Directory Server core configuration.
try
{
}
{
if (ex instanceof ConfigException
|| ex instanceof InitializationException)
{
}
else
{
message =
}
return 1;
}
// Initializes the Directory Server crypto manager.
try
{
}
{
if (ex instanceof ConfigException
|| ex instanceof InitializationException)
{
}
else
{
message =
}
return 1;
}
return 0;
}
/**
* Initializes and sets the rebuild index configuration.
*
* @param rebuildBaseDN
* The selected base DN.
* @return A rebuild configuration.
*/
final DN rebuildBaseDN)
{
{
}
if (rebuildAll.isPresent())
{
}
else if (rebuildDegraded.isPresent())
{
}
else
{
if (clearDegradedState.isPresent())
{
config.isClearDegradedState(true);
}
}
return config;
}
/**
* Launches the rebuild index process.
*
* @param backend
* The directory server backend.
* @param rebuildConfig
* The configuration which is going to be used by the rebuild index
* process.
* @return An integer representing the result of the process.
*/
final RebuildConfig rebuildConfig)
{
int returnCode = 0;
// Acquire an exclusive lock for the backend.
//TODO: Find a way to do this with the server online.
try
{
{
return 1;
}
}
catch (Exception e)
{
.getBackendID(), getExceptionMessage(e));
return 1;
}
try
{
}
catch (InitializationException e)
{
returnCode = 1;
}
catch (Exception e)
{
.get(getExceptionMessage(e)));
returnCode = 1;
}
finally
{
// Release the shared lock on the backend.
try
{
{
}
}
catch (Exception e)
{
.getBackendID(), getExceptionMessage(e)));
}
}
return returnCode;
}
/**
* Gets information about the backends defined in the server. Iterates through
* them, finding the one that holds the base DN.
*
* @param selectedDN
* The user selected DN.
* @return The backend which holds the selected base DN.
* @throws ConfigException
* If the backend is poorly configured.
* @throws Exception
* If an exception occurred during the backend search.
*/
{
DN[] baseDNArray;
for (int i = 0; i < numBackends; i++)
{
{
{
{
backend = b;
}
else
{
throw new ConfigException(message);
}
break;
}
}
}
{
throw new ConfigException(message);
}
if (!(backend instanceof BackendImpl))
{
throw new ConfigException(message);
}
return backend;
}
/**
* This function allow internal use of the rebuild index tools. This function
* rebuilds indexes shared by multiple backends.
*
* @param initializeServer
* Indicates whether to initialize the server.
* @param out
* Usually redirected into a logger if the tool is used as external.
* @param args
* The arguments used to launch the rebuild index process.
* @return An integer indicating the result of this action.
*/
public int rebuildIndexesWithinMultipleBackends(
{
try
{
try
{
initializeArguments(true);
}
catch (ArgumentException ae)
{
return 1;
}
try
{
}
catch (ArgumentException ae)
{
return 1;
}
if (initializeServer)
{
if (init != 0)
{
return init;
}
}
{
if (!configureRebuildProcess(dn))
{
return 1;
}
final int result =
// If the rebuild index is going bad, process is stopped.
if (result != 0)
{
"An error occurs during the rebuild index process" +
" in %s, rebuild index(es) aborted.",
dn));
return 1;
}
}
}
finally
{
}
return 0;
}
/**
* {@inheritDoc}
*/
{
// NYI.
return null;
}
/**
* {@inheritDoc}
*/
{
//
// Required attributes
//
{
}
{
}
{
}
&& !rebuildDegraded.getValue()
{
}
{
values));
}
}
/**
* {@inheritDoc}
*/
{
return "ds-task-rebuild";
}
/**
* {@inheritDoc}
*/
{
return RebuildTask.class;
}
/**
* Returns the rebuild configuration.
*
* @return The rebuild configuration.
*/
{
return rebuildConfig;
}
/**
* Sets the rebuild configuration.
*
* @param rebuildConfig
* The rebuild configuration to set.
*/
{
this.rebuildConfig = rebuildConfig;
}
/**
* Returns the current backend.
*
* @return The current backend.
*/
{
return currentBackend;
}
/**
* Sets the current backend.
*
* @param currentBackend
* The current backend to set.
*/
{
this.currentBackend = currentBackend;
}
}