Skip to content

Commit d7aa0a2

Browse files
Gabriel Beims Bräscheryadvr
authored andcommitted
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.
1 parent b576972 commit d7aa0a2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

engine/schema/src/main/java/com/cloud/dc/dao/VlanDaoImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ public List<VlanVO> listVlansForPod(long podId) {
167167
List<PodVlanMapVO> vlanMaps = _podVlanMapDao.listPodVlanMapsByPod(podId);
168168
List<VlanVO> result = new ArrayList<VlanVO>();
169169
for (PodVlanMapVO pvmvo : vlanMaps) {
170-
result.add(findById(pvmvo.getVlanDbId()));
170+
VlanVO vlanByPodId = findById(pvmvo.getVlanDbId());
171+
if (vlanByPodId != null) {
172+
result.add(vlanByPodId);
173+
}
171174
}
172175
return result;
173176
}
@@ -315,12 +318,6 @@ public Pair<String, VlanVO> assignPodDirectAttachIpAddress(long zoneId, long pod
315318
}
316319

317320
return null;
318-
// String ipAddress = _ipAddressDao.assignIpAddress(accountId, domainId, vlan.getId(), false).getAddress();
319-
// if (ipAddress == null) {
320-
// return null;
321-
// }
322-
// return new Pair<String, VlanVO>(ipAddress, vlan);
323-
324321
}
325322

326323
@Override

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
266266
@Inject
267267
DomainVlanMapDao _domainVlanMapDao;
268268
@Inject
269-
PodVlanMapDao _podVlanMapDao;
269+
PodVlanMapDao podVlanMapDao;
270270
@Inject
271271
DataCenterDao _zoneDao;
272272
@Inject
@@ -3950,7 +3950,7 @@ public VlanVO doInTransaction(final TransactionStatus status) {
39503950
} else if (podId != null) {
39513951
// This VLAN is pod-wide, so create a PodVlanMapVO entry
39523952
final PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId());
3953-
_podVlanMapDao.persist(podVlanMapVO);
3953+
podVlanMapDao.persist(podVlanMapVO);
39543954
}
39553955
return vlan;
39563956
}
@@ -4046,7 +4046,17 @@ public boolean deleteVlanAndPublicIpRange(final long userId, final long vlanDbId
40464046
@Override
40474047
public void doInTransactionWithoutResult(final TransactionStatus status) {
40484048
_publicIpAddressDao.deletePublicIPRange(vlanDbId);
4049+
s_logger.debug(String.format("Delete Public IP Range (from user_ip_address, where vlan_db_d=%s)", vlanDbId));
4050+
40494051
_vlanDao.remove(vlanDbId);
4052+
s_logger.debug(String.format("Mark vlan as Remove vlan (vlan_db_id=%s)", vlanDbId));
4053+
4054+
SearchBuilder<PodVlanMapVO> sb = podVlanMapDao.createSearchBuilder();
4055+
sb.and("vlan_db_id", sb.entity().getVlanDbId(), SearchCriteria.Op.EQ);
4056+
SearchCriteria<PodVlanMapVO> sc = sb.create();
4057+
sc.setParameters("vlan_db_id", vlanDbId);
4058+
podVlanMapDao.remove(sc);
4059+
s_logger.debug(String.format("Delete vlan_db_id=%s in pod_vlan_map", vlanDbId));
40504060
}
40514061
});
40524062

0 commit comments

Comments
 (0)