Martin Peřina has uploaded a new change for review.

Change subject: core: Introduce RestartVdsVmsOperation
......................................................................

core: Introduce RestartVdsVmsOperation

Moves restart of VMs running in Vds that is fenced into new class
RestartVdsVmsOperation. The same operation will be used when kdump is
detected for host (following patch).

Change-Id: I7ec38f74c1c7e99f080f2b1a4a1d72938aa4aade
Bug-Url: https://bugzilla.redhat.com/1079821
Signed-off-by: Martin Perina <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsVmsOperation.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StartVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVdsCommand.java
4 files changed, 143 insertions(+), 62 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/28735/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
index d0bd4bc..d195770 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
@@ -11,18 +11,14 @@
 import java.util.concurrent.Future;
 
 import org.apache.commons.lang.StringUtils;
-import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.FenceVdsActionParameters;
-import org.ovirt.engine.core.common.action.IdParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
 import org.ovirt.engine.core.common.businessentities.FenceAgentOrder;
 import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VMStatus;
-import org.ovirt.engine.core.common.businessentities.VmExitStatus;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
@@ -30,9 +26,7 @@
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
-import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
-import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
@@ -444,60 +438,6 @@
      */
     protected FenceExecutor createExecutorForProxyCheck() {
         return new FenceExecutor(getVds(), FenceActionType.Status);
-    }
-
-    protected void destroyVmOnDestination(VM vm) {
-        if (vm.getStatus() == VMStatus.MigratingFrom) {
-            try {
-                if (vm.getMigratingToVds() != null) {
-                    Backend.getInstance()
-                            .getResourceManager()
-                            .RunVdsCommand(
-                                    VDSCommandType.DestroyVm,
-                                    new DestroyVmVDSCommandParameters(new 
Guid(vm.getMigratingToVds().toString()), vm
-                                            .getId(), true, false, 0));
-                    log.infoFormat("Stopped migrating vm: {0} on vds: {1}", 
vm.getName(), vm.getMigratingToVds());
-                }
-            } catch (RuntimeException ex) {
-                log.infoFormat("Could not stop migrating vm: {0} on vds: {1}, 
Error: {2}", vm.getName(),
-                        vm.getMigratingToVds(), ex.getMessage());
-                // intentionally ignored
-            }
-        }
-    }
-
-    protected void restartVdsVms() {
-        List<Guid> autoStartVmIdsToRerun = new ArrayList<>();
-        // restart all running vms of a failed vds.
-        for (VM vm : mVmList) {
-            destroyVmOnDestination(vm);
-            VDSReturnValue returnValue = Backend
-                    .getInstance()
-                    .getResourceManager()
-                    .RunVdsCommand(VDSCommandType.SetVmStatus,
-                            new SetVmStatusVDSCommandParameters(vm.getId(), 
VMStatus.Down, VmExitStatus.Error));
-            // Write that this VM was shut down by host reboot or manual fence
-            if (returnValue != null && returnValue.getSucceeded()) {
-                LogSettingVmToDown(getVds().getId(), vm.getId());
-            }
-            setVmId(vm.getId());
-            setVmName(vm.getName());
-            setVm(vm);
-            
Backend.getInstance().runInternalAction(VdcActionType.ProcessDownVm,
-                    new IdParameters(vm.getId()),
-                    
ExecutionHandler.createDefaultContexForTasks(getExecutionContext()));
-
-            // Handle highly available VMs
-            if (vm.isAutoStartup()) {
-                autoStartVmIdsToRerun.add(vm.getId());
-            }
-        }
-        if (!autoStartVmIdsToRerun.isEmpty()) {
-            
AutoStartVmsRunner.getInstance().addVmsToRun(autoStartVmIdsToRerun);
-        }
-        setVm(null);
-        setVmId(Guid.Empty);
-        setVmName(null);
     }
 
     protected void setStatus() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsVmsOperation.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsVmsOperation.java
