Search in sources :

Example 6 with ExecResult

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();
    }
}
Also used : ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpExecContext(com.qlangtech.tis.fullbuild.servlet.impl.HttpExecContext) DefaultChainContext(com.qlangtech.tis.exec.impl.DefaultChainContext) ExecResult(com.qlangtech.tis.assemble.ExecResult)

Example 7 with ExecResult

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();
}
Also used : WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory) ExecResult(com.qlangtech.tis.assemble.ExecResult)

Aggregations

ExecResult (com.qlangtech.tis.assemble.ExecResult)7 Func (com.qlangtech.tis.manage.spring.aop.Func)3 JSONObject (com.alibaba.fastjson.JSONObject)2 WorkFlowBuildHistory (com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)2 Date (java.util.Date)2 DefaultChainContext (com.qlangtech.tis.exec.impl.DefaultChainContext)1 HttpExecContext (com.qlangtech.tis.fullbuild.servlet.impl.HttpExecContext)1 IWorkFlowBuildHistoryDAO (com.qlangtech.tis.workflow.dao.IWorkFlowBuildHistoryDAO)1 WorkFlowBuildHistoryCriteria (com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistoryCriteria)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ServletException (javax.servlet.ServletException)1