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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations