From caf817124e807a63c56ba02f536a36206c78dd04 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Sun, 2 Oct 2016 20:42:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83=E6=B3=A8?= =?UTF-8?q?=E5=86=8C:=201=E3=80=81=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C;=202=E3=80=81=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E6=97=B6,=E5=8A=A0=E8=BD=BD=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E5=9C=B0=E5=9D=80,push=E7=BB=99=E6=89=A7=E8=A1=8C=E5=99=A8,?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E8=8E=B7=E5=8F=96=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E5=9C=B0=E5=9D=80,failover=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E8=BF=9B=E8=A1=8C=E5=9B=9E=E8=B0=83;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../job/admin/core/jobbean/RemoteHttpJobBean.java | 14 +++++++++++--- .../xxl/job/core/router/model/RequestModel.java | 12 +++++++----- .../core/router/thread/TriggerCallbackThread.java | 15 ++++++++++----- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java index 302bd514..692c18cf 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java @@ -30,7 +30,7 @@ import java.util.*; //@DisallowConcurrentExecution public class RemoteHttpJobBean extends QuartzJobBean { private static Logger logger = LoggerFactory.getLogger(RemoteHttpJobBean.class); - + @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { @@ -43,7 +43,15 @@ public class RemoteHttpJobBean extends QuartzJobBean { jobLog.setJobName(jobInfo.getJobName()); DynamicSchedulerUtil.xxlJobLogDao.save(jobLog); logger.info(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId()); - + + // admin address + List adminAddressList = JobRegistryHelper.discover(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name()); + Set adminAddressSet = new HashSet(); + if (adminAddressList!=null) { + adminAddressSet.addAll(adminAddressList); + } + adminAddressSet.add(XxlJobLogCallbackServer.getTrigger_log_address()); + // trigger request RequestModel requestModel = new RequestModel(); requestModel.setTimestamp(System.currentTimeMillis()); @@ -53,7 +61,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { requestModel.setExecutorHandler(jobInfo.getExecutorHandler()); requestModel.setExecutorParams(jobInfo.getExecutorParam()); requestModel.setGlueSwitch((jobInfo.getGlueSwitch()==0)?false:true); - requestModel.setLogAddress(XxlJobLogCallbackServer.getTrigger_log_address()); + requestModel.setLogAddress(adminAddressSet); requestModel.setLogId(jobLog.getId()); // parse address diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/model/RequestModel.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/model/RequestModel.java index 91badd0c..bcd10eae 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/model/RequestModel.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/model/RequestModel.java @@ -1,5 +1,7 @@ package com.xxl.job.core.router.model; +import java.util.Set; + /** * Created by xuxueli on 16/7/22. */ @@ -16,13 +18,14 @@ public class RequestModel { private boolean glueSwitch; - private String logAddress; + private Set logAddress; private int logId; private long logDateTim; private String status; private String msg; + public long getTimestamp() { return timestamp; } @@ -79,11 +82,11 @@ public class RequestModel { this.glueSwitch = glueSwitch; } - public String getLogAddress() { + public Set getLogAddress() { return logAddress; } - public void setLogAddress(String logAddress) { + public void setLogAddress(Set logAddress) { this.logAddress = logAddress; } @@ -129,12 +132,11 @@ public class RequestModel { ", executorHandler='" + executorHandler + '\'' + ", executorParams='" + executorParams + '\'' + ", glueSwitch=" + glueSwitch + - ", logAddress='" + logAddress + '\'' + + ", logAddress=" + logAddress + ", logId=" + logId + ", logDateTim=" + logDateTim + ", status='" + status + '\'' + ", msg='" + msg + '\'' + '}'; } - } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java index ade01068..2e37e371 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/thread/TriggerCallbackThread.java @@ -23,11 +23,16 @@ public class TriggerCallbackThread { try { RequestModel callback = callBackQueue.take(); if (callback != null) { - try { - ResponseModel responseModel = XxlJobNetCommUtil.postHex(XxlJobNetCommUtil.addressToUrl(callback.getLogAddress()), callback); - logger.info(">>>>>>>>>>> xxl-job callback , RequestModel:{}, ResponseModel:{}", new Object[]{callback.toString(), responseModel.toString()}); - } catch (Exception e) { - logger.info("JobThread Exception:", e); + for (String address : callback.getLogAddress()) { + try { + ResponseModel responseModel = XxlJobNetCommUtil.postHex(XxlJobNetCommUtil.addressToUrl(address), callback); + logger.info(">>>>>>>>>>> xxl-job callback , RequestModel:{}, ResponseModel:{}", new Object[]{callback.toString(), responseModel.toString()}); + if (ResponseModel.SUCCESS.equals(responseModel.getStatus())) { + break; + } + } catch (Exception e) { + logger.info("JobThread Exception:", e); + } } } } catch (Exception e) {