diff --git a/doc/db/tables_xxl_log.sql b/doc/db/tables_xxl_job.sql similarity index 100% rename from doc/db/tables_xxl_log.sql rename to doc/db/tables_xxl_job.sql diff --git a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java new file mode 100644 index 00000000..53171a17 --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java @@ -0,0 +1,22 @@ +package com.xxl.job.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * job code controller + * @author xuxueli 2015-12-19 16:13:16 + */ +@Controller +@RequestMapping("/jobcode") +public class JobCodeController { + + @RequestMapping + public String index(Model model, HttpServletRequest request) { + return "jobcode/index"; + } + +} diff --git a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java index 05962f44..b9f70d3c 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java @@ -1,6 +1,5 @@ package com.xxl.job.controller; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -9,7 +8,6 @@ import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; import org.quartz.CronExpression; -import org.quartz.Job; import org.quartz.SchedulerException; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -25,14 +23,11 @@ import com.xxl.job.core.model.XxlJobInfo; import com.xxl.job.core.util.DynamicSchedulerUtil; import com.xxl.job.dao.IXxlJobInfoDao; import com.xxl.job.service.job.RemoteHttpJobBean; -import com.xxl.job.service.job.impl.DemoConcurrentJobBean; -import com.xxl.job.service.job.impl.DemoNomalJobBean; /** * index controller * @author xuxueli 2015-12-19 16:13:16 */ -@SuppressWarnings("unchecked") @Controller @RequestMapping("/jobinfo") public class JobInfoController { @@ -40,19 +35,8 @@ public class JobInfoController { @Resource private IXxlJobInfoDao xxlJobInfoDao; - // remote job bean - public static Class remoteJobBean = RemoteHttpJobBean.class; - // loacal job bean - public static List> localJobBeanList = new ArrayList>(); - static{ - localJobBeanList.add((Class) DemoNomalJobBean.class); - localJobBeanList.add((Class) DemoConcurrentJobBean.class); - } - @RequestMapping public String index(Model model) { - model.addAttribute("localJobBeanList", localJobBeanList); // 本地任务-列表 - model.addAttribute("remoteJobBean", remoteJobBean); // 远程任务-jobBean model.addAttribute("JobGroupList", JobGroupEnum.values()); // 任务组列表 return "jobinfo/index"; } @@ -84,8 +68,8 @@ public class JobInfoController { @RequestMapping("/add") @ResponseBody - public ReturnT add(String jobGroup, String jobName, String jobCron, String jobDesc, String jobClass, - String handler_params, String handler_address, String handler_name, + public ReturnT add(String jobGroup, String jobName, String jobCron, String jobDesc, + String handler_address, String handler_name, String handler_params, String author, String alarmEmail, int alarmThreshold) { // valid @@ -101,25 +85,11 @@ public class JobInfoController { if (StringUtils.isBlank(jobDesc)) { return new ReturnT(500, "请输入“任务描述”"); } - Class jobClass_ = null; - try { - Class clazz = Class.forName(jobClass); - if (clazz!=null) { - jobClass_ = (Class) clazz; - } - } catch (ClassNotFoundException e1) { - e1.printStackTrace(); + if (StringUtils.isBlank(handler_address)) { + return new ReturnT(500, "请输入“机器地址”"); } - if (jobClass_ == null) { - return new ReturnT(500, "请选择“JobBean”"); - } - if (jobClass_.getClass().getName().equals(remoteJobBean.getName())) { - if (StringUtils.isBlank(handler_address)) { - return new ReturnT(500, "请输入“远程-机器地址”"); - } - if (StringUtils.isBlank(handler_name)) { - return new ReturnT(500, "请输入“远程-执行器”"); - } + if (StringUtils.isBlank(handler_name)) { + return new ReturnT(500, "请输入“执行器”"); } if (StringUtils.isBlank(author)) { return new ReturnT(500, "请输入“负责人”"); @@ -127,6 +97,9 @@ public class JobInfoController { if (StringUtils.isBlank(alarmEmail)) { return new ReturnT(500, "请输入“报警邮件”"); } + if (alarmThreshold < 0) { + alarmThreshold = 0; + } try { if (DynamicSchedulerUtil.checkExists(jobName, jobGroup)) { @@ -139,9 +112,9 @@ public class JobInfoController { // parse jobDataMap HashMap jobDataMap = new HashMap(); - jobDataMap.put(HandlerRepository.HANDLER_PARAMS, handler_params); jobDataMap.put(HandlerRepository.HANDLER_ADDRESS, handler_address); jobDataMap.put(HandlerRepository.HANDLER_NAME, handler_name); + jobDataMap.put(HandlerRepository.HANDLER_PARAMS, handler_params); // Backup to the database XxlJobInfo jobInfo = new XxlJobInfo(); @@ -149,7 +122,7 @@ public class JobInfoController { jobInfo.setJobName(jobName); jobInfo.setJobCron(jobCron); jobInfo.setJobDesc(jobDesc); - jobInfo.setJobClass(jobClass); + jobInfo.setJobClass(RemoteHttpJobBean.class.getName()); jobInfo.setJobData(JacksonUtil.writeValueAsString(jobDataMap)); jobInfo.setAuthor(author); jobInfo.setAlarmEmail(alarmEmail); @@ -173,8 +146,8 @@ public class JobInfoController { @RequestMapping("/reschedule") @ResponseBody - public ReturnT reschedule(String jobGroup, String jobName, String jobCron, String jobDesc, String jobClass, - String handler_params, String handler_address, String handler_name, + 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) { // valid @@ -187,12 +160,30 @@ public class JobInfoController { if (!CronExpression.isValidExpression(jobCron)) { return new ReturnT(500, "“corn”不合法"); } + if (StringUtils.isBlank(jobDesc)) { + return new ReturnT(500, "请输入“任务描述”"); + } + if (StringUtils.isBlank(handler_address)) { + return new ReturnT(500, "请输入“机器地址”"); + } + if (StringUtils.isBlank(handler_name)) { + return new ReturnT(500, "请输入“执行器”"); + } + if (StringUtils.isBlank(author)) { + return new ReturnT(500, "请输入“负责人”"); + } + if (StringUtils.isBlank(alarmEmail)) { + return new ReturnT(500, "请输入“报警邮件”"); + } + if (alarmThreshold < 0) { + alarmThreshold = 0; + } // parse jobDataMap HashMap jobDataMap = new HashMap(); - jobDataMap.put(HandlerRepository.HANDLER_PARAMS, handler_params); jobDataMap.put(HandlerRepository.HANDLER_ADDRESS, handler_address); jobDataMap.put(HandlerRepository.HANDLER_NAME, handler_name); + jobDataMap.put(HandlerRepository.HANDLER_PARAMS, handler_params); XxlJobInfo jobInfo = xxlJobInfoDao.load(jobGroup, jobName); jobInfo.setJobCron(jobCron); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/service/job/LocalNomalJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/service/job/LocalNomalJobBean.java index 7d555cd6..aa5351fd 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/service/job/LocalNomalJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/service/job/LocalNomalJobBean.java @@ -1,92 +1,93 @@ -package com.xxl.job.service.job; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang.StringUtils; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.JobKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.scheduling.quartz.QuartzJobBean; - -import com.xxl.job.client.handler.HandlerRepository; -import com.xxl.job.client.util.HttpUtil.RemoteCallBack; -import com.xxl.job.client.util.JacksonUtil; -import com.xxl.job.core.model.XxlJobInfo; -import com.xxl.job.core.model.XxlJobLog; -import com.xxl.job.core.thread.JobMonitorHelper; -import com.xxl.job.core.util.DynamicSchedulerUtil; - -/** - * http job bean - * @author xuxueli 2015-12-17 18:20:34 - */ -public abstract class LocalNomalJobBean extends QuartzJobBean { - private static Logger logger = LoggerFactory.getLogger(LocalNomalJobBean.class); - - @Override - protected void executeInternal(JobExecutionContext context) - throws JobExecutionException { - JobKey jobKey = context.getTrigger().getJobKey(); - - XxlJobInfo jobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(jobKey.getGroup(), jobKey.getName()); - @SuppressWarnings("unchecked") - HashMap jobDataMap = (HashMap) JacksonUtil.readValueRefer(jobInfo.getJobData(), Map.class); - - // save log - XxlJobLog jobLog = new XxlJobLog(); - jobLog.setJobGroup(jobInfo.getJobGroup()); - jobLog.setJobName(jobInfo.getJobName()); - jobLog.setJobCron(jobInfo.getJobCron()); - jobLog.setJobDesc(jobInfo.getJobDesc()); - jobLog.setJobClass(jobInfo.getJobClass()); - jobLog.setJobData(jobInfo.getJobData()); - - jobLog.setJobClass(RemoteHttpJobBean.class.getName()); - jobLog.setJobData(jobInfo.getJobData()); - DynamicSchedulerUtil.xxlJobLogDao.save(jobLog); - logger.info(">>>>>>>>>>> xxl-job trigger start, jobLog:{}", jobLog); - - // trigger request - String handler_params = jobDataMap.get(HandlerRepository.HANDLER_PARAMS); - String[] handlerParams = null; - if (StringUtils.isNotBlank(handler_params)) { - handlerParams = handler_params.split(","); - } - - jobLog.setTriggerTime(new Date()); - jobLog.setTriggerStatus(RemoteCallBack.SUCCESS); - jobLog.setTriggerMsg(null); - - try { - Object responseMsg = this.handle(handlerParams); - - jobLog.setHandleTime(new Date()); - jobLog.setHandleStatus(RemoteCallBack.SUCCESS); - jobLog.setHandleMsg(JacksonUtil.writeValueAsString(responseMsg)); - } catch (Exception e) { - logger.info("HandlerThread Exception:", e); - StringWriter out = new StringWriter(); - e.printStackTrace(new PrintWriter(out)); - - jobLog.setHandleTime(new Date()); - jobLog.setHandleStatus(RemoteCallBack.FAIL); - jobLog.setHandleMsg(out.toString()); - } - - // update trigger info - DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog); - DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(jobLog); - JobMonitorHelper.monitor(jobLog.getId()); - logger.info(">>>>>>>>>>> xxl-job trigger end, jobLog.id:{}, jobLog:{}", jobLog.getId(), jobLog); - - } - - public abstract Object handle(String... param); - -} \ No newline at end of file +//package com.xxl.job.service.job; +// +//import java.io.PrintWriter; +//import java.io.StringWriter; +//import java.util.Date; +//import java.util.HashMap; +//import java.util.Map; +// +//import org.apache.commons.lang.StringUtils; +//import org.quartz.JobExecutionContext; +//import org.quartz.JobExecutionException; +//import org.quartz.JobKey; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.scheduling.quartz.QuartzJobBean; +// +//import com.xxl.job.client.handler.HandlerRepository; +//import com.xxl.job.client.util.HttpUtil.RemoteCallBack; +//import com.xxl.job.client.util.JacksonUtil; +//import com.xxl.job.core.model.XxlJobInfo; +//import com.xxl.job.core.model.XxlJobLog; +//import com.xxl.job.core.thread.JobMonitorHelper; +//import com.xxl.job.core.util.DynamicSchedulerUtil; +// +///** +// * http job bean +// * @author xuxueli 2015-12-17 18:20:34 +// */ +//@Deprecated +//public abstract class LocalNomalJobBean extends QuartzJobBean { +// private static Logger logger = LoggerFactory.getLogger(LocalNomalJobBean.class); +// +// @Override +// protected void executeInternal(JobExecutionContext context) +// throws JobExecutionException { +// JobKey jobKey = context.getTrigger().getJobKey(); +// +// XxlJobInfo jobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(jobKey.getGroup(), jobKey.getName()); +// @SuppressWarnings("unchecked") +// HashMap jobDataMap = (HashMap) JacksonUtil.readValueRefer(jobInfo.getJobData(), Map.class); +// +// // save log +// XxlJobLog jobLog = new XxlJobLog(); +// jobLog.setJobGroup(jobInfo.getJobGroup()); +// jobLog.setJobName(jobInfo.getJobName()); +// jobLog.setJobCron(jobInfo.getJobCron()); +// jobLog.setJobDesc(jobInfo.getJobDesc()); +// jobLog.setJobClass(jobInfo.getJobClass()); +// jobLog.setJobData(jobInfo.getJobData()); +// +// jobLog.setJobClass(RemoteHttpJobBean.class.getName()); +// jobLog.setJobData(jobInfo.getJobData()); +// DynamicSchedulerUtil.xxlJobLogDao.save(jobLog); +// logger.info(">>>>>>>>>>> xxl-job trigger start, jobLog:{}", jobLog); +// +// // trigger request +// String handler_params = jobDataMap.get(HandlerRepository.HANDLER_PARAMS); +// String[] handlerParams = null; +// if (StringUtils.isNotBlank(handler_params)) { +// handlerParams = handler_params.split(","); +// } +// +// jobLog.setTriggerTime(new Date()); +// jobLog.setTriggerStatus(RemoteCallBack.SUCCESS); +// jobLog.setTriggerMsg(null); +// +// try { +// Object responseMsg = this.handle(handlerParams); +// +// jobLog.setHandleTime(new Date()); +// jobLog.setHandleStatus(RemoteCallBack.SUCCESS); +// jobLog.setHandleMsg(JacksonUtil.writeValueAsString(responseMsg)); +// } catch (Exception e) { +// logger.info("HandlerThread Exception:", e); +// StringWriter out = new StringWriter(); +// e.printStackTrace(new PrintWriter(out)); +// +// jobLog.setHandleTime(new Date()); +// jobLog.setHandleStatus(RemoteCallBack.FAIL); +// jobLog.setHandleMsg(out.toString()); +// } +// +// // update trigger info +// DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog); +// DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(jobLog); +// JobMonitorHelper.monitor(jobLog.getId()); +// logger.info(">>>>>>>>>>> xxl-job trigger end, jobLog.id:{}, jobLog:{}", jobLog.getId(), jobLog); +// +// } +// +// public abstract Object handle(String... param); +// +//} \ No newline at end of file diff --git a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java index 678347c8..a207e4ca 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java @@ -1,28 +1,29 @@ -package com.xxl.job.service.job.impl; - -import java.util.concurrent.TimeUnit; - -import org.quartz.DisallowConcurrentExecution; - -import com.xxl.job.service.job.LocalNomalJobBean; - -/** - * demo job bean for no-concurrent - * @author xuxueli 2016-3-12 14:25:14 - */ -@DisallowConcurrentExecution // 串行;线程数要多配置几个,否则不生效; -public class DemoConcurrentJobBean extends LocalNomalJobBean { - - @Override - public Object handle(String... param) { - - try { - TimeUnit.SECONDS.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return false; - } - -} +//package com.xxl.job.service.job.impl; +// +//import java.util.concurrent.TimeUnit; +// +//import org.quartz.DisallowConcurrentExecution; +// +//import com.xxl.job.service.job.LocalNomalJobBean; +// +///** +// * demo job bean for no-concurrent +// * @author xuxueli 2016-3-12 14:25:14 +// */ +//@Deprecated +//@DisallowConcurrentExecution // 串行;线程数要多配置几个,否则不生效; +//public class DemoConcurrentJobBean extends LocalNomalJobBean { +// +// @Override +// public Object handle(String... param) { +// +// try { +// TimeUnit.SECONDS.sleep(10); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// return false; +// } +// +//} diff --git a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java index 66b6e3a4..1380abbd 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java @@ -1,30 +1,31 @@ -package com.xxl.job.service.job.impl; - -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.xxl.job.service.job.LocalNomalJobBean; - -/** - * demo job bean for concurrent - * @author xuxueli 2016-3-12 14:25:57 - */ -public class DemoNomalJobBean extends LocalNomalJobBean { - private static Logger Logger = LoggerFactory.getLogger(DemoNomalJobBean.class); - - @Override - public Object handle(String... param) { - Logger.info("DemoNomalJobBean run :" + param); - - try { - TimeUnit.SECONDS.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return false; - } - -} +//package com.xxl.job.service.job.impl; +// +//import java.util.concurrent.TimeUnit; +// +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import com.xxl.job.service.job.LocalNomalJobBean; +// +///** +// * demo job bean for concurrent +// * @author xuxueli 2016-3-12 14:25:57 +// */ +//@Deprecated +//public class DemoNomalJobBean extends LocalNomalJobBean { +// private static Logger Logger = LoggerFactory.getLogger(DemoNomalJobBean.class); +// +// @Override +// public Object handle(String... param) { +// Logger.info("DemoNomalJobBean run :" + param); +// +// try { +// TimeUnit.SECONDS.sleep(10); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// return false; +// } +// +//} diff --git a/xxl-job-admin/src/main/resources/jdbc.properties b/xxl-job-admin/src/main/resources/jdbc.properties index ff308dab..23736973 100644 --- a/xxl-job-admin/src/main/resources/jdbc.properties +++ b/xxl-job-admin/src/main/resources/jdbc.properties @@ -1,4 +1,4 @@ c3p0.driverClass=com.mysql.jdbc.Driver -c3p0.url=jdbc:mysql://localhost:3306/test?Unicode=true&characterEncoding=UTF-8 +c3p0.url=jdbc:mysql://localhost:3306/xxl-job?Unicode=true&characterEncoding=UTF-8 c3p0.user=root c3p0.password=root_pwd \ No newline at end of file diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.exception.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.exception.ftl index 89b9fee7..749b1f46 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.exception.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.exception.ftl @@ -24,7 +24,7 @@

应用程序异常

抱歉!您访问的页面出现异常,请稍后重试或联系管理员。

详 情 - 返 回 + 返 回

diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/help.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/help.ftl index efae5723..525ddce9 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/help.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/help.ftl @@ -1,7 +1,7 @@ - 调度中心 + 任务调度中心 <#import "/common/common.macro.ftl" as netCommon> <@netCommon.commonStyle /> @@ -16,11 +16,13 @@
-

使用教程调度管理平台

+

任务调度中心使用教程

+
diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl new file mode 100644 index 00000000..6bddc624 --- /dev/null +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl @@ -0,0 +1,105 @@ + + + + 任务调度中心 + <#import "/common/common.macro.ftl" as netCommon> + <@netCommon.commonStyle /> + + + + + + +
+ +
+ +
+

任务调度中心任务CODE管理

+
+ + +
+ +
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+
+ + + <@netCommon.commonFooter /> +
+ +<@netCommon.comAlert /> +<@netCommon.commonScript /> + + + + + + + diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl index ba0b97c6..2773184b 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl @@ -1,7 +1,7 @@ - 调度中心 + 任务调度中心 <#import "/common/common.macro.ftl" as netCommon> <@netCommon.commonStyle /> @@ -19,11 +19,13 @@
-

调度管理调度中心

+

任务调度中心调度管理

+
@@ -104,7 +106,7 @@