use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.
the class Agent method stop.
public void stop(final String reason) {
logger.info("Stopping the agent due to: {}", reason);
if (this._connection != null) {
final ShutdownCommand cmd = new ShutdownCommand(reason);
try {
if (this._link != null) {
final Request req = new Request(this._id != null ? this._id : -1, -1, cmd, false);
this._link.send(req.toBytes());
}
} catch (final ClosedChannelException e) {
logger.warn("Unable to send: " + cmd.toString());
} catch (final Exception e) {
logger.warn("Unable to send: " + cmd.toString() + " due to exception: ", e);
}
logger.debug("Sending shutdown to management server");
try {
Thread.sleep(1000);
} catch (final InterruptedException e) {
logger.debug("Who the heck interrupted me here?");
}
this._connection.stop();
this._connection = null;
}
if (this.resource != null) {
this.resource.stop();
}
this._urgentTaskPool.shutdownNow();
synchronized (this) {
this.notifyAll();
}
}
use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.
the class Agent method postRequest.
@Override
public void postRequest(final AgentControlCommand cmd) throws AgentControlChannelException {
final Request request = new Request(getId(), -1, new Command[] { cmd }, true, false);
request.setSequence(getNextSequence());
postRequest(request);
}
use of com.cloud.common.transport.Request 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.common.transport.Request in project cosmic by MissionCriticalCloud.
the class ClusteredAgentManagerImpl method finishRebalance.
protected void finishRebalance(final long hostId, final long futureOwnerId, final Event event) {
final boolean success = event == Event.RebalanceCompleted ? true : false;
if (s_logger.isDebugEnabled()) {
s_logger.debug("Finishing rebalancing for the agent " + hostId + " with event " + event);
}
final AgentAttache attache = findAttache(hostId);
if (attache == null || !(attache instanceof ClusteredAgentAttache)) {
s_logger.debug("Unable to find forward attache for the host id=" + hostId + ", assuming that the agent disconnected already");
this._hostTransferDao.completeAgentTransfer(hostId);
return;
}
final ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache) attache;
if (success) {
// 1) Set transfer mode to false - so the agent can start processing requests normally
forwardAttache.setTransferMode(false);
// 2) Get all transfer requests and route them to peer
Request requestToTransfer = forwardAttache.getRequestToTransfer();
while (requestToTransfer != null) {
s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + this._nodeId + " to " + futureOwnerId);
final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes());
if (!routeResult) {
logD(requestToTransfer.getBytes(), "Failed to route request to peer");
}
requestToTransfer = forwardAttache.getRequestToTransfer();
}
s_logger.debug("Management server " + this._nodeId + " completed agent " + hostId + " rebalance to " + futureOwnerId);
} else {
failRebalance(hostId);
}
s_logger.debug("Management server " + this._nodeId + " completed agent " + hostId + " rebalance");
this._hostTransferDao.completeAgentTransfer(hostId);
}
use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.
the class AgentAttache method sendNext.
protected synchronized void sendNext(final long seq) {
_currentSequence = null;
if (_requests.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(seq, "No more commands found"));
}
return;
}
final Request req = _requests.pop();
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(req.getSequence(), "Sending now. is current sequence."));
}
try {
send(req);
} catch (final AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(req.getSequence(), "Unable to send the next sequence"));
}
cancel(req.getSequence());
}
_currentSequence = req.getSequence();
}
Aggregations