Search in sources :

Example 1 with CheckRouterAnswer

use of com.cloud.agent.api.CheckRouterAnswer in project cloudstack by apache.

the class LibvirtComputingResourceTest method testNetworkElementCommand.

@Test
public void testNetworkElementCommand() {
    final CheckRouterCommand command = new CheckRouterCommand();
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    when(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, libvirtComputingResource);
    assertFalse(answer.getResult());
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CheckRouterAnswer

use of com.cloud.agent.api.CheckRouterAnswer in project cloudstack by apache.

the class MockVmManagerImpl method checkRouter.

@Override
public CheckRouterAnswer checkRouter(final CheckRouterCommand cmd) {
    final String router_name = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final MockVm vm = _mockVmDao.findByVmName(router_name);
    final String args = vm.getBootargs();
    if (args.indexOf("router_pr=100") > 0) {
        s_logger.debug("Router priority is for PRIMARY");
        final CheckRouterAnswer ans = new CheckRouterAnswer(cmd, "Status: PRIMARY", true);
        ans.setState(VirtualRouter.RedundantState.PRIMARY);
        return ans;
    } else {
        s_logger.debug("Router priority is for BACKUP");
        final CheckRouterAnswer ans = new CheckRouterAnswer(cmd, "Status: BACKUP", true);
        ans.setState(VirtualRouter.RedundantState.BACKUP);
        return ans;
    }
}
Also used : MockVm(com.cloud.simulator.MockVm) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer)

Example 3 with CheckRouterAnswer

use of com.cloud.agent.api.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(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, libvirtComputingResource);
    assertFalse(answer.getResult());
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) Test(org.junit.Test)

Example 4 with CheckRouterAnswer

use of com.cloud.agent.api.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() != 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 = "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.agent.api.CheckRouterCommand) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) RedundantState(com.cloud.network.router.VirtualRouter.RedundantState) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer)

Example 5 with CheckRouterAnswer

use of com.cloud.agent.api.CheckRouterAnswer 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.PRIMARY) {
                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
            }
        }
    }
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) 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) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) 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

CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)6 Answer (com.cloud.agent.api.Answer)4 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)2 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)2 VirtualRoutingResource (com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource)2 ManagementServerHostVO (com.cloud.cluster.ManagementServerHostVO)2 HostVO (com.cloud.host.HostVO)2 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)2 RedundantState (com.cloud.network.router.VirtualRouter.RedundantState)2 Test (org.junit.Test)2 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1 GetRouterMonitorResultsAnswer (com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer)1 GroupAnswer (com.cloud.agent.api.routing.GroupAnswer)1 MockVm (com.cloud.simulator.MockVm)1 AttachAnswer (com.cloud.storage.command.AttachAnswer)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1