ImportTask.java revision c0a5d19fa897c532ced3e13e01f18f869270e9a0
/*
* 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 2013-2015 ForgeRock AS
*/
/**
* This class provides an implementation of a Directory Server task that can
* be used to import data from an LDIF file into a backend.
*/
public class ImportTask extends Task
{
/** Stores mapping between configuration attribute name and its label. */
private static final Map<String, LocalizableMessage> argDisplayMap = new HashMap<String, LocalizableMessage>();
static
{
argDisplayMap.put(ATTR_IMPORT_SKIP_SCHEMA_VALIDATION, INFO_IMPORT_ARG_SKIP_SCHEMA_VALIDATION.get());
}
private boolean append;
private boolean isCompressed;
private boolean isEncrypted;
private boolean overwrite;
private boolean replaceExisting;
private boolean skipSchemaValidation;
private boolean clearBackend;
private boolean skipDNValidation;
private String tmpDirectory;
private int threadCount;
private String rejectFile;
private String templateFile;
private int randomSeed;
private LDIFImportConfig importConfig;
/** {@inheritDoc} */
public LocalizableMessage getDisplayName() {
return INFO_TASK_IMPORT_NAME.get();
}
/** {@inheritDoc} */
}
/** {@inheritDoc} */
{
// If the client connection is available, then make sure the associated
// client has the LDIF_IMPORT privilege.
{
{
}
}
AttributeType typeSkipSchemaValidation = getAttributeType(ATTR_IMPORT_SKIP_SCHEMA_VALIDATION, true);
for (String s : ldifFilestmp)
{
if (!f.isAbsolute())
{
try
{
s = f.getCanonicalPath();
}
{
s = f.getAbsolutePath();
}
}
}
if (templateFile != null)
{
if (!f.isAbsolute())
{
.getAbsolutePath();
}
}
// Make sure that either the "includeBranchStrings" argument or the
// "backendID" argument was provided.
{
}
for (String s : includeBranchStrings)
{
try
{
}
catch (DirectoryException de)
{
s, de.getMessageObject());
}
catch (Exception e)
{
s, getExceptionMessage(e));
}
}
for (String s : excludeBranchStrings)
{
try
{
}
catch (DirectoryException de)
{
s, de.getMessageObject());
}
catch (Exception e)
{
s, getExceptionMessage(e));
}
}
{
try
{
}
catch (DirectoryException de)
{
}
}
{
try
{
}
catch (DirectoryException de)
{
}
}
{
{
}
{
}
// Make sure that if the "backendID" argument was provided, no include
// base was included, and the "append" option was not provided, the
// "clearBackend" argument was also provided if there are more then one
// baseDNs for the backend being imported.
{
{
}
}
}
else
{
// Find the backend that includes all the branches.
{
if(locatedBackend != null)
{
{
}
else if(backend != locatedBackend)
{
// The include branches span across multiple backends.
}
}
else
{
// The include branch is not associated with any backend.
}
}
}
// Make sure the selected backend will handle all the include branches
{
}
{
{
}
}
}
{
}
{
}
{
}
{
}
/** {@inheritDoc} */
{
{
}
}
/** {@inheritDoc} */
public boolean isInterruptable()
{
return true;
}
/** {@inheritDoc} */
{
// filters. If so, then process them.
{
try
{
}
catch (DirectoryException de)
{
return TaskState.STOPPED_BY_ERROR;
}
}
{
try
{
}
catch (DirectoryException de)
{
return TaskState.STOPPED_BY_ERROR;
}
}
// Get the backend into which the LDIF should be imported.
for (String s : includeBranchStrings)
{
try
{
}
catch (DirectoryException de)
{
return TaskState.STOPPED_BY_ERROR;
}
catch (Exception e)
{
return TaskState.STOPPED_BY_ERROR;
}
}
{
{
return TaskState.STOPPED_BY_ERROR;
}
{
return TaskState.STOPPED_BY_ERROR;
}
// Make sure that if the "backendID" argument was provided, no include
// base was included, and the "append" option was not provided, the
// "clearBackend" argument was also provided if there are more then one
// baseDNs for the backend being imported.
{
{
}
return TaskState.STOPPED_BY_ERROR;
}
}
else
{
// Find the backend that includes all the branches.
{
if(locatedBackend != null)
{
{
}
else if(backend != locatedBackend)
{
// The include branches span across multiple backends.
return TaskState.STOPPED_BY_ERROR;
}
}
}
}
// Find backends with subordinate base DNs that should be excluded from the
// import.
{
}
{
{
{
{
{
break;
}
}
}
}
}
for (String s : excludeBranchStrings)
{
try
{
}
catch (DirectoryException de)
{
return TaskState.STOPPED_BY_ERROR;
}
catch (Exception e)
{
return TaskState.STOPPED_BY_ERROR;
}
}
if (includeBranchStrings.isEmpty())
{
}
else
{
// Make sure the selected backend will handle all the include branches
{
{
return TaskState.STOPPED_BY_ERROR;
}
}
}
// Create the LDIF import configuration to use when reading the LDIF.
if (templateFile != null)
{
try
{
}
catch (Exception e)
{
}
try
{
}
catch (Exception e)
{
return TaskState.STOPPED_BY_ERROR;
}
}
else
{
}
if(tmpDirectory == null)
{
tmpDirectory = "import-tmp";
}
// FIXME -- Should this be conditional?
if (rejectFile != null)
{
try
{
}
catch (Exception e)
{
return TaskState.STOPPED_BY_ERROR;
}
}
{
try
{
}
catch (Exception e)
{
return TaskState.STOPPED_BY_ERROR;
}
}
// Get the set of base DNs for the backend as an array.
// Notify the task listeners that an import is going to start
// this must be done before disabling the backend to allow
// listeners to get access to the backend configuration
// and to take appropriate actions.
// Disable the backend.
try
{
}
catch (DirectoryException e)
{
logger.traceException(e);
return TaskState.STOPPED_BY_ERROR;
}
try
{
// Acquire an exclusive lock for the backend.
try
{
{
return TaskState.STOPPED_BY_ERROR;
}
}
catch (Exception e)
{
logger.traceException(e);
return TaskState.STOPPED_BY_ERROR;
}
// Launch the import.
try
{
}
catch (DirectoryException de)
{
{
}
else
{
}
return TaskState.STOPPED_BY_ERROR;
}
catch (Exception e)
{
logger.traceException(e);
return TaskState.STOPPED_BY_ERROR;
}
finally
{
// Release the exclusive lock on the backend.
try
{
{
return TaskState.COMPLETED_WITH_ERRORS;
}
}
catch (Exception e)
{
logger.traceException(e);
return TaskState.COMPLETED_WITH_ERRORS;
}
}
}
finally
{
// Enable the backend.
try
{
// It is necessary to retrieve the backend structure again
// because disabling and enabling it again may have resulted
// in a new backend being registered to the server.
}
catch (DirectoryException e)
{
logger.traceException(e);
return TaskState.STOPPED_BY_ERROR;
}
}
// Clean up after the import by closing the import config.
return getFinalTaskState();
}
{
{
{
}
}
return attrTypes;
}
}