mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Fix findByNetwork()/findByNetworkAndPod()'s return
Add null check and some missed empty check.
This commit is contained in:
parent
c55e56c4bd
commit
872116890b
@ -132,7 +132,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
|
||||
@Override
|
||||
public boolean shutdown(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
boolean result = true;
|
||||
@ -145,7 +145,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
|
||||
@Override
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(config.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
boolean result = true;
|
||||
@ -192,7 +192,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
|
||||
NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, null);
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.trace("Can't find dhcp element in network " + network.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, null);
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.trace("Can't find virtual router element in network " + network.getId());
|
||||
return true;
|
||||
}
|
||||
@ -159,7 +159,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
||||
if (canHandle(config.getGuestType(),dc)) {
|
||||
long networkId = config.getId();
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual router doesn't exist in the network " + config.getId());
|
||||
return true;
|
||||
}
|
||||
@ -212,7 +212,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
||||
if (canHandle(network.getGuestType(),dc)) {
|
||||
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual router doesn't exist in the network " + network.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -389,7 +389,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Override
|
||||
public boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile) throws ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.warn("Unable save password, router doesn't exist in network " + network.getId());
|
||||
throw new CloudRuntimeException("Unable to save password to router");
|
||||
}
|
||||
@ -894,17 +894,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
DataCenterDeployment plan = null;
|
||||
DataCenter dc = _dcDao.findById(dcId);
|
||||
DomainRouterVO router = null;
|
||||
List<DomainRouterVO> routers = null;
|
||||
Long podId = dest.getPod().getId();
|
||||
|
||||
// In Basic zone and Guest network we have to start domR per pod, not per network
|
||||
if ((dc.getNetworkType() == NetworkType.Basic || guestNetwork.isSecurityGroupEnabled()) && guestNetwork.getTrafficType() == TrafficType.Guest) {
|
||||
router = _routerDao.findByNetworkAndPod(guestNetwork.getId(), podId).get(0);
|
||||
routers = _routerDao.findByNetworkAndPod(guestNetwork.getId(), podId);
|
||||
plan = new DataCenterDeployment(dcId, podId, null, null, null);
|
||||
} else {
|
||||
router = _routerDao.findByNetwork(guestNetwork.getId()).get(0);
|
||||
routers = _routerDao.findByNetwork(guestNetwork.getId());
|
||||
plan = new DataCenterDeployment(dcId);
|
||||
}
|
||||
|
||||
if (routers != null && !routers.isEmpty()) {
|
||||
router = routers.get(0);
|
||||
}
|
||||
|
||||
if (router == null) {
|
||||
long id = _routerDao.getNextInSequence(Long.class, "id");
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -1422,7 +1427,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Override
|
||||
public String[] applyVpnUsers(Network network, List<? extends VpnUser> users) throws ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.size() == 0) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
|
||||
throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + network.getId(), DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
@ -1726,7 +1731,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Override
|
||||
public boolean associateIP(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.warn("Unable to associate ip addresses, virtual router doesn't exist in the network " + network.getId());
|
||||
throw new ResourceUnavailableException("Unable to assign ip addresses", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
@ -1750,7 +1755,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Override
|
||||
public boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
|
||||
if (routers.isEmpty()) {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.warn("Unable to apply lb rules, virtual router doesn't exist in the network " + network.getId());
|
||||
throw new ResourceUnavailableException("Unable to apply lb rules", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user