Yair Zaslavsky has uploaded a new change for review.

Change subject: [WIP] core: Fix endAction with partial tasks when engine is 
running
......................................................................

[WIP] core: Fix endAction with partial tasks when engine is running

This patch fixes an issue with endAction of partial tasks (no vdsm
Task ID) when engine is running -

If engine is running and there is a VDSM communication exception,
no CommandAsyncTask object will be created.
As a result, AsyncTaskManager will not have the tasks in the
"tasks to poll" collection (which is ok) +
the CommandMultiAsyncTasks at the _multiTasksByCommandIds map for the
root command Id will not contain information on the task.
This will cause end of command coordination to ignore the partial task.
The patch fixes this by adding the created task at place holder stage
to a map at async tasks manager from command Id to list of async tasks objects.
This data structure can be used to check at end of command coordination stage
whether the task has empty vdsm task Id.

Bug-Url: https://bugzilla.redhat.com/982003

Change-Id: Ic9281f2038f677eea39aa69a4f4b471917ed859c
Signed-off-by: Yair Zaslavsky <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SPMAsyncTask.java
3 files changed, 31 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/50/16550/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java
index d57c6b4..0d28e1c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java
@@ -71,6 +71,11 @@
      */
     private Map<Guid, AsyncTasks> partiallyCompletedCommandTasks = new 
ConcurrentHashMap<>();
 
+    /**
+     * Map of root command ID to the list of its tasks
+     */
+    private Map<Guid, List<AsyncTasks>> rootCommandIdToTasksMap = new 
ConcurrentHashMap<>();
+
     private static final AsyncTaskManager _taskManager = new 
AsyncTaskManager();
 
     public static AsyncTaskManager getInstance() {
@@ -91,7 +96,7 @@
                 
Config.<Integer>GetValue(ConfigValues.AsyncTaskStatusCacheRefreshRateInSeconds),
 TimeUnit.SECONDS);
         _cacheTimeInMinutes = 
Config.<Integer>GetValue(ConfigValues.AsyncTaskStatusCachingTimeInMinutes);
         tasksInDbAfterRestart = new ConcurrentHashMap();
-        Map<Guid, List<AsyncTasks>> rootCommandIdToTasksMap = 
groupTasksByRootCommandId(DbFacade.getInstance().getAsyncTaskDao().getAll());
+        rootCommandIdToTasksMap = 
groupTasksByRootCommandId(DbFacade.getInstance().getAsyncTaskDao().getAll());
         for (Entry<Guid, List<AsyncTasks>> entry : 
rootCommandIdToTasksMap.entrySet()) {
             if 
(hasTasksWithoutVdsmId(rootCommandIdToTasksMap.get(entry.getKey()))) {
                 log.infoFormat("Root Command {0} has tasks without vdsm id.", 
entry.getKey());
@@ -228,11 +233,10 @@
      * @return
      */
     private Map<Guid, List<AsyncTasks>> 
groupTasksByRootCommandId(List<AsyncTasks> tasksInDB) {
-        Map<Guid, List<AsyncTasks>> rootCommandIdToCommandsMap = new 
HashMap<>();
         for (AsyncTasks task : tasksInDB) {
-            MultiValueMapUtils.addToMap(task.getRootCommandId(), task, 
rootCommandIdToCommandsMap);
+            MultiValueMapUtils.addToMap(task.getRootCommandId(), task, 
rootCommandIdToTasksMap);
         }
-        return rootCommandIdToCommandsMap;
+        return rootCommandIdToTasksMap;
     }
 
     /**
@@ -785,4 +789,24 @@
 
         return false;
     }
+
+    public boolean hasPartialTasks(Guid rootCommandId) {
+        List<AsyncTasks> tasks = rootCommandIdToTasksMap.get(rootCommandId);
+        if (tasks == null) {
+            log.infoFormat("Command {0} has no associated tasks ", 
rootCommandId);
+            return false;
+        }
+
+        for (AsyncTasks task : tasks) {
+            if (task.getVdsmTaskId().equals(Guid.Empty)) {
+                return true;
+            }
+        }
+        return false;
+
+    }
+
+    public void addTaskOnRootCommand(AsyncTasks task) {
+        MultiValueMapUtils.addToMap(task.getRootCommandId(), task, 
rootCommandIdToTasksMap);
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index 2a6d41d..306a99a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -1367,6 +1367,7 @@
         Guid taskId = Guid.Empty;
         try {
             AsyncTasks task = createAsyncTask(new AsyncTaskCreationInfo(), 
parentCommand);
+            getAsyncTaskManager().addTaskOnRootCommand(task);
             taskId = task.getTaskId();
             AsyncTaskUtils.addOrUpdateTaskInDB(task, null, EMPTY_GUID_ARRAY);
             taskKeyToTaskIdMap.put(taskKey, taskId);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SPMAsyncTask.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SPMAsyncTask.java
index 5ee40fb..21f43e7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SPMAsyncTask.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SPMAsyncTask.java
@@ -211,7 +211,8 @@
 
         // A task that belongs to a partially submitted command needs to be
         // failed no matter what the status of the task is.
-        if (isPartiallyCompletedCommandTask()) {
+        if (isPartiallyCompletedCommandTask()
+                || 
AsyncTaskManager.getInstance().hasPartialTasks(getParameters().getDbAsyncTask().getRootCommandId()))
 {
             
getParameters().getDbAsyncTask().getTaskParameters().setTaskGroupSuccess(false);
             
ExecutionHandler.endTaskStep(privateParameters.getDbAsyncTask().getStepId(), 
JobExecutionStatus.FAILED);
             OnTaskEndFailure();


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic9281f2038f677eea39aa69a4f4b471917ed859c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yair Zaslavsky <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to