任务组,改为执行器

v1.5
xueli.xue 8 years ago
parent 087cd1d435
commit eb369ec67e

@ -1,7 +1,8 @@
package com.xxl.job.admin.controller;
import com.xxl.job.admin.core.constant.Constants.JobGroupEnum;
import com.xxl.job.admin.core.model.ReturnT;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.dao.IXxlJobGroupDao;
import com.xxl.job.admin.service.IXxlJobService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
@ -19,13 +21,19 @@ import java.util.Map;
@Controller
@RequestMapping("/jobinfo")
public class JobInfoController {
@Resource
private IXxlJobGroupDao xxlJobGroupDao;
@Resource
private IXxlJobService xxlJobService;
@RequestMapping
public String index(Model model) {
model.addAttribute("JobGroupList", JobGroupEnum.values()); // 任务组列表
// 任务组
List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
model.addAttribute("JobGroupList", jobGroupList);
return "jobinfo/jobinfo.index";
}

@ -1,9 +1,10 @@
package com.xxl.job.admin.controller;
import com.xxl.job.admin.core.constant.Constants.JobGroupEnum;
import com.xxl.job.admin.core.model.ReturnT;
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.dao.IXxlJobGroupDao;
import com.xxl.job.admin.dao.IXxlJobInfoDao;
import com.xxl.job.admin.dao.IXxlJobLogDao;
import com.xxl.job.core.router.HandlerRouter.ActionRepository;
@ -34,15 +35,21 @@ import java.util.Map;
public class JobLogController {
@Resource
public IXxlJobLogDao xxlJobLogDao;
private IXxlJobGroupDao xxlJobGroupDao;
@Resource
public IXxlJobInfoDao xxlJobInfoDao;
@Resource
public IXxlJobLogDao xxlJobLogDao;
@RequestMapping
public String index(Model model, String jobGroup, String jobName) {
// 任务组
List<XxlJobGroup> jobGroupList = xxlJobGroupDao.findAll();
model.addAttribute("jobGroup", jobGroup);
model.addAttribute("jobName", jobName);
model.addAttribute("JobGroupList", JobGroupEnum.values());
model.addAttribute("JobGroupList", jobGroupList);
return "joblog/joblog.index";
}

@ -1,32 +0,0 @@
package com.xxl.job.admin.core.constant;
/**
* job group
* @author xuxueli 2016-1-15 14:23:05
*/
public class Constants {
public enum JobGroupEnum{
defaults("默认"),
waimai("外卖"),
movie("电影");
private String desc;
private JobGroupEnum(String desc){
this.desc = desc;
}
public String getDesc() {
return desc;
}
public static JobGroupEnum match(String name){
if (name==null || name.trim().length()==0) {
return null;
}
for (JobGroupEnum group : JobGroupEnum.values()) {
if (group.name().equals(name)) {
return group;
}
}
return null;
}
}
}

@ -1,6 +1,6 @@
package com.xxl.job.admin.core.thread;
import com.xxl.job.admin.core.constant.Constants;
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.util.DynamicSchedulerUtil;
@ -59,8 +59,8 @@ public class JobMonitorHelper {
Set<String> emailSet = new HashSet<String>(Arrays.asList(info.getAlarmEmail().split(",")));
for (String email: emailSet) {
String title = "《调度监控报警-任务调度中心XXL-JOB》";
String content = MessageFormat.format("任务调度失败, 任务组:{0}, 任务描述:{1}.",
Constants.JobGroupEnum.match(info.getJobGroup()).getDesc(), info.getJobDesc());
XxlJobGroup group = DynamicSchedulerUtil.xxlJobGroupDao.load(info.getJobGroup());
String content = MessageFormat.format("任务调度失败, 执行器名称:{0}, 任务描述:{1}.", group!=null?group.getTitle():"null", info.getJobDesc());
MailUtil.sendMail(email, title, content, false, null);
}
}

@ -4,6 +4,7 @@ import com.xxl.job.admin.core.callback.XxlJobLogCallbackServer;
import com.xxl.job.admin.core.jobbean.RemoteHttpJobBean;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.thread.JobRegistryHelper;
import com.xxl.job.admin.dao.IXxlJobGroupDao;
import com.xxl.job.admin.dao.IXxlJobInfoDao;
import com.xxl.job.admin.dao.IXxlJobLogDao;
import com.xxl.job.admin.dao.IXxlJobRegistryDao;
@ -66,12 +67,14 @@ public final class DynamicSchedulerUtil implements ApplicationContextAware, Init
public static IXxlJobLogDao xxlJobLogDao;
public static IXxlJobInfoDao xxlJobInfoDao;
public static IXxlJobRegistryDao xxlJobRegistryDao;
public static IXxlJobGroupDao xxlJobGroupDao;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
DynamicSchedulerUtil.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class);
DynamicSchedulerUtil.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class);
DynamicSchedulerUtil.xxlJobRegistryDao = applicationContext.getBean(IXxlJobRegistryDao.class);
DynamicSchedulerUtil.xxlJobGroupDao = applicationContext.getBean(IXxlJobGroupDao.class);
}
@Override

