| | |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.opends.server.tasks; |
| | | import org.opends.messages.Message; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.messages.TaskMessages; |
| | | |
| | | import static org.opends.server.core.DirectoryServer.getAttributeType; |
| | |
| | | /** |
| | | * Stores mapping between configuration attribute name and its label. |
| | | */ |
| | | static private Map<String,Message> argDisplayMap = |
| | | new HashMap<String,Message>(); |
| | | static private Map<String,LocalizableMessage> argDisplayMap = |
| | | new HashMap<String,LocalizableMessage>(); |
| | | static { |
| | | argDisplayMap.put( |
| | | ATTR_TASK_EXPORT_LDIF_FILE, |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public Message getDisplayName() { |
| | | public LocalizableMessage getDisplayName() { |
| | | return INFO_TASK_EXPORT_NAME.get(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public Message getAttributeDisplayName(String name) { |
| | | public LocalizableMessage getAttributeDisplayName(String name) { |
| | | return argDisplayMap.get(name); |
| | | } |
| | | |
| | |
| | | ClientConnection clientConnection = operation.getClientConnection(); |
| | | if (! clientConnection.hasPrivilege(Privilege.LDIF_EXPORT, operation)) |
| | | { |
| | | Message message = ERR_TASK_LDIFEXPORT_INSUFFICIENT_PRIVILEGES.get(); |
| | | LocalizableMessage message = ERR_TASK_LDIFEXPORT_INSUFFICIENT_PRIVILEGES.get(); |
| | | throw new DirectoryException(ResultCode.INSUFFICIENT_ACCESS_RIGHTS, |
| | | message); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void interruptTask(TaskState interruptState, Message interruptReason) |
| | | public void interruptTask(TaskState interruptState, LocalizableMessage interruptReason) |
| | | { |
| | | if (TaskState.STOPPED_BY_ADMINISTRATOR.equals(interruptState) && |
| | | exportConfig != null) |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_PARSE_EXCLUDE_FILTER.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_PARSE_EXCLUDE_FILTER.get( |
| | | filterString, de.getMessageObject()); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_PARSE_EXCLUDE_FILTER.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_PARSE_EXCLUDE_FILTER.get( |
| | | filterString, getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_PARSE_INCLUDE_FILTER.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_PARSE_INCLUDE_FILTER.get( |
| | | filterString, de.getMessageObject()); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_PARSE_INCLUDE_FILTER.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_PARSE_INCLUDE_FILTER.get( |
| | | filterString, getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | |
| | | if (backend == null) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_NO_BACKENDS_FOR_ID.get(backendID); |
| | | LocalizableMessage message = ERR_LDIFEXPORT_NO_BACKENDS_FOR_ID.get(backendID); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | else if (! backend.supportsLDIFExport()) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_EXPORT_BACKEND.get(backendID); |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_EXPORT_BACKEND.get(backendID); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_DECODE_EXCLUDE_BASE.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_DECODE_EXCLUDE_BASE.get( |
| | | s, de.getMessageObject()); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_DECODE_EXCLUDE_BASE.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_DECODE_EXCLUDE_BASE.get( |
| | | s, getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | Message message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get( |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get( |
| | | s, de.getMessageObject()); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get( |
| | | LocalizableMessage message = ERR_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE.get( |
| | | s, getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | if (! Backend.handlesEntry(includeBranch, defaultIncludeBranches, |
| | | excludeBranches)) |
| | | { |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_LDIFEXPORT_INVALID_INCLUDE_BASE.get(s, backendID); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.acquireSharedLock(lockFile, failureReason)) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_LOCK_BACKEND.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_LOCK_BACKEND.get( |
| | | backend.getBackendID(), String.valueOf(failureReason)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = ERR_LDIFEXPORT_CANNOT_LOCK_BACKEND.get( |
| | | LocalizableMessage message = ERR_LDIFEXPORT_CANNOT_LOCK_BACKEND.get( |
| | | backend.getBackendID(), getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | catch (DirectoryException de) |
| | | { |
| | | DirectoryServer.notifyExportEnded(backend, exportConfig, false); |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_LDIFEXPORT_ERROR_DURING_EXPORT.get(de.getMessageObject()); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | catch (Exception e) |
| | | { |
| | | DirectoryServer.notifyExportEnded(backend, exportConfig, false); |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_LDIFEXPORT_ERROR_DURING_EXPORT.get(getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | |
| | | StringBuilder failureReason = new StringBuilder(); |
| | | if (! LockFileManager.releaseLock(lockFile, failureReason)) |
| | | { |
| | | Message message = WARN_LDIFEXPORT_CANNOT_UNLOCK_BACKEND.get( |
| | | LocalizableMessage message = WARN_LDIFEXPORT_CANNOT_UNLOCK_BACKEND.get( |
| | | backend.getBackendID(), String.valueOf(failureReason)); |
| | | logError(message); |
| | | return TaskState.COMPLETED_WITH_ERRORS; |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = WARN_LDIFEXPORT_CANNOT_UNLOCK_BACKEND.get( |
| | | LocalizableMessage message = WARN_LDIFEXPORT_CANNOT_UNLOCK_BACKEND.get( |
| | | backend.getBackendID(), getExceptionMessage(e)); |
| | | logError(message); |
| | | return TaskState.COMPLETED_WITH_ERRORS; |