Arik Hadas has uploaded a new change for review.

Change subject: core: add auto startup VMs to start in bulk
......................................................................

core: add auto startup VMs to start in bulk

VdsUpdateRunTimeInfo checks all the VMs which run on the VDS it
monitors, and at the end of the process it has all the HA VMs that ran
on that VDS and went down. So Instead of iterating over those VMs and
pass each of the separately to the AutoStartVmsRunner job, it now pass
them as a bulk (through the VdsEventListener) which is a bit more
efficient.

Change-Id: I560383c8e73bb1728441fe5786954eba7ba88e60
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AutoStartVmsRunner.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
4 files changed, 43 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/04/19504/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AutoStartVmsRunner.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AutoStartVmsRunner.java
index a481445..81c7ab3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AutoStartVmsRunner.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AutoStartVmsRunner.java
@@ -59,6 +59,23 @@
         autoStartVmsToRun.addAll(initialFailedVms);
     }
 
+    /**
+     * Add the given VM IDs to the set of VMs which will be started in the 
next iteration.
+     *
+     * @param vmIds
+     *              List of VM IDs to start in the next iteration of the job
+     */
+    public void addVmsToRun(List<Guid> vmIds) {
+        final DateTime now = DateTime.getNow();
+        List<Pair<Guid, DateTime>> vmsToAdd = new LinkedList<>();
+
+        for (Guid vmId: vmIds) {
+            vmsToAdd.add(new Pair<>(vmId, now));
+        }
+
+        autoStartVmsToRun.addAll(vmsToAdd);
+    }
+
     @OnTimerMethodAnnotation("startFailedAutoStartVms")
     public void startFailedAutoStartVms() {
         LinkedList<Pair<Guid, DateTime>> idsToRemove = new LinkedList<>();
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
index cf83525..86d6be6 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
@@ -277,15 +277,18 @@
     }
 
     @Override
-    public void runFailedAutoStartVM(Guid vmId) {
-        // Alert that the virtual machine failed:
-        final AuditLogableBase event = new AuditLogableBase();
-        event.setVmId(vmId);
-        AuditLogDirector.log(event, AuditLogType.HA_VM_FAILED);
-        log.infoFormat("Highly Available VM went down. Attempting to restart. 
VM Name: {0}, VM Id:{1}",
-                event.getVmName(), vmId);
+    public void runFailedAutoStartVMs(List<Guid> vmIds) {
+        for (Guid vmId: vmIds) {
+            // Alert that the virtual machine failed:
+            AuditLogableBase event = new AuditLogableBase();
+            event.setVmId(vmId);
+            AuditLogDirector.log(event, AuditLogType.HA_VM_FAILED);
 
-        AutoStartVmsRunner.getInstance().addVmToRun(vmId);
+            log.infoFormat("Highly Available VM went down. Attempting to 
restart. VM Name: {0}, VM Id:{1}",
+                    event.getVmName(), vmId);
+        }
+
+        AutoStartVmsRunner.getInstance().addVmsToRun(vmIds);
     }
 
     @Override
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
index cd1b424..ed781e9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
@@ -55,7 +55,7 @@
 
     void storagePoolStatusChanged(Guid storagePoolId, StoragePoolStatus 
status);
 
-    void runFailedAutoStartVM(Guid vmId);
+    void runFailedAutoStartVMs(List<Guid> vmIds);
 
     boolean restartVds(Guid vdsId);
 
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index 860ef2e..254ca39 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -21,6 +21,7 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
 import org.ovirt.engine.core.common.businessentities.Entities;
+import org.ovirt.engine.core.common.businessentities.IVdsEventListener;
 import org.ovirt.engine.core.common.businessentities.OriginType;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
@@ -167,7 +168,7 @@
         
getDbFacade().getDiskImageDynamicDao().updateAllInBatch(_vmDiskImageDynamicToSave.values());
         saveVmDevicesToDb();
         saveVmGuestAgentNetworkDevices();
-        
ResourceManager.getInstance().getEventListener().addExternallyManagedVms(_externalVmsToAdd);
+        getVdsEventListener().addExternallyManagedVms(_externalVmsToAdd);
     }
 
     private void saveVmGuestAgentNetworkDevices() {
@@ -376,6 +377,10 @@
                 _vds.getName());
     }
 
+    protected IVdsEventListener getVdsEventListener() {
+        return ResourceManager.getInstance().getEventListener();
+    }
+
     public void AfterRefreshTreatment() {
         try {
             if (processHardwareCapsNeeded) {
@@ -384,13 +389,13 @@
             }
 
             if (refreshedCapabilities) {
-                
ResourceManager.getInstance().getEventListener().handleVdsVersion(_vds.getId());
+                getVdsEventListener().handleVdsVersion(_vds.getId());
                 markIsSetNonOperationalExecuted();
             }
 
             if (_vds.getStatus() == VDSStatus.Maintenance) {
                 try {
-                    
ResourceManager.getInstance().getEventListener().vdsMovedToMaintenance(_vds);
+                    getVdsEventListener().vdsMovedToMaintenance(_vds);
                 } catch (RuntimeException ex) {
                     log.errorFormat("Host encounter a problem moving to 
maintenance mode, probably error during disconnecting it from pool {0}. The 
Host will stay in Maintenance",
                             ex.getMessage());
@@ -418,18 +423,15 @@
             for (Guid vm_guid : _succededToRunVms) {
                 _vdsManager.SuccededToRunVm(vm_guid);
             }
+
+            // Refrain from auto-start HA VM during its re-run attempts.
+            _autoVmsToRun.removeAll(_vmsToRerun);
             // run all vms that crushed that marked with auto startup
-            for (Guid vm_guid : _autoVmsToRun) {
-                // Refrain from auto-start HA VM during its re-run attempts.
-                if (!_vmsToRerun.contains(vm_guid)) {
-                    
ResourceManager.getInstance().getEventListener().runFailedAutoStartVM(vm_guid);
-                }
-            }
+            getVdsEventListener().runFailedAutoStartVMs(_autoVmsToRun);
 
             // process all vms that their ip changed.
             for (Entry<VM, VmDynamic> pair : _vmsClientIpChanged.entrySet()) {
-                ResourceManager.getInstance().getEventListener()
-                        .processOnClientIpChange(_vds, 
pair.getValue().getId());
+                getVdsEventListener().processOnClientIpChange(_vds, 
pair.getValue().getId());
             }
 
             // process all vms that powering up.
@@ -443,7 +445,7 @@
 
             // process all vms that went down
             for (Guid vm_guid : _vmsMovedToDown) {
-                
ResourceManager.getInstance().getEventListener().processOnVmStop(vm_guid);
+                getVdsEventListener().processOnVmStop(vm_guid);
             }
             for (Guid vm_guid : _vmsToRemoveFromAsync) {
                 ResourceManager.getInstance().RemoveAsyncRunningVm(vm_guid);


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

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

Reply via email to