Sahina Bose has uploaded a new change for review.

Change subject: engine: Gluster task monitoring for tasks started from CLI
......................................................................

engine: Gluster task monitoring for tasks started from CLI

Added code to detect tasks started from CLI
and create a Job in engine so that these can be monitored
and managed from engine

Change-Id: Ibb6385cbcad988351f23bda2294c8e85dde54560
Signed-off-by: Sahina Bose <sab...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
1 file changed, 62 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/83/19183/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
index fd16179..0c6e088 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
@@ -5,23 +5,32 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.gluster.tasks.GlusterTasksService;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.job.JobRepository;
 import org.ovirt.engine.core.bll.job.JobRepositoryFactory;
+import org.ovirt.engine.core.common.action.AddExternalStepParameters;
+import org.ovirt.engine.core.common.action.AddInternalJobParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
+import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported;
 import org.ovirt.engine.core.common.job.JobExecutionStatus;
 import org.ovirt.engine.core.common.job.Step;
+import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.job.ExecutionMessageDirector;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
+import org.ovirt.engine.core.utils.transaction.TransactionMethod;
+import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
 public class GlusterTasksSyncJob extends GlusterJob  {
     private static final Log log = 
LogFactory.getLog(GlusterTasksSyncJob.class);
@@ -72,9 +81,21 @@
 
         for  (Entry<Guid, GlusterAsyncTask> entry :  runningTasks.entrySet()) {
             Guid taskId = entry.getKey();
-            GlusterAsyncTask task =  entry.getValue();
+            final GlusterAsyncTask task =  entry.getValue();
 
             List<Step> steps = getStepDao().getStepsByExternalId(taskId);
+            if (steps == null) {
+                // the task may have been started from the CLI
+                // need to add job to monitor
+                TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
+
+                    @Override
+                    public Void runInTransaction() {
+                        createJobToMonitor(task);
+                        return null;
+                    }
+                });
+            }
             //update status in step table
             for (Step step: steps) {
                 if (step.getEndTime() != null) {
@@ -90,12 +111,52 @@
                     getJobRepository().updateStep(step);
                 }
             }
+
         }
 
         return runningTasks;
     }
 
 
+    private void createJobToMonitor(GlusterAsyncTask task) {
+        if (task.getStatus() != JobExecutionStatus.STARTED) {
+            return; //there's no need to monitor jobs that are failed or 
completed
+        }
+        StepEnum step = task.getType().getStep();
+        VdcActionType actionType;
+        switch (step) {
+        case REBALANCING_VOLUME:
+            actionType = VdcActionType.StartRebalanceGlusterVolume;
+        default:
+            actionType = VdcActionType.Unknown;
+        }
+
+        VdcReturnValueBase result = 
Backend.getInstance().RunAction(VdcActionType.AddExternalJob,
+                new AddInternalJobParameters(actionType, true) );
+        if (!result.getSucceeded()) {
+            //log and return
+            throw new VdcBLLException(result.getFault().getError());
+        }
+        Guid jobId = (Guid)result.getActionReturnValue();
+
+        result = Backend.getInstance().RunAction(VdcActionType.AddExternalStep,
+                new AddExternalStepParameters(jobId, "", StepEnum.EXECUTING));
+        if (!result.getSucceeded()) {
+            //log and return
+            throw new VdcBLLException(result.getFault().getError());
+        }
+
+        Guid execStepId = (Guid)result.getActionReturnValue();
+
+        result = Backend.getInstance().RunAction(VdcActionType.AddExternalStep,
+                new AddExternalStepParameters(execStepId, "", step));
+
+        if (!result.getSucceeded()) {
+            //log and return
+            throw new VdcBLLException(result.getFault().getError());
+        }
+    }
+
     private void releaseVolumeLock(Guid taskId) {
         //get volume associated with task
         GlusterVolumeEntity vol= getVolumeDao().getVolumeByGlusterTask(taskId);


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

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

Reply via email to