use of com.qlangtech.tis.fullbuild.servlet.impl.HttpExecContext in project tis by qlangtech.
the class BuildTriggerServlet method createHttpExecContext.
@Override
protected HttpExecContext createHttpExecContext(HttpServletRequest req) {
final Map<String, String> params = new HashMap<String, String>();
params.put(IFullBuildContext.KEY_APP_NAME, req.getParameter(KEY_INDEX_NAME));
params.put(AbstractActionInvocation.COMMAND_KEY_DIRECTBUILD, Boolean.TRUE.toString());
params.put(DefaultChainContext.KEY_PARTITION, req.getParameter(KEY_DUMP_START));
params.put(KEY_DUMP_ROW_COUNT, req.getParameter(KEY_DUMP_ROW_COUNT));
String hdfsSplitChar = null;
if ((hdfsSplitChar = req.getParameter(ImportDataProcessInfo.KEY_DELIMITER)) != null) {
params.put(ImportDataProcessInfo.KEY_DELIMITER, hdfsSplitChar);
}
HttpExecContext execContext = new HttpExecContext(req, params, false);
return execContext;
}
use of com.qlangtech.tis.fullbuild.servlet.impl.HttpExecContext 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.fullbuild.servlet.impl.HttpExecContext in project tis by qlangtech.
the class TisServlet method doDelete.
/**
* 执行任务终止
*
* @param req
* @param resp
* @throws ServletException
* @throws IOException
*/
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpExecContext execContext = new HttpExecContext(req, Maps.newHashMap(), true);
int taskId = execContext.getInt(IExecChainContext.KEY_TASK_ID);
// 当前是否是异步任务
final boolean asynJob = execContext.getBoolean(IExecChainContext.KEY_ASYN_JOB_NAME);
String appName = execContext.getString(IFullBuildContext.KEY_APP_NAME);
logger.info("receive a processing job CANCEL signal,taskId:{},asynJob:{},appName:{}", taskId, asynJob, appName);
if (asynJob) {
IncrStatusUmbilicalProtocolImpl incrController = IncrStatusUmbilicalProtocolImpl.getInstance();
// 给远程进程服下毒丸,让其终止
incrController.stop(appName);
} else {
Map.Entry<String, ExecuteLock> targetExecLock = null;
synchronized (this) {
for (Map.Entry<String, ExecuteLock> execLock : idles.entrySet()) {
if (execLock.getValue().matchTask(taskId)) {
targetExecLock = execLock;
}
}
if (targetExecLock == null) {
writeResult(false, "任务已经失效,无法终止", resp);
return;
}
targetExecLock.getValue().cancelAllFuture();
targetExecLock.getValue().clearLockFutureQueue();
}
}
PhaseStatusCollection phaseStatusCollection = TrackableExecuteInterceptor.getTaskPhaseReference(taskId);
if (phaseStatusCollection != null) {
// 这样会将当前状态写入本地磁盘
phaseStatusCollection.flushStatus2Local();
}
writeResult(true, null, resp, new KV(IExecChainContext.KEY_TASK_ID, String.valueOf(taskId)));
}
Aggregations