diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteBusyover.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteBusyover.java index 7a8dfc04..837e3d18 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteBusyover.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteBusyover.java @@ -32,7 +32,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter { logger.error(e.getMessage(), e); idleBeatResult = new ReturnT(ReturnT.FAIL_CODE, ""+e ); } - idleBeatResultSB.append("
----------------------
") + idleBeatResultSB.append( (idleBeatResultSB.length()>0)?"

":"") .append("空闲检测:") .append("
address:").append(address) .append("
code:").append(idleBeatResult.getCode()) @@ -43,7 +43,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter { jobLog.setExecutorAddress(address); ReturnT runResult = runExecutor(triggerParam, address); - idleBeatResultSB.append("
----------------------
").append(runResult.getMsg()); + idleBeatResultSB.append("

").append(runResult.getMsg()); return new ReturnT(runResult.getCode(), idleBeatResultSB.toString()); } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteConsistentHash.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteConsistentHash.java index 9cb5cac6..08cc6c85 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteConsistentHash.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteConsistentHash.java @@ -85,8 +85,6 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFailover.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFailover.java index c70e460f..2b25a909 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFailover.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFailover.java @@ -32,7 +32,7 @@ public class ExecutorRouteFailover extends ExecutorRouter { logger.error(e.getMessage(), e); beatResult = new ReturnT(ReturnT.FAIL_CODE, ""+e ); } - beatResultSB.append("
----------------------
") + beatResultSB.append( (beatResultSB.length()>0)?"

":"") .append("心跳检测:") .append("
address:").append(address) .append("
code:").append(beatResult.getCode()) @@ -43,7 +43,7 @@ public class ExecutorRouteFailover extends ExecutorRouter { jobLog.setExecutorAddress(address); ReturnT runResult = runExecutor(triggerParam, address); - beatResultSB.append("
----------------------
").append(runResult.getMsg()); + beatResultSB.append("

").append(runResult.getMsg()); return new ReturnT(runResult.getCode(), beatResultSB.toString()); } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFirst.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFirst.java index 3c185957..181ab1e4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFirst.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteFirst.java @@ -25,8 +25,6 @@ public class ExecutorRouteFirst extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java index e2403efd..ade528f3 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java @@ -65,8 +65,6 @@ public class ExecutorRouteLFU extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java index ef55227f..3c309c86 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java @@ -64,8 +64,6 @@ public class ExecutorRouteLRU extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLast.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLast.java index fe863cc3..f1369ffc 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLast.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLast.java @@ -24,8 +24,6 @@ public class ExecutorRouteLast extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRandom.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRandom.java index c05a1750..6014c038 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRandom.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRandom.java @@ -28,8 +28,6 @@ public class ExecutorRouteRandom extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java index 726b8906..83bae76b 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java @@ -44,10 +44,6 @@ public class ExecutorRouteRound extends ExecutorRouter { // run executor ReturnT runResult = runExecutor(triggerParam, address); - runResult.setMsg("
----------------------
" + runResult.getMsg()); - return runResult; - - } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java index bd142fdf..940c4eb8 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java @@ -31,87 +31,79 @@ public class XxlJobTrigger { */ public static void trigger(int jobId) { - // load job - XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId); + // load data + XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId); // job info + XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup()); // group info - // log part-1 + ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION); // block strategy + ExecutorFailStrategyEnum failStrategy = ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), ExecutorFailStrategyEnum.FAIL_ALARM); // fail strategy + ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null); // route strategy + ArrayList addressList = (ArrayList) group.getRegistryList(); + + // 1、save log-id XxlJobLog jobLog = new XxlJobLog(); jobLog.setJobGroup(jobInfo.getJobGroup()); jobLog.setJobId(jobInfo.getId()); XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog); logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId()); - // log part-2 param + // 2、prepare trigger-info //jobLog.setExecutorAddress(executorAddress); jobLog.setGlueType(jobInfo.getGlueType()); jobLog.setExecutorHandler(jobInfo.getExecutorHandler()); jobLog.setExecutorParam(jobInfo.getExecutorParam()); jobLog.setTriggerTime(new Date()); - // trigger request - TriggerParam triggerParam = new TriggerParam(); - triggerParam.setJobId(jobInfo.getId()); - triggerParam.setExecutorHandler(jobInfo.getExecutorHandler()); - triggerParam.setExecutorParams(jobInfo.getExecutorParam()); - triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy()); - triggerParam.setGlueType(jobInfo.getGlueType()); - triggerParam.setGlueSource(jobInfo.getGlueSource()); - triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime()); - triggerParam.setLogId(jobLog.getId()); - triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime()); - - // do trigger - ReturnT triggerResult = doTrigger(triggerParam, jobInfo, jobLog); - - // fail retry - if (triggerResult.getCode()==ReturnT.FAIL_CODE && - ExecutorFailStrategyEnum.match(jobInfo.getExecutorFailStrategy(), null) == ExecutorFailStrategyEnum.FAIL_RETRY) { - ReturnT retryTriggerResult = doTrigger(triggerParam, jobInfo, jobLog); - - triggerResult.setCode(retryTriggerResult.getCode()); - triggerResult.setMsg(triggerResult.getMsg() + "

>>>>>>>>>>>失败重试<<<<<<<<<<<

" +retryTriggerResult.getMsg()); + ReturnT triggerResult = new ReturnT(null); + StringBuffer triggerMsgSb = new StringBuffer(); + triggerMsgSb.append("注册方式:").append( (group.getAddressType() == 0)?"自动注册":"手动录入" ); + triggerMsgSb.append("
阻塞处理策略:").append(blockStrategy.getTitle()); + triggerMsgSb.append("
失败处理策略:").append(failStrategy.getTitle()); + triggerMsgSb.append("
地址列表:").append(group.getRegistryList()); + triggerMsgSb.append("
路由策略:").append(executorRouteStrategyEnum.getTitle()); + + // 3、trigger-valid + if (triggerResult.getCode()==ReturnT.SUCCESS_CODE && CollectionUtils.isEmpty(addressList)) { + triggerResult.setCode(ReturnT.FAIL_CODE); + triggerMsgSb.append("
----------------------
").append("调度失败:").append("执行器地址为空"); + } + if (triggerResult.getCode() == ReturnT.SUCCESS_CODE && executorRouteStrategyEnum == null) { + triggerResult.setCode(ReturnT.FAIL_CODE); + triggerMsgSb.append("
----------------------
").append("调度失败:").append("执行器路由策略为空"); + } + + if (triggerResult.getCode() == ReturnT.SUCCESS_CODE) { + // 4.1、trigger-param + TriggerParam triggerParam = new TriggerParam(); + triggerParam.setJobId(jobInfo.getId()); + triggerParam.setExecutorHandler(jobInfo.getExecutorHandler()); + triggerParam.setExecutorParams(jobInfo.getExecutorParam()); + triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy()); + triggerParam.setGlueType(jobInfo.getGlueType()); + triggerParam.setGlueSource(jobInfo.getGlueSource()); + triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime()); + triggerParam.setLogId(jobLog.getId()); + triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime()); + + // 4.2、trigger-run (route run / trigger remote executor) + triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList, jobLog); + triggerMsgSb.append("

>>>>>>>>>>>触发调度<<<<<<<<<<<
").append(triggerResult.getMsg()); + + // 4.3、trigger (fail retry) + if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_RETRY) { + triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList, jobLog); + triggerMsgSb.append("

>>>>>>>>>>>失败重试<<<<<<<<<<<
").append(triggerResult.getMsg()); + } } - // log part-2 + // 5、save trigger-info jobLog.setTriggerCode(triggerResult.getCode()); - jobLog.setTriggerMsg(triggerResult.getMsg()); + jobLog.setTriggerMsg(triggerMsgSb.toString()); XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog); - // monitor triger + // 6、monitor triger JobFailMonitorHelper.monitor(jobLog.getId()); logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId()); } - private static ReturnT doTrigger(TriggerParam triggerParam, XxlJobInfo jobInfo, XxlJobLog jobLog){ - StringBuffer triggerSb = new StringBuffer(); - - // exerutor address list - XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup()); - triggerSb.append( (group.getAddressType() == 0)?"注册方式:自动注册":"注册方式:手动录入" ); - ArrayList addressList = (ArrayList) group.getRegistryList(); - - triggerSb.append("
阻塞处理策略:").append(ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION).getTitle()); - triggerSb.append("
失败处理策略:").append(ExecutorFailStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorFailStrategyEnum.FAIL_ALARM).getTitle()); - triggerSb.append("
地址列表:").append(addressList!=null?addressList.toString():""); - if (CollectionUtils.isEmpty(addressList)) { - triggerSb.append("
----------------------
").append("调度失败:").append("执行器地址为空"); - return new ReturnT(ReturnT.FAIL_CODE, triggerSb.toString()); - } - - // executor route strategy - ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null); - if (executorRouteStrategyEnum == null) { - triggerSb.append("
----------------------
").append("调度失败:").append("执行器路由策略为空"); - return new ReturnT(ReturnT.FAIL_CODE, triggerSb.toString()); - } - triggerSb.append("
路由策略:").append(executorRouteStrategyEnum.name() + "-" + executorRouteStrategyEnum.getTitle()); - - - // route run / trigger remote executor - ReturnT routeRunResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList, jobLog); - triggerSb.append("
----------------------
").append(routeRunResult.getMsg()); - return new ReturnT(routeRunResult.getCode(), triggerSb.toString()); - - } - } diff --git a/xxl-job-executor-springboot-example/src/main/resources/application.properties b/xxl-job-executor-springboot-example/src/main/resources/application.properties index dc2a1b06..b4073e98 100644 --- a/xxl-job-executor-springboot-example/src/main/resources/application.properties +++ b/xxl-job-executor-springboot-example/src/main/resources/application.properties @@ -11,7 +11,7 @@ xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin ### xxl-job executor address xxl.job.executor.appname=xxl-job-executor-example xxl.job.executor.ip= -xxl.job.executor.port=9999 +xxl.job.executor.port=9998 ### xxl-job log path xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/