}
private WebResponse processDebugCancel(MasterContext context, WebRequest req) {
WebResponse ret = null;
String debugId = req.getId();
DebugHistory history = context.getDebugHistoryManager()
.findDebugHistory(debugId);
SocketLog.info("receive web debug cancel request,rid=" + req.getRid()
+ ",debugId=" + debugId);
for (String debug : new ArrayList<String>(context.getDebugQueue())) {
if (debug.equals(debugId)) {
if (context.getDebugQueue().remove(debugId)) {
ret = WebResponse.newBuilder().setRid(req.getRid())
.setOperate(req.getOperate()).setStatus(Status.OK)
.build();
history.getLog().appendZeus("任务被取消");
context.getDebugHistoryManager().updateDebugHistoryLog(
history.getId(), history.getLog().getContent());
break;
}
}
}
for (Channel key : new HashSet<Channel>(context.getWorkers().keySet())) {
MasterWorkerHolder worker = context.getWorkers().get(key);
if (worker.getDebugRunnings().containsKey(debugId)) {
Future<Response> f = new MasterCancelJob().cancel(context,
worker.getChannel(), ExecuteKind.DebugKind, debugId);
worker.getDebugRunnings().remove(debugId);
try {
f.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
}
ret = WebResponse.newBuilder().setRid(req.getRid())
.setOperate(req.getOperate()).setStatus(Status.OK)
.build();
SocketLog.info("send web debug cancel response,rid="
+ req.getRid() + ",debugId=" + debugId);
}
}
if (ret == null) {
// 找不到job,失败
ret = WebResponse.newBuilder().setRid(req.getRid())
.setOperate(req.getOperate()).setStatus(Status.ERROR)
.setErrorText("Debug任务中找不到匹配的job("+history.getFileId()+","+history.getId()+"),无法执行取消命令").build();
}
// 再查一次,获取最新数据
history = context.getDebugHistoryManager().findDebugHistory(debugId);
history.setEndTime(new Date());
history.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
context.getDebugHistoryManager().updateDebugHistory(history);
return ret;
}