Search in sources :

Example 1 with ExecResult

use of com.qlangtech.tis.assemble.ExecResult in project tis by qlangtech.

the class CoreAction method doCancelTask.

/**
 * 终止正在执行的任务
 *
 * @param context
 * @throws Exception
 */
@Func(value = PermissionConstant.APP_UPDATE)
public void doCancelTask(Context context) throws Exception {
    Integer taskId = this.getInt(IExecChainContext.KEY_TASK_ID);
    IWorkFlowBuildHistoryDAO workFlowBuildDAO = this.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO();
    WorkFlowBuildHistory buildHistory = workFlowBuildDAO.loadFromWriteDB(taskId);
    ExecResult processState = ExecResult.parse(buildHistory.getState());
    if (!processState.isProcessing()) {
        this.addErrorMessage(context, "当前任务状态为已终止,不能执行终止操作");
        return;
    }
    List<ConfigFileContext.Header> headers = Lists.newArrayList();
    headers.add(new ConfigFileContext.Header(IExecChainContext.KEY_TASK_ID, String.valueOf(taskId)));
    headers.add(new ConfigFileContext.Header(IParamContext.KEY_ASYN_JOB_NAME, String.valueOf(processState == ExecResult.ASYN_DOING)));
    headers.add(new ConfigFileContext.Header(IFullBuildContext.KEY_APP_NAME, IAppSourcePipelineController.DATAX_FULL_PIPELINE + buildHistory.getAppName()));
    TriggerBuildResult triggerResult = CoreAction.triggerBuild(this, context, ConfigFileContext.HTTPMethod.DELETE, Collections.emptyList(), headers);
    if (!triggerResult.success) {
        return;
    }
    WorkFlowBuildHistory record = new WorkFlowBuildHistory();
    record.setState((byte) ExecResult.CANCEL.getValue());
    WorkFlowBuildHistoryCriteria criteria = new WorkFlowBuildHistoryCriteria();
    criteria.createCriteria().andIdEqualTo(triggerResult.getTaskid());
    workFlowBuildDAO.updateByExampleSelective(record, criteria);
    this.addActionMessage(context, "已经成功终止当前任务");
    this.setBizResult(context, new ExtendWorkFlowBuildHistory(this.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().loadFromWriteDB(triggerResult.getTaskid())));
}
Also used : IWorkFlowBuildHistoryDAO(com.qlangtech.tis.workflow.dao.IWorkFlowBuildHistoryDAO) ExecResult(com.qlangtech.tis.assemble.ExecResult) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 2 with ExecResult

use of com.qlangtech.tis.assemble.ExecResult 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 3 with ExecResult

use of com.qlangtech.tis.assemble.ExecResult in project tis by qlangtech.

the class ExtendWorkFlowBuildHistory method getConsuming.

/**
 * 耗时
 *
 * @return
 */
public String getConsuming() {
    ExecResult result = ExecResult.parse(this.delegate.getState());
    Date endTime = ((result == ExecResult.FAILD || result == ExecResult.SUCCESS) && this.getEndTime() != null) ? this.getEndTime() : new Date();
    int consuming = (int) ((endTime.getTime() - this.getStartTime().getTime()) / 1000);
    if (consuming < 60) {
        return consuming + "秒";
    } else {
        return (consuming / 60) + "分钟";
    }
}
Also used : Date(java.util.Date) ExecResult(com.qlangtech.tis.assemble.ExecResult)

Example 4 with ExecResult

use of com.qlangtech.tis.assemble.ExecResult in project tis by qlangtech.

the class FullbuildWorkflowAction method doTaskComplete.

/**
 * 执行阶段结束
 * do_task_complete
 * @param context
 */
@Func(value = PermissionConstant.DATAFLOW_MANAGE, sideEffect = false)
public void doTaskComplete(Context context) {
    Integer taskid = this.getInt(IParamContext.KEY_TASK_ID);
    // 执行结果
    ExecResult execResult = ExecResult.parse(this.getInt(IParamContext.KEY_EXEC_RESULT));
    String[] asynJobsName = this.getStringArray(IParamContext.KEY_ASYN_JOB_NAME);
    updateWfHistory(taskid, execResult, asynJobsName, 0);
}
Also used : ExecResult(com.qlangtech.tis.assemble.ExecResult) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 5 with ExecResult

use of com.qlangtech.tis.assemble.ExecResult in project tis by qlangtech.

the class FullbuildWorkflowAction method updateAsynTaskState.

private void updateAsynTaskState(Integer taskid, String jobName, boolean execSuccess, int tryCount) {
    validateMaxCasRetryCount(taskid, tryCount);
    final WorkFlowBuildHistory history = getBuildHistory(taskid);
    if (ExecResult.ASYN_DOING != ExecResult.parse(history.getState())) {
        updateAsynTaskState(taskid, jobName, execSuccess, ++tryCount);
        return;
    }
    JSONObject status = JSON.parseObject(history.getAsynSubTaskStatus());
    JSONObject tskStat = status.getJSONObject(jobName);
    if (tskStat == null) {
        throw new IllegalStateException("jobName:" + jobName + " relevant status is not in history,now exist keys:" + status.keySet().stream().collect(Collectors.joining(",")));
    }
    tskStat.put(IParamContext.KEY_ASYN_JOB_COMPLETE, true);
    tskStat.put(IParamContext.KEY_ASYN_JOB_SUCCESS, execSuccess);
    status.put(jobName, tskStat);
    boolean[] allComplete = new boolean[] { true };
    boolean[] faild = new boolean[] { false };
    status.forEach((key, val) -> {
        JSONObject s = (JSONObject) val;
        if (s.getBoolean(IParamContext.KEY_ASYN_JOB_COMPLETE)) {
            if (!s.getBoolean(IParamContext.KEY_ASYN_JOB_SUCCESS)) {
                faild[0] = true;
            }
        } else {
            allComplete[0] = false;
        }
    });
    WorkFlowBuildHistory updateHistory = new WorkFlowBuildHistory();
    updateHistory.setAsynSubTaskStatus(status.toJSONString());
    updateHistory.setLastVer(history.getLastVer() + 1);
    ExecResult execResult = null;
    if (faild[0]) {
        // 有任务失败了
        execResult = ExecResult.FAILD;
    } else if (allComplete[0]) {
        execResult = ExecResult.SUCCESS;
    }
    if (execResult != null) {
        updateHistory.setState((byte) execResult.getValue());
        updateHistory.setEndTime(new Date());
    }
    WorkFlowBuildHistoryCriteria hq = new WorkFlowBuildHistoryCriteria();
    hq.createCriteria().andIdEqualTo(taskid).andLastVerEqualTo(history.getLastVer());
    if (getHistoryDAO().updateByExampleSelective(updateHistory, hq) < 1) {
        // System.out.println("old lastVer:" + history.getLastVer() + ",new UpdateVersion:" + updateHistory.getLastVer());
        updateAsynTaskState(taskid, jobName, execSuccess, ++tryCount);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Date(java.util.Date) 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