Search in sources :

Example 1 with CheckOnHostCommand

use of com.cloud.legacymodel.communication.command.CheckOnHostCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testCheckOnHostCommand.

@Test
public void testCheckOnHostCommand() {
    final com.cloud.legacymodel.dc.Host host = Mockito.mock(com.cloud.legacymodel.dc.Host.class);
    final CheckOnHostCommand onHostCommand = new CheckOnHostCommand(host);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(onHostCommand, this.citrixResourceBase);
    assertFalse(answer.getResult());
}
Also used : CheckOnHostCommand(com.cloud.legacymodel.communication.command.CheckOnHostCommand) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CheckOnHostCommand

use of com.cloud.legacymodel.communication.command.CheckOnHostCommand in project cosmic by MissionCriticalCloud.

the class XenServerInvestigator method isAgentAlive.

@Override
public HostStatus isAgentAlive(final Host agent) {
    if (agent.getHypervisorType() != HypervisorType.XenServer) {
        return null;
    }
    final CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
    final List<HostVO> neighbors = _resourceMgr.listAllHostsInCluster(agent.getClusterId());
    for (final HostVO neighbor : neighbors) {
        if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != HypervisorType.XenServer) {
            continue;
        }
        final Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
        if (answer != null && answer.getResult()) {
            final CheckOnHostAnswer ans = (CheckOnHostAnswer) answer;
            if (!ans.isDetermined()) {
                s_logger.debug("Host " + neighbor + " couldn't determine the status of " + agent);
                continue;
            }
            // even it returns true, that means host is up, but XAPI may not work
            return ans.isAlive() ? null : HostStatus.Down;
        }
    }
    return null;
}
Also used : CheckOnHostCommand(com.cloud.legacymodel.communication.command.CheckOnHostCommand) CheckOnHostAnswer(com.cloud.legacymodel.communication.answer.CheckOnHostAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckOnHostAnswer(com.cloud.legacymodel.communication.answer.CheckOnHostAnswer) HostVO(com.cloud.host.HostVO)

Example 3 with CheckOnHostCommand

use of com.cloud.legacymodel.communication.command.CheckOnHostCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckOnHostCommand.

@Test
public void testCheckOnHostCommand() {
    final Host host = Mockito.mock(Host.class);
    final CheckOnHostCommand command = new CheckOnHostCommand(host);
    final KvmHaMonitor monitor = Mockito.mock(KvmHaMonitor.class);
    when(this.libvirtComputingResource.getMonitor()).thenReturn(monitor);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getMonitor();
}
Also used : CheckOnHostCommand(com.cloud.legacymodel.communication.command.CheckOnHostCommand) 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) Host(com.cloud.legacymodel.dc.Host) KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor) Test(org.junit.Test)

Example 4 with CheckOnHostCommand

use of com.cloud.legacymodel.communication.command.CheckOnHostCommand in project cosmic by MissionCriticalCloud.

the class XenServer56WrapperTest method testCheckOnHostCommand.

@Test
public void testCheckOnHostCommand() {
    final Host host = Mockito.mock(Host.class);
    final CheckOnHostCommand onHostCommand = new CheckOnHostCommand(host);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(onHostCommand, this.xenServer56Resource);
    assertTrue(answer.getResult());
}
Also used : CheckOnHostCommand(com.cloud.legacymodel.communication.command.CheckOnHostCommand) Answer(com.cloud.legacymodel.communication.answer.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.cloud.legacymodel.dc.Host) Test(org.junit.Test)

Example 5 with CheckOnHostCommand

use of com.cloud.legacymodel.communication.command.CheckOnHostCommand in project cosmic by MissionCriticalCloud.

the class KvmInvestigator method isAgentAlive.

@Override
public HostStatus isAgentAlive(final Host agent) {
    if (agent.getHypervisorType() != HypervisorType.KVM) {
        return null;
    }
    HostStatus hostStatus = null;
    HostStatus neighbourStatus = null;
    final CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
    try {
        final Answer answer = agentMgr.easySend(agent.getId(), cmd);
        if (answer != null) {
            hostStatus = answer.getResult() ? HostStatus.Down : HostStatus.Up;
        }
    } catch (final Exception e) {
        logger.debug("Failed to send command to host: " + agent.getId());
    }
    if (hostStatus == null) {
        hostStatus = HostStatus.Disconnected;
    }
    final List<HostVO> neighbors = resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), HostStatus.Up);
    for (final HostVO neighbor : neighbors) {
        if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != HypervisorType.KVM) {
            continue;
        }
        logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId());
        try {
            final Answer answer = agentMgr.easySend(neighbor.getId(), cmd);
            if (answer != null) {
                neighbourStatus = answer.getResult() ? HostStatus.Down : HostStatus.Up;
                logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId());
                if (neighbourStatus == HostStatus.Up) {
                    break;
                }
            }
        } catch (final Exception e) {
            logger.debug("Failed to send command to host: " + neighbor.getId());
        }
    }
    if (neighbourStatus == HostStatus.Up && (hostStatus == HostStatus.Disconnected || hostStatus == HostStatus.Down)) {
        hostStatus = HostStatus.Disconnected;
    }
    if (neighbourStatus == HostStatus.Down && (hostStatus == HostStatus.Disconnected || hostStatus == HostStatus.Down)) {
        hostStatus = HostStatus.Down;
    }
    return hostStatus;
}
Also used : CheckOnHostCommand(com.cloud.legacymodel.communication.command.CheckOnHostCommand) Answer(com.cloud.legacymodel.communication.answer.Answer) HostStatus(com.cloud.legacymodel.dc.HostStatus) HostVO(com.cloud.host.HostVO)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)5 CheckOnHostCommand (com.cloud.legacymodel.communication.command.CheckOnHostCommand)5 Test (org.junit.Test)3 HostVO (com.cloud.host.HostVO)2 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)2 Host (com.cloud.legacymodel.dc.Host)2 KvmHaMonitor (com.cloud.agent.resource.kvm.ha.KvmHaMonitor)1 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 CheckOnHostAnswer (com.cloud.legacymodel.communication.answer.CheckOnHostAnswer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 HostStatus (com.cloud.legacymodel.dc.HostStatus)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1