ListBackends.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-2008 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* This program provides a utility that may be used to list the backends in the
* server, as well as to determine which backend holds a given entry.
*/
public class ListBackends
{
/**
* Parses the provided command-line arguments and uses that information to
* list the backend information.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Parses the provided command-line arguments and uses that information to
* list the backend information.
*
* @param args The command-line arguments provided to this program.
*
* @return A return code indicating whether the processing was successful.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to
* list the backend information.
*
* @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</CODE> if standard output is not
* needed.
* @param errStream The output stream to use for standard error, or
* <CODE>null</CODE> if standard error is not
* needed.
*
* @return A return code indicating whether the processing was successful.
*/
{
// Define the command-line arguments that may be used with this program.
// Create the command-line argument parser for use with this program.
new ArgumentParser("org.opends.server.tools.ListBackends",
toolDescription, false);
// Initialize all the command-line argument types and register them with the
// parser.
try
{
OPTION_LONG_CONFIG_CLASS, true, false,
true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
configClass.setHidden(true);
null,
configFile.setHidden(true);
backendID = new StringArgument(
"backendid", 'n', "backendID", false,
baseDN = new StringArgument(
"basedn", OPTION_SHORT_BASEDN,
OPTION_LONG_BASEDN, false, true, true,
}
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 it's already been done so just return.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Make sure that the user did not provide both the backend ID and base DN
// arguments.
{
printWrappedText(err, ERR_TOOL_CONFLICTING_ARGS.get(backendID.getLongIdentifier(), baseDN.getLongIdentifier()));
return 1;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
return 1;
}
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
if (initializeServer)
{
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;
}
}
// Retrieve a list of the backends defined in the server.
try
{
backends = getBackends();
}
catch (ConfigException ce)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// See what action we need to take based on the arguments provided. If the
// backend ID argument was present, then list the base DNs for that backend.
// If the base DN argument was present, then list the backend for that base
// DN. If no arguments were provided, then list all backends and base DNs.
boolean invalidDn = false;
{
// Create a map from the base DNs of the backends to the corresponding
// backend ID.
{
{
}
}
// Iterate through the base DN values specified by the user. Determine
// the backend for that entry, and whether the provided DN is a base DN
// for that backend.
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
{
while (true)
{
{
invalidDn = true;
break;
}
else
{
{
break;
}
}
}
}
else
{
}
}
}
else
{
{
}
else
{
}
// Figure out the length of the longest backend ID and base DN defined in
// the server. We'll use that information to try to align the output.
int backendIDLength = 10;
int baseDNLength = 7;
{
{
}
else
{
{
}
}
}
if (backendIDs.isEmpty())
{
return 1;
}
{
}
{
boolean isFirst = true;
{
if (!isFirst)
{
}
else
{
isFirst = false;
}
{
}
else
{
}
}
}
}
// If we've gotten here, then everything completed successfully.
}
/**
* Retrieves information about the backends configured in the Directory Server
* mapped between the backend ID to the set of base DNs for that backend.
*
* @return Information about the backends configured in the Directory Server.
*
* @throws ConfigException If a problem occurs while reading the server
* configuration.
*/
throws ConfigException
{
// Get the base entry for all backend configuration.
try
{
}
catch (DirectoryException de)
{
}
catch (Exception e)
{
throw new ConfigException(message, e);
}
try
{
}
catch (ConfigException ce)
{
}
catch (Exception e)
{
throw new ConfigException(message, e);
}
// Iterate through the immediate children, attempting to parse them as backends.
{
// Get the backend ID attribute from the entry. If there isn't one, then
// skip the entry.
try
{
true, false, true);
{
continue;
}
else
{
}
}
catch (ConfigException ce)
{
LocalizableMessage message = ERR_CANNOT_DETERMINE_BACKEND_ID.get(configEntry.getDN(), ce.getMessage());
}
catch (Exception e)
{
LocalizableMessage message = ERR_CANNOT_DETERMINE_BACKEND_ID.get(configEntry.getDN(), getExceptionMessage(e));
throw new ConfigException(message, e);
}
// Get the base DN attribute from the entry. If there isn't one, then
// just skip this entry.
try
{
true, true, true);
if (baseDNAttr != null)
{
}
}
catch (Exception e)
{
throw new ConfigException(message, e);
}
}
return backendMap;
}
}