From 2be4542a8e5d33f09935b6597af669f00857b6eb Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Tue, 14 Jun 2011 20:11:39 -0700 Subject: [PATCH] bug 9154: Send alert if found two virtual routers in master state Notice it's a simple version that assume both virtual routers are controlled by same mgmt server. We can improve it later. --- .../VirtualNetworkApplianceManagerImpl.java | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index b7205b7531c..d505ecd0b91 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -708,12 +708,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public CheckRouterTask() { } - @Override - public void run() { - - final List routers = _routerDao.listVirtualUpByHostId(null); - s_logger.debug("Found " + routers.size() + " running routers. "); - + private void updateRoutersRedundantState(List routers) { for (DomainRouterVO router : routers) { if (!router.getIsRedundantRouter()) { continue; @@ -760,6 +755,38 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } } + + private void checkDuplicateMaster(List routers) { + Map networkRouterMaps = new HashMap(); + for (DomainRouterVO router : routers) { + if (router.getRedundantState() == RedundantState.MASTER) { + if (networkRouterMaps.containsKey(router.getNetworkId())) { + DomainRouterVO dupRouter = networkRouterMaps.get(router.getNetworkId()); + String title = "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName(); + String context = "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: " + + dupRouter.getHostName() + ", id: " + router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. "; + + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterIdToDeployIn(), router.getPodIdToDeployIn(), title, context); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterIdToDeployIn(), dupRouter.getPodIdToDeployIn(), title, context); + } else { + networkRouterMaps.put(router.getNetworkId(), router); + } + } + } + } + + @Override + public void run() { + + final List routers = _routerDao.listVirtualUpByHostId(null); + s_logger.debug("Found " + routers.size() + " running routers. "); + + updateRoutersRedundantState(routers); + + /* FIXME assumed the a pair of redundant routers managed by same mgmt server, + * then the update above can get the latest status */ + checkDuplicateMaster(routers); + } } public static boolean isAdmin(short accountType) {