Ravi Nori has uploaded a new change for review.

Change subject: engine : Fail tasks that dont have Vdsm Id
......................................................................

engine : Fail tasks that dont have Vdsm Id

This patch introduces the next step in async
task modularization.

We fail a task which does not have vdsm task id

Change-Id: I110c483842027d1596f64dd8c3f635d62924a93f
Signed-off-by: Ravi Nori <rn...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskManager.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/TaskHelper.java
3 files changed, 59 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/14368/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskManager.java
index 8f76a21..d88641e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskManager.java
@@ -25,9 +25,11 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
+import org.ovirt.engine.core.common.job.JobExecutionStatus;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.DateTime;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.NGuid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
@@ -35,6 +37,7 @@
 import org.ovirt.engine.core.utils.linq.Predicate;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
+import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
 import org.ovirt.engine.core.utils.timer.SchedulerUtil;
 import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl;
@@ -45,18 +48,24 @@
  * AsyncTaskManager: Singleton, manages all tasks in the system.
  */
 public final class AsyncTaskManager {
+
     private static final Log log = LogFactory.getLog(AsyncTaskManager.class);
-
-    /** Map which consist all tasks that currently are monitored **/
+    /**
+     * Map which consist all tasks that currently are monitored *
+     */
     private ConcurrentMap<Guid, SPMTask> _tasks;
-
-    /** Indication if _tasks has changed for logging process. **/
+    /**
+     * Indication if _tasks has changed for logging process. *
+     */
     private boolean logChangedMap = true;
-
-    /** The period of time (in minutes) to hold the asynchronous tasks' 
statuses in the asynchronous tasks cache **/
+    /**
+     * The period of time (in minutes) to hold the asynchronous tasks' statuses
+     * in the asynchronous tasks cache *
+     */
     private final int _cacheTimeInMinutes;
-
-    /**Map of tasks in DB per storage pool that exist after restart **/
+    /**
+     * Map of tasks in DB per storage pool that exist after restart *
+     */
     private ConcurrentMap<Guid, List<AsyncTasks>> tasksInDbAfterRestart = null;
     private static AsyncTaskManager taskManager;
     private static final Object LOCK = new Object();
@@ -64,7 +73,7 @@
 
     public static AsyncTaskManager getInstance(CommandCoordinator coco) {
         if (taskManager == null) {
-            synchronized(LOCK) {
+            synchronized (LOCK) {
                 if (taskManager == null) {
                     taskManager = new AsyncTaskManager(coco);
                 }
@@ -87,7 +96,11 @@
                 Config.<Integer> 
GetValue(ConfigValues.AsyncTaskStatusCacheRefreshRateInSeconds), 
TimeUnit.SECONDS);
         _cacheTimeInMinutes = Config.<Integer> 
GetValue(ConfigValues.AsyncTaskStatusCachingTimeInMinutes);
         tasksInDbAfterRestart = new ConcurrentHashMap<Guid, 
List<AsyncTasks>>();
-        for (AsyncTasks task: 
DbFacade.getInstance().getAsyncTaskDao().getAll()) {
+        for (AsyncTasks task : 
DbFacade.getInstance().getAsyncTaskDao().getAll()) {
+            if (task.getVdsmTaskId().equals(NGuid.Empty)) {
+                failTaskWithoutVdsmId(task);
+                continue;
+            }
             tasksInDbAfterRestart.putIfAbsent(task.getStoragePoolId(), new 
ArrayList<AsyncTasks>());
             List<AsyncTasks> tasksPerStoragePool = 
tasksInDbAfterRestart.get(task.getStoragePoolId());
             tasksInDbAfterRestart.put(task.getStoragePoolId(), 
tasksPerStoragePool);
@@ -146,7 +159,7 @@
         // for SubtractMinutesAsMills of minutes.
         return (task.getState() == AsyncTaskState.Cleared || task.getState() 
== AsyncTaskState.ClearFailed)
                 && task.getLastAccessToStatusSinceEnd() < (System
-                        .currentTimeMillis() - SubtractMinutesAsMills);
+                .currentTimeMillis() - SubtractMinutesAsMills);
     }
 
     public synchronized boolean hasTasksByStoragePoolId(Guid storagePoolID) {
@@ -176,6 +189,19 @@
         return retVal;
     }
 
+    private void failTaskWithoutVdsmId(final AsyncTasks task) {
+        task.getTaskParameters().setTaskGroupSuccess(false);
+        coco.endTaskStep(task.getStepId(), JobExecutionStatus.FAILED);
+        ThreadPoolUtil.execute(new Runnable() {
+            @SuppressWarnings("synthetic-access")
+            @Override
+            public void run() {
+                coco.endAction(task.getStepId(), task.getaction_type(), task);
+            }
+        });
+
+    }
+
     private boolean isCurrentTaskLookedFor(Guid id, SPMTask task) {
         return (task.isEntityAsyncTask()) && 
id.equals(task.getParameters().getEntityId())
                 && (task.getState() != AsyncTaskState.Cleared)
@@ -200,7 +226,7 @@
 
                     log.infoFormat("Cleaning zombie tasks: Stopping async task 
{0} that started at {1}",
                             
task.getParameters().getDbAsyncTask().getaction_type(), task
-                                    
.getParameters().getDbAsyncTask().getStartTime());
+                            .getParameters().getDbAsyncTask().getStartTime());
 
                     task.stopTask(true);
                 } else {
@@ -208,7 +234,7 @@
 
                     log.infoFormat("Cleaning zombie tasks: Clearing async task 
{0} that started at {1}",
                             
task.getParameters().getDbAsyncTask().getaction_type(), task
-                                    
.getParameters().getDbAsyncTask().getStartTime());
+                            .getParameters().getDbAsyncTask().getStartTime());
 
                     task.clearAsyncTask(true);
                 }
@@ -243,7 +269,7 @@
     private void pollAndUpdateAsyncTasks() {
         if (logChangedMap) {
             log.infoFormat("Polling and updating Async Tasks: {0} tasks, {1} 
tasks to poll now",
-                           _tasks.size(), numberOfTasksToPoll());
+                    _tasks.size(), numberOfTasksToPoll());
         }
 
         // Fetch Set of pool id's
@@ -383,7 +409,7 @@
                         
(task.getParameters().getDbAsyncTask().getaction_type()),
                         task.getParameters().getClass().getName(),
                         (task.getShouldPoll() ? "polling started."
-                                : "polling hasn't started yet."));
+                        : "polling hasn't started yet."));
 
                 // Set the indication to true for logging _tasks status on next
                 // quartz execution.
