Search in sources :

Example 31 with Command

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

the class Request method log.

protected String log(String msg, boolean logContent, Level level) {
    StringBuilder content = new StringBuilder();
    if (logContent) {
        if (_cmds == null) {
            try {
                _cmds = s_gson.fromJson(_content, this instanceof Response ? Answer[].class : Command[].class);
            } catch (RuntimeException e) {
                s_logger.error("Unable to deserialize from json: " + _content);
                throw e;
            }
        }
        try {
            s_gogger.toJson(_cmds, content);
        } catch (Throwable e) {
            StringBuilder buff = new StringBuilder();
            for (Command cmd : _cmds) {
                buff.append(cmd.getClass().getSimpleName()).append("/");
            }
            s_logger.error("Gson serialization error " + buff.toString(), e);
            assert false : "More gson errors on " + buff.toString();
            return "";
        }
        if (content.length() <= (1 + _cmds.length * 3)) {
            return null;
        }
    } else {
        if (_cmds == null) {
            _cmds = s_gson.fromJson(_content, this instanceof Response ? Answer[].class : Command[].class);
        }
        content.append("{ ");
        for (Command cmd : _cmds) {
            content.append(cmd.getClass().getSimpleName()).append(", ");
        }
        content.replace(content.length() - 2, content.length(), " }");
    }
    StringBuilder buf = new StringBuilder("Seq ");
    buf.append(_agentId).append("-").append(_seq).append(": ");
    buf.append(msg);
    buf.append(" { ").append(getType());
    if (_agentName != null) {
        buf.append(", MgmtId: ").append(_mgmtId).append(", via: ").append(_via).append("(" + _agentName + ")");
    } else {
        buf.append(", MgmtId: ").append(_mgmtId).append(", via: ").append(_via);
    }
    buf.append(", Ver: ").append(_ver.toString());
    buf.append(", Flags: ").append(Integer.toBinaryString(getFlags())).append(", ");
    String cleanContent = content.toString();
    if (cleanContent.contains("password")) {
        buf.append(cleanPassword(cleanContent));
    } else {
        buf.append(content);
    }
    buf.append(" }");
    return buf.toString();
}
Also used : Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Command(com.cloud.agent.api.Command)

Example 32 with Command

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

the class AgentManagerImpl method send.

@Override
public long send(final Long hostId, final Commands commands, final Listener listener) throws AgentUnavailableException {
    final AgentAttache agent = getAttache(hostId);
    if (agent.isClosed()) {
        throw new AgentUnavailableException("Agent " + agent.getId() + " is closed", agent.getId());
    }
    final Command[] cmds = checkForCommandsAndTag(commands);
    final Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
    req.setSequence(agent.getNextSequence());
    agent.send(req, listener);
    return req.getSequence();
}
Also used : 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) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Request(com.cloud.agent.transport.Request)

Example 33 with Command

use of com.cloud.agent.api.Command 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)

Aggregations

Command (com.cloud.agent.api.Command)33 Answer (com.cloud.agent.api.Answer)17 StartupCommand (com.cloud.agent.api.StartupCommand)17 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)13 PingCommand (com.cloud.agent.api.PingCommand)13 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)11 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)10 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)8 ReadyCommand (com.cloud.agent.api.ReadyCommand)8 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)8 MaintainCommand (com.cloud.agent.api.MaintainCommand)7 StartupAnswer (com.cloud.agent.api.StartupAnswer)7 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)6 CronCommand (com.cloud.agent.api.CronCommand)6 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)5 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)5 StartCommand (com.cloud.agent.api.StartCommand)5 Request (com.cloud.agent.transport.Request)5