Search in sources :

Example 1 with CheckRouterAnswer

use of com.cloud.legacymodel.communication.answer.CheckRouterAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testNetworkElementCommand.

@Test
public void testNetworkElementCommand() {
    final CheckRouterCommand command = new CheckRouterCommand();
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
    when(virtRouterResource.executeRequest(command)).thenReturn(new CheckRouterAnswer(command, "mock_resource"));
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
}
Also used : CheckRouterCommand(com.cloud.legacymodel.communication.command.CheckRouterCommand) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) Test(org.junit.Test)

Example 2 with CheckRouterAnswer

use of com.cloud.legacymodel.communication.answer.CheckRouterAnswer in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method updateRoutersRedundantState.

protected void updateRoutersRedundantState(final DomainRouterVO router) {
    boolean updated;
    updated = false;
    final RedundantState prevState = router.getRedundantState();
    if (router.getState() != VirtualMachine.State.Starting && 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() != HostStatus.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 = "Virtual router " + router.getInstanceName() + " just switch from " + prevState + " to " + currState;
        final String context = "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.legacymodel.communication.command.CheckRouterCommand) NetworkUsageAnswer(com.cloud.legacymodel.communication.answer.NetworkUsageAnswer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) RedundantState(com.cloud.legacymodel.network.VirtualRouter.RedundantState) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)2 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 CheckRouterCommand (com.cloud.legacymodel.communication.command.CheckRouterCommand)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 ManagementServerHostVO (com.cloud.cluster.ManagementServerHostVO)1 VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)1 HostVO (com.cloud.host.HostVO)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)1 NetworkUsageAnswer (com.cloud.legacymodel.communication.answer.NetworkUsageAnswer)1 RedundantState (com.cloud.legacymodel.network.VirtualRouter.RedundantState)1 Test (org.junit.Test)1