use of com.cloud.legacymodel.dc.HostStatus in project cosmic by MissionCriticalCloud.
the class AgentManagerImpl method easySend.
@Override
public Answer easySend(final Long hostId, final Command cmd) {
try {
final Host h = this._hostDao.findById(hostId);
if (h == null || h.getRemoved() != null) {
s_logger.debug("Host with id " + hostId + " doesn't exist");
return null;
}
final HostStatus status = h.getStatus();
if (!status.equals(HostStatus.Up) && !status.equals(HostStatus.Connecting)) {
s_logger.debug("Can not send command " + cmd + " due to Host " + hostId + " is not up");
return null;
}
final Answer answer = send(hostId, cmd);
if (answer == null) {
s_logger.warn("send returns null answer");
return null;
}
if (s_logger.isDebugEnabled() && answer.getDetails() != null) {
s_logger.debug("Details from executing " + cmd.getClass() + ": " + answer.getDetails());
}
return answer;
} catch (final AgentUnavailableException e) {
s_logger.warn(e.getMessage());
return null;
} catch (final OperationTimedoutException e) {
s_logger.warn("Operation timed out: " + e.getMessage());
return null;
} catch (final Exception e) {
s_logger.warn("Exception while sending", e);
return null;
}
}
use of com.cloud.legacymodel.dc.HostStatus 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;
}
Aggregations