Moti Asayag has uploaded a new change for review.

Change subject: engine Use VmNic within ChangeVMClusterCommand
......................................................................

engine Use VmNic within ChangeVMClusterCommand

The patch uses the VmNic backend internal entity for vnic
related actions, specifically for fetching the entity
from the database.

Change-Id: I864201b27d1572bf73a40d692ef3bb503a0f36ca
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
1 file changed, 19 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/71/17271/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
index c88eef4..7af9542 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVMClusterCommand.java
@@ -3,6 +3,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.ObjectUtils;
+import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.validator.VmNicValidator;
 import org.ovirt.engine.core.common.AuditLogType;
@@ -12,7 +14,7 @@
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.network.Network;
-import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
+import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -53,8 +55,7 @@
                     return false;
                 }
 
-                List<VmNetworkInterface> interfaces = 
DbFacade.getInstance().getVmNetworkInterfaceDao()
-                .getAllForVm(getParameters().getVmId());
+                List<VmNic> interfaces = 
getVmNicDao().getAllForVm(getParameters().getVmId());
 
                 Version clusterCompatibilityVersion = 
targetCluster.getcompatibility_version();
                 if (!validateDestinationClusterContainsNetworks(interfaces)
@@ -95,9 +96,9 @@
      * @return Whether the NICs are linked correctly and network name is valid 
(with regards to the destination
      *         cluster).
      */
-    private boolean validateNics(List<VmNetworkInterface> interfaces,
+    private boolean validateNics(List<VmNic> interfaces,
             Version clusterCompatibilityVersion) {
-        for (VmNetworkInterface iface : interfaces) {
+        for (VmNic iface : interfaces) {
             VmNicValidator nicValidator = new VmNicValidator(iface, 
clusterCompatibilityVersion);
             if (!validate(nicValidator.emptyNetworkValid()) || 
!validate(nicValidator.linkedCorrectly())) {
                 return false;
@@ -115,16 +116,16 @@
      *            The NICs to check networks on.
      * @return Whether the destination cluster has all networks configured or 
not.
      */
-    private boolean 
validateDestinationClusterContainsNetworks(List<VmNetworkInterface> interfaces) 
{
+    private boolean validateDestinationClusterContainsNetworks(List<VmNic> 
interfaces) {
         List<Network> networks =
                 
DbFacade.getInstance().getNetworkDao().getAllForCluster(getParameters().getClusterId());
         StringBuilder missingNets = new StringBuilder();
-        for (VmNetworkInterface iface : interfaces) {
-            String netName = iface.getNetworkName();
-            if (netName != null) {
+        for (VmNic iface : interfaces) {
+            Network network = 
NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
+            if (network != null) {
                 boolean exists = false;
                 for (Network net : networks) {
-                    if (net.getName().equals(netName)) {
+                    if (net.getName().equals(network.getName())) {
                         exists = true;
                         break;
                     }
@@ -133,7 +134,7 @@
                     if (missingNets.length() > 0) {
                         missingNets.append(", ");
                     }
-                    missingNets.append(netName);
+                    missingNets.append(network.getName());
                 }
             }
         }
@@ -156,19 +157,19 @@
         }
 
         // update vm interfaces
-        List<Network> networks = DbFacade.getInstance().getNetworkDao()
-                .getAllForCluster(getParameters().getClusterId());
-        List<VmNetworkInterface> interfaces = 
DbFacade.getInstance().getVmNetworkInterfaceDao()
-                .getAllForVm(getParameters().getVmId());
+        List<Network> networks = 
getNetworkDAO().getAllForCluster(getParameters().getClusterId());
+        List<VmNic> interfaces = 
getVmNicDao().getAllForVm(getParameters().getVmId());
 
-        for (final VmNetworkInterface iface : interfaces) {
-            if (iface.getNetworkName() != null) {
+        for (final VmNic iface : interfaces) {
+            if (iface.getVnicProfileId() != null) {
                 Network net = LinqUtils.firstOrNull(networks, new 
Predicate<Network>() {
                     @Override
                     public boolean eval(Network n) {
-                        return iface.getNetworkName().equals(n.getName());
+                        Network network = 
NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
+                        return ObjectUtils.equals(n.getId(), network.getId());
                     }
                 });
+
                 // if network not exists in cluster we remove the network to
                 // interface connection
                 if (net == null) {


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

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

Reply via email to