Alona Kaplan has uploaded a new change for review.

Change subject: engine: Reuse VmInfoBuilder to add profile data to nic in VDS 
commands
......................................................................

engine: Reuse VmInfoBuilder to add profile data to nic in VDS commands

HotPlugNicVDSCommand, UpdateVmInterfaceVDSCommand and VmInfoBuider
has the same logic for adding the profile data to the nic on the struct
sent to vdsm.

This patch adds a static method to VmInfoBuilder- addProfileDataToNic(..).
Using this method also fixes some bugs-
- Makes VmInfoBuilder work with VmNic instead of VmNetworkInterface.
- VmInfoBuilder didn't use the vnic_profile to get the network name and
port mirroring.
- UpdateVmInterfaceVDSCommand didn't add the
vm.getRuntimeDeviceCustomProperties().get(vmDevice) to the custom
properties that were sent to the host.

Change-Id: I234bb2854a5d2d8bdb97dd7d76d34167016c87e7
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HotPlugNicVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
3 files changed, 41 insertions(+), 58 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/17930/1

diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HotPlugNicVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HotPlugNicVDSCommand.java
index 38849bc..7cf97de 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HotPlugNicVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HotPlugNicVDSCommand.java
@@ -1,15 +1,12 @@
 package org.ovirt.engine.core.vdsbroker.vdsbroker;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.ovirt.engine.core.common.FeatureSupported;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
-import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
-import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.common.vdscommands.VmNicDeviceVDSParameters;
 import org.ovirt.engine.core.compat.Version;
@@ -39,20 +36,14 @@
         Map<String, Object> map = new HashMap<String, Object>();
         VmNic nic = getParameters().getNic();
         VmDevice vmDevice = getParameters().getVmDevice();
-        VnicProfile vnicProfile = null;
-        Network network = null;
-        if (nic.getVnicProfileId() != null) {
-            vnicProfile = 
getDbFacade().getVnicProfileDao().get(nic.getVnicProfileId());
-            if (vnicProfile != null) {
-                network = 
getDbFacade().getNetworkDao().get(vnicProfile.getNetworkId());
-            }
-        }
+        Version clusterVersion = 
getParameters().getVm().getVdsGroupCompatibilityVersion();
+
+        VmInfoBuilder.addProfileDataToNic(map, getParameters().getVm(), 
vmDevice, nic, clusterVersion);
+
         map.put(VdsProperties.Type, vmDevice.getType().getValue());
         map.put(VdsProperties.Device, VmDeviceType.BRIDGE.getName());
         map.put(VdsProperties.MAC_ADDR, nic.getMacAddress());
-        map.put(VdsProperties.NETWORK, network == null ? "" : 
network.getName());
 
-        Version clusterVersion = 
getParameters().getVm().getVdsGroupCompatibilityVersion();
         if (FeatureSupported.networkLinking(clusterVersion)) {
             map.put(VdsProperties.LINK_ACTIVE, String.valueOf(nic.isLinked()));
         }
@@ -65,17 +56,6 @@
             map.put(VdsProperties.BootOrder, 
String.valueOf(vmDevice.getBootOrder()));
         }
 
-        if (vnicProfile != null && vnicProfile.isPortMirroring()) {
-            map.put(VdsProperties.PORT_MIRRORING, network == null
-                    ? Collections.<String> emptyList() : 
Collections.singletonList(network.getName()));
-        }
-
-        Map<String, String> customProperties = vnicProfile == null ? null : 
vnicProfile.getCustomProperties();
-        VmInfoBuilder.addCustomPropertiesForDevice(map,
-                getParameters().getVm(),
-                vmDevice,
-                clusterVersion,
-                customProperties);
         VmInfoBuilder.addNetworkFiltersToNic(map, clusterVersion);
         return map;
     }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
index fd2e90d..d9759cf 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
@@ -1,14 +1,12 @@
 package org.ovirt.engine.core.vdsbroker.vdsbroker;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.ovirt.engine.core.common.FeatureSupported;
-import org.ovirt.engine.core.common.businessentities.network.Network;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
-import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
 import org.ovirt.engine.core.common.vdscommands.VmNicDeviceVDSParameters;
+import org.ovirt.engine.core.compat.Version;
 
 public class UpdateVmInterfaceVDSCommand extends 
