Search in sources :

Example 1 with CreateNewTaskResult

use of com.qlangtech.tis.manage.common.CreateNewTaskResult in project tis by qlangtech.

the class TestFullbuildWorkflowAction method testAsynJobExecute.

/**
 * 执行异步任务 创建->任务提提交->等待反馈-> 完成
 *
 * @throws Exception
 */
public void testAsynJobExecute() throws Exception {
    FullbuildWorkflowAction.MAX_CAS_RETRY_COUNT = 100;
    /**
     *=====================================================
     * 创建任务
     *     =======================================================
     */
    int taskId = -1;
    final int subTaskSize = 20;
    try {
        String dataxName = "ttt";
        request.setParameter("emethod", "createNewTask");
        request.setParameter("action", "fullbuild_workflow_action");
        request.setParameter(IFullBuildContext.KEY_TRIGGER_TYPE, String.valueOf(TriggerType.MANUAL.getValue()));
        request.setParameter(IFullBuildContext.KEY_APP_NAME, dataxName);
        ActionProxy proxy = getActionProxy();
        this.replay();
        String result = proxy.execute();
        assertEquals("FullbuildWorkflowAction_ajax", result);
        AjaxValve.ActionExecResult aResult = showBizResult();
        assertNotNull(aResult);
        assertTrue(aResult.isSuccess());
        CreateNewTaskResult bizResult = (CreateNewTaskResult) aResult.getBizResult();
        assertNotNull(bizResult);
        taskId = bizResult.getTaskid();
        assertTrue(taskId > 0);
        this.verifyAll();
        this.setUp();
        /**
         *======================================================
         * 提交异步任务
         *       ========================================================
         */
        request.setParameter("emethod", "taskComplete");
        request.setParameter("action", "fullbuild_workflow_action");
        request.setParameter(IParamContext.KEY_TASK_ID, String.valueOf(taskId));
        request.setParameter(IParamContext.KEY_EXEC_RESULT, String.valueOf(ExecResult.SUCCESS.getValue()));
        Set<String> jobs = Sets.newHashSet();
        String[] jobsName = new String[subTaskSize];
        for (int i = 0; i < subTaskSize; i++) {
            jobsName[i] = "customer_order_relation_" + i + ".json";
            jobs.add(jobsName[i]);
        }
        request.setParameter(IParamContext.KEY_ASYN_JOB_NAME, jobsName);
        proxy = getActionProxy();
        result = proxy.execute();
        assertEquals("FullbuildWorkflowAction_ajax", result);
        aResult = showBizResult();
        assertNotNull(aResult);
        assertTrue(aResult.isSuccess());
        WorkFlowBuildHistory history = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
        assertNotNull("taskid:" + taskId + " relevant history", history);
        assertTrue(ExecResult.parse(history.getState()) == ExecResult.ASYN_DOING);
        JSONObject subTaskStatus = JSON.parseObject(history.getAsynSubTaskStatus());
        assertEquals(subTaskSize, subTaskStatus.keySet().size());
        subTaskStatus.forEach((key, val) -> {
            assertTrue(jobs.contains(key));
            JSONObject s = (JSONObject) val;
            assertFalse(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_SUCCESS));
            assertFalse(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_COMPLETE));
        });
        /**
         *======================================================
         * 等待接收反馈信息
         *       ========================================================
         */
        ExecutorService executorService = Executors.newFixedThreadPool(20);
        Throwable[] excep = new Throwable[1];
        CountDownLatch countDown = new CountDownLatch(subTaskSize);
        final int tskid = taskId;
        for (String jobName : jobsName) {
            executorService.submit(() -> {
                try {
                    TestFullbuildWorkflowAction subTest = new TestFullbuildWorkflowAction();
                    subTest.setUp();
                    subTest.feedbackAsynTaskStatus(tskid, jobName);
                    subTest.tearDown();
                } catch (Throwable e) {
                    excep[0] = e;
                } finally {
                    countDown.countDown();
                }
            });
        // this.setUp();
        // feedbackAsynTaskStatus(tskid, jobName);
        }
        countDown.await();
        if (excep[0] != null) {
            throw new RuntimeException(excep[0]);
        }
        history = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
        subTaskStatus = JSON.parseObject(history.getAsynSubTaskStatus());
        assertEquals(subTaskSize, subTaskStatus.keySet().size());
        subTaskStatus.forEach((key, val) -> {
            assertTrue(jobs.contains(key));
            JSONObject s = (JSONObject) val;
            assertTrue(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_SUCCESS));
            assertTrue(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_COMPLETE));
        });
        assertEquals(ExecResult.SUCCESS, ExecResult.parse(history.getState()));
        assertEquals((int) subTaskSize + 1, (int) history.getLastVer());
    } finally {
        if (taskId > 0) {
            this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().deleteByPrimaryKey(taskId);
        }
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) CountDownLatch(java.util.concurrent.CountDownLatch) JSONObject(com.alibaba.fastjson.JSONObject) CreateNewTaskResult(com.qlangtech.tis.manage.common.CreateNewTaskResult) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) ExecutorService(java.util.concurrent.ExecutorService) WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)

