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;
}
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));
}
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;
}
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();
}
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;
}
}
Aggregations