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

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


The following commit(s) were added to refs/heads/master by this push:
     new d7aa0a2  server: Prevent NullPointer on a network with removed IP 
ranges/"VLANs" (#3551)
d7aa0a2 is described below

commit d7aa0a2718381fcf57fc1f9df8296a4478d31d00
Author: Gabriel Beims Bräscher <gabr...@pcextreme.nl>
AuthorDate: Thu Aug 15 05:05:58 2019 -0300

    server: Prevent NullPointer on a network with removed IP ranges/"VLANs" 
(#3551)
    
    When a network IP range is removed, the "vlan" stays mapped on 
pod_vlan_map; therefore, the method that lists the VLANs by pod id will return 
null VLANS.
    
    This PR adds proper verifications to avoid null pointer exception when 
deploying VRs on a pod with removed VLANs. The exception was caused on 
getPlaceholderNicForRouter.
---
 .../schema/src/main/java/com/cloud/dc/dao/VlanDaoImpl.java | 11 ++++-------
 .../com/cloud/configuration/ConfigurationManagerImpl.java  | 14 ++++++++++++--
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/VlanDaoImpl.java 
b/engine/schema/src/main/java/com/cloud/dc/dao/VlanDaoImpl.java
index 2737beb..7b3ca13 100644
--- a/engine/schema/src/main/java/com/cloud/dc/dao/VlanDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/dc/dao/VlanDaoImpl.java
@@ -167,7 +167,10 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, 
Long> implements VlanDao
         List<PodVlanMapVO> vlanMaps = 
_podVlanMapDao.listPodVlanMapsByPod(podId);
         List<VlanVO> result = new ArrayList<VlanVO>();
         for (PodVlanMapVO pvmvo : vlanMaps) {
-            result.add(findById(pvmvo.getVlanDbId()));
+            VlanVO vlanByPodId = findById(pvmvo.getVlanDbId());
+            if (vlanByPodId != null) {
+                result.add(vlanByPodId);
+            }
         }
         return result;
     }
@@ -315,12 +318,6 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, 
Long> implements VlanDao
         }
 
         return null;
-//        String ipAddress = _ipAddressDao.assignIpAddress(accountId, 
domainId, vlan.getId(), false).getAddress();
-//        if (ipAddress == null) {
-//            return null;
-//        }
-//        return new Pair<String, VlanVO>(ipAddress, vlan);
-
     }
 
     @Override
diff --git 
a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java 
b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
index 288c5df..61f828b 100755
--- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -266,7 +266,7 @@ public class ConfigurationManagerImpl extends ManagerBase 
implements Configurati
     @Inject
     DomainVlanMapDao _domainVlanMapDao;
     @Inject
-    PodVlanMapDao _podVlanMapDao;
+    PodVlanMapDao podVlanMapDao;
     @Inject
     DataCenterDao _zoneDao;
     @Inject
@@ -3950,7 +3950,7 @@ public class ConfigurationManagerImpl extends ManagerBase 
implements Configurati
                 } else if (podId != null) {
                     // This VLAN is pod-wide, so create a PodVlanMapVO entry
                     final PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, 
vlan.getId());
-                    _podVlanMapDao.persist(podVlanMapVO);
+                    podVlanMapDao.persist(podVlanMapVO);
                 }
                 return vlan;
             }
@@ -4046,7 +4046,17 @@ public class ConfigurationManagerImpl extends 
ManagerBase implements Configurati
             @Override
             public void doInTransactionWithoutResult(final TransactionStatus 
status) {
                 _publicIpAddressDao.deletePublicIPRange(vlanDbId);
+                s_logger.debug(String.format("Delete Public IP Range (from 
user_ip_address, where vlan_db_d=%s)", vlanDbId));
+
                 _vlanDao.remove(vlanDbId);
+                s_logger.debug(String.format("Mark vlan as Remove vlan 
(vlan_db_id=%s)", vlanDbId));
+
+                SearchBuilder<PodVlanMapVO> sb = 
podVlanMapDao.createSearchBuilder();
+                sb.and("vlan_db_id", sb.entity().getVlanDbId(), 
SearchCriteria.Op.EQ);
+                SearchCriteria<PodVlanMapVO> sc = sb.create();
+                sc.setParameters("vlan_db_id", vlanDbId);
+                podVlanMapDao.remove(sc);
+                s_logger.debug(String.format("Delete vlan_db_id=%s in 
pod_vlan_map", vlanDbId));
             }
         });
 

Reply via email to