mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Fix NPE when a router is fail to start
Also enforce the check for restartNetworkCommand
This commit is contained in:
parent
92131e9859
commit
9366290423
@ -62,6 +62,7 @@ import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
@ -152,17 +153,22 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
||||
}
|
||||
|
||||
/* Get the host_id in order to find the cluster */
|
||||
long host_id = 0;
|
||||
Long host_id = new Long(0);
|
||||
for (DomainRouterVO router : routers) {
|
||||
host_id = router.getHostId();
|
||||
if (host_id == null || host_id == 0) {
|
||||
host_id = (router.getHostId() != null ? router.getHostId() : router.getLastHostId());
|
||||
}
|
||||
/* FIXME it's not completely safe to ignore these failure, but we would try to push on now */
|
||||
if (_routerMgr.stopRouter(router.getId(), false) == null) {
|
||||
if (router.getState() != State.Stopped || _routerMgr.stopRouter(router.getId(), false) == null) {
|
||||
s_logger.warn("Failed to stop virtual router element " + router + " as a part of network " + network + " restart");
|
||||
}
|
||||
if (!_routerMgr.destroyRouter(router.getId())) {
|
||||
s_logger.warn("Failed to destroy virtual router element " + router + " as a part of network " + network + " restart");
|
||||
}
|
||||
}
|
||||
if (host_id == null || host_id == 0) {
|
||||
throw new ResourceUnavailableException("Fail to locate virtual router element in network " + network.getId(), this.getClass(), 0);
|
||||
}
|
||||
|
||||
/* The cluster here is only used to determine hypervisor type, not the real deployment */
|
||||
Cluster cluster = _configMgr.getCluster(_hostDao.findById(host_id).getClusterId());
|
||||
|
||||
@ -1061,7 +1061,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
if (state != State.Running) {
|
||||
router = startVirtualRouter(router, _accountService.getSystemUser(), _accountService.getSystemAccount(), params);
|
||||
}
|
||||
runningRouters.add(router);
|
||||
if (router != null) {
|
||||
runningRouters.add(router);
|
||||
}
|
||||
}
|
||||
}
|
||||
return runningRouters;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user