This is an automated email from the ASF dual-hosted git repository.

nvazquez pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.18 by this push:
     new 5e71cea2c59 Fix Tungsten Fabric errors on adding a new zone due to 
duplicated entries on ntwk_service_map (#7455)
5e71cea2c59 is described below

commit 5e71cea2c59217c92e8f271b315c8fd78136e89d
Author: Nicolas Vazquez <[email protected]>
AuthorDate: Wed May 24 11:00:29 2023 -0300

    Fix Tungsten Fabric errors on adding a new zone due to duplicated entries 
on ntwk_service_map (#7455)
    
    * Fix Tungsten Fabric errors on adding a new zone due to duplicated entries 
on ntwk_service_map
    
    * Address review comments
---
 .../command/ConfigTungstenFabricServiceCmd.java    | 33 ++++++++++++++++++++--
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git 
a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java
 
b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java
index 1085804fd31..8544ec9bf97 100644
--- 
a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java
+++ 
b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java
@@ -107,7 +107,10 @@ public class ConfigTungstenFabricServiceCmd extends 
BaseCmd {
                     Network managementNetwork = 
networkModel.getSystemNetworkByZoneAndTrafficType(zoneId, 
Networks.TrafficType.Management);
                     NetworkServiceMapVO managementNetworkServiceMapVO = new 
NetworkServiceMapVO(managementNetwork.getId(),
                         Network.Service.Connectivity, 
Network.Provider.Tungsten);
-                    
networkServiceMapDao.persist(managementNetworkServiceMapVO);
+                    if 
(!networkServiceMapDao.canProviderSupportServiceInNetwork(managementNetwork.getId(),
+                            Network.Service.Connectivity, 
Network.Provider.Tungsten)) {
+                        
networkServiceMapDao.persist(managementNetworkServiceMapVO);
+                    }
 
                     List<NetworkOfferingVO> systemNetworkOffering = 
networkOfferingDao.listSystemNetworkOfferings();
                     for (NetworkOfferingVO networkOffering : 
systemNetworkOffering) {
@@ -132,6 +135,30 @@ public class ConfigTungstenFabricServiceCmd extends 
BaseCmd {
 
     private void persistDefaultSystemNetwork() {
         Transaction.execute(new TransactionCallbackNoReturn() {
+
+            private void persistNetworkServiceMapAvoidingDuplicates(Network 
network,
+                                                                    
NetworkServiceMapVO mapVO) {
+                if (mapVO == null) {
+                    s_logger.error("Expected a network-service-provider 
mapping entity to be persisted");
+                    return;
+                }
+                Network.Service service = 
Network.Service.getService(mapVO.getService());
+                Network.Provider provider = 
Network.Provider.getProvider(mapVO.getProvider());
+                if (service == null || provider == null) {
+                    s_logger.error(String.format("Could not obtain the service 
or the provider " +
+                            "from the network-service-provider map with ID = 
%s", mapVO.getId()));
+                    return;
+                }
+                if 
(networkServiceMapDao.canProviderSupportServiceInNetwork(network.getId(), 
service, provider)) {
+                    s_logger.debug(String.format("A mapping between the 
network, service and provider (%s, %s, %s) " +
+                                    "already exists, skipping duplicated 
entry",
+                            network.getId(), service.getName(), 
provider.getName()));
+                    return;
+
+                }
+                networkServiceMapDao.persist(mapVO);
+            }
+
             @Override
             public void doInTransactionWithoutResult(final TransactionStatus 
status) {
                 NetworkOfferingVO networkOfferingVO = 
networkOfferingDao.findByUniqueName(NETWORKOFFERING);
@@ -169,12 +196,12 @@ public class ConfigTungstenFabricServiceCmd extends 
BaseCmd {
                 Network publicNetwork = 
networkModel.getSystemNetworkByZoneAndTrafficType(zoneId, 
Networks.TrafficType.Public);
                 NetworkServiceMapVO publicNetworkServiceMapVO = new 
NetworkServiceMapVO(publicNetwork.getId(),
                         Network.Service.Connectivity, 
Network.Provider.Tungsten);
-                networkServiceMapDao.persist(publicNetworkServiceMapVO);
+                persistNetworkServiceMapAvoidingDuplicates(publicNetwork, 
publicNetworkServiceMapVO);
 
                 Network managementNetwork = 
networkModel.getSystemNetworkByZoneAndTrafficType(zoneId, 
Networks.TrafficType.Management);
                 NetworkServiceMapVO managementNetworkServiceMapVO = new 
NetworkServiceMapVO(managementNetwork.getId(),
                         Network.Service.Connectivity, 
Network.Provider.Tungsten);
-                networkServiceMapDao.persist(managementNetworkServiceMapVO);
+                persistNetworkServiceMapAvoidingDuplicates(managementNetwork, 
managementNetworkServiceMapVO);
 
                 List<NetworkOfferingVO> systemNetworkOffering = 
networkOfferingDao.listSystemNetworkOfferings();
                 for (NetworkOfferingVO networkOffering : 
systemNetworkOffering) {

Reply via email to