Search in sources :

Example 6 with HostStatus

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;
    }
}
Also used : AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) PingAnswer(com.cloud.legacymodel.communication.answer.PingAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) Host(com.cloud.legacymodel.dc.Host) HostStatus(com.cloud.legacymodel.dc.HostStatus) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) UnsupportedVersionException(com.cloud.legacymodel.exceptions.UnsupportedVersionException) HypervisorVersionChangedException(com.cloud.legacymodel.exceptions.HypervisorVersionChangedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ConfigurationException(javax.naming.ConfigurationException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) TaskExecutionException(com.cloud.legacymodel.exceptions.TaskExecutionException) ClosedChannelException(java.nio.channels.ClosedChannelException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NioConnectionException(com.cloud.legacymodel.exceptions.NioConnectionException)

Example 7 with HostStatus

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;
}
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

HostStatus (com.cloud.legacymodel.dc.HostStatus)7 HostVO (com.cloud.host.HostVO)6 Answer (com.cloud.legacymodel.communication.answer.Answer)3 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)3 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)2 PingAnswer (com.cloud.legacymodel.communication.answer.PingAnswer)2 ReadyAnswer (com.cloud.legacymodel.communication.answer.ReadyAnswer)2 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)2 UnsupportedAnswer (com.cloud.legacymodel.communication.answer.UnsupportedAnswer)2 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)2 Zone (com.cloud.db.model.Zone)1 HostPodVO (com.cloud.dc.HostPodVO)1 CheckHealthCommand (com.cloud.legacymodel.communication.command.CheckHealthCommand)1 CheckOnHostCommand (com.cloud.legacymodel.communication.command.CheckOnHostCommand)1 Host (com.cloud.legacymodel.dc.Host)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 ConnectionException (com.cloud.legacymodel.exceptions.ConnectionException)1 HypervisorVersionChangedException (com.cloud.legacymodel.exceptions.HypervisorVersionChangedException)1 NioConnectionException (com.cloud.legacymodel.exceptions.NioConnectionException)1 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)1