@@ -487,8 +513,8 @@
         } catch (RuntimeException e) {
             log.error(
                     String.format(
-                            "Getting existing tasks on Storage Pool %1$s 
failed.",
-                            sp.getname()),
+                    "Getting existing tasks on Storage Pool %1$s failed.",
+                    sp.getname()),
                     e);
         }
 
@@ -505,8 +531,8 @@
                             newlyAddedTasks.add(task);
                         } catch (Exception e) {
                             log.errorFormat("Failed to load task of type {0} 
with id {1}, due to: {2}.",
-                                       creationInfo.getTaskType(), 
creationInfo.getVdsmTaskId(),
-                                       ExceptionUtils.getRootCauseMessage(e));
+                                    creationInfo.getTaskType(), 
creationInfo.getVdsmTaskId(),
+                                    ExceptionUtils.getRootCauseMessage(e));
                         }
                     }
                 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
index e57e3aa..b4be650 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandCoordinatorImpl.java
@@ -469,6 +469,18 @@
                 new 
IrsBaseVDSCommandParameters(storagePoolID)).getReturnValue();
     }
 
+    @Override
+    public void removeTaskFromDB(Guid taskId) {
+        try {
+            if (DbFacade.getInstance().getAsyncTaskDao().remove(taskId) != 0) {
+                log.infoFormat("BaseAsyncTask::RemoveTaskFromDB: Removed task 
{0} from DataBase", taskId);
+            }
+        } catch (RuntimeException e) {
+            log.error(String.format(
+                    "BaseAsyncTask::RemoveTaskFromDB: Removing task %1$s from 
DataBase threw an exception.",
+                    taskId), e);
+        }
+    }
     private BackendInternal getBackend() {
         return Backend.getInstance();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/TaskHelper.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/TaskHelper.java
index fa8c23a..fd41a85 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/TaskHelper.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/interfaces/TaskHelper.java
@@ -48,4 +48,6 @@
     public SPMTask construct(AsyncTaskType taskType, AsyncTaskParameters 
asyncTaskParams, boolean duringInit);
 
     public void handleEndActionResult(EntityMultiAsyncTasks entityInfo, 
VdcReturnValueBase vdcReturnValue, AsyncTasks dbAsyncTask);
+
+    public void removeTaskFromDB(Guid taskId);
 }


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

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

Reply via email to