ImportLDIF.java revision 332075ed0cd6330412de06f07be130b68a7eb7a9
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* 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(errorLogPublisher != null)
{
}
if(retCode != 0)
{
}
}
/**
* Processes the command-line arguments and invokes the import process.
*
* @param args The command-line arguments provided to thisprogram.
*
* @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.
{
}
else
{
}
{
}
else
{
}
// FIXME -- Need to add a mechanism for verifying the file signature.
// Create the command-line argument parser for use with this program.
new LDAPConnectionArgumentParser("org.opends.server.tools.ImportLDIF",
toolDescription, false);
// Initialize all the command-line argument types and register them with the
// parser.
try
{
OPTION_LONG_CONFIG_CLASS, true, false,
true, OPTION_VALUE_CONFIG_CLASS,
configClass.setHidden(true);
configFile.setHidden(true);
OPTION_LONG_LDIF_FILE, false, true, true,
append =
new BooleanArgument(
"replaceexisting", 'r', "replaceExisting",
new StringArgument(
"includeattribute", 'i', "includeAttribute",
new StringArgument(
"excludeattribute", 'e', "excludeAttribute",
new StringArgument(
"includefilter", 'I', "includeFilter",
skipFile =
OPTION_LONG_RANDOM_SEED, false, false,
true, OPTION_VALUE_RANDOM_SEED,
}
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;
}
// 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;
}
// Don't write non-error messages to console if quite
}
}
/**
* {@inheritDoc}
*/
{
//
// Required attributes
//
}
}
//
// Optional attributes
//
}
}
backendID.getDefaultValue())) {
}
}
}
}
}
}
}
}
}
}
}
}
}
rejectFile.getDefaultValue())) {
}
skipFile.getDefaultValue())) {
}
overwrite.getDefaultValue())) {
}
}
isCompressed.getDefaultValue())) {
}
isEncrypted.getDefaultValue())) {
}
clearBackend.getDefaultValue())) {
}
}
/**
* {@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 (ConfigException ce)
{
return 1;
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server core configuration.
try
{
}
catch (ConfigException ce)
{
ce.getMessage());
return 1;
}
catch (InitializationException ie)
{
ie.getMessage());
return 1;
}
catch (Exception e)
{
getExceptionMessage(e));
return 1;
}
// Initialize the Directory Server crypto manager.
try
{
}
catch (ConfigException ce)
{
ce.getMessage());
return 1;
}
catch (InitializationException ie)
{
ie.getMessage());
return 1;
}
catch (Exception e)
{
getExceptionMessage(e));
return 1;
}
{
// FIXME -- Install a custom logger to capture information about the
// state of the import.
try
{
}
catch(Exception e)
{
}
}
// Initialize all the password policy information.
try
{
}
catch (ConfigException ce)
{
ce.getMessage());
return 1;
}
catch (InitializationException ie)
{
ie.getMessage());
return 1;
}
catch (Exception e)
{
getExceptionMessage(e));
return 1;
}
// Make sure that the Directory Server plugin initialization is performed.
try
{
}
catch (ConfigException ce)
{
ce.getMessage());
return 1;
}
catch (InitializationException ie)
{
ie.getMessage());
return 1;
}
catch (Exception e)
{
getExceptionMessage(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)
{
s, de.getMessageObject());
return 1;
}
catch (Exception e)
{
s, getExceptionMessage(e));
return 1;
}
}
}
if (code != 0)
{
return code;
}
for (int i=0; i < numBackends; i++)
{
{
{
continue;
}
}
else
{
boolean useBackend = false;
{
{
{
useBackend = true;
break;
}
}
if(useBackend)
{
break;
}
}
if(!useBackend)
{
continue;
}
}
{
backend = b;
}
else
{
return 1;
}
}
{
return 1;
}
else if (! backend.supportsLDIFImport())
{
return 1;
}
{
{
{
{
{
}
break;
}
}
}
}
// Make sure that if the "backendID" argument was provided, no include base
// was included, and the "append" ption was not provided, the "clearBackend"
// argument was also provided if there are more then one baseDNs for the
// backend being imported.
{
{
}
return 1;
}
{
try
{
}
catch (DirectoryException de)
{
s, de.getMessageObject());
return 1;
}
catch (Exception e)
{
s, getExceptionMessage(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
{
if (randomSeed.isPresent())
{
try
{
}
catch (Exception e)
{
}
}
else
{
}
try
{
}
catch (Exception e)
{
return 1;
}
}
// Create the LDIF import configuration to use when reading the LDIF.
// FIXME -- Should this be conditional?
if (rejectFile != null)
{
try
{
{
}
else
{
}
}
catch (Exception e)
{
return 1;
}
}
{
try
{
{
}
else
{
}
}
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)
{
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;
}
}