执行器路由逻辑优化

v1.8.2
xuxueli 7 years ago
parent 2ed78c55df
commit b607bcde28

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route; package com.xxl.job.admin.core.route;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam; import com.xxl.job.core.biz.model.TriggerParam;
@ -21,9 +20,9 @@ public abstract class ExecutorRouter {
* *
* @param triggerParam * @param triggerParam
* @param addressList * @param addressList
* @return * @return ReturnT.content: final address
*/ */
public abstract ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog); public abstract ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList);
/** /**
* run executor * run executor

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
@ -19,7 +18,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
StringBuffer idleBeatResultSB = new StringBuffer(); StringBuffer idleBeatResultSB = new StringBuffer();
for (String address : addressList) { for (String address : addressList) {
@ -40,12 +39,14 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
// beat success // beat success
if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) { if (idleBeatResult.getCode() == ReturnT.SUCCESS_CODE) {
jobLog.setExecutorAddress(address);
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
idleBeatResultSB.append("<br><br>").append(runResult.getMsg()); idleBeatResultSB.append("<br><br>").append(runResult.getMsg());
return new ReturnT<String>(runResult.getCode(), idleBeatResultSB.toString()); // result
runResult.setMsg(idleBeatResultSB.toString());
runResult.setContent(address);
return runResult;
} }
} }

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam; import com.xxl.job.core.biz.model.TriggerParam;
@ -78,13 +77,13 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }
} }

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
@ -19,7 +18,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
StringBuffer beatResultSB = new StringBuffer(); StringBuffer beatResultSB = new StringBuffer();
for (String address : addressList) { for (String address : addressList) {
@ -40,12 +39,14 @@ public class ExecutorRouteFailover extends ExecutorRouter {
// beat success // beat success
if (beatResult.getCode() == ReturnT.SUCCESS_CODE) { if (beatResult.getCode() == ReturnT.SUCCESS_CODE) {
jobLog.setExecutorAddress(address);
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
beatResultSB.append("<br><br>").append(runResult.getMsg()); beatResultSB.append("<br><br>").append(runResult.getMsg());
return new ReturnT<String>(runResult.getCode(), beatResultSB.toString()); // result
runResult.setMsg(beatResultSB.toString());
runResult.setContent(address);
return runResult;
} }
} }
return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString()); return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString());

@ -17,14 +17,14 @@ public class ExecutorRouteFirst extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }
} }

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam; import com.xxl.job.core.biz.model.TriggerParam;
@ -57,14 +56,14 @@ public class ExecutorRouteLFU extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam; import com.xxl.job.core.biz.model.TriggerParam;
@ -56,14 +55,14 @@ public class ExecutorRouteLRU extends ExecutorRouter {
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }

@ -17,13 +17,13 @@ public class ExecutorRouteLast extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }
} }

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam; import com.xxl.job.core.biz.model.TriggerParam;
@ -21,13 +20,13 @@ public class ExecutorRouteRandom extends ExecutorRouter {
} }
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }

@ -1,6 +1,5 @@
package com.xxl.job.admin.core.route.strategy; package com.xxl.job.admin.core.route.strategy;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.admin.core.route.ExecutorRouter;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam; import com.xxl.job.core.biz.model.TriggerParam;
@ -36,14 +35,14 @@ public class ExecutorRouteRound extends ExecutorRouter {
@Override @Override
public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList, XxlJobLog jobLog) { public ReturnT<String> routeRun(TriggerParam triggerParam, ArrayList<String> addressList) {
// address // address
String address = route(triggerParam.getJobId(), addressList); String address = route(triggerParam.getJobId(), addressList);
jobLog.setExecutorAddress(address);
// run executor // run executor
ReturnT<String> runResult = runExecutor(triggerParam, address); ReturnT<String> runResult = runExecutor(triggerParam, address);
runResult.setContent(address);
return runResult; return runResult;
} }
} }

@ -86,17 +86,18 @@ public class XxlJobTrigger {
triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime()); triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());
// 4.2、trigger-run (route run / trigger remote executor) // 4.2、trigger-run (route run / trigger remote executor)
triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList, jobLog); triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList);
triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>触发调度<<<<<<<<<<< </span><br>").append(triggerResult.getMsg()); triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>触发调度<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
// 4.3、trigger (fail retry) // 4.3、trigger (fail retry)
if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_RETRY) { if (triggerResult.getCode()!=ReturnT.SUCCESS_CODE && failStrategy == ExecutorFailStrategyEnum.FAIL_RETRY) {
triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList, jobLog); triggerResult = executorRouteStrategyEnum.getRouter().routeRun(triggerParam, addressList);
triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>失败重试<<<<<<<<<<< </span><br>").append(triggerResult.getMsg()); triggerMsgSb.append("<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>失败重试<<<<<<<<<<< </span><br>").append(triggerResult.getMsg());
} }
} }
// 5、save trigger-info // 5、save trigger-info
jobLog.setExecutorAddress(triggerResult.getContent());
jobLog.setTriggerCode(triggerResult.getCode()); jobLog.setTriggerCode(triggerResult.getCode());
jobLog.setTriggerMsg(triggerMsgSb.toString()); jobLog.setTriggerMsg(triggerMsgSb.toString());
XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog); XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);

@ -110,7 +110,7 @@ $(function() {
} }
var temp = ''; var temp = '';
temp += '' + row.executorAddress; temp += '' + (row.executorAddress?row.executorAddress:'');
temp += '<br>' + glueTypeTitle; temp += '<br>' + glueTypeTitle;
temp += '<br>' + row.executorParam; temp += '<br>' + row.executorParam;

Loading…
Cancel
Save