Search in sources :

Example 1 with StartupAnswer

use of com.cloud.agent.api.StartupAnswer in project cloudstack by apache.

the class Agent method processStartupAnswer.

public void processStartupAnswer(final Answer answer, final Response response, final Link link) {
    boolean cancelled = false;
    synchronized (this) {
        if (_startup != null) {
            _startup.cancel();
            _startup = null;
        } else {
            cancelled = true;
        }
    }
    final StartupAnswer startup = (StartupAnswer) answer;
    if (!startup.getResult()) {
        s_logger.error("Not allowed to connect to the server: " + answer.getDetails());
        System.exit(1);
    }
    if (cancelled) {
        s_logger.warn("Threw away a startup answer because we're reconnecting.");
        return;
    }
    s_logger.info("Proccess agent startup answer, agent id = " + startup.getHostId());
    setId(startup.getHostId());
    // change to ms.
    _pingInterval = (long) startup.getPingInterval() * 1000;
    setLastPingResponseTime();
    scheduleWatch(link, response, _pingInterval, _pingInterval);
    _ugentTaskPool.setKeepAliveTime(2 * _pingInterval, TimeUnit.MILLISECONDS);
    s_logger.info("Startup Response Received: agent id = " + getId());
}
Also used : StartupAnswer(com.cloud.agent.api.StartupAnswer)

Example 2 with StartupAnswer

use of com.cloud.agent.api.StartupAnswer in project cloudstack by apache.

the class AgentManagerImpl method connectAgent.

protected void connectAgent(final Link link, final Command[] cmds, final Request request) {
    // send startupanswer to agent in the very beginning, so agent can move on without waiting for the answer for an undetermined time, if we put this logic into another
    // thread pool.
    final StartupAnswer[] answers = new StartupAnswer[cmds.length];
    Command cmd;
    for (int i = 0; i < cmds.length; i++) {
        cmd = cmds[i];
        if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand || cmd instanceof StartupStorageCommand) {
            answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, getPingInterval());
            break;
        }
    }
    Response response = null;
    response = new Response(request, answers[0], _nodeId, -1);
    try {
        link.send(response.toBytes());
    } catch (final ClosedChannelException e) {
        s_logger.debug("Failed to send startupanswer: " + e.toString());
    }
    _connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
}
Also used : StartupAnswer(com.cloud.agent.api.StartupAnswer) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) StartupCommand(com.cloud.agent.api.StartupCommand) Response(com.cloud.agent.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) SetHostParamsCommand(com.cloud.agent.api.SetHostParamsCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 3 with StartupAnswer

use of com.cloud.agent.api.StartupAnswer in project cloudstack by apache.

the class DirectAgentAttache method process.

@Override
public void process(Answer[] answers) {
    if (answers != null && answers[0] instanceof StartupAnswer) {
        StartupAnswer startup = (StartupAnswer) answers[0];
        int interval = startup.getPingInterval();
        s_logger.info("StartupAnswer received " + startup.getHostId() + " Interval = " + interval);
        _futures.add(_agentMgr.getCronJobPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
    }
}
Also used : StartupAnswer(com.cloud.agent.api.StartupAnswer)

Example 4 with StartupAnswer

use of com.cloud.agent.api.StartupAnswer in project CloudStack-archive by CloudStack-extras.

the class Agent method processStartupAnswer.

public void processStartupAnswer(Answer answer, Response response, Link link) {
    boolean cancelled = false;
    synchronized (this) {
        if (_startup != null) {
            _startup.cancel();
            _startup = null;
        } else {
            cancelled = true;
        }
    }
    final StartupAnswer startup = (StartupAnswer) answer;
    if (!startup.getResult()) {
        s_logger.error("Not allowed to connect to the server: " + answer.getDetails());
        System.exit(1);
    }
    if (cancelled) {
        s_logger.warn("Threw away a startup answer because we're reconnecting.");
        return;
    }
    s_logger.info("Proccess agent startup answer, agent id = " + startup.getHostId());
    setId(startup.getHostId());
    // change to ms.
    _pingInterval = startup.getPingInterval() * 1000;
    setLastPingResponseTime();
    scheduleWatch(link, response, _pingInterval, _pingInterval);
    _ugentTaskPool.setKeepAliveTime(2 * _pingInterval, TimeUnit.MILLISECONDS);
    s_logger.info("Startup Response Received: agent id = " + getId());
}
Also used : StartupAnswer(com.cloud.agent.api.StartupAnswer)

Example 5 with StartupAnswer

use of com.cloud.agent.api.StartupAnswer in project cloudstack by apache.

the class AgentManagerImpl method handleDirectConnectAgent.

@Override
public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, final boolean forRebalance, boolean newHost) throws ConnectionException {
    AgentAttache attache;
    attache = createAttacheForDirectConnect(host, resource);
    final StartupAnswer[] answers = new StartupAnswer[cmds.length];
    for (int i = 0; i < answers.length; i++) {
        answers[i] = new StartupAnswer(cmds[i], attache.getId(), PingInterval.value());
    }
    attache.process(answers);
    if (newHost) {
        notifyMonitorsOfNewlyAddedHost(host.getId());
    }
    attache = notifyMonitorsOfConnection(attache, cmds, forRebalance);
    return attache != null;
}
Also used : StartupAnswer(com.cloud.agent.api.StartupAnswer)

Aggregations

StartupAnswer (com.cloud.agent.api.StartupAnswer)6 Command (com.cloud.agent.api.Command)2 PingCommand (com.cloud.agent.api.PingCommand)2 Response (com.cloud.agent.transport.Response)2 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)1 Answer (com.cloud.agent.api.Answer)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CronCommand (com.cloud.agent.api.CronCommand)1 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)1 ReadyCommand (com.cloud.agent.api.ReadyCommand)1 SetHostParamsCommand (com.cloud.agent.api.SetHostParamsCommand)1 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)1 StartupCommand (com.cloud.agent.api.StartupCommand)1 StartupProxyCommand (com.cloud.agent.api.StartupProxyCommand)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1 StartupSecondaryStorageCommand (com.cloud.agent.api.StartupSecondaryStorageCommand)1 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1