VdsBrokerCommand<VmNicDeviceVDSParameters> {
 
@@ -28,23 +26,11 @@
         deviceStruct.put(VdsProperties.Alias, 
getParameters().getVmDevice().getAlias());
 
         VmNic nic = getParameters().getNic();
-        VnicProfile vnicProfile = null;
-        Network network = null;
-        if (nic.getVnicProfileId() != null) {
-            vnicProfile = 
getDbFacade().getVnicProfileDao().get(nic.getVnicProfileId());
-            if (vnicProfile != null) {
-                network = 
getDbFacade().getNetworkDao().get(vnicProfile.getNetworkId());
-            }
-        }
-        deviceStruct.put(VdsProperties.NETWORK, network == null ? "" : 
network.getName());
         deviceStruct.put(VdsProperties.LINK_ACTIVE, 
String.valueOf(nic.isLinked()));
-        deviceStruct.put(VdsProperties.PORT_MIRRORING, vnicProfile != null && 
vnicProfile.isPortMirroring()
-                && network != null ? 
Collections.singletonList(network.getName()) : Collections.<String> 
emptyList());
+        VmDevice vmDevice = getParameters().getVmDevice();
+        Version clusterVersion = 
getParameters().getVm().getVdsGroupCompatibilityVersion();
 
-        if (vnicProfile != null
-                && 
FeatureSupported.deviceCustomProperties(getParameters().getVm().getVdsGroupCompatibilityVersion()))
 {
-            deviceStruct.put(VdsProperties.Custom, 
vnicProfile.getCustomProperties());
-        }
+        VmInfoBuilder.addProfileDataToNic(deviceStruct, 
getParameters().getVm(), vmDevice, nic, clusterVersion);
 
         return deviceStruct;
     }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
index 9ac1c61..ae7202c 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
@@ -24,8 +24,9 @@
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
 import org.ovirt.engine.core.common.businessentities.VolumeFormat;
+import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
-import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
+import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
@@ -319,7 +320,7 @@
                                 VmDeviceGeneralType.INTERFACE,
                                 VmDeviceType.BRIDGE.getName()));
 
-        for (VmNetworkInterface vmInterface : vm.getInterfaces()) {
+        for (VmNic vmInterface : vm.getInterfaces()) {
             // get vm device for this disk from DB
             VmDevice vmDevice =
                     devicesByDeviceId.get(new VmDeviceId(vmInterface.getId(), 
vmInterface.getVmId()));
@@ -512,13 +513,12 @@
     }
 
     private void addNetworkInterfaceProperties(Map<String, Object> struct,
-            VmNetworkInterface vmInterface,
+            VmNic vmInterface,
             VmDevice vmDevice,
             String nicModel,
             Version clusterVersion) {
         struct.put(VdsProperties.Type, vmDevice.getType().getValue());
         struct.put(VdsProperties.Device, vmDevice.getDevice());
-        struct.put(VdsProperties.NETWORK, 
StringUtils.defaultString(vmInterface.getNetworkName()));
 
         if (FeatureSupported.networkLinking(clusterVersion)) {
             struct.put(VdsProperties.LINK_ACTIVE, 
String.valueOf(vmInterface.isLinked()));
@@ -530,28 +530,45 @@
         struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
         struct.put(VdsProperties.DeviceId, 
String.valueOf(vmDevice.getId().getDeviceId()));
         struct.put(VdsProperties.NIC_TYPE, nicModel);
-        if (vmInterface.isPortMirroring()) {
-            List<String> networks = new ArrayList<String>();
-            if (vmInterface.getNetworkName() != null) {
-                networks.add(vmInterface.getNetworkName());
+
+        addProfileDataToNic(struct, vm, vmDevice, vmInterface, clusterVersion);
+        addNetworkFiltersToNic(struct, clusterVersion);
+    }
+
+    public static void addProfileDataToNic(Map<String, Object> struct,
+            VM vm,
+            VmDevice vmDevice,
+            VmNic nic,
+            Version clusterVersion) {
+        VnicProfile vnicProfile = null;
+        Network network = null;
+        if (nic.getVnicProfileId() != null) {
+            vnicProfile = 
DbFacade.getInstance().getVnicProfileDao().get(nic.getVnicProfileId());
+            if (vnicProfile != null) {
+                network = 
DbFacade.getInstance().getNetworkDao().get(vnicProfile.getNetworkId());
             }
-            struct.put(VdsProperties.PORT_MIRRORING, networks);
+        }
+
+        struct.put(VdsProperties.NETWORK, network == null ? "" : 
network.getName());
+
+        if (vnicProfile != null && vnicProfile.isPortMirroring()) {
+            struct.put(VdsProperties.PORT_MIRRORING, network == null
+                    ? Collections.<String> emptyList() : 
Collections.singletonList(network.getName()));
         }
 
         addCustomPropertiesForDevice(struct,
                 vm,
                 vmDevice,
                 clusterVersion,
-                getVnicCustomProperties(vmInterface.getVnicProfileId()));
-        addNetworkFiltersToNic(struct, clusterVersion);
+                getVnicCustomProperties(vnicProfile));
+
     }
 
-    private Map<String, String> getVnicCustomProperties(Guid vnicProfileId) {
+    public static Map<String, String> getVnicCustomProperties(VnicProfile 
vnicProfile) {
         Map<String, String> customProperties = null;
 
-        if (vnicProfileId != null) {
-            VnicProfile profile = 
DbFacade.getInstance().getVnicProfileDao().get(vnicProfileId);
-            customProperties = profile == null ? null : 
profile.getCustomProperties();
+        if (vnicProfile != null) {
+            customProperties = vnicProfile.getCustomProperties();
         }
 
         return customProperties == null ? new HashMap<String, String>() : 
customProperties;


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

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

Reply via email to