From c1cda137d56540e178838fbdcfdb99681ec109c2 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Tue, 19 Jul 2016 23:13:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=8E=BB=E9=99=A4"=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=90=8DJobName"=E5=B1=9E=E6=80=A7,"=E6=8F=8F=E8=BF=B0"?= =?UTF-8?q?=E6=94=B9=E4=B8=BA"=E5=90=8D=E7=A7=B0"=E5=B1=9E=E6=80=A7,"?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=90=8D"=E6=94=B9=E4=B8=BA"=E5=88=86?= =?UTF-8?q?=E7=BB=84"=E5=B1=9E=E6=80=A7;=202=E3=80=81=E5=8E=BB=E9=99=A4"Jo?= =?UTF-8?q?bhandler"=E5=B1=9E=E6=80=A7,=E6=96=B0=E5=A2=9EJobKey,=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=90=8C=E5=8E=9F"JobHander=E5=B1=9E=E6=80=A7",?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E4=B8=8D=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?;=203=E3=80=81=E5=8E=BB=E9=99=A4"GLUE=E6=A8=A1=E5=BC=8F"?= =?UTF-8?q?=E5=A4=8D=E9=80=89=E6=A1=86,=E6=94=B9=E4=B8=BA=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=9A=84"=E4=BB=BB=E5=8A=A1=E6=A8=A1=E5=BC=8F"?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E6=A1=86,=E4=B8=94=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/JobInfoController.java | 26 ++--- .../admin/controller/JobLogController.java | 35 +++--- .../admin/core/jobbean/RemoteHttpJobBean.java | 7 +- .../xxl/job/admin/service/IXxlJobService.java | 6 +- .../admin/service/impl/XxlJobServiceImpl.java | 31 ++--- .../template/jobinfo/jobinfo.index.ftl | 49 ++++---- .../main/webapp/static/js/jobinfo.index.1.js | 77 +++++------- .../core/executor/jetty/XxlJobExecutor.java | 2 +- .../job/core/handler/HandlerRepository.java | 110 ++++++++---------- .../core/handler/annotation/JobHander.java | 2 +- .../service/jobhandler/DemoJobHandler.java | 2 +- 11 files changed, 148 insertions(+), 199 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java index d644df59..c082b031 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java @@ -1,18 +1,16 @@ package com.xxl.job.admin.controller; -import java.util.Map; - -import javax.annotation.Resource; - +import com.xxl.job.admin.core.constant.Constants.JobGroupEnum; +import com.xxl.job.admin.core.model.ReturnT; +import com.xxl.job.admin.service.IXxlJobService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import com.xxl.job.admin.core.constant.Constants.JobGroupEnum; -import com.xxl.job.admin.core.model.ReturnT; -import com.xxl.job.admin.service.IXxlJobService; +import javax.annotation.Resource; +import java.util.Map; /** * index controller @@ -43,22 +41,22 @@ public class JobInfoController { @RequestMapping("/add") @ResponseBody public ReturnT add(String jobGroup, String jobName, String jobCron, String jobDesc, - String executorAddress, String executorHandler, String executorParam, + String executorAddress, String executorParam, String author, String alarmEmail, int alarmThreshold, int glueSwitch, String glueSource, String glueRemark) { - return xxlJobService.add(jobGroup, jobCron, jobDesc, executorAddress, executorHandler, executorParam, + return xxlJobService.add(jobGroup, jobCron, jobDesc, executorAddress, executorParam, author, alarmEmail, alarmThreshold, glueSwitch, glueSource, glueRemark); } @RequestMapping("/reschedule") @ResponseBody public ReturnT reschedule(String jobGroup, String jobName, String jobCron, String jobDesc, - String executorAddress, String executorHandler, String executorParam, - String author, String alarmEmail, int alarmThreshold, int glueSwitch) { - - return xxlJobService.reschedule(jobGroup, jobName, jobCron, jobDesc, executorAddress, executorHandler, executorParam, author, - alarmEmail, alarmThreshold, glueSwitch); + String executorAddress, String executorParam, + String author, String alarmEmail, int alarmThreshold) { + + return xxlJobService.reschedule(jobGroup, jobName, jobCron, jobDesc, executorAddress, executorParam, author, + alarmEmail, alarmThreshold); } @RequestMapping("/remove") diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java index f9c71fd0..0bc38efe 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java @@ -1,21 +1,5 @@ package com.xxl.job.admin.controller; -import java.text.ParseException; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.time.DateUtils; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - import com.xxl.job.admin.core.constant.Constants.JobGroupEnum; import com.xxl.job.admin.core.model.ReturnT; import com.xxl.job.admin.core.model.XxlJobInfo; @@ -26,6 +10,20 @@ import com.xxl.job.core.handler.HandlerRepository.ActionEnum; import com.xxl.job.core.handler.HandlerRepository.HandlerParamEnum; import com.xxl.job.core.util.HttpUtil; import com.xxl.job.core.util.HttpUtil.RemoteCallBack; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateUtils; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.text.ParseException; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * index controller @@ -155,11 +153,10 @@ public class JobLogController { Map reqMap = new HashMap(); reqMap.put(HandlerParamEnum.TIMESTAMP.name(), String.valueOf(System.currentTimeMillis())); reqMap.put(HandlerParamEnum.ACTION.name(), ActionEnum.KILL.name()); - reqMap.put(HandlerParamEnum.GLUE_SWITCH.name(), String.valueOf(jobInfo.getGlueSwitch())); - reqMap.put(HandlerParamEnum.EXECUTOR_HANDLER.name(), log.getExecutorHandler()); reqMap.put(HandlerParamEnum.JOB_GROUP.name(), log.getJobGroup()); reqMap.put(HandlerParamEnum.JOB_NAME.name(), log.getJobName()); - + reqMap.put(HandlerParamEnum.GLUE_SWITCH.name(), String.valueOf(jobInfo.getGlueSwitch())); + RemoteCallBack callBack = HttpUtil.post(HttpUtil.addressToUrl(log.getExecutorAddress()), reqMap); if (HttpUtil.RemoteCallBack.SUCCESS.equals(callBack.getStatus())) { log.setHandleStatus(HttpUtil.RemoteCallBack.FAIL); 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 1cb8113e..8227fdda 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 @@ -58,12 +58,11 @@ public class RemoteHttpJobBean extends QuartzJobBean { params.put(HandlerParamEnum.LOG_ADDRESS.name(), XxlJobLogCallbackServer.getTrigger_log_address()); params.put(HandlerParamEnum.LOG_ID.name(), String.valueOf(jobLog.getId())); - params.put(HandlerParamEnum.EXECUTOR_HANDLER.name(), jobInfo.getExecutorHandler()); + params.put(HandlerParamEnum.JOB_GROUP.name(), jobInfo.getJobGroup()); + params.put(HandlerParamEnum.JOB_NAME.name(), jobInfo.getJobName()); params.put(HandlerParamEnum.EXECUTOR_PARAMS.name(), jobInfo.getExecutorParam()); params.put(HandlerParamEnum.GLUE_SWITCH.name(), String.valueOf(jobInfo.getGlueSwitch())); - params.put(HandlerParamEnum.JOB_GROUP.name(), jobInfo.getJobGroup()); - params.put(HandlerParamEnum.JOB_NAME.name(), jobInfo.getJobName()); // failover trigger RemoteCallBack callback = failoverTrigger(jobInfo.getExecutorAddress(), params, jobLog); @@ -86,7 +85,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { /** * failover for trigger remote address - * @param addressArr + * @param handler_address * @return */ public RemoteCallBack failoverTrigger(String handler_address, HashMap handler_params, XxlJobLog jobLog){ diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java index 51003f10..b1fd8c56 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/IXxlJobService.java @@ -14,13 +14,13 @@ public interface IXxlJobService { public Map pageList(int start, int length, String jobGroup, String jobDesc, String filterTime); public ReturnT add(String jobGroup, String jobCron, String jobDesc, - String executorAddress, String executorHandler, String executorParam, + String executorAddress, String executorParam, String author, String alarmEmail, int alarmThreshold, int glueSwitch, String glueSource, String glueRemark); public ReturnT reschedule(String jobGroup, String jobName, String jobCron, String jobDesc, - String handler_address, String handler_name, String handler_params, - String author, String alarmEmail, int alarmThreshold, int glueSwitch); + String handler_address, String handler_params, + String author, String alarmEmail, int alarmThreshold); public ReturnT remove(String jobGroup, String jobName); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index 89daa08a..c86a9bc5 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -1,13 +1,12 @@ package com.xxl.job.admin.service.impl; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateFormatUtils; +import org.apache.commons.lang.time.FastDateFormat; import org.quartz.CronExpression; import org.quartz.SchedulerException; import org.springframework.stereotype.Service; @@ -60,7 +59,7 @@ public class XxlJobServiceImpl implements IXxlJobService { @Override public ReturnT add(String jobGroup, String jobCron, String jobDesc, - String executorAddress, String executorHandler, String executorParam, + String executorAddress, String executorParam, String author, String alarmEmail, int alarmThreshold, int glueSwitch, String glueSource, String glueRemark) { // valid @@ -76,9 +75,6 @@ public class XxlJobServiceImpl implements IXxlJobService { if (StringUtils.isBlank(executorAddress)) { return new ReturnT(500, "请输入“执行器地址”"); } - if (glueSwitch==0 && StringUtils.isBlank(executorHandler)) { - return new ReturnT(500, "请输入“jobHandler”"); - } if (StringUtils.isBlank(author)) { return new ReturnT(500, "请输入“负责人”"); } @@ -90,14 +86,14 @@ public class XxlJobServiceImpl implements IXxlJobService { } // generate jobName - String jobName = UUID.randomUUID().toString(); + String jobName = FastDateFormat.getInstance("yyyyMMddHHmmssSSSS").format(new Date()); try { if (DynamicSchedulerUtil.checkExists(jobName, jobGroup)) { - return new ReturnT(500, "此任务已存在,请更换任务组或任务名"); + return new ReturnT(500, "系统繁忙,请稍后重试"); } } catch (SchedulerException e1) { e1.printStackTrace(); - return new ReturnT(500, "此任务已存在,请更换任务组或任务名"); + return new ReturnT(500, "系统繁忙,请稍后重试"); } // Backup to the database @@ -114,7 +110,6 @@ public class XxlJobServiceImpl implements IXxlJobService { jobInfo.setGlueSource(glueSource); jobInfo.setGlueRemark(glueRemark); jobInfo.setExecutorAddress(executorAddress); - jobInfo.setExecutorHandler(executorHandler); jobInfo.setExecutorParam(executorParam); xxlJobInfoDao.save(jobInfo); @@ -135,8 +130,8 @@ public class XxlJobServiceImpl implements IXxlJobService { @Override public ReturnT reschedule(String jobGroup, String jobName, String jobCron, String jobDesc, - String executorAddress, String executorHandler, String executorParam, - String author, String alarmEmail, int alarmThreshold, int glueSwitch) { + String executorAddress, String executorParam, + String author, String alarmEmail, int alarmThreshold) { // valid if (JobGroupEnum.match(jobGroup) == null) { @@ -154,18 +149,12 @@ public class XxlJobServiceImpl implements IXxlJobService { if (StringUtils.isBlank(executorAddress)) { return new ReturnT(500, "请输入“执行器地址”"); } - if (glueSwitch==0 && StringUtils.isBlank(executorHandler)) { - return new ReturnT(500, "请输入“jobHandler”"); - } if (StringUtils.isBlank(author)) { return new ReturnT(500, "请输入“负责人”"); } if (StringUtils.isBlank(alarmEmail)) { return new ReturnT(500, "请输入“报警邮件”"); } - if (alarmThreshold < 0) { - alarmThreshold = 0; - } XxlJobInfo jobInfo = xxlJobInfoDao.load(jobGroup, jobName); jobInfo.setJobDesc(jobDesc); @@ -173,9 +162,7 @@ public class XxlJobServiceImpl implements IXxlJobService { jobInfo.setAuthor(author); jobInfo.setAlarmEmail(alarmEmail); jobInfo.setAlarmThreshold(alarmThreshold); - jobInfo.setGlueSwitch(glueSwitch); jobInfo.setExecutorAddress(executorAddress); - jobInfo.setExecutorHandler(executorHandler); jobInfo.setExecutorParam(executorParam); try { diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl index a0b264b5..51228341 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl @@ -73,7 +73,6 @@ Cron JobBean 执行器地址 - JobHandler 任务参数 新增时间 更新时间 @@ -121,16 +120,16 @@
- -
+ +
- -
+ +
@@ -139,20 +138,19 @@
- -
+ +
+ +
-
-
- - -
-
@@ -207,17 +205,17 @@ public class DemoJobHandler extends IJobHandler {
- -
+ +
- -
+ +
@@ -226,20 +224,21 @@ public class DemoJobHandler extends IJobHandler {
- -
+ +
+ +
+ +
-
-
- - -
-
diff --git a/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js b/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js index 30408c24..dc72a572 100644 --- a/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js +++ b/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js @@ -39,7 +39,6 @@ $(function() { { "data": 'jobCron', "visible" : true}, { "data": 'jobClass', "visible" : false}, { "data": 'executorAddress', "visible" : false}, - { "data": 'executorHandler', "visible" : false}, { "data": 'executorParam', "visible" : false}, { "data": 'addTime', @@ -100,7 +99,6 @@ $(function() { ' jobDesc="'+ row.jobDesc +'" '+ ' jobClass="'+ row.jobClass +'" '+ ' executorAddress="'+row.executorAddress +'" '+ - ' executorHandler="'+ row.executorHandler +'" '+ ' executorParam="'+ row.executorParam +'" '+ ' author="'+ row.author +'" '+ ' alarmEmail="'+ row.alarmEmail +'" '+ @@ -225,9 +223,6 @@ $(function() { executorAddress : { required : true }, - executorHandler : { - required : true - }, alarmEmail : { required : true }, @@ -249,9 +244,6 @@ $(function() { executorAddress : { required :"请输入“执行器地址”." }, - executorHandler : { - required : "请输入“JobHandler”." - }, alarmEmail : { required : "请输入“报警邮件”." }, @@ -296,50 +288,28 @@ $(function() { $(".remote_panel").show(); // remote }); - // GLUE模式开启 - $("#addModal .form .ifGLUE").click(function(){ - var ifGLUE = $(this).is(':checked'); - var $executorHandler = $("#addModal .form input[name='executorHandler']"); - var $glueSwitch = $("#addModal .form input[name='glueSwitch']"); - if (ifGLUE) { - $executorHandler.val(""); - $executorHandler.attr("readonly","readonly"); - $glueSwitch.val(1); - } else { - $executorHandler.removeAttr("readonly"); - $glueSwitch.val(0); - } - }); - $("#updateModal .form .ifGLUE").click(function(){ - var ifGLUE = $(this).is(':checked'); - var $executorHandler = $("#updateModal .form input[name='executorHandler']"); - var $glueSwitch = $("#updateModal .form input[name='glueSwitch']"); - if (ifGLUE) { - $executorHandler.val(""); - $executorHandler.attr("readonly","readonly"); - $glueSwitch.val(1); - } else { - $executorHandler.removeAttr("readonly"); - $glueSwitch.val(0); - } - }); - // 更新 $("#job_list").on('click', '.update',function() { // base data - $("#updateModal .form input[name='jobGroupTitle']").find("option[value='" + $(this).parent('p').attr("jobGroup") + "']").attr("selected",true); $("#updateModal .form input[name='jobGroup']").val($(this).parent('p').attr("jobGroup")); $("#updateModal .form input[name='jobName']").val($(this).parent('p').attr("jobName")); $("#updateModal .form input[name='jobDesc']").val($(this).parent('p').attr("jobDesc")); $("#updateModal .form input[name='jobCron']").val($(this).parent('p').attr("jobCron")); $("#updateModal .form input[name='executorAddress']").val($(this).parent('p').attr("executorAddress")); - $("#updateModal .form input[name='executorHandler']").val($(this).parent('p').attr("executorHandler")); $("#updateModal .form input[name='executorParam']").val($(this).parent('p').attr("executorParam")); $("#updateModal .form input[name='author']").val($(this).parent('p').attr("author")); $("#updateModal .form input[name='alarmEmail']").val($(this).parent('p').attr("alarmEmail")); $("#updateModal .form input[name='alarmThreshold']").val($(this).parent('p').attr("alarmThreshold")); - $("#updateModal .form input[name='glueSwitch']").val($(this).parent('p').attr("glueSwitch")); + + // job group selected + $("#updateModal .form select[name='jobGroupTitle']").find("option[value='" + $(this).parent('p').attr("jobGroup") + "']").attr("selected",true); + + // job group selected + $("#updateModal .form select[name='glueSwitch']").find("option[value='" + $(this).parent('p').attr("glueSwitch") + "']").attr("selected",true); + + // generate job key + $("#updateModal .form input[name='jobKey']").val( $(this).parent('p').attr("jobGroup") + "_" + $(this).parent('p').attr("jobName") ); // GLUE check var $glueSwitch = $("#updateModal .form input[name='glueSwitch']"); @@ -370,9 +340,6 @@ $(function() { executorAddress : { required : true }, - executorHandler : { - required : true - }, alarmEmail : { required : true }, @@ -394,9 +361,6 @@ $(function() { executorAddress : { required :"请输入“执行器地址”." }, - executorHandler : { - required : "请输入“JobHandler”." - }, alarmEmail : { required : "请输入“报警邮件”." }, @@ -419,6 +383,8 @@ $(function() { element.parent('div').append(error); }, submitHandler : function(form) { + + // post $.post(base_url + "/jobinfo/reschedule", $("#updateModal .form").serialize(), function(data, status) { if (data.code == "200") { ComAlert.show(1, "更新成功", function(){ @@ -437,8 +403,24 @@ $(function() { $("#updateModal").on('hide.bs.modal', function () { $("#updateModal .form")[0].reset() }); - - + + // GLUE模式开启 + /* + $("#addModal .form .ifGLUE").click(function(){ + var ifGLUE = $(this).is(':checked'); + var $executorHandler = $("#addModal .form input[name='executorHandler']"); + var $glueSwitch = $("#addModal .form input[name='glueSwitch']"); + if (ifGLUE) { + $executorHandler.val(""); + $executorHandler.attr("readonly","readonly"); + $glueSwitch.val(1); + } else { + $executorHandler.removeAttr("readonly"); + $glueSwitch.val(0); + } + }); + */ + /* // 新增-添加参数 $("#addModal .addParam").on('click', function () { @@ -454,4 +436,5 @@ $(function() { }); }); */ + }); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java b/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java index 96f89a20..6e18d9d1 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java @@ -88,7 +88,7 @@ public class XxlJobExecutor implements ApplicationContextAware { Map serviceBeanMap = XxlJobExecutor.applicationContext.getBeansWithAnnotation(JobHander.class); if (serviceBeanMap!=null && serviceBeanMap.size()>0) { for (Object serviceBean : serviceBeanMap.values()) { - String jobName = serviceBean.getClass().getAnnotation(JobHander.class).name(); + String jobName = serviceBean.getClass().getAnnotation(JobHander.class).value(); if (jobName!=null && jobName.trim().length()>0 && serviceBean instanceof IJobHandler) { IJobHandler handler = (IJobHandler) serviceBean; HandlerRepository.regist(jobName, handler); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/handler/HandlerRepository.java b/xxl-job-core/src/main/java/com/xxl/job/core/handler/HandlerRepository.java index f856c69b..2c514d9c 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/handler/HandlerRepository.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/handler/HandlerRepository.java @@ -1,19 +1,18 @@ package com.xxl.job.core.handler; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.xxl.job.core.handler.impl.GlueJobHandler; import com.xxl.job.core.log.XxlJobFileAppender; import com.xxl.job.core.util.HttpUtil; import com.xxl.job.core.util.HttpUtil.RemoteCallBack; import com.xxl.job.core.util.JacksonUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; /** * handler repository @@ -32,9 +31,13 @@ public class HandlerRepository { */ ACTION, /** - * remote executor jobhandler + * job group + */ + JOB_GROUP, + /** + * job name */ - EXECUTOR_HANDLER, + JOB_NAME, /** * params of jobhandler */ @@ -43,14 +46,6 @@ public class HandlerRepository { * switch of glue job: 0-no,1-yes */ GLUE_SWITCH, - /** - * job group - */ - JOB_GROUP, - /** - * job name - */ - JOB_NAME, /** * address for callback log */ @@ -99,37 +94,39 @@ public class HandlerRepository { // parse namespace if (namespace.equals(ActionEnum.RUN.name())) { - // push data to queue + + // generate jobKey + String job_group = _param.get(HandlerParamEnum.JOB_GROUP.name()); + String job_name = _param.get(HandlerParamEnum.JOB_NAME.name()); + if (job_group == null || job_group.trim().length()==0 || job_name == null || job_name.trim().length()==0) { + callback.setMsg("JOB_GROUP or JOB_NAME is null."); + return JacksonUtil.writeValueAsString(callback); + } + String jobKey = job_group.concat("_").concat(job_name); + + // glue switch String handler_glue_switch = _param.get(HandlerParamEnum.GLUE_SWITCH.name()); - HandlerThread handlerThread = null; + if (handler_glue_switch==null || handler_glue_switch.trim().length()==0){ + callback.setMsg("GLUE_SWITCH is null."); + return JacksonUtil.writeValueAsString(callback); + } + + HandlerThread handlerThread = handlerTreadMap.get(jobKey);; if ("0".equals(handler_glue_switch)) { // bean model - String handler_name = _param.get(HandlerParamEnum.EXECUTOR_HANDLER.name()); - if (handler_name == null || handler_name.trim().length()==0) { - callback.setMsg("bean model handler[HANDLER_NAME] not found."); - return JacksonUtil.writeValueAsString(callback); - } - handlerThread = handlerTreadMap.get(handler_name); if (handlerThread == null) { - callback.setMsg("handler[" + handler_name + "] not found."); + callback.setMsg("handler for jobKey=[" + jobKey + "] not found."); return JacksonUtil.writeValueAsString(callback); } } else { // glue - String job_group = _param.get(HandlerParamEnum.JOB_GROUP.name()); - String job_name = _param.get(HandlerParamEnum.JOB_NAME.name()); - if (job_group == null || job_group.trim().length()==0 || job_name == null || job_name.trim().length()==0) { - callback.setMsg("glue model handler[job group or name] is null."); - return JacksonUtil.writeValueAsString(callback); - } - String glueHandleName = "glue_".concat(job_group).concat("_").concat(job_name); - handlerThread = handlerTreadMap.get(glueHandleName); if (handlerThread==null) { - HandlerRepository.regist(glueHandleName, new GlueJobHandler(job_group, job_name)); + HandlerRepository.regist(jobKey, new GlueJobHandler(job_group, job_name)); } - handlerThread = handlerTreadMap.get(glueHandleName); + handlerThread = handlerTreadMap.get(jobKey); } - + + // push data to queue handlerThread.pushData(_param); callback.setStatus(RemoteCallBack.SUCCESS); } else if (namespace.equals(ActionEnum.LOG.name())) { @@ -154,36 +151,25 @@ public class HandlerRepository { callback.setStatus(RemoteCallBack.SUCCESS); callback.setMsg(logConteng); } else if (namespace.equals(ActionEnum.KILL.name())) { - // kill handlerThread, and create new one - String handler_glue_switch = _param.get(HandlerParamEnum.GLUE_SWITCH.name()); - String handlerName = null; - if ("0".equals(handler_glue_switch)) { - String executor_handler = _param.get(HandlerParamEnum.EXECUTOR_HANDLER.name()); - if (executor_handler==null) { - callback.setMsg("bean job , param[EXECUTOR_HANDLER] is null"); - return JacksonUtil.writeValueAsString(callback); - } - handlerName = executor_handler; - } else { - // glue - String job_group = _param.get(HandlerParamEnum.JOB_GROUP.name()); - String job_name = _param.get(HandlerParamEnum.JOB_NAME.name()); - if (job_group==null || job_group.trim().length()==0 || job_name==null || job_name.trim().length()==0) { - callback.setMsg("glue job , param[JOB_GROUP or JOB_NAME] is null"); - return JacksonUtil.writeValueAsString(callback); - } - handlerName = "glue_".concat(job_group).concat("_").concat(job_name); + // generate jobKey + String job_group = _param.get(HandlerParamEnum.JOB_GROUP.name()); + String job_name = _param.get(HandlerParamEnum.JOB_NAME.name()); + if (job_group == null || job_group.trim().length()==0 || job_name == null || job_name.trim().length()==0) { + callback.setMsg("JOB_GROUP or JOB_NAME is null."); + return JacksonUtil.writeValueAsString(callback); } - - HandlerThread handlerThread = handlerTreadMap.get(handlerName); + String jobKey = job_group.concat("_").concat(job_name); + + // kill handlerThread, and create new one + HandlerThread handlerThread = handlerTreadMap.get(jobKey); if (handlerThread != null) { IJobHandler handler = handlerThread.getHandler(); handlerThread.toStop(); handlerThread.interrupt(); - regist(handlerName, handler); + regist(jobKey, handler); callback.setStatus(RemoteCallBack.SUCCESS); } else { - callback.setMsg("job handler[" + handlerName + "] not found."); + callback.setMsg("handler for jobKey=[" + jobKey + "] not found."); } } else if (namespace.equals(ActionEnum.BEAT.name())) { diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java b/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java index 1e1b0cb8..0172f5f6 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java @@ -15,6 +15,6 @@ import java.lang.annotation.Target; @Inherited public @interface JobHander { - String name(); + String value() default ""; } diff --git a/xxl-job-executor-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java b/xxl-job-executor-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java index d57f3600..831a5a63 100644 --- a/xxl-job-executor-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java +++ b/xxl-job-executor-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java @@ -20,7 +20,7 @@ import com.xxl.job.core.handler.annotation.JobHander; * * @author xuxueli 2015-12-19 19:43:36 */ -@JobHander(name="demoJobHandler") +@JobHander(value="defaults_201607192222270796") @Service public class DemoJobHandler extends IJobHandler { private static transient Logger logger = LoggerFactory.getLogger(DemoJobHandler.class);