Example 2 with CreateNewTaskResult

use of com.qlangtech.tis.manage.common.CreateNewTaskResult in project tis by qlangtech.

the class FullbuildWorkflowAction method doFeedbackAsynTaskStatus.

/**
 * 接收异步执行任务执行状态
 *
 * @param context
 */
@Func(value = PermissionConstant.DATAFLOW_MANAGE, sideEffect = false)
public void doFeedbackAsynTaskStatus(Context context) {
    Integer taskid = this.getInt(IParamContext.KEY_TASK_ID);
    String jobName = this.getString(IParamContext.KEY_ASYN_JOB_NAME);
    boolean execSuccess = this.getBoolean(IParamContext.KEY_ASYN_JOB_SUCCESS);
    this.updateAsynTaskState(taskid, jobName, execSuccess, 0);
    this.setBizResult(context, new CreateNewTaskResult(taskid, null));
}
Also used : CreateNewTaskResult(com.qlangtech.tis.manage.common.CreateNewTaskResult) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 3 with CreateNewTaskResult

use of com.qlangtech.tis.manage.common.CreateNewTaskResult in project tis by qlangtech.

the class FullbuildWorkflowAction method doCreateNewTask.

/**
 * assemble 节点接收到来自console节点的触发任务,开始执行需要创建一个new的workflowbuildhistory记录
 *
 * @param context
 */
@Func(value = PermissionConstant.DATAFLOW_MANAGE, sideEffect = false)
public void doCreateNewTask(Context context) {
    final TriggerType triggerType = TriggerType.parse(this.getInt(IFullBuildContext.KEY_TRIGGER_TYPE));
    Application app = null;
    // appname 可以为空
    String appname = this.getString(IFullBuildContext.KEY_APP_NAME);
    if (StringUtils.isNotBlank(appname)) {
        app = this.getApplicationDAO().selectByName(appname);
        if (app == null) {
            throw new IllegalStateException("appname:" + appname + " relevant app pojo is not exist");
        }
    }
    WorkFlowBuildHistory task = new WorkFlowBuildHistory();
    task.setCreateTime(new Date());
    task.setStartTime(new Date());
    // task.setWorkFlowId(worflowid);
    task.setTriggerType(triggerType.getValue());
    task.setState((byte) ExecResult.DOING.getValue());
    // Integer buildHistoryId = null;
    // 从什么阶段开始执行
    FullbuildPhase fromPhase = FullbuildPhase.parse(getInt(IParamContext.COMPONENT_START, FullbuildPhase.FullDump.getValue()));
    FullbuildPhase endPhase = FullbuildPhase.parse(getInt(IParamContext.COMPONENT_END, FullbuildPhase.IndexBackFlow.getValue()));
    if (app == null) {
        if (endPhase.bigThan(FullbuildPhase.JOIN)) {
            endPhase = FullbuildPhase.JOIN;
        }
    }
    if (fromPhase.getValue() > FullbuildPhase.FullDump.getValue()) {
        // 如果是从非第一步开始执行的话,需要客户端提供依赖的history记录id
        task.setHistoryId(this.getInt(IFullBuildContext.KEY_BUILD_HISTORY_TASK_ID));
    }
    // 说明只有workflow的流程和索引没有关系,所以不可能执行到索引build阶段去
    // task.setEndPhase((app == null) ? FullbuildPhase.JOIN.getValue() : FullbuildPhase.IndexBackFlow.getValue());
    task.setEndPhase(endPhase.getValue());
    task.setStartPhase(fromPhase.getValue());
    if (app != null) {
        task.setAppId(app.getAppId());
        task.setAppName(app.getProjectName());
    }
    // 生成一个新的taskid
    this.setBizResult(context, new CreateNewTaskResult(getHistoryDAO().insertSelective(task), app));
}
Also used : TriggerType(com.qlangtech.tis.assemble.TriggerType) CreateNewTaskResult(com.qlangtech.tis.manage.common.CreateNewTaskResult) Application(com.qlangtech.tis.manage.biz.dal.pojo.Application) FullbuildPhase(com.qlangtech.tis.assemble.FullbuildPhase) Date(java.util.Date) Func(com.qlangtech.tis.manage.spring.aop.Func)

Aggregations

CreateNewTaskResult (com.qlangtech.tis.manage.common.CreateNewTaskResult)3 Func (com.qlangtech.tis.manage.spring.aop.Func)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 FullbuildPhase (com.qlangtech.tis.assemble.FullbuildPhase)1 TriggerType (com.qlangtech.tis.assemble.TriggerType)1 Application (com.qlangtech.tis.manage.biz.dal.pojo.Application)1 AjaxValve (com.qlangtech.tis.manage.common.valve.AjaxValve)1 WorkFlowBuildHistory (com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)1 Date (java.util.Date)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1