use of com.qlangtech.tis.assemble.ExecResult in project tis by qlangtech.
the class TisServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
final HttpExecContext execContext = createHttpExecContext(req);
final MDCParamContext mdcContext = this.getMDCParam(execContext, res);
try {
if (!isValidParams(execContext, req, res)) {
return;
}
if (!mdcContext.validateParam()) {
return;
}
final ExecuteLock lock = mdcContext.getExecLock();
// getLog().info("start to execute index swap work flow");
final CountDownLatch countDown = new CountDownLatch(1);
DefaultChainContext chainContext = new DefaultChainContext(execContext);
chainContext.setMdcParamContext(mdcContext);
chainContext.setAppSourcePipelineController(IncrStatusUmbilicalProtocolImpl.getInstance());
final Integer newTaskId = createNewTask(chainContext);
lock.addTaskFuture(newTaskId, executeService.submit(() -> {
// MDC.put("app", indexName);
getLog().info("index swap start to work");
try {
while (true) {
try {
if (lock.lock()) {
try {
String msg = "trigger task" + mdcContext.getExecLockKey() + " successful";
getLog().info(msg);
mdcContext.resetParam(newTaskId);
writeResult(true, msg, res, new KV(IExecChainContext.KEY_TASK_ID, String.valueOf(newTaskId)));
// IndexBuilderTriggerFactory builderFactory = HeteroEnum.INDEX_BUILD_CONTAINER.getPlugin();
// Objects.requireNonNull(builderFactory, "builderFactory can not be null");
// chainContext.setIndexBuildFileSystem(builderFactory.getFsFactory());
// chainContext.setIndexBuilderTriggerFactory(builderFactory);
// IPluginStore<TableDumpFactory> tableDumpFactory = TIS.getPluginStore(TableDumpFactory.class);
// if (tableDumpFactory.getPlugin() != null) {
// Objects.requireNonNull(tableDumpFactory.getPlugin(), "tableDumpFactory can not be null");
// chainContext.setTableDumpFactory(tableDumpFactory.getPlugin());
// }
countDown.countDown();
/**
**********************************************************
* 开始执行内部任务
***********************************************************
*/
ExecResult execResult = startWork(chainContext).isSuccess() ? ExecResult.SUCCESS : ExecResult.FAILD;
DagTaskUtils.createTaskComplete(newTaskId, chainContext, execResult);
} catch (InterruptedException e) {
// 说明当前任务被 终止了
logger.info("taskid:{} has been canceled", newTaskId);
return;
} catch (Throwable e) {
DagTaskUtils.createTaskComplete(newTaskId, chainContext, ExecResult.FAILD);
getLog().error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
lock.clearLockFutureQueue();
}
} else {
if (lock.isExpire()) {
getLog().warn("this lock has expire,this lock will cancel");
// 执行已經超時
lock.clearLockFutureQueue();
// while (lock.futureQueue.size() >= 1)
// {
// lock.futureQueue.poll().cancel(true);
// }
getLog().warn("this lock[" + lock.getTaskOwnerUniqueName() + "] has expire,has unlocked");
continue;
} else {
String msg = "pre task[" + lock.getTaskOwnerUniqueName() + "] is executing ,so this commit will be ignore";
getLog().warn(msg);
writeResult(false, msg, res);
}
countDown.countDown();
}
// }
break;
} catch (Throwable e) {
getLog().error(e.getMessage(), e);
try {
if (countDown.getCount() > 0) {
writeResult(false, ExceptionUtils.getMessage(e), res);
}
} catch (Exception e1) {
} finally {
try {
countDown.countDown();
} catch (Throwable ee) {
}
}
break;
}
}
} finally {
mdcContext.removeParam();
}
// end run
}));
try {
countDown.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
}
} finally {
mdcContext.removeParam();
}
}
use of com.qlangtech.tis.assemble.ExecResult in project tis by qlangtech.
the class DataXJobConsumer method isCurrentJobProcessing.
@Override
protected boolean isCurrentJobProcessing(Integer jobId) {
WorkFlowBuildHistory wfStatus = DagTaskUtils.getWFStatus(jobId);
ExecResult execStat = ExecResult.parse(wfStatus.getState());
return execStat.isProcessing();
}
Aggregations