From 4eae26a35367fc5635b6b10d00327a2f39fb8f20 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sun, 16 Sep 2018 05:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/JobInfoController.java | 3 ++- .../admin/core/jobbean/RemoteHttpJobBean.java | 3 ++- .../core/thread/JobFailMonitorHelper.java | 3 ++- .../core/thread/JobTriggerPoolHelper.java | 9 ++++--- .../admin/core/trigger/TriggerTypeEnum.java | 26 +++++++++++++++++++ .../job/admin/core/trigger/XxlJobTrigger.java | 6 ++--- .../job/admin/service/impl/AdminBizImpl.java | 5 ++-- 7 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/TriggerTypeEnum.java 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 412669e7..1098e0d5 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 @@ -4,6 +4,7 @@ import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; +import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.dao.XxlJobGroupDao; import com.xxl.job.admin.service.XxlJobService; @@ -91,7 +92,7 @@ public class JobInfoController { @RequestMapping("/trigger") @ResponseBody public ReturnT triggerJob(int id) { - JobTriggerPoolHelper.trigger(id, -1, I18nUtil.getString("jobconf_trigger_type_manual")); + JobTriggerPoolHelper.trigger(id, -1, TriggerTypeEnum.MANUAL); return ReturnT.SUCCESS; } 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 bd5dc1a6..f2ccf74a 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 @@ -1,6 +1,7 @@ package com.xxl.job.admin.core.jobbean; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; +import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; @@ -28,7 +29,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { // trigger //XxlJobTrigger.trigger(jobId); - JobTriggerPoolHelper.trigger(jobId, -1, I18nUtil.getString("jobconf_trigger_type_cron")); + JobTriggerPoolHelper.trigger(jobId, -1, TriggerTypeEnum.CRON); } } \ No newline at end of file diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java index 46228d8e..6dc3f27f 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java @@ -4,6 +4,7 @@ import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; +import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.core.util.MailUtil; import com.xxl.job.core.biz.model.ReturnT; @@ -75,7 +76,7 @@ public class JobFailMonitorHelper { // TODO,分片任务失败重试优化,仅重试失败分片 - JobTriggerPoolHelper.trigger(log.getJobId(), (log.getExecutorFailRetryCount()-1), I18nUtil.getString("jobconf_trigger_type_retry")); + JobTriggerPoolHelper.trigger(log.getJobId(), (log.getExecutorFailRetryCount()-1), TriggerTypeEnum.RETRY); String retryMsg = "

>>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_type_retry") +"<<<<<<<<<<<
"; log.setTriggerMsg(log.getTriggerMsg() + retryMsg); XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(log); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobTriggerPoolHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobTriggerPoolHelper.java index 65060c0a..57844c59 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobTriggerPoolHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobTriggerPoolHelper.java @@ -1,5 +1,6 @@ package com.xxl.job.admin.core.thread; +import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.trigger.XxlJobTrigger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,11 +29,11 @@ public class JobTriggerPoolHelper { new ThreadPoolExecutor.CallerRunsPolicy()); - public void addTrigger(final int jobId, final int failRetryCount, final String type){ + public void addTrigger(final int jobId, final int failRetryCount, final TriggerTypeEnum triggerType){ triggerPool.execute(new Runnable() { @Override public void run() { - XxlJobTrigger.trigger(jobId, failRetryCount, type); + XxlJobTrigger.trigger(jobId, failRetryCount, triggerType); } }); } @@ -55,8 +56,8 @@ public class JobTriggerPoolHelper { * <0: use param from job info config * */ - public static void trigger(int jobId, int failRetryCount, String type) { - helper.addTrigger(jobId, failRetryCount, type); + public static void trigger(int jobId, int failRetryCount, TriggerTypeEnum triggerType) { + helper.addTrigger(jobId, failRetryCount, triggerType); } public static void toStop(){ diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/TriggerTypeEnum.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/TriggerTypeEnum.java new file mode 100644 index 00000000..bfb66d05 --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/TriggerTypeEnum.java @@ -0,0 +1,26 @@ +package com.xxl.job.admin.core.trigger; + +import com.xxl.job.admin.core.util.I18nUtil; + +/** + * trigger type enum + * + * @author xuxueli 2018-09-16 04:56:41 + */ +public enum TriggerTypeEnum { + + MANUAL(I18nUtil.getString("jobconf_trigger_type_manual")), + CRON(I18nUtil.getString("jobconf_trigger_type_cron")), + RETRY(I18nUtil.getString("jobconf_trigger_type_retry")), + PARENT(I18nUtil.getString("jobconf_trigger_type_parent")), + API(I18nUtil.getString("jobconf_trigger_type_api")); + + private TriggerTypeEnum(String title){ + this.title = title; + } + private String title; + public String getTitle() { + return title; + } + +} 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 456baf46..424b5fd7 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 @@ -35,7 +35,7 @@ public class XxlJobTrigger { * <0: use param from job info config * */ - public static void trigger(int jobId, int failRetryCount, String type) { + public static void trigger(int jobId, int failRetryCount, TriggerTypeEnum triggerType) { // load data XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId); // job info @@ -75,7 +75,7 @@ public class XxlJobTrigger { ReturnT triggerResult = new ReturnT(null); StringBuffer triggerMsgSb = new StringBuffer(); - triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(type); + triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle()); triggerMsgSb.append("
").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp()); triggerMsgSb.append("
").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":") .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") ); @@ -134,7 +134,7 @@ public class XxlJobTrigger { ReturnT triggerResult = new ReturnT(null); StringBuffer triggerMsgSb = new StringBuffer(); - triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(type); + triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle()); triggerMsgSb.append("
").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp()); triggerMsgSb.append("
").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":") .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") ); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java index 14a2e351..2df56fdb 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java @@ -3,6 +3,7 @@ package com.xxl.job.admin.service.impl; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; +import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.dao.XxlJobInfoDao; import com.xxl.job.admin.dao.XxlJobLogDao; @@ -70,7 +71,7 @@ public class AdminBizImpl implements AdminBiz { int childJobId = (StringUtils.isNotBlank(childJobIds[i]) && StringUtils.isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1; if (childJobId > 0) { - JobTriggerPoolHelper.trigger(childJobId, 0, I18nUtil.getString("jobconf_trigger_type_parent")); + JobTriggerPoolHelper.trigger(childJobId, 0, TriggerTypeEnum.PARENT); ReturnT triggerChildResult = ReturnT.SUCCESS; // add msg @@ -129,7 +130,7 @@ public class AdminBizImpl implements AdminBiz { @Override public ReturnT triggerJob(int jobId) { - JobTriggerPoolHelper.trigger(jobId, -1, I18nUtil.getString("jobconf_trigger_type_api")); + JobTriggerPoolHelper.trigger(jobId, -1, TriggerTypeEnum.API); return ReturnT.SUCCESS; }