From 8934c06aded44c0ffcce0cda1af6fa2ec8816626 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 23 Feb 2012 16:21:47 -0800 Subject: [PATCH] bug 13971: return only offerings with matching tags when zoneId is passed in and corresponding zone has more than 1 physical network status 13971: resolved fixed Reviewed-by: Prachi Damle --- .../ConfigurationManagerImpl.java | 28 ++++++++++++++++++- .../network/dao/PhysicalNetworkDaoImpl.java | 3 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 5b6526ff386..ddd7b7c64ea 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3508,6 +3508,22 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura List offerings = _networkOfferingDao.search(sc, searchFilter); Boolean sourceNatSupported = cmd.getSourceNatSupported(); + List pNtwkTags = new ArrayList(); + boolean checkForTags = false; + if (zone != null) { + List pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest); + if (pNtwks.size() > 1) { + checkForTags = true; + //go through tags + for (PhysicalNetworkVO pNtwk : pNtwks) { + List pNtwkTag = pNtwk.getTags(); + if (pNtwkTag == null || pNtwkTag.isEmpty()) { + throw new CloudRuntimeException("Tags are not defined for physical network in the zone id=" + zoneId); + } + pNtwkTags.addAll(pNtwkTag); + } + } + } // filter by supported services boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); @@ -3535,7 +3551,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura for (NetworkOfferingVO offering : offerings) { boolean addOffering = true; List checkForProviders = new ArrayList(); - + + if (checkForTags) { + if (!pNtwkTags.contains(offering.getTags())) { + continue; + } + } + if (listBySupportedServices) { addOffering = addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices); } @@ -3553,10 +3575,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (sourceNatSupported != null) { addOffering = addOffering && (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported); } + + if (addOffering) { supportedOfferings.add(offering); } + + } return supportedOfferings; diff --git a/server/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java b/server/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java index 6334871d801..17b5feb5680 100644 --- a/server/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java +++ b/server/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java @@ -26,9 +26,11 @@ import com.cloud.network.PhysicalNetworkVO; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; @Local(value=PhysicalNetworkDao.class) @DB(txn=false) @@ -42,7 +44,6 @@ public class PhysicalNetworkDaoImpl extends GenericDaoBase