Search in sources :

Example 1 with StartupAnswer

use of com.cloud.legacymodel.communication.answer.StartupAnswer in project cosmic by MissionCriticalCloud.

the class Agent method processStartupAnswer.

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

Example 2 with StartupAnswer

use of com.cloud.legacymodel.communication.answer.StartupAnswer in project cosmic by MissionCriticalCloud.

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], this._nodeId, -1);
    try {
        link.send(response.toBytes());
    } catch (final ClosedChannelException e) {
        s_logger.debug("Failed to send startupanswer: " + e.toString());
    }
    this._connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
}
Also used : StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) StartupProxyCommand(com.cloud.legacymodel.communication.command.startup.StartupProxyCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Response(com.cloud.common.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) StartupStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupStorageCommand) StartupSecondaryStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) CheckHealthCommand(com.cloud.legacymodel.communication.command.CheckHealthCommand) PingRoutingCommand(com.cloud.legacymodel.communication.command.PingRoutingCommand) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) StartupProxyCommand(com.cloud.legacymodel.communication.command.startup.StartupProxyCommand) StartupSecondaryStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand) StartupStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupStorageCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)

Example 3 with StartupAnswer

use of com.cloud.legacymodel.communication.answer.StartupAnswer in project cosmic by MissionCriticalCloud.

the class AgentManagerImpl method handleDirectConnectAgent.

@Override
public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, final boolean forRebalance) 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(), this.PingInterval.value());
    }
    attache.process(answers);
    attache = notifyMonitorsOfConnection(attache, cmds, forRebalance);
    return attache != null;
}
Also used : StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer)

Example 4 with StartupAnswer

use of com.cloud.legacymodel.communication.answer.StartupAnswer in project cosmic by MissionCriticalCloud.

the class DirectAgentAttache method send.

@Override
public void send(final Request req) throws AgentUnavailableException {
    req.logD("Executing: ", true);
    if (req instanceof Response) {
        final Response resp = (Response) req;
        final Answer[] answers = resp.getAnswers();
        if (answers != null && answers[0] instanceof StartupAnswer) {
            final StartupAnswer startup = (StartupAnswer) answers[0];
            final int interval = startup.getPingInterval();
            this._futures.add(this._agentMgr.getCronJobPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
        }
    } else {
        final Command[] cmds = req.getCommands();
        if (cmds.length > 0 && !(cmds[0] instanceof CronCommand)) {
            queueTask(new Task(req));
            scheduleFromQueue();
        } else {
            final CronCommand cmd = (CronCommand) cmds[0];
            this._futures.add(this._agentMgr.getCronJobPool().scheduleAtFixedRate(new CronTask(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
        }
    }
}
Also used : Response(com.cloud.common.transport.Response) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) Command(com.cloud.legacymodel.communication.command.Command) CronCommand(com.cloud.legacymodel.communication.command.CronCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) CronCommand(com.cloud.legacymodel.communication.command.CronCommand)

Example 5 with StartupAnswer

use of com.cloud.legacymodel.communication.answer.StartupAnswer in project cosmic by MissionCriticalCloud.

the class DirectAgentAttache method process.

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

Aggregations

StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)5 Response (com.cloud.common.transport.Response)2 Command (com.cloud.legacymodel.communication.command.Command)2 PingCommand (com.cloud.legacymodel.communication.command.PingCommand)2 Answer (com.cloud.legacymodel.communication.answer.Answer)1 CheckHealthCommand (com.cloud.legacymodel.communication.command.CheckHealthCommand)1 CronCommand (com.cloud.legacymodel.communication.command.CronCommand)1 PingRoutingCommand (com.cloud.legacymodel.communication.command.PingRoutingCommand)1 ReadyCommand (com.cloud.legacymodel.communication.command.ReadyCommand)1 ShutdownCommand (com.cloud.legacymodel.communication.command.ShutdownCommand)1 AgentControlCommand (com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand)1 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)1 StartupProxyCommand (com.cloud.legacymodel.communication.command.startup.StartupProxyCommand)1 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)1 StartupSecondaryStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand)1 StartupStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupStorageCommand)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1