Search in sources :

Example 1 with Listener

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

the class AgentManagerImpl method handleControlCommand.

private AgentControlAnswer handleControlCommand(final AgentAttache attache, final AgentControlCommand cmd) {
    AgentControlAnswer answer = null;
    for (final Pair<Integer, Listener> listener : _cmdMonitors) {
        answer = listener.second().processControlCommand(attache.getId(), cmd);
        if (answer != null) {
            return answer;
        }
    }
    s_logger.warn("No handling of agent control command: " + cmd + " sent from " + attache.getId());
    return new AgentControlAnswer(cmd);
}
Also used : Listener(com.cloud.agent.Listener) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer)

Example 2 with Listener

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

the class AgentAttache method processAnswers.

public boolean processAnswers(final long seq, final Response resp) {
    resp.logD("Processing: ", true);
    final Answer[] answers = resp.getAnswers();
    boolean processed = false;
    try {
        Listener monitor = getListener(seq);
        if (monitor == null) {
            if (answers[0] != null && answers[0].getResult()) {
                processed = true;
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(log(seq, "Unable to find listener."));
            }
        } else {
            processed = monitor.processAnswers(_id, seq, answers);
            if (s_logger.isTraceEnabled()) {
                s_logger.trace(log(seq, (processed ? "" : " did not ") + " processed "));
            }
            if (!monitor.isRecurring()) {
                unregisterListener(seq);
            }
        }
        _agentMgr.notifyAnswersToMonitors(_id, seq, answers);
    } finally {
        // we should always trigger next command execution, even in failure cases - otherwise in exception case all the remaining will be stuck in the sync queue forever
        if (resp.executeInSequence()) {
            sendNext(seq);
        }
    }
    return processed;
}
Also used : Answer(com.cloud.agent.api.Answer) Listener(com.cloud.agent.Listener)

Example 3 with Listener

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

the class AgentAttache method cancelAllCommands.

protected void cancelAllCommands(final Status state, final boolean cancelActive) {
    if (cancelActive) {
        final Set<Map.Entry<Long, Listener>> entries = _waitForList.entrySet();
        final Iterator<Map.Entry<Long, Listener>> it = entries.iterator();
        while (it.hasNext()) {
            final Map.Entry<Long, Listener> entry = it.next();
            it.remove();
            final Listener monitor = entry.getValue();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(log(entry.getKey(), "Sending disconnect to " + monitor.getClass()));
            }
            monitor.processDisconnect(_id, state);
        }
    }
}
Also used : Listener(com.cloud.agent.Listener) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with Listener

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

the class AgentAttache method getNonRecurringListenersSize.

public int getNonRecurringListenersSize() {
    List<Listener> nonRecurringListenersList = new ArrayList<Listener>();
    if (_waitForList.isEmpty()) {
        return 0;
    } else {
        final Set<Map.Entry<Long, Listener>> entries = _waitForList.entrySet();
        final Iterator<Map.Entry<Long, Listener>> it = entries.iterator();
        while (it.hasNext()) {
            final Map.Entry<Long, Listener> entry = it.next();
            final Listener monitor = entry.getValue();
            if (!monitor.isRecurring()) {
                //TODO - remove this debug statement later
                s_logger.debug("Listener is " + entry.getValue() + " waiting on " + entry.getKey());
                nonRecurringListenersList.add(monitor);
            }
        }
    }
    return nonRecurringListenersList.size();
}
Also used : Listener(com.cloud.agent.Listener) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with Listener

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

the class AgentAttache method cancel.

protected synchronized void cancel(final long seq) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(log(seq, "Cancelling."));
    }
    final Listener listener = _waitForList.remove(seq);
    if (listener != null) {
        listener.processDisconnect(_id, Status.Disconnected);
    }
    int index = findRequest(seq);
    if (index >= 0) {
        _requests.remove(index);
    }
}
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