提交 | 用户 | 时间
|
e7c126
|
1 |
package com.xxl.job.admin.core.route.strategy; |
H |
2 |
|
|
3 |
import com.xxl.job.admin.core.scheduler.XxlJobScheduler; |
|
4 |
import com.xxl.job.admin.core.route.ExecutorRouter; |
|
5 |
import com.xxl.job.admin.core.util.I18nUtil; |
|
6 |
import com.xxl.job.core.biz.ExecutorBiz; |
|
7 |
import com.xxl.job.core.biz.model.ReturnT; |
|
8 |
import com.xxl.job.core.biz.model.TriggerParam; |
|
9 |
|
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by xuxueli on 17/3/10. |
|
14 |
*/ |
|
15 |
public class ExecutorRouteFailover extends ExecutorRouter { |
|
16 |
|
|
17 |
@Override |
|
18 |
public ReturnT<String> route(TriggerParam triggerParam, List<String> addressList) { |
|
19 |
|
|
20 |
StringBuffer beatResultSB = new StringBuffer(); |
|
21 |
for (String address : addressList) { |
|
22 |
// beat |
|
23 |
ReturnT<String> beatResult = null; |
|
24 |
try { |
|
25 |
ExecutorBiz executorBiz = XxlJobScheduler.getExecutorBiz(address); |
|
26 |
beatResult = executorBiz.beat(); |
|
27 |
} catch (Exception e) { |
|
28 |
logger.error(e.getMessage(), e); |
|
29 |
beatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e ); |
|
30 |
} |
|
31 |
beatResultSB.append( (beatResultSB.length()>0)?"<br><br>":"") |
|
32 |
.append(I18nUtil.getString("jobconf_beat") + ":") |
|
33 |
.append("<br>address:").append(address) |
|
34 |
.append("<br>code:").append(beatResult.getCode()) |
|
35 |
.append("<br>msg:").append(beatResult.getMsg()); |
|
36 |
|
|
37 |
// beat success |
|
38 |
if (beatResult.getCode() == ReturnT.SUCCESS_CODE) { |
|
39 |
|
|
40 |
beatResult.setMsg(beatResultSB.toString()); |
|
41 |
beatResult.setContent(address); |
|
42 |
return beatResult; |
|
43 |
} |
|
44 |
} |
|
45 |
return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString()); |
|
46 |
|
|
47 |
} |
|
48 |
} |