From 91f8974bf156c3c666520c8a0ec57155d5daf24e Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 25 Sep 2007 02:35:50 +0000
Subject: [PATCH] Enabled the task schedulable utilities to track progress of running tasks by polling the corresponding entry in the task backend and printing log messages until the task is complete. If LDAP connection arguments are specified and no start time is specified the default behavior is to track the running task until it is finished executing. If a start time is specified, the task utilities will schedule the task and exit immediately.
---
opends/src/messages/messages/tools.properties | 19 +++------
opends/src/server/org/opends/server/tools/tasks/TaskTool.java | 55 +++++++++++++++++++++------
2 files changed, 49 insertions(+), 25 deletions(-)
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 73df212..8684d3a 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2142,21 +2142,16 @@
INFO_DESCRIPTION_START_DATETIME_1456=Indicates the date/time at which the this \
operation will start when scheduled as a server task expressed in format \
'YYYYMMDDhhmmss'. A value of '0' will cause the task to be scheduled for \
- immediate execution
+ immediate execution. When this option is specified the operation will be \
+ scheduled to start at the specified time after which this utility will exit \
+ immediately
SEVERE_ERR_START_DATETIME_FORMAT_1457=The start date/time must in format \
'YYYYMMDDhhmmss'
INFO_TASK_TOOL_TASK_SCHEDULED_FUTURE_1458=%s task %s scheduled to start %s
-SEVERE_ERR_TASK_TOOL_START_TIME_NO_LDAP_1459=You have provided a task start \
- time but options provided for connecting to the server's tasks backend \
- resulted in the following error: '%s'
-SEVERE_ERR_TASK_TOOL_LDAP_NO_START_TIME_1460=You have provided options that \
- specify information for specifying a connection to the Directory Server but \
- no -t/--startTime option. In order to schedule a server task you must \
- provide the -t/--startTime argument with either the start time in format \
- 'YYYYMMDDhhmmss' as the value or '0' to schedule the task for immediate \
- execution. To run this operation locally and not as a server task omit the \
- Directory Server connection options
+SEVERE_ERR_TASK_TOOL_START_TIME_NO_LDAP_1459=You have provided a options for \
+ scheduling this operation as a task but options provided for connecting to \
+ the server's tasks backend resulted in the following error: '%s'
INFO_DESCRIPTION_PROP_FILE_PATH_1461=Path to the file which contains default \
properties value used for command line argument
INFO_DESCRIPTION_NO_PROP_FILE_1462=Indicates that we will not use properties \
- file to get default command line argument value
+ file to get default command line argument value
\ No newline at end of file
diff --git a/opends/src/server/org/opends/server/tools/tasks/TaskTool.java b/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
index 9e4020d..f88681c 100644
--- a/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
+++ b/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -47,6 +47,9 @@
import java.io.PrintStream;
import java.text.ParseException;
import java.util.Date;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.List;
import java.io.IOException;
/**
@@ -63,8 +66,13 @@
*/
public static final String NOW = "0";
+ // Number of milliseconds this utility will wait before reloading
+ // this task's entry in the directory while it is polling for status
+ private static final int SYNCHRONOUS_TASK_POLL_INTERVAL = 1000;
+
LDAPConnectionArgumentParser argParser;
+ // Argument for describing the task's start time
StringArgument startArg;
/**
@@ -96,14 +104,13 @@
toolDescription, false);
try {
- startArg =
- new StringArgument(
- OPTION_LONG_START_DATETIME,
- OPTION_SHORT_START_DATETIME,
- OPTION_LONG_START_DATETIME, false, false,
- true, OPTION_VALUE_START_DATETIME,
- null, null,
- INFO_DESCRIPTION_START_DATETIME.get());
+ startArg = new StringArgument(
+ OPTION_LONG_START_DATETIME,
+ OPTION_SHORT_START_DATETIME,
+ OPTION_LONG_START_DATETIME, false, false,
+ true, OPTION_VALUE_START_DATETIME,
+ null, null,
+ INFO_DESCRIPTION_START_DATETIME.get());
argParser.addArgument(startArg);
} catch (ArgumentException e) {
// should never happen
@@ -134,6 +141,8 @@
*/
public Date getStartDateTime() {
Date start = null;
+
+ // If the start time arg is present parse its value
if (startArg != null && startArg.isPresent()) {
if (NOW.equals(startArg.getValue())) {
start = new Date();
@@ -164,7 +173,7 @@
PrintStream out, PrintStream err) {
int ret;
- if (startArg.isPresent())
+ if (argParser.argumentsPresent())
{
if (initializeServer)
{
@@ -202,6 +211,30 @@
taskEntry.getScheduledStartTime()),
MAX_LINE_WIDTH));
}
+ if (!startArg.isPresent() || NOW.equals(startArg.getValue())) {
+
+ // Poll the task printing log messages until finished
+ String taskId = taskEntry.getId();
+ taskEntry = tc.getTaskEntry(taskId);
+ Set<Message> printedLogMessages = new HashSet<Message>();
+ do {
+ List<Message> logs = taskEntry.getLogMessages();
+ for (Message log : logs) {
+ if (!printedLogMessages.contains(log)) {
+ printedLogMessages.add(log);
+ out.println(log);
+ }
+ }
+
+ try {
+ Thread.sleep(SYNCHRONOUS_TASK_POLL_INTERVAL);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+
+ taskEntry = tc.getTaskEntry(taskId);
+ } while (!taskEntry.isDone());
+ }
ret = 0;
} catch (LDAPConnectionException e) {
Message message = ERR_TASK_TOOL_START_TIME_NO_LDAP.get(e.getMessage());
@@ -224,10 +257,6 @@
if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
ret = 1;
}
- } else if (argParser.argumentsPresent()) {
- Message message = ERR_TASK_TOOL_LDAP_NO_START_TIME.get();
- if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
- ret = 1;
} else {
ret = processLocal(initializeServer, out, err);
}
--
Gitblit v1.10.0