@ -1,9 +1,10 @@
package com.xxl.job.admin.service.impl;
import com.xxl.job.admin.core.constant.Constants.JobGroupEnum;
import com.xxl.job.admin.core.model.ReturnT;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.util.DynamicSchedulerUtil;
import com.xxl.job.admin.dao.IXxlJobGroupDao;
import com.xxl.job.admin.dao.IXxlJobInfoDao;
import com.xxl.job.admin.dao.IXxlJobLogDao;
import com.xxl.job.admin.dao.IXxlJobLogGlueDao;
@ -31,6 +32,8 @@ import java.util.Map;
public class XxlJobServiceImpl implements IXxlJobService {
private static Logger logger = LoggerFactory.getLogger(XxlJobServiceImpl.class);
@Resource
private IXxlJobGroupDao xxlJobGroupDao;
@Resource
private IXxlJobInfoDao xxlJobInfoDao;
@Resource
@ -65,8 +68,9 @@ public class XxlJobServiceImpl implements IXxlJobService {
String executorAppname, String executorAddress, String executorHandler, String executorParam,
int glueSwitch, String glueSource, String glueRemark, String childJobKey) {
// valid
if (JobGroupEnum.match(jobGroup) == null) {
return new ReturnT<String>(500, "请选择“任务组”");
XxlJobGroup group = xxlJobGroupDao.load(jobGroup);
if (group == null) {
return new ReturnT<String>(500, "请选择“执行器”");
}
if (!CronExpression.isValidExpression(jobCron)) {
return new ReturnT<String>(500, "请输入格式正确的“Cron”");
@ -153,8 +157,9 @@ public class XxlJobServiceImpl implements IXxlJobService {
String executorAppname, String executorAddress, String executorHandler, String executorParam, int glueSwitch, String childJobKey) {
// valid
if (JobGroupEnum.match(jobGroup) == null) {
return new ReturnT<String>(500, "请选择“任务组”");
XxlJobGroup group = xxlJobGroupDao.load(jobGroup);
if (group == null) {
return new ReturnT<String>(500, "请选择“执行器”");
}
if (StringUtils.isBlank(jobName)) {
return new ReturnT<String>(500, "请输入“任务名”");

@ -40,10 +40,10 @@
<div class="row">
<div class="col-xs-4">
<div class="input-group">
<span class="input-group-addon">任务组</span>
<span class="input-group-addon">执行器</span>
<select class="form-control" id="jobGroup" >
<#list JobGroupList as group>
<option value="${group}" >${group.desc}</option>
<option value="${group.appName}" >${group.title}</option>
</#list>
</select>
</div>
@ -115,11 +115,11 @@
<div class="modal-body">
<form class="form-horizontal form" role="form" >
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">任务组<font color="red">*</font></label>
<label for="firstname" class="col-sm-2 control-label">执行器<font color="red">*</font></label>
<div class="col-sm-4">
<select class="form-control" name="jobGroup" >
<#list JobGroupList as group>
<option value="${group}" >${group.desc}</option>
<option value="${group.appName}" >${group.title}</option>
</#list>
</select>
</div>
@ -207,7 +207,7 @@ public class DemoGlueJobHandler extends IJobHandler {
<div class="modal-body">
<form class="form-horizontal form" role="form" >
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">任务组<font color="red">*</font></label>
<label for="firstname" class="col-sm-2 control-label">执行器<font color="red">*</font></label>
<div class="col-sm-4">
<input type="text" class="form-control jobGroupTitle" maxlength="50" readonly >
</div>

@ -34,11 +34,11 @@
<div class="row">
<div class="col-xs-3">
<div class="input-group">
<span class="input-group-addon">任务组</span>
<span class="input-group-addon">执行器</span>
<select class="form-control" id="jobGroup" paramVal="${jobGroup}" >
<option value="" selected>请选择</option>
<#list JobGroupList as group>
<option value="${group}" <#if jobGroup == group && false>selected</#if> >${group.desc}</option>
<option value="${group.appName}" <#if jobGroup == group.appName && false>selected</#if> >${group.title}</option>
</#list>
</select>
</div>

Loading…
Cancel
Save