Search in sources :

Example 6 with Listener

use of com.cloud.agent.Listener in project cloudstack by apache.

the class AgentManagerImpl method notifyMonitorsOfConnection.

protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, final StartupCommand[] cmd, final boolean forRebalance) throws ConnectionException {
    final long hostId = attache.getId();
    final HostVO host = _hostDao.findById(hostId);
    for (final Pair<Integer, Listener> monitor : _hostMonitors) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName());
        }
        for (int i = 0; i < cmd.length; i++) {
            try {
                monitor.second().processConnect(host, cmd[i], forRebalance);
            } catch (final Exception e) {
                if (e instanceof ConnectionException) {
                    final ConnectionException ce = (ConnectionException) e;
                    if (ce.isSetupError()) {
                        s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
                        handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
                        throw ce;
                    } else {
                        s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
                        handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
                        return attache;
                    }
                } else if (e instanceof HypervisorVersionChangedException) {
                    handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
                    throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
                } else {
                    s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
                    handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
                    throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
                }
            }
        }
    }
    final Long dcId = host.getDataCenterId();
    final ReadyCommand ready = new ReadyCommand(dcId, host.getId());
    final Answer answer = easySend(hostId, ready);
    if (answer == null || !answer.getResult()) {
        // this is tricky part for secondary storage
        // make it as disconnected, wait for secondary storage VM to be up
        // return the attache instead of null, even it is disconnectede
        handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
    }
    agentStatusTransitTo(host, Event.Ready, _nodeId);
    attache.ready();
    return attache;
}
Also used : Listener(com.cloud.agent.Listener) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.exception.ConnectionException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TaskExecutionException(com.cloud.utils.exception.TaskExecutionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClosedChannelException(java.nio.channels.ClosedChannelException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) UnsupportedVersionException(com.cloud.exception.UnsupportedVersionException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) PingAnswer(com.cloud.agent.api.PingAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) ReadyCommand(com.cloud.agent.api.ReadyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConnectionException(com.cloud.exception.ConnectionException) NioConnectionException(com.cloud.utils.exception.NioConnectionException)

Example 7 with Listener

use of com.cloud.agent.Listener in project cloudstack by apache.

the class ClusteredAgentAttache method cancel.

@Override
public void cancel(final long seq) {
    if (forForward()) {
        Listener listener = getListener(seq);
        if (listener != null && listener instanceof SynchronousListener) {
            SynchronousListener synchronous = (SynchronousListener) listener;
            String peerName = synchronous.getPeer();
            if (peerName != null) {
                if (s_clusteredAgentMgr != null) {
                    s_logger.debug(log(seq, "Forwarding to peer to cancel due to timeout"));
                    s_clusteredAgentMgr.cancel(peerName, _id, seq, "Timed Out");
                } else {
                    s_logger.error("Unable to forward cancel, ClusteredAgentAttache is not properly initialized");
                }
            }
        }
    }
    super.cancel(seq);
}
Also used : Listener(com.cloud.agent.Listener)

Aggregations

Listener (com.cloud.agent.Listener)7 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 Answer (com.cloud.agent.api.Answer)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PingAnswer (com.cloud.agent.api.PingAnswer)1 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)1 ReadyCommand (com.cloud.agent.api.ReadyCommand)1 StartupAnswer (com.cloud.agent.api.StartupAnswer)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConnectionException (com.cloud.exception.ConnectionException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 UnsupportedVersionException (com.cloud.exception.UnsupportedVersionException)1 HostVO (com.cloud.host.HostVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 HypervisorVersionChangedException (com.cloud.utils.exception.HypervisorVersionChangedException)1 NioConnectionException (com.cloud.utils.exception.NioConnectionException)1 TaskExecutionException (com.cloud.utils.exception.TaskExecutionException)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1