new file mode 100644
index 0000000..d8e46aa
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestartVdsVmsOperation.java
@@ -0,0 +1,133 @@
+package org.ovirt.engine.core.bll;
+
+import org.ovirt.engine.core.bll.job.ExecutionContext;
+import org.ovirt.engine.core.bll.job.ExecutionHandler;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.IdParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VmExitStatus;
+import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
+import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
+import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
+import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
+import org.ovirt.engine.core.utils.log.Log;
+import org.ovirt.engine.core.utils.log.LogFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Restart VMs running on Vds, that was stopped using PM or kdump was detected
+ * on it
+ */
+public class RestartVdsVmsOperation {
+    private static final Log log = 
LogFactory.getLog(RestartVdsVmsOperation.class);
+
+    /**
+     * Execution context of command, that instantiates this class
+     */
+    private ExecutionContext executionContext;
+
+    /**
+     * VDS, that VMs was executed on
+     */
+    private VDS vds;
+
+    /**
+     * Creates instance with specified params
+     */
+    public RestartVdsVmsOperation(
+            ExecutionContext executionContext,
+            VDS vds
+    ) {
+        this.executionContext = executionContext;
+        this.vds = vds;
+    }
+
+    /**
+     * Destroys VM migration to another host
+     * @param vm vm migrated to another host
+     */
+    protected void destroyVmOnDestination(VM vm) {
+        if (vm.getStatus() == VMStatus.MigratingFrom) {
+            try {
+                if (vm.getMigratingToVds() != null) {
+                    Backend.getInstance().getResourceManager().RunVdsCommand(
+                            VDSCommandType.DestroyVm,
+                            new DestroyVmVDSCommandParameters(
+                                    new 
Guid(vm.getMigratingToVds().toString()),
+                                    vm.getId(),
+                                    true,
+                                    false,
+                                    0
+                            )
+                    );
+                    log.infoFormat(
+                            "Stopped migrating vm: {0} on vds: {1}",
+                            vm.getName(),
+                            vm.getMigratingToVds()
+                    );
+                }
+            } catch (RuntimeException ex) {
+                log.infoFormat(
+                        "Could not stop migrating vm: {0} on vds: {1}, Error: 
{2}",
+                        vm.getName(),
+                        vm.getMigratingToVds(),
+                        ex.getMessage()
+                );
+                // intentionally ignored
+            }
+        }
+    }
+
+
+    /**
+     * Changes status of specified VMs to Down and starts HA VMs on another 
hosts
+     *
+     * @param vms list of VM to stopped/restarted
+     */
+    public void restartVms(List<VM> vms) {
+        List<Guid> autoStartVmIdsToRerun = new ArrayList<>();
+        // restart all running vms of a failed vds.
+        for (VM vm : vms) {
+            destroyVmOnDestination(vm);
+            VDSReturnValue returnValue = 
Backend.getInstance().getResourceManager().RunVdsCommand(
+                    VDSCommandType.SetVmStatus,
+                    new SetVmStatusVDSCommandParameters(
+                            vm.getId(),
+                            VMStatus.Down,
+                            VmExitStatus.Error
+                    )
+            );
+            // Write that this VM was shut down by host reboot or manual fence
+            if (returnValue != null && returnValue.getSucceeded()) {
+                AuditLogDirector.log(
+                        new AuditLogableBase(
+                                vds.getId(),
+                                vm.getId()
+                        ),
+                        
AuditLogType.VM_WAS_SET_DOWN_DUE_TO_HOST_REBOOT_OR_MANUAL_FENCE
+                );
+            }
+            Backend.getInstance().runInternalAction(
+                    VdcActionType.ProcessDownVm,
+                    new IdParameters(vm.getId()),
+                    
ExecutionHandler.createDefaultContexForTasks(executionContext)
+            );
+
+            // Handle highly available VMs
+            if (vm.isAutoStartup()) {
+                autoStartVmIdsToRerun.add(vm.getId());
+            }
+        }
+        if (!autoStartVmIdsToRerun.isEmpty()) {
+            
AutoStartVmsRunner.getInstance().addVmsToRun(autoStartVmIdsToRerun);
+        }
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StartVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StartVdsCommand.java
index 40d48e3..d7b2520 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StartVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StartVdsCommand.java
@@ -79,7 +79,11 @@
 
     @Override
     protected void handleSpecificCommandActions() {
-        restartVdsVms();
+        RestartVdsVmsOperation restartVmsOper = new RestartVdsVmsOperation(
+                getExecutionContext(),
+                getVds()
+        );
+        restartVmsOper.restartVms(mVmList);
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVdsCommand.java
index 95ecbce..cc92404 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVdsCommand.java
@@ -81,7 +81,11 @@
     @Override
     protected void handleSpecificCommandActions() {
         if (mVmList.size() > 0) {
-            restartVdsVms();
+            RestartVdsVmsOperation restartVmsOper = new RestartVdsVmsOperation(
+                    getExecutionContext(),
+                    getVds()
+            );
+            restartVmsOper.restartVms(mVmList);
             Backend.getInstance()
                     .getResourceManager()
                     .RunVdsCommand(VDSCommandType.UpdateVdsVMsCleared,


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

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

Reply via email to