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