| | |
| | | |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.tools.ToolConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | |
| | | * server process (e.g., via the tasks interface). |
| | | */ |
| | | public class ImportLDIF extends TaskTool { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** |
| | | * The buffer size that should be used when reading data from LDIF. |
| | | */ |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_PARSE_EXCLUDE_FILTER.get( |
| | | filterString, de.getMessageObject()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_PARSE_EXCLUDE_FILTER, filterString, de.getMessageObject()); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_PARSE_EXCLUDE_FILTER.get( |
| | | filterString, getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_PARSE_EXCLUDE_FILTER, filterString, getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_PARSE_INCLUDE_FILTER.get( |
| | | filterString, de.getMessageObject()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_PARSE_INCLUDE_FILTER, filterString, de.getMessageObject()); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_PARSE_INCLUDE_FILTER.get( |
| | | filterString, getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_PARSE_INCLUDE_FILTER, filterString, getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get( |
| | | s, de.getMessageObject()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE, s, de.getMessageObject()); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get( |
| | | s, getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE, s, getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_MULTIPLE_BACKENDS_FOR_ID.get(); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_MULTIPLE_BACKENDS_FOR_ID); |
| | | return 1; |
| | | } |
| | | } |
| | | |
| | | if (backend == null) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_LDIFIMPORT_NO_BACKENDS_FOR_ID.get(); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_NO_BACKENDS_FOR_ID); |
| | | return 1; |
| | | } |
| | | else if (! backend.supportsLDIFImport()) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_IMPORT.get(backendID.getValue()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_IMPORT, backendID.getValue()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_DECODE_EXCLUDE_BASE.get( |
| | | s, de.getMessageObject()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_DECODE_EXCLUDE_BASE, s, de.getMessageObject()); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_DECODE_EXCLUDE_BASE.get( |
| | | s, getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_DECODE_EXCLUDE_BASE, s, getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | if (! Backend.handlesEntry(includeBranch, defaultIncludeBranches, |
| | | excludeBranches)) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_INVALID_INCLUDE_BASE.get( |
| | | includeBranch.toNormalizedString(), backendID.getValue()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch.toNormalizedString(), backendID.getValue()); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | File f = new File(pathname); |
| | | if (!f.canRead()) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_READ_FILE.get(pathname); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_READ_FILE, pathname); |
| | | badFileCount++; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_PARSE_TEMPLATE_FILE.get( |
| | | templateFile.getValue(), e.getMessage()); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_PARSE_TEMPLATE_FILE, templateFile.getValue(), e.getMessage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | LocalizableMessage msg = ERR_LDIFIMPORT_CANNOT_PARSE_THREAD_COUNT.get( |
| | | threadCount.getValue(), e.getMessage()); |
| | | logError(msg); |
| | | logger.error(msg); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_OPEN_REJECTS_FILE.get( |
| | | rejectFile.getValue(), getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_OPEN_REJECTS_FILE, rejectFile.getValue(), getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_OPEN_SKIP_FILE.get( |
| | | skipFile.getValue(), getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_OPEN_SKIP_FILE, skipFile.getValue(), getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.acquireExclusiveLock(lockFile, failureReason)) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_LOCK_BACKEND.get( |
| | | backend.getBackendID(), String.valueOf(failureReason)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_LOCK_BACKEND, backend.getBackendID(), String.valueOf(failureReason)); |
| | | return 1; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_LOCK_BACKEND.get( |
| | | backend.getBackendID(), getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_CANNOT_LOCK_BACKEND, backend.getBackendID(), getExceptionMessage(e)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | message = ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(de.getMessageObject()); |
| | | } |
| | | logError(message); |
| | | logger.error(message); |
| | | retCode = 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.error(ERR_LDIFIMPORT_ERROR_DURING_IMPORT, getExceptionMessage(e)); |
| | | retCode = 1; |
| | | } |
| | | |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.releaseLock(lockFile, failureReason)) |
| | | { |
| | | LocalizableMessage message = WARN_LDIFIMPORT_CANNOT_UNLOCK_BACKEND.get( |
| | | backend.getBackendID(), String.valueOf(failureReason)); |
| | | logError(message); |
| | | logger.warn(WARN_LDIFIMPORT_CANNOT_UNLOCK_BACKEND, backend.getBackendID(), String.valueOf(failureReason)); |
| | | retCode = 1; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizableMessage message = WARN_LDIFIMPORT_CANNOT_UNLOCK_BACKEND.get( |
| | | backend.getBackendID(), getExceptionMessage(e)); |
| | | logError(message); |
| | | logger.warn(WARN_LDIFIMPORT_CANNOT_UNLOCK_BACKEND, backend.getBackendID(), getExceptionMessage(e)); |
| | | retCode = 1; |
| | | } |
| | | |