Search in sources :

Example 11 with Response

use of com.cloud.agent.transport.Response in project cloudstack by apache.

the class DirectAgentAttache method send.

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

Example 12 with Response

use of com.cloud.agent.transport.Response in project cosmic by MissionCriticalCloud.

the class Agent method processOtherTask.

public void processOtherTask(final Task task) {
    final Object obj = task.get();
    if (obj instanceof Response) {
        if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * agentProperties.getPingRetries()) {
            logger.error("Ping Interval has gone past " + _pingInterval * agentProperties.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
            return;
        }
        final PingCommand ping = resource.getCurrentStatus(getId());
        final Request request = new Request(_id, -1, ping, false);
        request.setSequence(getNextSequence());
        if (logger.isDebugEnabled()) {
            logger.debug("Sending ping: " + request.toString());
        }
        try {
            task.getLink().send(request.toBytes());
            // if i can send pingcommand out, means the link is ok
            setLastPingResponseTime();
        } catch (final ClosedChannelException e) {
            logger.warn("Unable to send request: " + request.toString());
        }
    } else if (obj instanceof Request) {
        final Request req = (Request) obj;
        final Command command = req.getCommand();
        if (command.getContextParam("logid") != null) {
            MDC.put("logcontextid", command.getContextParam("logid"));
        }
        Answer answer = null;
        _inProgress.incrementAndGet();
        try {
            answer = resource.executeRequest(command);
        } finally {
            _inProgress.decrementAndGet();
        }
        if (answer != null) {
            final Response response = new Response(req, answer);
            if (logger.isDebugEnabled()) {
                logger.debug("Watch Sent: " + response.toString());
            }
            try {
                task.getLink().send(response.toBytes());
            } catch (final ClosedChannelException e) {
                logger.warn("Unable to send response: " + response.toString());
            }
        }
    } else {
        logger.warn("Ignoring an unknown task");
    }
}
Also used : Response(com.cloud.agent.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) StartupAnswer(com.cloud.agent.api.StartupAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) MaintainCommand(com.cloud.agent.api.MaintainCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Command(com.cloud.agent.api.Command) PingCommand(com.cloud.agent.api.PingCommand) ReadyCommand(com.cloud.agent.api.ReadyCommand) CronCommand(com.cloud.agent.api.CronCommand) Request(com.cloud.agent.transport.Request) PingCommand(com.cloud.agent.api.PingCommand)

Aggregations

Response (com.cloud.agent.transport.Response)12 Answer (com.cloud.agent.api.Answer)10 Command (com.cloud.agent.api.Command)10 PingCommand (com.cloud.agent.api.PingCommand)10 StartupAnswer (com.cloud.agent.api.StartupAnswer)10 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)8 CronCommand (com.cloud.agent.api.CronCommand)8 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)8 StartupCommand (com.cloud.agent.api.StartupCommand)8 ClosedChannelException (java.nio.channels.ClosedChannelException)8 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)6 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)6 MaintainCommand (com.cloud.agent.api.MaintainCommand)6 ReadyCommand (com.cloud.agent.api.ReadyCommand)6 Request (com.cloud.agent.transport.Request)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 ModifySshKeysCommand (com.cloud.agent.api.ModifySshKeysCommand)2 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)2 StartupProxyCommand (com.cloud.agent.api.StartupProxyCommand)2 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)2