Search in sources :

Example 1 with CheckOnHostCommand

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

the class HypervInvestigator method isAgentAlive.

@Override
public Status isAgentAlive(Host agent) {
    if (agent.getHypervisorType() != Hypervisor.HypervisorType.Hyperv) {
        return null;
    }
    CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
    List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
    for (HostVO neighbor : neighbors) {
        if (neighbor.getId() == agent.getId() || neighbor.getHypervisorType() != Hypervisor.HypervisorType.Hyperv) {
            continue;
        }
        try {
            Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
            if (answer != null) {
                return answer.getResult() ? Status.Down : Status.Up;
            }
        } catch (Exception e) {
            s_logger.debug("Failed to send command to host: " + neighbor.getId(), e);
        }
    }
    return null;
}
Also used : CheckOnHostCommand(com.cloud.agent.api.CheckOnHostCommand) Answer(com.cloud.agent.api.Answer) HostVO(com.cloud.host.HostVO)

Example 2 with CheckOnHostCommand

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

the class KVMInvestigator method isAgentAlive.

@Override
public Status isAgentAlive(Host agent) {
    if (agent.getHypervisorType() != Hypervisor.HypervisorType.KVM && agent.getHypervisorType() != Hypervisor.HypervisorType.LXC) {
        return null;
    }
    if (haManager.isHAEligible(agent)) {
        return haManager.getHostStatus(agent);
    }
    List<StoragePoolVO> clusterPools = _storagePoolDao.listPoolsByCluster(agent.getClusterId());
    boolean hasNfs = false;
    for (StoragePoolVO pool : clusterPools) {
        if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
            hasNfs = true;
            break;
        }
    }
    if (!hasNfs) {
        List<StoragePoolVO> zonePools = _storagePoolDao.findZoneWideStoragePoolsByHypervisor(agent.getDataCenterId(), agent.getHypervisorType());
        for (StoragePoolVO pool : zonePools) {
            if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
                hasNfs = true;
                break;
            }
        }
    }
    if (!hasNfs) {
        s_logger.warn("Agent investigation was requested on host " + agent + ", but host does not support investigation because it has no NFS storage. Skipping investigation.");
        return Status.Disconnected;
    }
    Status hostStatus = null;
    Status neighbourStatus = null;
    CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
    try {
        Answer answer = _agentMgr.easySend(agent.getId(), cmd);
        if (answer != null) {
            hostStatus = answer.getResult() ? Status.Down : Status.Up;
        }
    } catch (Exception e) {
        s_logger.debug("Failed to send command to host: " + agent.getId());
    }
    if (hostStatus == null) {
        hostStatus = Status.Disconnected;
    }
    List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
    for (HostVO neighbor : neighbors) {
        if (neighbor.getId() == agent.getId() || (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
            continue;
        }
        s_logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId());
        try {
            Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
            if (answer != null) {
                neighbourStatus = answer.getResult() ? Status.Down : Status.Up;
                s_logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId());
                if (neighbourStatus == Status.Up) {
                    break;
                }
            }
        } catch (Exception e) {
            s_logger.debug("Failed to send command to host: " + neighbor.getId());
        }
    }
    if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
        hostStatus = Status.Disconnected;
    }
    if (neighbourStatus == Status.Down && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
        hostStatus = Status.Down;
    }
    s_logger.debug("HA: HOST is ineligible legacy state " + hostStatus + " for host " + agent.getId());
    return hostStatus;
}
Also used : Status(com.cloud.host.Status) CheckOnHostCommand(com.cloud.agent.api.CheckOnHostCommand) Answer(com.cloud.agent.api.Answer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HostVO(com.cloud.host.HostVO)

Example 3 with CheckOnHostCommand

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

the class KVMHostActivityChecker method isAgentActive.

private boolean isAgentActive(Host agent) {
    if (agent.getHypervisorType() != Hypervisor.HypervisorType.KVM && agent.getHypervisorType() != Hypervisor.HypervisorType.LXC) {
        throw new IllegalStateException(String.format("Calling KVM investigator for non KVM Host of type [%s].", agent.getHypervisorType()));
    }
    Status hostStatus = Status.Unknown;
    Status neighbourStatus = Status.Unknown;
    final CheckOnHostCommand cmd = new CheckOnHostCommand(agent);
    try {
        LOG.debug(String.format("Checking %s status...", agent.toString()));
        Answer answer = agentMgr.easySend(agent.getId(), cmd);
        if (answer != null) {
            hostStatus = answer.getResult() ? Status.Down : Status.Up;
            LOG.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus));
            if (hostStatus == Status.Up) {
                return true;
            }
        } else {
            LOG.debug(String.format("Setting %s to \"Disconnected\" status.", agent.toString()));
            hostStatus = Status.Disconnected;
        }
    } catch (Exception e) {
        LOG.warn(String.format("Failed to send command CheckOnHostCommand to %s.", agent.toString()), e);
    }
    List<HostVO> neighbors = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
    for (HostVO neighbor : neighbors) {
        if (neighbor.getId() == agent.getId() || (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
            continue;
        }
        try {
            LOG.debug(String.format("Investigating %s via neighbouring %s.", agent.toString(), neighbor.toString()));
            Answer answer = agentMgr.easySend(neighbor.getId(), cmd);
            if (answer != null) {
                neighbourStatus = answer.getResult() ? Status.Down : Status.Up;
                LOG.debug(String.format("Neighbouring %s returned status [%s] for the investigated %s.", neighbor.toString(), neighbourStatus, agent.toString()));
                if (neighbourStatus == Status.Up) {
                    break;
                }
            } else {
                LOG.debug(String.format("Neighbouring %s is Disconnected.", neighbor.toString()));
            }
        } catch (Exception e) {
            LOG.warn(String.format("Failed to send command CheckOnHostCommand to %s.", neighbor.toString()), e);
        }
    }
    if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
        hostStatus = Status.Disconnected;
    }
    if (neighbourStatus == Status.Down && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
        hostStatus = Status.Down;
    }
    LOG.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus));
    return hostStatus == Status.Up;
}
Also used : Status(com.cloud.host.Status) CheckOnHostCommand(com.cloud.agent.api.CheckOnHostCommand) Answer(com.cloud.agent.api.Answer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) HACheckerException(org.apache.cloudstack.ha.provider.HACheckerException) HostVO(com.cloud.host.HostVO)

Example 4 with CheckOnHostCommand

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

the class NotAValidCommand method testCheckOnHostCommand.

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

Example 5 with CheckOnHostCommand

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

the class XenServer56WrapperTest method testCheckOnHostCommand.

@Test
public void testCheckOnHostCommand() {
    final com.cloud.host.Host host = Mockito.mock(com.cloud.host.Host.class);
    final CheckOnHostCommand onHostCommand = new CheckOnHostCommand(host);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(onHostCommand, xenServer56Resource);
    assertTrue(answer.getResult());
}
Also used : CheckOnHostCommand(com.cloud.agent.api.CheckOnHostCommand) Answer(com.cloud.agent.api.Answer) Host(com.cloud.host.Host) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)15 CheckOnHostCommand (com.cloud.agent.api.CheckOnHostCommand)15 HostVO (com.cloud.host.HostVO)8 Test (org.junit.Test)6 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)3 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 Status (com.cloud.host.Status)2 AttachAnswer (com.cloud.storage.command.AttachAnswer)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)1 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1