Moti Asayag has uploaded a new change for review.

Change subject: engine: Save VM Guest Agent network devices
......................................................................

engine: Save VM Guest Agent network devices

The patch saves the VM Guest Agent network devices to the
database. Saving the information to the database is executed based
on a change of the devices hash.

Change-Id: I9ffea1862feef78c25a71a3d1735d8fa630437f3
Signed-off-by: Moti Asayag <masa...@redhat.com>
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
1 file changed, 58 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/10232/1

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 0460c35..d135685 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
@@ -32,6 +32,7 @@
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 import org.ovirt.engine.core.common.businessentities.VmExitStatus;
+import org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface;
 import org.ovirt.engine.core.common.businessentities.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.VmNetworkStatistics;
 import org.ovirt.engine.core.common.businessentities.VmPauseStatus;
@@ -88,6 +89,8 @@
     private final List<VmDevice> newVmDevices = new ArrayList<VmDevice>();
     private final List<VmDeviceId> removedDeviceIds = new 
ArrayList<VmDeviceId>();
     private final Map<VM, VmDynamic> _vmsClientIpChanged = new HashMap<VM, 
VmDynamic>();
+    private final Map<Guid, List<VmGuestAgentInterface>> vmGuestAgentNics =
+            new HashMap<Guid, List<VmGuestAgentInterface>>();
     private final List<VmDynamic> _poweringUpVms = new ArrayList<VmDynamic>();
     private final List<Guid> _vmsToRerun = new ArrayList<Guid>();
     private final List<Guid> _autoVmsToRun = new ArrayList<Guid>();
@@ -146,6 +149,30 @@
         updateAllInTransaction(allVmInterfaceStatistics, 
getDbFacade().getVmNetworkStatisticsDao());
         updateAllInTransaction(_vmDiskImageDynamicToSave.values(), 
getDbFacade().getDiskImageDynamicDao());
         saveVmDevicesToDb();
+        saveVmGuestAgentNetworkDevices();
+    }
+
+    private void saveVmGuestAgentNetworkDevices() {
+        if (!vmGuestAgentNics.isEmpty()) {
+            TransactionSupport.executeInScope(TransactionScopeOption.Required,
+                    new TransactionMethod<Void>() {
+                        @Override
+                        public Void runInTransaction() {
+                            for (Guid vmId : vmGuestAgentNics.keySet()) {
+                                
getDbFacade().getVmGuestAgentInterfaceDao().removeAllForVm(vmId);
+                            }
+
+                            for (List<VmGuestAgentInterface> nics : 
vmGuestAgentNics.values()) {
+                                if (nics != null && !nics.isEmpty()) {
+                                    for (VmGuestAgentInterface nic : nics) {
+                                        
getDbFacade().getVmGuestAgentInterfaceDao().save(nic);
+                                    }
+                                }
+                            }
+                            return null;
+                        }
+                    });
+        }
     }
 
     private void saveVmDevicesToDb() {
@@ -828,6 +855,9 @@
             if 
(!VmDeviceCommonUtils.isOldClusterVersion(_vds.getvds_group_compatibility_version()))
 {
                 handleVmDeviceChange();
             }
+
+            prepareGuestAgentNetworkDevicesForUpdate();
+
         } else if (command.getVDSReturnValue().getExceptionObject() != null) {
             if (command.getVDSReturnValue().getExceptionObject() instanceof 
VDSErrorException) {
                 log.errorFormat("Failed vds listing,  vds = {0} : {1}, error = 
{2}", _vds.getId(),
@@ -846,6 +876,34 @@
     }
 
     /**
+     * Prepare the VM Guest Agent network devices for update. <br>
+     * The evaluation of the network devices for update is done by comparing 
the calculated hash of the network devices
+     * from VDSM to the latest hash kept on engine side.
+     */
+    private void prepareGuestAgentNetworkDevicesForUpdate() {
+        for (VmInternalData vmInternalData : _runningVms.values()) {
+            VmDynamic vmDynamic = vmInternalData.getVmDynamic();
+            if (vmDynamic != null) {
+                VM vm = _vmDict.get(vmDynamic.getId());
+                if (vm != null) {
+                    List<VmGuestAgentInterface> vmGuestAgentInterfaces = 
vmInternalData.getVmGuestAgentInterfaces();
+                    int guestAgentNicHash = vmGuestAgentInterfaces == null ? 0 
: vmGuestAgentInterfaces.hashCode();
+                    if (guestAgentNicHash != vmDynamic.getGuestAgentNicHash()) 
{
+                        vmGuestAgentNics.put(vmDynamic.getId(), 
vmGuestAgentInterfaces);
+
+                        // update new hash value
+                        if (_vmDynamicToSave.containsKey(vm.getId())) {
+                            
_vmDynamicToSave.get(vm.getId()).setGuestAgentNicHash(guestAgentNicHash);
+                        } else {
+                            AddVmDynamicToList(vmDynamic);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
      * Handle changes in all VM devices
      */
     private void handleVmDeviceChange() {


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

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

Reply via email to