Search in sources :

Example 1 with WorkFlowBuildHistory

use of com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory in project tis by qlangtech.

the class DefaultChainContext method loadPhaseStatusFromLatest.

@Override
public PhaseStatusCollection loadPhaseStatusFromLatest(String appName) {
    Optional<WorkFlowBuildHistory> latestWFSuccessTask = DagTaskUtils.getLatestWFSuccessTaskId(appName);
    if (!latestWFSuccessTask.isPresent()) {
        return null;
    }
    WorkFlowBuildHistory h = latestWFSuccessTask.get();
    PhaseStatusCollection phaseStatusCollection = IndexSwapTaskflowLauncher.loadPhaseStatusFromLocal(h.getId());
    if (phaseStatusCollection == null) {
        return null;
    }
    return phaseStatusCollection;
}
Also used : PhaseStatusCollection(com.qlangtech.tis.fullbuild.phasestatus.PhaseStatusCollection) WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)

Example 2 with WorkFlowBuildHistory

use of com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory 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 3 with WorkFlowBuildHistory

use of com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory in project tis by qlangtech.

the class TestFullbuildWorkflowAction method feedbackAsynTaskStatus.

// public void testFeedbackAsynTaskStatus() throws Exception {
// feedbackAsynTaskStatus(887, "customer_order_relation_7.json");
// while (true) {
// WorkFlowBuildHistory buildHistory = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(887);
// System.out.println("last_ver:" + buildHistory.getLastVer());
// Thread.sleep(1000);
// }
// }
private void feedbackAsynTaskStatus(int taskId, String jobName) throws Exception {
    WorkFlowBuildHistory buildHistory = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
    assertNotNull("buildHistory can not be null", buildHistory);
    request.setParameter(IParamContext.KEY_REQUEST_DISABLE_TRANSACTION, String.valueOf(true));
    request.setParameter("emethod", "feedbackAsynTaskStatus");
    request.setParameter("action", "fullbuild_workflow_action");
    request.setParameter(IParamContext.KEY_TASK_ID, String.valueOf(taskId));
    request.setParameter(IParamContext.KEY_ASYN_JOB_NAME, jobName);
    request.setParameter(IParamContext.KEY_ASYN_JOB_SUCCESS, String.valueOf(true));
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("FullbuildWorkflowAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)

Example 4 with WorkFlowBuildHistory

use of com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory in project tis by qlangtech.

the class DataxAction method doGetExecStatistics.

@Func(value = PermissionConstant.DATAX_MANAGE, sideEffect = false)
public void doGetExecStatistics(Context context) throws Exception {
    WorkFlowBuildHistoryCriteria historyCriteria = new WorkFlowBuildHistoryCriteria();
    Date from = ManageUtils.getOffsetDate(-7);
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd");
    Map<String, DataXExecStatus> execStatis = Maps.newTreeMap();
    ExecResult execResult = null;
    DataXExecStatus execStatus = null;
    String timeLab = null;
    for (int i = 0; i < 8; i++) {
        timeLab = dateFormat.format(ManageUtils.getOffsetDate(-i));
        execStatis.put(timeLab, new DataXExecStatus(timeLab));
    }
    int successCount = 0;
    int errCount = 0;
    historyCriteria.createCriteria().andAppIdEqualTo(this.getAppDomain().getAppid()).andCreateTimeGreaterThan(from);
    for (WorkFlowBuildHistory h : this.wfDAOFacade.getWorkFlowBuildHistoryDAO().selectByExample(historyCriteria)) {
        execResult = ExecResult.parse(h.getState());
        execStatus = execStatis.get(dateFormat.format(h.getCreateTime()));
        if (execStatus == null) {
            continue;
        }
        if (execResult == ExecResult.SUCCESS) {
            execStatus.successCount++;
            successCount++;
        } else if (execResult == ExecResult.FAILD) {
            execStatus.errCount++;
            errCount++;
        }
    }
    Map<String, Object> bizResult = Maps.newHashMap();
    bizResult.put("data", execStatis.values());
    Map<String, Integer> allStatis = Maps.newHashMap();
    allStatis.put("errCount", errCount);
    allStatis.put("successCount", successCount);
    bizResult.put("statis", allStatis);
    this.setBizResult(context, bizResult);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory) WorkFlowBuildHistoryCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistoryCriteria) ExecResult(com.qlangtech.tis.assemble.ExecResult) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 5 with WorkFlowBuildHistory

use of com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory in project tis by qlangtech.

the class WorkFlowBuildHistoryDAOImpl method deleteByPrimaryKey.

public int deleteByPrimaryKey(Integer id) {
    WorkFlowBuildHistory key = new WorkFlowBuildHistory();
    key.setId(id);
    return this.deleteRecords("work_flow_build_history.ibatorgenerated_deleteByPrimaryKey", key);
}
Also used : WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)

Aggregations

WorkFlowBuildHistory (com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)8 JSONObject (com.alibaba.fastjson.JSONObject)2 ActionProxy (com.opensymphony.xwork2.ActionProxy)2 ExecResult (com.qlangtech.tis.assemble.ExecResult)2 AjaxValve (com.qlangtech.tis.manage.common.valve.AjaxValve)2 PhaseStatusCollection (com.qlangtech.tis.fullbuild.phasestatus.PhaseStatusCollection)1 CreateNewTaskResult (com.qlangtech.tis.manage.common.CreateNewTaskResult)1 Func (com.qlangtech.tis.manage.spring.aop.Func)1 WorkFlowBuildHistoryCriteria (com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistoryCriteria)1 SimpleDateFormat (java.text.SimpleDateFormat)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1