Search in sources :

Example 1 with ExecutorBiz

use of com.xxl.job.core.biz.ExecutorBiz in project xxl-job by xuxueli.

the class XxlJobDynamicScheduler method getExecutorBiz.

public static ExecutorBiz getExecutorBiz(String address) throws Exception {
    // valid
    if (address == null || address.trim().length() == 0) {
        return null;
    }
    // load-cache
    address = address.trim();
    ExecutorBiz executorBiz = executorBizRepository.get(address);
    if (executorBiz != null) {
        return executorBiz;
    }
    // set-cache
    executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, address, accessToken).getObject();
    executorBizRepository.put(address, executorBiz);
    return executorBiz;
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) NetComClientProxy(com.xxl.job.core.rpc.netcom.NetComClientProxy)

Example 2 with ExecutorBiz

use of com.xxl.job.core.biz.ExecutorBiz in project xxl-job by xuxueli.

the class XxlJobTrigger method runExecutor.

/**
 * run executor
 * @param triggerParam
 * @param address
 * @return  ReturnT.content: final address
 */
public static ReturnT<String> runExecutor(TriggerParam triggerParam, String address) {
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
        runResult = executorBiz.run(triggerParam);
    } catch (Exception e) {
        logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e);
        runResult = new ReturnT<String>(ReturnT.FAIL_CODE, "" + e);
    }
    StringBuffer runResultSB = new StringBuffer(I18nUtil.getString("jobconf_trigger_run") + ":");
    runResultSB.append("<br>address:").append(address);
    runResultSB.append("<br>code:").append(runResult.getCode());
    runResultSB.append("<br>msg:").append(runResult.getMsg());
    runResult.setMsg(runResultSB.toString());
    runResult.setContent(address);
    return runResult;
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) ReturnT(com.xxl.job.core.biz.model.ReturnT)

Example 3 with ExecutorBiz

use of com.xxl.job.core.biz.ExecutorBiz in project xxl-job by xuxueli.

the class JobLogController method logKill.

@RequestMapping("/logKill")
@ResponseBody
public ReturnT<String> logKill(int id) {
    // base check
    XxlJobLog log = xxlJobLogDao.load(id);
    XxlJobInfo jobInfo = xxlJobInfoDao.loadById(log.getJobId());
    if (jobInfo == null) {
        return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
    }
    if (ReturnT.SUCCESS_CODE != log.getTriggerCode()) {
        return new ReturnT<String>(500, I18nUtil.getString("joblog_kill_log_limit"));
    }
    // request of kill
    ReturnT<String> runResult = null;
    try {
        ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(log.getExecutorAddress());
        runResult = executorBiz.kill(jobInfo.getId());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        runResult = new ReturnT<String>(500, e.getMessage());
    }
    if (ReturnT.SUCCESS_CODE == runResult.getCode()) {
        log.setHandleCode(ReturnT.FAIL_CODE);
        log.setHandleMsg(I18nUtil.getString("joblog_kill_log_byman") + ":" + (runResult.getMsg() != null ? runResult.getMsg() : ""));
        log.setHandleTime(new Date());
        xxlJobLogDao.updateHandleInfo(log);
        return new ReturnT<String>(runResult.getMsg());
    } else {
        return new ReturnT<String>(500, runResult.getMsg());
    }
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) ReturnT(com.xxl.job.core.biz.model.ReturnT) XxlJobLog(com.xxl.job.admin.core.model.XxlJobLog) ParseException(java.text.ParseException) Date(java.util.Date) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ExecutorBiz

use of com.xxl.job.core.biz.ExecutorBiz in project xxl-job by xuxueli.

the class ExecutorRouteBusyover method routeRun.

@Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
    StringBuffer idleBeatResultSB = new StringBuffer();
    for (String address : addressList) {
        // beat
        ReturnT<String> idleBeatResult = null;
        try {
            ExecutorBiz executorBiz = XxlJobDynamicScheduler.getExecutorBiz(address);
            idleBeatResult = executorBiz.idleBeat(triggerParam.getJobId());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            idleBeatResult = new ReturnT<String>(ReturnT.FAIL_CODE, "" + e);
        }
        idleBeatResultSB.append((idleBeatResultSB.length() > 0) ? "<br><br>" : "").append(I18nUtil.getString("jobconf_idleBeat") + ":").append("<br>address:").append(address).append("<br>code:").append(idleBeatResult.getCode()).append("<br>msg:").append(idleBeatResult.getMsg());
        // beat success
        if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
            ReturnT<String> runResult = XxlJobTrigger.runExecutor(triggerParam, address);
            idleBeatResultSB.append("<br><br>").append(runResult.getMsg());
            // result
            runResult.setMsg(idleBeatResultSB.toString());
            runResult.setContent(address);
            return runResult;
        }
    }
    return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString());
}
Also used : ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) ReturnT(com.xxl.job.core.biz.model.ReturnT)

Example 5 with ExecutorBiz

use of com.xxl.job.core.biz.ExecutorBiz in project xxl-job by xuxueli.

the class DemoJobHandlerTest method main.

public static void main(String[] args) throws Exception {
    // param
    String jobHandler = "demoJobHandler";
    String params = "";
    // trigger data
    TriggerParam triggerParam = new TriggerParam();
    triggerParam.setJobId(1);
    triggerParam.setExecutorHandler(jobHandler);
    triggerParam.setExecutorParams(params);
    triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
    triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
    triggerParam.setGlueSource(null);
    triggerParam.setGlueUpdatetime(System.currentTimeMillis());
    triggerParam.setLogId(1);
    triggerParam.setLogDateTim(System.currentTimeMillis());
    // do remote trigger
    String accessToken = null;
    ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, "127.0.0.1:9999", null).getObject();
    ReturnT<String> runResult = executorBiz.run(triggerParam);
}
Also used : TriggerParam(com.xxl.job.core.biz.model.TriggerParam) ExecutorBiz(com.xxl.job.core.biz.ExecutorBiz) NetComClientProxy(com.xxl.job.core.rpc.netcom.NetComClientProxy)

Aggregations

ExecutorBiz (com.xxl.job.core.biz.ExecutorBiz)7 ReturnT (com.xxl.job.core.biz.model.ReturnT)4 XxlJobLog (com.xxl.job.admin.core.model.XxlJobLog)2 NetComClientProxy (com.xxl.job.core.rpc.netcom.NetComClientProxy)2 ParseException (java.text.ParseException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 XxlJobInfo (com.xxl.job.admin.core.model.XxlJobInfo)1 LogResult (com.xxl.job.core.biz.model.LogResult)1 TriggerParam (com.xxl.job.core.biz.model.TriggerParam)1 Date (java.util.Date)1