private WebResponse processManualCancel(MasterContext context,
WebRequest req) {
WebResponse ret = null;
String historyId = req.getId();
JobHistory history = context.getJobHistoryManager().findJobHistory(
historyId);
SocketLog.info("receive web cancel request,rid=" + req.getRid()
+ ",jobId=" + history.getJobId());
String jobId = history.getId();
for (String job : new ArrayList<String>(context.getManualQueue())) {
if (job.equals(historyId)) {
if (context.getManualQueue().remove(job)) {
ret = WebResponse.newBuilder().setRid(req.getRid())
.setOperate(req.getOperate()).setStatus(Status.OK)
.build();
history.getLog().appendZeus("任务被取消");
context.getJobHistoryManager().updateJobHistoryLog(
history.getId(), history.getLog().getContent());
break;
}
}
}
if (history.getTriggerType() == TriggerType.MANUAL) {
for (Channel key : new HashSet<Channel>(context.getWorkers()
.keySet())) {
MasterWorkerHolder worker = context.getWorkers().get(key);
if (worker.getManualRunnings().containsKey(historyId)) {
Future<Response> f = new MasterCancelJob().cancel(context,
worker.getChannel(), ExecuteKind.ManualKind,
historyId);
worker.getManualRunnings().remove(historyId);
try {
f.get(30, TimeUnit.SECONDS);
} catch (Exception e) {
}
ret = WebResponse.newBuilder().setRid(req.getRid())
.setOperate(req.getOperate()).setStatus(Status.OK)
.build();
SocketLog.info("send web cancel response,rid="
+ req.getRid() + ",jobId=" + jobId);
}
}
}
if (ret == null) {
// 找不到job,失败
ret = WebResponse.newBuilder().setRid(req.getRid())
.setOperate(req.getOperate()).setStatus(Status.ERROR)
.setErrorText("Mannual任务中找不到匹配的job("+history.getJobId()+","+history.getId()+"),无法执行取消命令").build();
}
history = context.getJobHistoryManager().findJobHistory(historyId);
history.setEndTime(new Date());
history.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
context.getJobHistoryManager().updateJobHistory(history);
return ret;
}