Search in sources :

Example 6 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class AgentManagerImpl method checkForCommandsAndTag.

/**
 * @param commands
 * @return
 */
private Command[] checkForCommandsAndTag(final Commands commands) {
    final Command[] cmds = commands.toCommands();
    assert cmds.length > 0 : "Ask yourself this about a hundred times.  Why am I  sending zero length commands?";
    setEmptyAnswers(commands, cmds);
    for (final Command cmd : cmds) {
        tagCommand(cmd);
    }
    return cmds;
}
Also used : 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)

Example 7 with Command

use of com.cloud.legacymodel.communication.command.Command 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 8 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class AgentManagerImpl method send.

@Override
public Answer[] send(final Long hostId, final Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
    assert hostId != null : "Who's not checking the agent id before sending?  ... (finger wagging)";
    if (hostId == null) {
        throw new AgentUnavailableException(-1);
    }
    if (timeout <= 0) {
        timeout = Wait.value();
    }
    if (this.CheckTxnBeforeSending.value()) {
        if (!noDbTxn()) {
            throw new CloudRuntimeException("We do not allow transactions to be wrapped around commands sent to be executed on remote agents.  " + "We cannot predict how long it takes a command to complete.  " + "The transaction may be rolled back because the connection took too long.");
        }
    } else {
        assert noDbTxn() : "I know, I know.  Why are we so strict as to not allow txn across an agent call?  ...  Why are we so cruel ... Why are we such a dictator .... Too" + " bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!";
    }
    final Command[] cmds = checkForCommandsAndTag(commands);
    final AgentAttache agent = getAttache(hostId);
    if (agent == null || agent.isClosed()) {
        throw new AgentUnavailableException("agent not logged into this management server", hostId);
    }
    final Request req = new Request(hostId, agent.getName(), this._nodeId, cmds, commands.stopOnError(), true);
    req.setSequence(agent.getNextSequence());
    final Answer[] answers = agent.send(req, timeout);
    notifyAnswersToMonitors(hostId, req.getSequence(), answers);
    commands.setAnswers(answers);
    return answers;
}
Also used : AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) PingAnswer(com.cloud.legacymodel.communication.answer.PingAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) 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) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Request(com.cloud.common.transport.Request)

Example 9 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class ClusteredAgentManagerImpl method propagateAgentEvent.

public Boolean propagateAgentEvent(final long agentId, final Event event) throws AgentUnavailableException {
    final String msPeer = getPeerName(agentId);
    if (msPeer == null) {
        return null;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Propagating agent change request event:" + event.toString() + " to agent:" + agentId);
    }
    final Command[] cmds = new Command[1];
    cmds[0] = new ChangeAgentCommand(agentId, event);
    final String ansStr = this._clusterMgr.execute(msPeer, agentId, this._gson.toJson(cmds), true);
    if (ansStr == null) {
        throw new AgentUnavailableException(agentId);
    }
    final Answer[] answers = this._gson.fromJson(ansStr, Answer[].class);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Result for agent change is " + answers[0].getResult());
    }
    return answers[0].getResult();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ChangeAgentAnswer(com.cloud.legacymodel.communication.answer.ChangeAgentAnswer) ScheduleHostScanTaskCommand(com.cloud.legacymodel.communication.command.ScheduleHostScanTaskCommand) CancelCommand(com.cloud.legacymodel.communication.command.CancelCommand) Command(com.cloud.legacymodel.communication.command.Command) PropagateResourceEventCommand(com.cloud.legacymodel.communication.command.PropagateResourceEventCommand) TransferAgentCommand(com.cloud.legacymodel.communication.command.TransferAgentCommand) ChangeAgentCommand(com.cloud.legacymodel.communication.command.ChangeAgentCommand) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ChangeAgentCommand(com.cloud.legacymodel.communication.command.ChangeAgentCommand)

Example 10 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class ClusteredAgentManagerImpl method sendRebalanceCommand.

private Answer[] sendRebalanceCommand(final long peer, final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) {
    final TransferAgentCommand transfer = new TransferAgentCommand(agentId, currentOwnerId, futureOwnerId, event);
    final Commands commands = new Commands(Command.OnError.Stop);
    commands.addCommand(transfer);
    final Command[] cmds = commands.toCommands();
    try {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Forwarding " + cmds[0].toString() + " to " + peer);
        }
        final String peerName = Long.toString(peer);
        final String cmdStr = this._gson.toJson(cmds);
        final String ansStr = this._clusterMgr.execute(peerName, agentId, cmdStr, true);
        final Answer[] answers = this._gson.fromJson(ansStr, Answer[].class);
        return answers;
    } catch (final Exception e) {
        s_logger.warn("Caught exception while talking to " + currentOwnerId, e);
        return null;
    }
}
Also used : TransferAgentCommand(com.cloud.legacymodel.communication.command.TransferAgentCommand) Answer(com.cloud.legacymodel.communication.answer.Answer) ChangeAgentAnswer(com.cloud.legacymodel.communication.answer.ChangeAgentAnswer) ScheduleHostScanTaskCommand(com.cloud.legacymodel.communication.command.ScheduleHostScanTaskCommand) CancelCommand(com.cloud.legacymodel.communication.command.CancelCommand) Command(com.cloud.legacymodel.communication.command.Command) PropagateResourceEventCommand(com.cloud.legacymodel.communication.command.PropagateResourceEventCommand) TransferAgentCommand(com.cloud.legacymodel.communication.command.TransferAgentCommand) ChangeAgentCommand(com.cloud.legacymodel.communication.command.ChangeAgentCommand) UnsupportedVersionException(com.cloud.legacymodel.exceptions.UnsupportedVersionException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ConfigurationException(javax.naming.ConfigurationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) TaskExecutionException(com.cloud.legacymodel.exceptions.TaskExecutionException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Aggregations

Command (com.cloud.legacymodel.communication.command.Command)21 Answer (com.cloud.legacymodel.communication.answer.Answer)13 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)10 AgentControlCommand (com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand)9 PingCommand (com.cloud.legacymodel.communication.command.PingCommand)8 ReadyCommand (com.cloud.legacymodel.communication.command.ReadyCommand)7 ShutdownCommand (com.cloud.legacymodel.communication.command.ShutdownCommand)7 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)7 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)7 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)7 PingRoutingCommand (com.cloud.legacymodel.communication.command.PingRoutingCommand)6 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)5 Response (com.cloud.common.transport.Response)4 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)4 CheckHealthCommand (com.cloud.legacymodel.communication.command.CheckHealthCommand)4 CronCommand (com.cloud.legacymodel.communication.command.CronCommand)4 MaintainCommand (com.cloud.legacymodel.communication.command.MaintainCommand)4 StartupProxyCommand (com.cloud.legacymodel.communication.command.startup.StartupProxyCommand)4 StartupSecondaryStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand)4 StartupStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupStorageCommand)4