Search in sources :

Example 1 with RedundantState

use of com.cloud.network.router.VirtualRouter.RedundantState in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method updateRoutersRedundantState.

protected void updateRoutersRedundantState(final List<DomainRouterVO> routers) {
    boolean updated;
    for (final DomainRouterVO router : routers) {
        updated = false;
        if (!router.getIsRedundantRouter()) {
            continue;
        }
        final RedundantState prevState = router.getRedundantState();
        if (router.getState() != VirtualMachine.State.Running) {
            router.setRedundantState(RedundantState.UNKNOWN);
            updated = true;
        } else {
            final String privateIP = router.getPrivateIpAddress();
            final HostVO host = _hostDao.findById(router.getHostId());
            if (host == null || host.getState() != Status.Up) {
                router.setRedundantState(RedundantState.UNKNOWN);
                updated = true;
            } else if (privateIP != null) {
                final CheckRouterCommand command = new CheckRouterCommand();
                command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
                command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
                command.setWait(30);
                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;
                if (answer != null) {
                    if (answer.getResult()) {
                        state = answer.getState();
                    } else {
                        s_logger.info("Agent response doesn't seem to be correct ==> " + answer.getResult());
                    }
                }
                router.setRedundantState(state);
                updated = true;
            }
        }
        if (updated) {
            _routerDao.update(router.getId(), router);
        }
        final RedundantState currState = router.getRedundantState();
        if (prevState != currState) {
            final String title = "Redundant virtual router " + router.getInstanceName() + " just switch from " + prevState + " to " + currState;
            final String context = "Redundant virtual router (name: " + router.getHostName() + ", id: " + router.getId() + ") " + " just switch from " + prevState + " to " + currState;
            s_logger.info(context);
            if (currState == RedundantState.MASTER) {
                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
            }
        }
    }
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) RedundantState(com.cloud.network.router.VirtualRouter.RedundantState) DomainRouterVO(com.cloud.vm.DomainRouterVO) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer)

Aggregations

AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1 ManagementServerHostVO (com.cloud.cluster.ManagementServerHostVO)1 HostVO (com.cloud.host.HostVO)1 RedundantState (com.cloud.network.router.VirtualRouter.RedundantState)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1