ImportLDIF.java revision 998747bfaaa3c6b28bbfaf0e282e6c0ccbf46bc0
/*
* 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 2011-2015 ForgeRock AS.
*/
/**
* This program provides a utility that may be used to import the contents of an
* LDIF file into 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).
*/
public class ImportLDIF extends TaskTool {
/**
* The buffer size that should be used when reading data from LDIF.
*/
public static final int LDIF_BUFFER_SIZE = 1048576;
/**
* The main method for ImportLDIF tool.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Processes the command-line arguments and invokes the import process.
*
* @param args The command-line arguments provided to this program.
* @return The error code.
*/
{
}
/**
* Processes the command-line arguments and invokes the import 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.
*/
{
}
/** Define the command-line arguments that may be used with this program. */
private BooleanArgument append;
private BooleanArgument countRejects;
private BooleanArgument displayUsage;
private BooleanArgument isCompressed;
private BooleanArgument isEncrypted;
private BooleanArgument overwrite;
private BooleanArgument quietMode;
private BooleanArgument replaceExisting;
private BooleanArgument skipSchemaValidation;
private BooleanArgument clearBackend;
private IntegerArgument randomSeed;
private StringArgument backendID;
private StringArgument configClass;
private StringArgument configFile;
private StringArgument excludeAttributeStrings;
private StringArgument excludeBranchStrings;
private StringArgument excludeFilterStrings;
private StringArgument includeAttributeStrings;
private StringArgument includeBranchStrings;
private StringArgument includeFilterStrings;
private StringArgument ldifFiles;
private StringArgument rejectFile;
private StringArgument skipFile;
private StringArgument templateFile;
private BooleanArgument skipDNValidation;
private IntegerArgument threadCount;
private StringArgument tmpDirectory;
// FIXME -- Need to add a mechanism for verifying the file signature.
// Create the command-line argument parser for use with this program.
createArgParser("org.opends.server.tools.ImportLDIF",
// 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);
OPTION_LONG_LDIF_FILE, false, true, true,
null,
append =
new BooleanArgument(
"replaceexisting", 'r', "replaceExisting",
true, true, INFO_BRANCH_DN_PLACEHOLDER.get(),
true, true, INFO_BRANCH_DN_PLACEHOLDER.get(),
new StringArgument(
"includeattribute", 'i', "includeAttribute",
null,
new StringArgument(
"excludeattribute", 'e', "excludeAttribute",
null,
new StringArgument(
"includefilter", 'I', "includeFilter",
false, true, true, INFO_FILTER_PLACEHOLDER.get(),
null,
skipFile =
null,
OPTION_LONG_RANDOM_SEED, false, false,
true, INFO_SEED_PLACEHOLDER.get(),
false, false, true,
0, null,
false, true, INFO_LDIFIMPORT_TEMP_DIR_PLACEHOLDER.get(),
"import-tmp",
}
catch (ArgumentException ae)
{
return 1;
}
// Init the default values so that they can appear also on the usage.
try
{
}
catch (ConfigException ce)
{
// Ignore.
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
catch (ClientException ce)
{
// No need to display the usage since the problem comes with a provided
// value.
return 1;
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Make sure that either the "ldifFile" argument or the "templateFile"
// argument was provided, but not both.
{
if (templateFile.isPresent())
{
return 1;
}
}
else if (! templateFile.isPresent())
{
return 1;
}
// Make sure that either the "includeBranchStrings" argument or the
// "backendID" argument was provided.
{
return 1;
}
// Count rejects option requires the ability to return result codes
// which are potentially greater than 1. This is not supported by
// the task framework.
if (countRejects.isPresent()
{
return 1;
}
// Don't write non-error messages to console if quite
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
return 1;
}
}
/** {@inheritDoc} */
{
// Required attributes
// Optional attributes
}
{
{
}
}
{
{
}
}
{
{
}
}
{
return values;
}
{
{
}
return values;
}
/** {@inheritDoc} */
public String getTaskObjectclass() {
return "ds-task-import";
}
/** {@inheritDoc} */
public Class<?> getTaskClass() {
return ImportTask.class;
}
/** {@inheritDoc} */
protected int processLocal(boolean initializeServer,
PrintStream err) {
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
if (initializeServer)
{
try
{
}
catch (Exception e)
{
getExceptionMessage(e));
return 1;
}
try
{
configFile.getValue());
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server schema elements.
try
{
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server core configuration.
try
{
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server crypto manager.
try
{
}
catch (Exception e)
{
return 1;
}
{
try
{
}
catch(Exception e)
{
}
}
// Initialize the root DNs.
try
{
}
catch (Exception e)
{
return 1;
}
// Initialize the plugin manager.
try
{
}
catch (Exception e)
{
return 1;
}
// Initialize the subentry manager.
try
{
}
catch (InitializationException ie)
{
ie.getMessage());
return 1;
}
// Initialize all the password policy information.
try
{
}
catch (Exception e)
{
return 1;
}
}
// Make sure that the plugin initialization is performed.
try
{
}
catch (Exception e)
{
return 1;
}
// filters. If so, then process them.
boolean excludeAllUserAttributes = false;
boolean excludeAllOperationalAttributes = false;
if (excludeAttributeStrings == null)
{
}
else
{
{
{
excludeAllUserAttributes = true;
}
{
excludeAllOperationalAttributes = true;
}
else
{
{
}
}
}
}
boolean includeAllUserAttributes = false;
boolean includeAllOperationalAttributes = false;
if (includeAttributeStrings == null)
{
}
else
{
{
{
includeAllUserAttributes = true;
}
{
includeAllOperationalAttributes = true;
}
else
{
{
}
}
}
}
if (excludeFilterStrings == null)
{
}
else
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
}
if (includeFilterStrings == null)
{
}
else
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
}
// Get information about the backends defined in the server. Iterate
// through them, finding the one backend into which the LDIF should be
// imported and finding backends with subordinate base DNs that should be
// excluded from the import.
if (includeBranchStrings.isPresent())
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
}
if (code != 0)
{
return code;
}
for (int i=0; i < numBackends; i++)
{
{
{
continue;
}
}
else
{
{
continue;
}
}
{
backend = b;
}
else
{
return 1;
}
}
{
return 1;
}
{
return 1;
}
{
{
{
{
break;
}
}
}
}
// Make sure that if the "backendID" argument was provided, no include base
// was included, the
// "clearBackend" argument was also provided if there are more then one
// baseDNs for the backend being imported.
{
return 1;
}
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
if (! includeBranchStrings.isPresent())
{
}
else
{
// Make sure the selected backend will handle all the include branches
{
{
return 1;
}
}
}
// See if the data should be read from LDIF files or generated via MakeLDIF.
{
int badFileCount = 0;
{
if (!f.canRead())
{
badFileCount++;
}
}
}
else
{
try
{
}
catch (Exception e)
{
return 1;
}
}
// Create the LDIF import configuration to use when reading the LDIF.
try
{
}
catch(Exception e)
{
return 1;
}
// FIXME -- Should this be conditional?
if (rejectFile != null)
{
try
{
}
catch (Exception e)
{
logger.error(ERR_LDIFIMPORT_CANNOT_OPEN_REJECTS_FILE, rejectFile.getValue(), getExceptionMessage(e));
return 1;
}
}
{
try
{
}
catch (Exception e)
{
return 1;
}
}
// Get the set of base DNs for the backend as an array.
// Acquire an exclusive lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
return 1;
}
// Launch the import.
int retCode = 0;
try
{
if (countRejects.isPresent())
{
{
}
else
{
}
}
}
catch (DirectoryException de)
{
{
}
else
{
}
retCode = 1;
}
catch (Exception e)
{
retCode = 1;
}
// Release the exclusive lock on the backend.
try
{
{
retCode = 1;
}
}
catch (Exception e)
{
retCode = 1;
}
// Clean up after the import by closing the import config.
return retCode;
}
{
try
{
throw e;
}
catch (ConfigException e2)
{
return e2.getMessage();
}
catch (InitializationException e2)
{
return e2.getMessage();
}
{
return getExceptionMessage(e2);
}
}
{
{
{
{
return true;
}
}
}
return false;
}
{
{
}
return builder;
}
{
if (randomSeed.isPresent())
{
try
{
}
{
// ignore
}
}
return new Random();
}
/** {@inheritDoc} */
// NYI.
return null;
}
}