Greg Padgett has uploaded a new change for review.

Change subject: [WIP] core: refactor async tasks to make way for EntityTask
......................................................................

[WIP] core: refactor async tasks to make way for EntityTask

Change-Id: I460b98c3d4b38243da61433d08c16f1cde5b9e17
Bug-Url: https://bugzilla.redhat.com/??????
Signed-off-by: Greg Padgett <gpadg...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandAsyncTask.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/SPMAsyncTask.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/SPMTask.java
4 files changed, 100 insertions(+), 53 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/12/26912/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskBase.java
index 2aba688..fe1c9c0 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskBase.java
@@ -19,7 +19,7 @@
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
-public class AsyncTaskBase implements AsyncTask {
+public abstract class AsyncTaskBase implements AsyncTask {
     CommandCoordinator coco;
     public AsyncTaskBase(CommandCoordinator coco, AsyncTaskParameters 
parameters) {
         this.coco = coco;
@@ -123,7 +123,7 @@
         if (state != AsyncTaskState.AttemptingEndAction
                 && state != AsyncTaskState.Cleared
                 && state != AsyncTaskState.ClearFailed) {
-            log.infoFormat("BaseAsyncTask::startPollingTask: Starting to poll 
task '{0}'.", getVdsmTaskId());
+            log.infoFormat("AsyncTaskBase::startPollingTask: Starting to poll 
task '{0}'.", getVdsmTaskId());
             concreteStartPollingTask();
         }
     }
@@ -194,7 +194,7 @@
         catch (RuntimeException e) {
             log.error(
                     String.format(
-                            "BaseAsyncTask::PollAndUpdateTask: Handling task 
'%1$s' (State: %2$s, Parent Command: %3$s, Parameters Type: %4$s) threw an 
exception",
+                            "AsyncTaskBase::PollAndUpdateTask: Handling task 
'%1$s' (State: %2$s, Parent Command: %3$s, Parameters Type: %4$s) threw an 
exception",
                             getVdsmTaskId(),
                             getState(),
                             (getParameters().getDbAsyncTask()
@@ -209,7 +209,7 @@
      * Handle ended task operation. Change task state to Ended ,Cleared or
      * Cleared Failed , and log appropriate message.
      */
-    private void HandleEndedTask() {
+    protected void HandleEndedTask() {
         // If task state is different from Ended change it to Ended and set the
         // last access time to now.
         if (getState() != AsyncTaskState.Ended) {
@@ -244,13 +244,13 @@
     protected void RemoveTaskFromDB() {
         try {
             if (coco.removeByVdsmTaskId(getVdsmTaskId()) != 0) {
-                log.infoFormat("BaseAsyncTask::RemoveTaskFromDB: Removed task 
{0} from DataBase", getVdsmTaskId());
+                log.infoFormat("AsyncTaskBase::RemoveTaskFromDB: Removed task 
{0} from DataBase", getVdsmTaskId());
             }
         }
 
         catch (RuntimeException e) {
             log.error(String.format(
-                    "BaseAsyncTask::RemoveTaskFromDB: Removing task %1$s from 
DataBase threw an exception.",
+                    "AsyncTaskBase::RemoveTaskFromDB: Removing task %1$s from 
DataBase threw an exception.",
                     getVdsmTaskId()), e);
         }
     }
@@ -274,7 +274,7 @@
 
     protected void LogEndTaskSuccess() {
         log.infoFormat(
-                "BaseAsyncTask::OnTaskEndSuccess: Task '{0}' (Parent Command 
{1}, Parameters Type {2}) ended successfully.",
+                "AsyncTaskBase::OnTaskEndSuccess: Task '{0}' (Parent Command 
{1}, Parameters Type {2}) ended successfully.",
                 getVdsmTaskId(),
                 (getParameters().getDbAsyncTask().getaction_type()),
                 getParameters()
@@ -288,7 +288,7 @@
 
     protected void LogEndTaskFailure() {
         log.errorFormat(
-                "BaseAsyncTask::LogEndTaskFailure: Task '{0}' (Parent Command 
{1}, Parameters Type {2}) ended with failure:"
+                "AsyncTaskBase::LogEndTaskFailure: Task '{0}' (Parent Command 
{1}, Parameters Type {2}) ended with failure:"
                         + "\r\n" + "-- Result: '{3}'" + "\r\n" + "-- Message: 
'{4}'," + "\r\n" + "-- Exception: '{5}'",
                 getVdsmTaskId(),
                 (getParameters().getDbAsyncTask().getaction_type()),
@@ -307,7 +307,7 @@
 
     protected void LogTaskDoesntExist() {
         log.errorFormat(
-                "BaseAsyncTask::LogTaskDoesntExist: Task '{0}' (Parent Command 
{1}, Parameters Type {2}) does not exist.",
+                "AsyncTaskBase::LogTaskDoesntExist: Task '{0}' (Parent Command 
{1}, Parameters Type {2}) does not exist.",
                 getVdsmTaskId(),
                 (getParameters().getDbAsyncTask().getaction_type()),
                 getParameters()
@@ -379,37 +379,6 @@
         }
     }
 
-    public void stopTask() {
-        stopTask(false);
-    }
-
-    public void stopTask(boolean forceFinish) {
-        if (getState() != AsyncTaskState.AttemptingEndAction && getState() != 
AsyncTaskState.Cleared
-                && getState() != AsyncTaskState.ClearFailed && 
!getLastTaskStatus().getTaskIsInUnusualState()) {
-            try {
-                log.infoFormat(
-                        "AsyncTaskBase::StopTask: Attempting to stop task 
'{0}' (Parent Command {1}, Parameters Type {2}).",
-                        getVdsmTaskId(),
-                        (getParameters().getDbAsyncTask().getaction_type()),
-                        getParameters().getClass().getName());
-
-                coco.stopTask(getStoragePoolID(), getVdsmTaskId());
-            } catch (RuntimeException e) {
-                log.error(
-                        String.format("AsyncTaskBase::StopTask: Stopping task 
'%1$s' threw an exception.", getVdsmTaskId()),
-                        e);
-            } finally {
-                if (forceFinish) {
-                    //Force finish flag allows to force the task completion, 
regardless of the result from call to SPMStopTask
-                    setState(AsyncTaskState.Ended);
-                    setLastTaskStatus(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished));
-                } else {
-                    setState(AsyncTaskState.Polling);
-                }
-            }
-        }
-    }
-
     public void clearAsyncTask() {
         // if we are calling updateTask on a task which has not been submitted,
         // to vdsm there is no need to clear the task. The task is just deleted
@@ -421,18 +390,13 @@
         clearAsyncTask(false);
     }
 
+    protected VDSReturnValue clearTaskRemote() {
+        /* Overridden for task types for which clearing involves remote 
actions */
+        return null;
+    }
+
     public void clearAsyncTask(boolean forceDelete) {
-        VDSReturnValue vdsReturnValue = null;
-
-        try {
-            log.infoFormat("AsyncTaskBase::ClearAsyncTask: Attempting to clear 
task '{0}'", getVdsmTaskId());
-            vdsReturnValue = coco.clearTask(getStoragePoolID(), 
getVdsmTaskId());
-        }
-
-        catch (RuntimeException e) {
-            log.error(String.format("AsyncTaskBase::ClearAsyncTask: Clearing 
task '%1$s' threw an exception.",
-                    getVdsmTaskId()), e);
-        }
+        VDSReturnValue vdsReturnValue = clearTaskRemote();
 
         boolean shouldGracefullyDeleteTask = false;
         if (!isTaskStateError(vdsReturnValue)) {
@@ -450,6 +414,40 @@
         }
     }
 
+    public void stopTask() {
+        stopTask(false);
+    }
+
+    protected abstract void stopTaskRemote();
+
+    public void stopTask(boolean forceFinish) {
+        if (getState() != AsyncTaskState.AttemptingEndAction && getState() != 
AsyncTaskState.Cleared
+                && getState() != AsyncTaskState.ClearFailed && 
!getLastTaskStatus().getTaskIsInUnusualState()) {
+            try {
+                log.infoFormat(
+                        "AsyncTaskBase::StopTask: Attempting to stop task 
'{0}' (Parent Command {1}, Parameters Type {2}).",
+                        getVdsmTaskId(),
+                        (getParameters().getDbAsyncTask().getaction_type()),
+                        getParameters().getClass().getName());
+
+                stopTaskRemote();
+            } catch (RuntimeException e) {
+                log.error(
+                        String.format("AsyncTaskBase::StopTask: Stopping task 
'%1$s' threw an exception.", getVdsmTaskId()),
+                        e);
+            } finally {
+                if (forceFinish) {
+                    //Force finish flag allows to force the task completion, 
regardless of the result from call to SPMStopTask
+                    setState(AsyncTaskState.Ended);
+                    setLastTaskStatus(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished));
+                } else {
+                    setState(AsyncTaskState.Polling);
+                }
+            }
+        }
+    }
+
+
     /**
      * Function return true if we got error 410 - which is SPM initializing and
      * we did not clear the task
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandAsyncTask.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandAsyncTask.java
index 436dc13..07d47ea 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandAsyncTask.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandAsyncTask.java
@@ -25,7 +25,7 @@
 /**
  * Base class for all tasks regarding a specific command.
  */
-public class CommandAsyncTask extends AsyncTaskBase {
+public class CommandAsyncTask extends SPMAsyncTask {
     private static final Object _lockObject = new Object();
 
     private static final Map<Guid, CommandMultiAsyncTasks> 
_multiTasksByCommandIds =
@@ -272,6 +272,6 @@
         EndActionIfNecessary();
     }
 
-
     private static final Log log = LogFactory.getLog(CommandAsyncTask.class);
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/SPMAsyncTask.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/SPMAsyncTask.java
new file mode 100644
index 0000000..8029537
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/SPMAsyncTask.java
@@ -0,0 +1,42 @@
+package org.ovirt.engine.core.bll.tasks;
+
+import org.ovirt.engine.core.bll.tasks.interfaces.CommandCoordinator;
+import org.ovirt.engine.core.bll.tasks.interfaces.SPMTask;
+import org.ovirt.engine.core.common.asynctasks.AsyncTaskParameters;
+import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.utils.log.Log;
+import org.ovirt.engine.core.utils.log.LogFactory;
+
+public class SPMAsyncTask extends AsyncTaskBase implements SPMTask {
+
+    public SPMAsyncTask(CommandCoordinator coco, AsyncTaskParameters 
parameters) {
+        super(coco, parameters);
+    }
+
+    public Guid getStoragePoolID() {
+        return getObjectId();
+    }
+
+    @Override
+    protected VDSReturnValue clearTaskRemote() {
+        VDSReturnValue vdsReturnValue = null;
+        try {
+            log.infoFormat("SPMAsyncTask::clearTaskRemote: Attempting to clear 
task '{0}'", getVdsmTaskId());
+            vdsReturnValue = coco.clearTask(getStoragePoolID(), 
getVdsmTaskId());
+        }
+        catch (RuntimeException e) {
+            log.error(String.format("SPMAsyncTask::clearTaskRemote: Clearing 
task '%1$s' threw an exception.",
+                    getVdsmTaskId()), e);
+        }
+        return vdsReturnValue;
+    }
+
+    @Override
+    protected void stopTaskRemote() {
+        coco.stopTask(getStoragePoolID(), getVdsmTaskId());
+    }
+
+    private static final Log log = LogFactory.getLog(SPMAsyncTask.class);
+
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/SPMTask.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/SPMTask.java
new file mode 100644
index 0000000..1e42b86
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/SPMTask.java
@@ -0,0 +1,7 @@
+package org.ovirt.engine.core.bll.tasks.interfaces;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public interface SPMTask extends AsyncTask {
+    public Guid getStoragePoolID();
+}


-- 
To view, visit http://gerrit.ovirt.org/26912
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I460b98c3d4b38243da61433d08c16f1cde5b9e17
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Greg Padgett <gpadg...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to