From eee90cc3e34f4e5a7d562ee9e60c66a61816985c Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 16 Oct 2007 20:19:45 +0000
Subject: [PATCH] Issue 2368: tasks should be interruptable. The four schedulable task (import-ldif, export-ldif, backup, and restore) can now be interrupted for purposes of cancellation. The manage-tasks utility now allows the user to cancel any one of these tasks if they are currently running. If interrupted while executing, the tasks try to break out of their work loop as soon as possible and return a 'stopped by administrator' status. Both the backup and export-ldif tasks perform some cleanup (removing the abandoned backup or exported LDIF file) if they are cancelled.
---
opends/src/server/org/opends/server/tasks/ExportTask.java | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/opends/src/server/org/opends/server/tasks/ExportTask.java b/opends/src/server/org/opends/server/tasks/ExportTask.java
index 10432f5..2d9f58f 100644
--- a/opends/src/server/org/opends/server/tasks/ExportTask.java
+++ b/opends/src/server/org/opends/server/tasks/ExportTask.java
@@ -26,6 +26,7 @@
*/
package org.opends.server.tasks;
import org.opends.messages.Message;
+import org.opends.messages.TaskMessages;
import static org.opends.server.core.DirectoryServer.getAttributeType;
import static org.opends.server.config.ConfigConstants.*;
@@ -55,6 +56,7 @@
import java.util.List;
import java.util.Map;
import java.util.HashMap;
+import java.io.File;
/**
* This class provides an implementation of a Directory Server task that can
@@ -136,6 +138,7 @@
private ArrayList<String> includeBranchStrings;
private ArrayList<String> excludeBranchStrings;
+ private LDIFExportConfig exportConfig;
/**
* {@inheritDoc}
@@ -259,6 +262,31 @@
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void interruptTask(TaskState interruptState, Message interruptReason)
+ {
+ if (TaskState.STOPPED_BY_ADMINISTRATOR.equals(interruptState) &&
+ exportConfig != null)
+ {
+ addLogMessage(TaskMessages.INFO_TASK_STOPPED_BY_ADMIN.get(
+ interruptReason));
+ setTaskInterruptState(interruptState);
+ exportConfig.cancel();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isInterruptable() {
+ return true;
+ }
+
+
/**
* {@inheritDoc}
*/
@@ -483,8 +511,7 @@
existingBehavior = ExistingFileBehavior.OVERWRITE;
}
- LDIFExportConfig exportConfig =
- new LDIFExportConfig(ldifFile, existingBehavior);
+ exportConfig = new LDIFExportConfig(ldifFile, existingBehavior);
exportConfig.setCompressData(compressLDIF);
exportConfig.setEncryptData(encryptLDIF);
exportConfig.setExcludeAttributes(excludeAttributes);
@@ -587,7 +614,19 @@
exportConfig.close();
}
+ // If the operation was cancelled delete the export file since
+ // if will be incomplete.
+ if (exportConfig.isCancelled())
+ {
+ File f = new File(ldifFile);
+ if (f.exists())
+ {
+ f.delete();
+ }
+ }
- return TaskState.COMPLETED_SUCCESSFULLY;
+ // If we got here the task either completed successfully or
+ // was interrupted
+ return getFinalTaskState();
}
}
--
Gitblit v1.10.0