| | |
| | | |
| | | import javax.mail.MessagingException; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.messages.Severity; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.ErrorLogger; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | |
| | | private LinkedList<String> dependencyIDs; |
| | | |
| | | // A set of log messages generated by this task. |
| | | // TODO: convert from String to Message objects. |
| | | // TODO: convert from String to LocalizableMessage objects. |
| | | // Since these are stored in an entry we would need |
| | | // to adopt some way for writing message to string in such |
| | | // a way that the information could be reparsed from its |
| | |
| | | * |
| | | * @return name of task |
| | | */ |
| | | public Message getDisplayName() { |
| | | public LocalizableMessage getDisplayName() { |
| | | // NOTE: this method is invoked via reflection. If you rename |
| | | // it be sure to modify the calls. |
| | | return null; |
| | |
| | | * |
| | | * @param name of an attribute type associated with the object |
| | | * class that represents this entry in the directory |
| | | * @return Message diaplay name |
| | | * @return LocalizableMessage diaplay name |
| | | */ |
| | | public Message getAttributeDisplayName(String name) { |
| | | public LocalizableMessage getAttributeDisplayName(String name) { |
| | | // Subclasses that are schedulable from the task interface |
| | | // should override this |
| | | |
| | |
| | | { |
| | | if (recurringTaskID == null) |
| | | { |
| | | Message message = ERR_TASK_MISSING_ATTR.get( |
| | | LocalizableMessage message = ERR_TASK_MISSING_ATTR.get( |
| | | String.valueOf(taskEntry.getName()), ATTR_TASK_ID); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | taskState = TaskState.fromString(stateString); |
| | | if (taskState == null) |
| | | { |
| | | Message message = ERR_TASK_INVALID_STATE.get(taskDN, stateString); |
| | | LocalizableMessage message = ERR_TASK_INVALID_STATE.get(taskDN, stateString); |
| | | throw new InitializationException(message); |
| | | } |
| | | } |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_TASK_CANNOT_PARSE_SCHEDULED_START_TIME.get(timeString, taskDN); |
| | | throw new InitializationException(message, e); |
| | | } |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_TASK_CANNOT_PARSE_ACTUAL_START_TIME.get(timeString, taskDN); |
| | | throw new InitializationException(message, e); |
| | | } |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_TASK_CANNOT_PARSE_COMPLETION_TIME.get(timeString, taskDN); |
| | | throw new InitializationException(message, e); |
| | | } |
| | |
| | | { |
| | | if (isRequired) |
| | | { |
| | | Message message = ERR_TASK_MISSING_ATTR.get( |
| | | LocalizableMessage message = ERR_TASK_MISSING_ATTR.get( |
| | | String.valueOf(taskEntry.getName()), attributeName); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | |
| | | if (attrList.size() > 1) |
| | | { |
| | | Message message = ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get( |
| | | LocalizableMessage message = ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get( |
| | | attributeName, String.valueOf(taskEntry.getName())); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | { |
| | | if (isRequired) |
| | | { |
| | | Message message = ERR_TASK_NO_VALUES_FOR_ATTR.get( |
| | | LocalizableMessage message = ERR_TASK_NO_VALUES_FOR_ATTR.get( |
| | | attributeName, String.valueOf(taskEntry.getName())); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | AttributeValue value = iterator.next(); |
| | | if (iterator.hasNext()) |
| | | { |
| | | Message message = ERR_TASK_MULTIPLE_VALUES_FOR_ATTR.get( |
| | | LocalizableMessage message = ERR_TASK_MULTIPLE_VALUES_FOR_ATTR.get( |
| | | attributeName, String.valueOf(taskEntry.getName())); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | |
| | | if (attrList.size() > 1) |
| | | { |
| | | Message message = ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get( |
| | | LocalizableMessage message = ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get( |
| | | attributeName, String.valueOf(taskEntry.getName())); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | |
| | | /** |
| | | * Sets a state for this task that is the result of a call to |
| | | * {@link #interruptTask(TaskState, org.opends.messages.Message)}. |
| | | * {@link #interruptTask(TaskState, org.opends.messages.LocalizableMessage)}. |
| | | * It may take this task some time to actually cancel to that |
| | | * actual state may differ until quiescence. |
| | | * |
| | |
| | | /** |
| | | * Gets the interrupt state for this task that was set as a |
| | | * result of a call to {@link #interruptTask(TaskState, |
| | | * org.opends.messages.Message)}. |
| | | * org.opends.messages.LocalizableMessage)}. |
| | | * |
| | | * @return interrupt state for this task |
| | | */ |
| | |
| | | /** |
| | | * Returns a state for this task after processing has completed. |
| | | * If the task was interrupted with a call to |
| | | * {@link #interruptTask(TaskState, org.opends.messages.Message)} |
| | | * {@link #interruptTask(TaskState, org.opends.messages.LocalizableMessage)} |
| | | * then that method's interruptState is returned here. Otherwse |
| | | * this method returns TaskState.COMPLETED_SUCCESSFULLY. It is |
| | | * assumed that if there were errors during task processing that |
| | |
| | | * |
| | | * @return The set of messages that were logged by this task. |
| | | */ |
| | | public final List<Message> getLogMessages() |
| | | public final List<LocalizableMessage> getLogMessages() |
| | | { |
| | | List<Message> msgList = new ArrayList<Message>(); |
| | | List<LocalizableMessage> msgList = new ArrayList<LocalizableMessage>(); |
| | | for(String logString : logMessages) { |
| | | // TODO: a better job or recreating the message |
| | | msgList.add(Message.raw(logString)); |
| | | msgList.add(LocalizableMessage.raw(logString)); |
| | | } |
| | | return Collections.unmodifiableList(msgList); |
| | | } |
| | |
| | | * |
| | | * @param message The message to be logged. |
| | | */ |
| | | protected void logError(Message message) |
| | | protected void logError(LocalizableMessage message) |
| | | { |
| | | // Simply pass this on to the server error logger, and it will call back |
| | | // to the addLogMessage method for this task. |
| | | ErrorLogger.logError(message); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds a log message to the set of messages logged by this task. This method |
| | | * Adds a log message to the set of messages logged by this task. This method |
| | | * should not be called directly by tasks, but rather will be called |
| | | * indirectly through the {@code ErrorLog.logError} methods. It does not |
| | | * automatically persist the updated task information to disk. |
| | | * |
| | | * @param message he log message |
| | | * @param message |
| | | * the log message. |
| | | */ |
| | | public void addLogMessage(Message message) |
| | | // TODO : remove this method |
| | | public void addLogMessage(LocalizableMessage message) { |
| | | addLogMessage(Severity.SEVERE_ERROR, message); |
| | | } |
| | | |
| | | /** |
| | | * Adds a log message to the set of messages logged by this task. This method |
| | | * should not be called directly by tasks, but rather will be called |
| | | * indirectly through the {@code ErrorLog.logError} methods. It does not |
| | | * automatically persist the updated task information to disk. |
| | | * |
| | | * @param severity |
| | | * the severity of message. |
| | | * @param message |
| | | * the log message. |
| | | */ |
| | | public void addLogMessage(Severity severity, LocalizableMessage message) { |
| | | addLogMessage(severity, message, null); |
| | | } |
| | | |
| | | /** |
| | | * Adds a log message to the set of messages logged by this task. This method |
| | | * should not be called directly by tasks, but rather will be called |
| | | * indirectly through the {@code ErrorLog.logError} methods. It does not |
| | | * automatically persist the updated task information to disk. |
| | | * |
| | | * @param severity |
| | | * the severity of message. |
| | | * @param message |
| | | * the log message. |
| | | * @param exception |
| | | * the exception to log. May be {@code null}. |
| | | */ |
| | | public void addLogMessage(Severity severity, LocalizableMessage message, Throwable exception) |
| | | { |
| | | // We cannot do task logging if the schema is either destroyed or |
| | | // not initialized eg during in-core restart from Restart task. |
| | |
| | | buffer.append("["); |
| | | buffer.append(TimeThread.getLocalTime()); |
| | | buffer.append("] severity=\""); |
| | | buffer.append(message.getDescriptor().getSeverity().name()); |
| | | buffer.append(severity.name()); |
| | | buffer.append("\" msgCount="); |
| | | buffer.append(logMessageCounter++); |
| | | buffer.append(" msgID="); |
| | | buffer.append(message.getDescriptor().getId()); |
| | | buffer.append(message.resourceName()); |
| | | buffer.append("-"); |
| | | buffer.append(message.ordinal()); |
| | | buffer.append(" message=\""); |
| | | buffer.append(message.toString()); |
| | | buffer.append("\""); |
| | | if (exception != null) |
| | | { |
| | | buffer.append(" exception=\""); |
| | | buffer.append(StaticUtils.stackTraceToSingleLineString(exception)); |
| | | buffer.append("\""); |
| | | } |
| | | |
| | | String messageString = buffer.toString(); |
| | | logMessages.add(messageString); |
| | |
| | | |
| | | taskState = TaskState.STOPPED_BY_ERROR; |
| | | |
| | | Message message = ERR_TASK_EXECUTE_FAILED.get( |
| | | LocalizableMessage message = ERR_TASK_EXECUTE_FAILED.get( |
| | | String.valueOf(taskEntry.getName()), stackTraceToSingleLineString(e)); |
| | | logError(message); |
| | | } |
| | |
| | | * successfully interrupted. |
| | | * @param interruptReason A human-readable explanation for the cancellation. |
| | | */ |
| | | public void interruptTask(TaskState interruptState, Message interruptReason) |
| | | public void interruptTask(TaskState interruptState, LocalizableMessage interruptReason) |
| | | { |
| | | // No action is performed by default. |
| | | |