1、去除"任务名JobName"属性,"描述"改为"名称"属性,"任务名"改为"分组"属性;

2、去除"Jobhandler"属性,新增JobKey,功能同原"JobHander属性",但是不支持修改;
3、去除"GLUE模式"复选框,改为新增的"任务模式"下拉框,且创建后不支持修改;
v1.4
xueli.xue 8 years ago
parent 5b8db953d6
commit c1cda137d5

@ -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<String> 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<String> 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")

@ -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<String, String> reqMap = new HashMap<String, String>();
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);

@ -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<String, String> handler_params, XxlJobLog jobLog){

@ -14,13 +14,13 @@ public interface IXxlJobService {
public Map<String, Object> pageList(int start, int length, String jobGroup, String jobDesc, String filterTime);
public ReturnT<String> 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<String> 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<String> remove(String jobGroup, String jobName);

@ -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<String> 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<String>(500, "请输入“执行器地址”");
}
if (glueSwitch==0 && StringUtils.isBlank(executorHandler)) {
return new ReturnT<String>(500, "请输入“jobHandler”");
}
if (StringUtils.isBlank(author)) {
return new ReturnT<String>(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<String>(500, "此任务已存在,请更换任务组或任务名");
return new ReturnT<String>(500, "系统繁忙,请稍后重试");
}
} catch (SchedulerException e1) {
e1.printStackTrace();
return new ReturnT<String>(500, "此任务已存在,请更换任务组或任务名");
return new ReturnT<String>(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<String> 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<String>(500, "请输入“执行器地址”");
}
if (glueSwitch==0 && StringUtils.isBlank(executorHandler)) {
return new ReturnT<String>(500, "请输入“jobHandler”");
}
if (StringUtils.isBlank(author)) {
return new ReturnT<String>(500, "请输入“负责人”");
}
if (StringUtils.isBlank(alarmEmail)) {
return new ReturnT<String>(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 {

@ -73,7 +73,6 @@
<th name="jobCron" >Cron</th>
<th name="jobClass" >JobBean</th>
<th name="executorAddress" >执行器地址</th>
<th name="executorHandler" >JobHandler</th>
<th name="executorParam" >任务参数</th>
<th name="addTime" >新增时间</th>
<th name="updateTime" >更新时间</th>
@ -121,16 +120,16 @@
<div class="col-sm-4"><input type="text" class="form-control" name="jobDesc" placeholder="请输入“描述”" maxlength="50" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">Cron<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="jobCron" placeholder="请输入“Cron”" maxlength="20" ></div>
<label for="lastname" class="col-sm-2 control-label">执行器地址<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="executorAddress" placeholder="请输入“执行器地址”,多个地址逗号分隔" maxlength="50" ></div>
<label for="lastname" class="col-sm-2 control-label">Cron<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="jobCron" placeholder="请输入“Cron”" maxlength="20" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">JobHandler<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="executorHandler" placeholder="请输入“jobHandler”" maxlength="50" ></div>
<label for="firstname" class="col-sm-2 control-label">执行参数<font color="black">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="executorParam" placeholder="请输入“执行参数”" maxlength="100" ></div>
<label for="lastname" class="col-sm-2 control-label">负责人<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="author" placeholder="请输入“负责人”" maxlength="50" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">报警邮件<font color="red">*</font></label>
@ -139,20 +138,19 @@
<div class="col-sm-4"><input type="text" class="form-control" name="alarmThreshold" placeholder="请输入“报警阈值”" maxlength="5" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">负责人<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="author" placeholder="请输入“负责人”" maxlength="50" ></div>
<label for="firstname" class="col-sm-2 control-label">任务模式<font color="red">*</font></label>
<div class="col-sm-4">
<select class="form-control" name="glueSwitch" >
<option value="0" >BEAN模式</option>
<option value="1" >GLUE模式</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-primary" >保存</button>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
</div>
<div class="col-sm-3">
<div class="checkbox">
<label><input type="checkbox" class="ifGLUE" >开启GLUE模式<font color="black">*</font></label>
<input type="hidden" name="glueSwitch" value="0" >
</div>
</div>
</div>
<input type="hidden" name="glueRemark" value="GLUE代码初始化" >
@ -207,17 +205,17 @@ public class DemoJobHandler extends IJobHandler {
<div class="col-sm-4"><input type="text" class="form-control" name="jobDesc" placeholder="请输入“描述”" maxlength="50" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">Cron<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="jobCron" placeholder="请输入“Cron”" maxlength="20" ></div>
<label for="lastname" class="col-sm-2 control-label">执行器地址<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="executorAddress" placeholder="请输入“执行器地址”,多个地址逗号分隔" maxlength="50" ></div>
<label for="lastname" class="col-sm-2 control-label">Cron<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="jobCron" placeholder="请输入“Cron”" maxlength="20" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">JobHandler<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="executorHandler" placeholder="请输入“jobHandler”" maxlength="50" ></div>
<label for="firstname" class="col-sm-2 control-label">执行参数<font color="black">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="executorParam" placeholder="请输入“执行参数”" maxlength="100" ></div>
<label for="lastname" class="col-sm-2 control-label">负责人<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="author" placeholder="请输入“负责人”" maxlength="50" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">报警邮件<font color="red">*</font></label>
@ -226,20 +224,21 @@ public class DemoJobHandler extends IJobHandler {
<div class="col-sm-4"><input type="text" class="form-control" name="alarmThreshold" placeholder="请输入“报警阈值”" maxlength="5" ></div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">负责人<font color="red">*</font></label>
<div class="col-sm-4"><input type="text" class="form-control" name="author" placeholder="请输入“负责人”" maxlength="50" ></div>
<label for="firstname" class="col-sm-2 control-label">任务模式<font color="red">*</font></label>
<div class="col-sm-4">
<select class="form-control" name="glueSwitch" disabled >
<option value="0" >BEAN模式</option>
<option value="1" >GLUE模式</option>
</select>
</div>
<label for="lastname" class="col-sm-2 control-label">JobKey</label>
<div class="col-sm-4"><input type="text" class="form-control" name="jobKey" placeholder="请输入“jobHandler”" readonly ></div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-primary" >保存</button>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
</div>
<div class="col-sm-3">
<div class="checkbox">
<label><input type="checkbox" class="ifGLUE" >开启GLUE模式<font color="black">*</font></label>
<input type="hidden" name="glueSwitch" value="0" >
</div>
</div>
</div>
</form>
</div>

@ -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() {
});
});
*/
});

@ -88,7 +88,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
Map<String, Object> 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);

@ -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-no1-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())) {

@ -15,6 +15,6 @@ import java.lang.annotation.Target;
@Inherited
public @interface JobHander {
String name();
String value() default "";
}

@ -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);

Loading…
Cancel
Save