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/server/org/opends/server/tools/tasks/TaskTool.java | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 42 insertions(+), 13 deletions(-)
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