for (DomainRouterVO router : routers) {
updated = false;
if (!router.getIsRedundantRouter()) {
continue;
}
RedundantState prevState = router.getRedundantState();
if (router.getState() != State.Running) {
router.setRedundantState(RedundantState.UNKNOWN);
router.setIsPriorityBumpUp(false);
updated = true;
} else {
String privateIP = router.getPrivateIpAddress();
HostVO host = _hostDao.findById(router.getHostId());
if (host == null || host.getStatus() != Status.Up) {
router.setRedundantState(RedundantState.UNKNOWN);
updated = true;
} else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
/* Only cover hosts managed by this management server */
continue;
} else if (privateIP != null) {
final CheckRouterCommand command = new CheckRouterCommand();
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
command.setWait(60);
final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
CheckRouterAnswer answer = null;
if (origAnswer instanceof CheckRouterAnswer) {
answer = (CheckRouterAnswer)origAnswer;
} else {
s_logger.warn("Unable to update router " + router.getHostName() + "'s status");
}
RedundantState state = RedundantState.UNKNOWN;
boolean isBumped = router.getIsPriorityBumpUp();
if (answer != null && answer.getResult()) {
state = answer.getState();
isBumped = answer.isBumped();
}
router.setRedundantState(state);
router.setIsPriorityBumpUp(isBumped);
updated = true;
}
}
if (updated) {
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
txn.start();
_routerDao.update(router.getId(), router);
txn.commit();
} catch (Exception e) {
txn.rollback();
s_logger.warn("Unable to update router status for account: " + router.getAccountId());
} finally {
txn.close();
}
}
RedundantState currState = router.getRedundantState();
if (prevState != currState) {
String title = "Redundant virtual router " + router.getInstanceName() +
" just switch from " + prevState + " to " + currState;
String context = "Redundant virtual router (name: " + router.getHostName() + ", id: " + router.getId() + ") " +
" just switch from " + prevState + " to " + currState;