add version

pull/41/head
姚仲杰 3 years ago
parent 3cf27f90b4
commit 5d2e4b4bbc

@ -12,6 +12,7 @@ CREATE TABLE `xxl_job_info` (
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_desc` varchar(255) NOT NULL,
`add_time` datetime DEFAULT NULL,
`version` varchar(128) default null comment '标签',
`update_time` datetime DEFAULT NULL,
`author` varchar(64) DEFAULT NULL COMMENT '作者',
`alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮件',
@ -80,6 +81,7 @@ CREATE TABLE `xxl_job_logglue` (
CREATE TABLE `xxl_job_registry` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`registry_version` varchar(128) default null comment '标签',
`registry_group` varchar(50) NOT NULL,
`registry_key` varchar(255) NOT NULL,
`registry_value` varchar(255) NOT NULL,

@ -4,6 +4,7 @@ import com.xxl.job.admin.core.cron.CronExpression;
import com.xxl.job.admin.core.exception.XxlJobException;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobRegistry;
import com.xxl.job.admin.core.model.XxlJobUser;
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
import com.xxl.job.admin.core.scheduler.MisfireStrategyEnum;
@ -13,12 +14,14 @@ 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.dao.XxlJobRegistryDao;
import com.xxl.job.admin.service.LoginService;
import com.xxl.job.admin.service.XxlJobService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.job.core.util.DateUtil;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@ -45,6 +48,8 @@ public class JobInfoController {
private XxlJobGroupDao xxlJobGroupDao;
@Resource
private XxlJobService xxlJobService;
@Resource
XxlJobRegistryDao xxlJobRegistryDao;
@RequestMapping
public String index(HttpServletRequest request, Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) {
@ -64,6 +69,28 @@ public class JobInfoController {
if (jobGroupList==null || jobGroupList.size()==0) {
throw new XxlJobException(I18nUtil.getString("jobgroup_empty"));
}
if (jobGroup==-1){
jobGroup=jobGroupList.get(0).getId();
}
List<String> list=new ArrayList<>();
for (XxlJobGroup group : jobGroupList) {
if (group.getId()==jobGroup){
if (group.getAddressList()!=null){
String[] split = group.getAddressList().split(",");
if (split.length>0){
list=new ArrayList<String>(Arrays.asList(split)) ;
}
}
}
}
if (list.size()>0) {
List<XxlJobRegistry> registryList = xxlJobRegistryDao
.findByGroup(jobGroup, list);
List<XxlJobRegistry> distinct = registryList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getRegistryValue() + ";" + o.getRegistryVersion()))), ArrayList::new));
model.addAttribute("registryList",distinct);
}
//这里可以去重,必要不大
model.addAttribute("JobGroupList", jobGroupList);
model.addAttribute("jobGroup", jobGroup);
@ -140,13 +167,13 @@ public class JobInfoController {
@RequestMapping("/trigger")
@ResponseBody
//@PermissionLimit(limit = false)
public ReturnT<String> triggerJob(int id, String executorParam, String addressList) {
public ReturnT<String> triggerJob(int id, String executorParam, String addressList,String version) {
// force cover job param
if (executorParam == null) {
executorParam = "";
}
JobTriggerPoolHelper.trigger(id, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList);
JobTriggerPoolHelper.trigger(id, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList,version);
return ReturnT.SUCCESS;
}

@ -57,7 +57,7 @@ public class XxlJobCompleter {
int childJobId = (childJobIds[i]!=null && childJobIds[i].trim().length()>0 && isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1;
if (childJobId > 0) {
JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null, null);
JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null, null,null);
ReturnT<String> triggerChildResult = ReturnT.SUCCESS;
// add msg

@ -14,6 +14,8 @@ public class XxlJobInfo {
private int jobGroup; // 执行器主键ID
private String jobDesc;
private String version;
private Date addTime;
private Date updateTime;
@ -67,6 +69,14 @@ public class XxlJobInfo {
this.jobDesc = jobDesc;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Date getAddTime() {
return addTime;
}

@ -9,6 +9,7 @@ public class XxlJobRegistry {
private int id;
private String registryGroup;
private String registryVersion;
private String registryKey;
private String registryValue;
private Date updateTime;
@ -25,6 +26,14 @@ public class XxlJobRegistry {
return registryGroup;
}
public String getRegistryVersion() {
return registryVersion;
}
public void setRegistryVersion(String registryVersion) {
this.registryVersion = registryVersion;
}
public void setRegistryGroup(String registryGroup) {
this.registryGroup = registryGroup;
}

@ -52,7 +52,7 @@ public class JobFailMonitorHelper {
// 1、fail retry monitor
if (log.getExecutorFailRetryCount() > 0) {
JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount()-1), log.getExecutorShardingParam(), log.getExecutorParam(), null);
JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount()-1), log.getExecutorShardingParam(), log.getExecutorParam(), null,null);
String retryMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_type_retry") +"<<<<<<<<<<< </span><br>";
log.setTriggerMsg(log.getTriggerMsg() + retryMsg);
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(log);

@ -159,9 +159,9 @@ public class JobRegistryHelper {
registryOrRemoveThreadPool.execute(new Runnable() {
@Override
public void run() {
int ret = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().registryUpdate(registryParam.getRegistryGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue(), new Date());
int ret = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().registryUpdate(registryParam.getRegistryGroup(),registryParam.getRegistryVersion(), registryParam.getRegistryKey(), registryParam.getRegistryValue(), new Date());
if (ret < 1) {
XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().registrySave(registryParam.getRegistryGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue(), new Date());
XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().registrySave(registryParam.getRegistryGroup(),registryParam.getRegistryVersion(), registryParam.getRegistryKey(), registryParam.getRegistryValue(), new Date());
// fresh
freshGroupRegistryInfo(registryParam);

@ -91,7 +91,7 @@ public class JobScheduleHelper {
MisfireStrategyEnum misfireStrategyEnum = MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), MisfireStrategyEnum.DO_NOTHING);
if (MisfireStrategyEnum.FIRE_ONCE_NOW == misfireStrategyEnum) {
// FIRE_ONCE_NOW 》 trigger
JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.MISFIRE, -1, null, null, null);
JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.MISFIRE, -1, null, null, null,null);
logger.debug(">>>>>>>>>>> xxl-job, schedule push trigger : jobId = " + jobInfo.getId() );
}
@ -102,7 +102,7 @@ public class JobScheduleHelper {
// 2.2、trigger-expire < 5sdirect-trigger && make next-trigger-time
// 1、trigger
JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.CRON, -1, null, null, null);
JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.CRON, -1, null, null, null,null);
logger.debug(">>>>>>>>>>> xxl-job, schedule push trigger : jobId = " + jobInfo.getId() );
// 2、fresh next
@ -250,7 +250,7 @@ public class JobScheduleHelper {
// do trigger
for (int jobId: ringItemData) {
// do trigger
JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null, null, null);
JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null, null, null,null);
}
// clear
ringItemData.clear();

@ -74,7 +74,7 @@ public class JobTriggerPoolHelper {
final int failRetryCount,
final String executorShardingParam,
final String executorParam,
final String addressList) {
final String addressList,final String version) {
// choose thread pool
ThreadPoolExecutor triggerPool_ = fastTriggerPool;
@ -92,7 +92,7 @@ public class JobTriggerPoolHelper {
try {
// do trigger
XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList);
XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList,version);
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
@ -143,8 +143,8 @@ public class JobTriggerPoolHelper {
* null: use job param
* not null: cover job param
*/
public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam, String executorParam, String addressList) {
helper.addTrigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList);
public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam, String executorParam, String addressList,String version) {
helper.addTrigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList,version);
}
}

@ -0,0 +1,20 @@
package com.xxl.job.admin.core.trigger;
/**
* @Description TODO
* @Author #80998699
* @Date 2022/1/4 16:45
*/
public enum VersionEnum {
DEFAULT("default"),
MASTER("master");
private String version;
VersionEnum(String version){
this.version=version;
}
public String get(){
return version;
}
}

@ -4,6 +4,7 @@ import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
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.model.XxlJobRegistry;
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
import com.xxl.job.admin.core.scheduler.XxlJobScheduler;
import com.xxl.job.admin.core.util.I18nUtil;
@ -13,10 +14,13 @@ import com.xxl.job.core.biz.model.TriggerParam;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.util.IpUtil;
import com.xxl.job.core.util.ThrowableUtil;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import org.springframework.util.StringUtils;
/**
* xxl-job trigger
@ -46,7 +50,7 @@ public class XxlJobTrigger {
int failRetryCount,
String executorShardingParam,
String executorParam,
String addressList) {
String addressList,String version) {
// load data
XxlJobInfo jobInfo = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(jobId);
@ -57,8 +61,22 @@ public class XxlJobTrigger {
if (executorParam != null) {
jobInfo.setExecutorParam(executorParam);
}
if (version !=null){
jobInfo.setVersion(version);
}
int finalFailRetryCount = failRetryCount>=0?failRetryCount:jobInfo.getExecutorFailRetryCount();
XxlJobGroup group = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().load(jobInfo.getJobGroup());
//版本过滤 分成手动模式和自动模式手动模式下取传入参数自动模式取jobinfo参数仅executorParam和version
if (!StringUtils.isEmpty(jobInfo.getVersion())&&!VersionEnum.DEFAULT.get().equals(jobInfo.getVersion())) {
List<XxlJobRegistry> byVersion = XxlJobAdminConfig.getAdminConfig()
.getXxlJobRegistryDao()
.findByVersion(jobInfo.getVersion(), group.getRegistryList());
List<String> addresses=new ArrayList<>();
for (XxlJobRegistry xxlJobRegistry : byVersion) {
addresses.add(xxlJobRegistry.getRegistryValue());
}
group.setAddressList(String.join(",",addresses));
}
// cover addressList
if (addressList!=null && addressList.trim().length()>0) {
@ -126,6 +144,7 @@ public class XxlJobTrigger {
// 2、init trigger-param
TriggerParam triggerParam = new TriggerParam();
triggerParam.setJobId(jobInfo.getId());
triggerParam.setVersion(jobInfo.getVersion());
triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
triggerParam.setExecutorParams(jobInfo.getExecutorParam());
triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());

@ -21,12 +21,16 @@ public interface XxlJobRegistryDao {
public List<XxlJobRegistry> findAll(@Param("timeout") int timeout,
@Param("nowTime") Date nowTime);
public List<XxlJobRegistry> findByGroup(@Param("groupId")int id,@Param("list")List<String> list);
public List<XxlJobRegistry> findByVersion(@Param("registryVersion") String version,@Param("list")List<String> list);
public int registryUpdate(@Param("registryGroup") String registryGroup,
@Param("registryVersion") String registryVersion,
@Param("registryKey") String registryKey,
@Param("registryValue") String registryValue,
@Param("updateTime") Date updateTime);
public int registrySave(@Param("registryGroup") String registryGroup,
@Param("registryVersion") String registryVersion,
@Param("registryKey") String registryKey,
@Param("registryValue") String registryValue,
@Param("updateTime") Date updateTime);

@ -266,6 +266,7 @@ public class XxlJobServiceImpl implements XxlJobService {
exists_jobInfo.setJobGroup(jobInfo.getJobGroup());
exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
exists_jobInfo.setVersion(jobInfo.getVersion());
exists_jobInfo.setAuthor(jobInfo.getAuthor());
exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
exists_jobInfo.setScheduleType(jobInfo.getScheduleType());

@ -25,7 +25,7 @@ mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root_pwd
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
### datasource-pool

@ -36,6 +36,7 @@
<result column="trigger_status" property="triggerStatus" />
<result column="trigger_last_time" property="triggerLastTime" />
<result column="trigger_next_time" property="triggerNextTime" />
<result column="version" property="version" />
</resultMap>
<sql id="Base_Column_List">
@ -62,7 +63,8 @@
t.child_jobid,
t.trigger_status,
t.trigger_last_time,
t.trigger_next_time
t.trigger_next_time,
t.version
</sql>
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
@ -135,7 +137,8 @@
child_jobid,
trigger_status,
trigger_last_time,
trigger_next_time
trigger_next_time,
version
) VALUES (
#{jobGroup},
#{jobDesc},
@ -159,7 +162,8 @@
#{childJobId},
#{triggerStatus},
#{triggerLastTime},
#{triggerNextTime}
#{triggerNextTime},
#{version}
);
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
@ -197,7 +201,8 @@
child_jobid = #{childJobId},
trigger_status = #{triggerStatus},
trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime}
trigger_next_time = #{triggerNextTime},
version=#{version}
WHERE id = #{id}
</update>

@ -8,6 +8,7 @@
<result column="registry_group" property="registryGroup" />
<result column="registry_key" property="registryKey" />
<result column="registry_value" property="registryValue" />
<result column="registry_version" property="registryVersion" />
<result column="update_time" property="updateTime" />
</resultMap>
@ -16,6 +17,7 @@
t.registry_group,
t.registry_key,
t.registry_value,
t.registry_version,
t.update_time
</sql>
@ -39,17 +41,43 @@
WHERE t.update_time <![CDATA[ > ]]> DATE_ADD(#{nowTime},INTERVAL -#{timeout} SECOND)
</select>
<select id="findByGroup" parameterType="java.util.HashMap" resultMap="XxlJobRegistry">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_registry AS t
INNER JOIN xxl_job_group g on g.id=#{groupId} and g.app_name=t.registry_key
where 1=1
<if test="list!=null and list.size !='' ">
and registry_value in
<foreach collection="list" separator="," item="item" open="(" close=")">
#{item}
</foreach>
</if>
</select>
<select id="findByVersion" parameterType="java.util.HashMap" resultMap="XxlJobRegistry">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_registry AS t
WHERE t.registry_version=#{registryVersion}
<if test="list!=null and list.size !='' ">
and registry_value in
<foreach collection="list" separator="," item="item" open="(" close=")">
#{item}
</foreach>
</if>
</select>
<update id="registryUpdate" >
UPDATE xxl_job_registry
SET `update_time` = #{updateTime}
WHERE `registry_group` = #{registryGroup}
AND `registry_key` = #{registryKey}
AND `registry_value` = #{registryValue}
AND `registry_version` = #{registryVersion}
</update>
<insert id="registrySave" >
INSERT INTO xxl_job_registry( `registry_group` , `registry_key` , `registry_value`, `update_time`)
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, #{updateTime})
INSERT INTO xxl_job_registry( `registry_group` , `registry_key` , `registry_value`,`registry_version`, `update_time`)
VALUES( #{registryGroup} , #{registryKey} , #{registryValue},#{registryVersion}, #{updateTime})
</insert>
<delete id="registryDelete" >

@ -266,7 +266,17 @@ $(function() {
$("#jobTriggerModal .form input[name='id']").val( row.id );
$("#jobTriggerModal .form textarea[name='executorParam']").val( row.executorParam );
let b=false;
$("#jobTriggerModal .form select[name=registry] option").each(function(){
var txt = $(this).val();
if (txt==row.version){
$(this).prop('selected', true);
b=true;
}
});
if(!b){
$('#jobTriggerModal .form select[name=registry] option[value=default]').prop('selected', true);
}
$('#jobTriggerModal').modal({backdrop: false, keyboard: false}).modal('show');
});
$("#jobTriggerModal .ok").on('click',function() {
@ -276,7 +286,8 @@ $(function() {
data : {
"id" : $("#jobTriggerModal .form input[name='id']").val(),
"executorParam" : $("#jobTriggerModal .textarea[name='executorParam']").val(),
"addressList" : $("#jobTriggerModal .textarea[name='addressList']").val()
"addressList" : $("#jobTriggerModal .textarea[name='addressList']").val(),
"version": $("#registry").find("option:selected").val()
},
dataType : "json",
success : function(data){
@ -576,7 +587,18 @@ $(function() {
$('#updateModal .form select[name=executorBlockStrategy] option[value='+ row.executorBlockStrategy +']').prop('selected', true);
$("#updateModal .form input[name='executorTimeout']").val( row.executorTimeout );
$("#updateModal .form input[name='executorFailRetryCount']").val( row.executorFailRetryCount );
//select version
let b=false;
$("#updateModal .form select[name=version] option").each(function(){
var txt = $(this).val();
if (txt==row.version){
$(this).prop('selected', true);
b=true;
}
});
if(!b){
$('#updateModal .form select[name=version] option[value=default]').prop('selected', true);
}
// show
$('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
});

@ -92,7 +92,7 @@
<div class="col-sm-10">
<input type="radio" name="addressType" value="0" checked />${I18n.jobgroup_field_addressType_0}
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="addressType" value="1" />${I18n.jobgroup_field_addressType_1}
<#-- <input type="radio" name="addressType" value="1" />${I18n.jobgroup_field_addressType_1}-->
</div>
</div>
<div class="form-group">
@ -136,7 +136,7 @@
<div class="col-sm-10">
<input type="radio" name="addressType" value="0" />${I18n.jobgroup_field_addressType_0}
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="addressType" value="1" />${I18n.jobgroup_field_addressType_1}
<#-- <input type="radio" name="addressType" value="1" />${I18n.jobgroup_field_addressType_1}-->
</div>
</div>
<div class="form-group">

@ -190,7 +190,19 @@
<br>
<p style="margin: 0 0 10px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">${I18n.jobinfo_conf_advanced}</p> <#-- -->
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label"><font color="black">*</font></label>
<div class="col-sm-4">
<select class="form-control" name="version" >
<option value="default" selected>--default--</option>
<#if registryList?exists>
<#list registryList as registry>
<option value="${(registry.registryVersion)!'null'}">${(registry.registryVersion)!'null'}--${registry.registryValue}</option>
</#list>
</#if>
</select>
</div>
</div>
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">${I18n.jobinfo_field_executorRouteStrategy}<font color="black">*</font></label>
<div class="col-sm-4">
@ -435,7 +447,19 @@ exit 0
<br>
<p style="margin: 0 0 10px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">${I18n.jobinfo_conf_advanced}</p> <#-- -->
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label"><font color="black">*</font></label>
<div class="col-sm-4">
<select class="form-control" name="version" >
<option value="default" selected>--default--</option>
<#if registryList?exists>
<#list registryList as registry>
<option value="${(registry.registryVersion)!'null'}">${(registry.registryVersion)!'null'}--${registry.registryValue}</option>
</#list>
</#if>
</select>
</div>
</div>
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">${I18n.jobinfo_field_executorRouteStrategy}<font color="red">*</font></label>
<div class="col-sm-4">
@ -501,6 +525,19 @@ exit 0
</div>
<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="black">*</font></label>
<div class="col-sm-4">
<select class="form-control" id="registry" name="registry" >
<option value="default" selected>--default--</option>
<#if registryList?exists>
<#list registryList as registry>
<option value="${(registry.registryVersion)!'null'}">${(registry.registryVersion)!'null'}--${registry.registryValue}</option>
</#list>
</#if>
</select>
</div>
</div>
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">${I18n.jobinfo_field_executorparam}<font color="black">*</font></label>
<div class="col-sm-10">

@ -17,9 +17,9 @@ public class XxlJobRegistryDaoTest {
@Test
public void test(){
int ret = xxlJobRegistryDao.registryUpdate("g1", "k1", "v1", new Date());
int ret = xxlJobRegistryDao.registryUpdate("g1", null,"k1", "v1", new Date());
if (ret < 1) {
ret = xxlJobRegistryDao.registrySave("g1", "k1", "v1", new Date());
ret = xxlJobRegistryDao.registrySave("g1", null,"k1", "v1", new Date());
}
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(1, new Date());

@ -50,7 +50,7 @@ public class AdminBizTest {
public void registry() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999",null);
ReturnT<String> returnT = adminBiz.registry(registryParam);
assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
@ -65,7 +65,7 @@ public class AdminBizTest {
public void registryRemove() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999",null);
ReturnT<String> returnT = adminBiz.registryRemove(registryParam);
assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);

@ -11,12 +11,22 @@ public class RegistryParam implements Serializable {
private String registryGroup;
private String registryKey;
private String registryValue;
private String registryVersion;
public RegistryParam(){}
public RegistryParam(String registryGroup, String registryKey, String registryValue) {
public RegistryParam(String registryGroup, String registryKey, String registryValue,String registryVersion) {
this.registryGroup = registryGroup;
this.registryKey = registryKey;
this.registryValue = registryValue;
this.registryVersion=registryVersion;
}
public String getRegistryVersion() {
return registryVersion;
}
public void setRegistryVersion(String registryVersion) {
this.registryVersion = registryVersion;
}
public String getRegistryGroup() {

@ -9,6 +9,7 @@ public class TriggerParam implements Serializable{
private static final long serialVersionUID = 42L;
private int jobId;
private String version;
private String executorHandler;
private String executorParams;
@ -34,6 +35,14 @@ public class TriggerParam implements Serializable{
this.jobId = jobId;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getExecutorHandler() {
return executorHandler;
}

@ -60,14 +60,15 @@ public class XxlJobContext {
*/
private String handleMsg;
private String version;
public XxlJobContext(long jobId, String jobParam, String jobLogFileName, int shardIndex, int shardTotal) {
public XxlJobContext(long jobId, String jobParam, String jobLogFileName, int shardIndex, int shardTotal,String version) {
this.jobId = jobId;
this.jobParam = jobParam;
this.jobLogFileName = jobLogFileName;
this.shardIndex = shardIndex;
this.shardTotal = shardTotal;
this.version=version;
this.handleCode = HANDLE_CODE_SUCCESS; // default success
}
@ -107,6 +108,14 @@ public class XxlJobContext {
return handleMsg;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
// ---------------------- tool ----------------------
private static InheritableThreadLocal<XxlJobContext> contextHolder = new InheritableThreadLocal<XxlJobContext>(); // support for child thread of job handler)

@ -34,6 +34,14 @@ public class XxlJobHelper {
return xxlJobContext.getJobId();
}
public static String getVersion() {
XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
if (xxlJobContext == null) {
return null;
}
return xxlJobContext.getVersion();
}
/**
* current JobParam
*

@ -37,6 +37,15 @@ public class XxlJobExecutor {
private int port;
private String logPath;
private int logRetentionDays;
private String version;
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public void setAdminAddresses(String adminAddresses) {
this.adminAddresses = adminAddresses;
@ -81,7 +90,7 @@ public class XxlJobExecutor {
TriggerCallbackThread.getInstance().start();
// init executor-server
initEmbedServer(address, ip, port, appname, accessToken);
initEmbedServer(address, ip, port, appname, accessToken,version);
}
public void destroy(){
@ -140,7 +149,7 @@ public class XxlJobExecutor {
// ---------------------- executor-server (rpc provider) ----------------------
private EmbedServer embedServer = null;
private void initEmbedServer(String address, String ip, int port, String appname, String accessToken) throws Exception {
private void initEmbedServer(String address, String ip, int port, String appname, String accessToken,String version) throws Exception {
// fill ip port
port = port>0?port: NetUtil.findAvailablePort(9999);
@ -159,7 +168,7 @@ public class XxlJobExecutor {
// start
embedServer = new EmbedServer();
embedServer.start(address, port, appname, accessToken);
embedServer.start(address, port, appname, accessToken,version);
}
private void stopEmbedServer() {

@ -33,7 +33,7 @@ public class EmbedServer {
private ExecutorBiz executorBiz;
private Thread thread;
public void start(final String address, final int port, final String appname, final String accessToken) {
public void start(final String address, final int port, final String appname, final String accessToken,final String version) {
executorBiz = new ExecutorBizImpl();
thread = new Thread(new Runnable() {
@Override
@ -82,7 +82,7 @@ public class EmbedServer {
logger.info(">>>>>>>>>>> xxl-job remoting server start success, nettype = {}, port = {}", EmbedServer.class, port);
// start registry
startRegistry(appname, address);
startRegistry(appname, address,version);
// wait util stop
future.channel().closeFuture().sync();
@ -244,9 +244,9 @@ public class EmbedServer {
// ---------------------- registry ----------------------
public void startRegistry(final String appname, final String address) {
public void startRegistry(final String appname, final String address,final String version) {
// start registry
ExecutorRegistryThread.getInstance().start(appname, address);
ExecutorRegistryThread.getInstance().start(appname, address,version);
}
public void stopRegistry() {

@ -23,7 +23,7 @@ public class ExecutorRegistryThread {
private Thread registryThread;
private volatile boolean toStop = false;
public void start(final String appname, final String address){
public void start(final String appname, final String address, final String version){
// valid
if (appname==null || appname.trim().length()==0) {
@ -42,7 +42,7 @@ public class ExecutorRegistryThread {
// registry
while (!toStop) {
try {
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address);
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address,version);
for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
try {
ReturnT<String> registryResult = adminBiz.registry(registryParam);
@ -78,7 +78,7 @@ public class ExecutorRegistryThread {
// registry remove
try {
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address);
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address,version);
for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
try {
ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);

@ -124,7 +124,7 @@ public class JobThread extends Thread{
triggerParam.getExecutorParams(),
logFileName,
triggerParam.getBroadcastIndex(),
triggerParam.getBroadcastTotal());
triggerParam.getBroadcastTotal(),triggerParam.getVersion());
// init job context
XxlJobContext.setXxlJobContext(xxlJobContext);

@ -193,7 +193,7 @@ public class TriggerCallbackThread {
null,
logFileName,
-1,
-1));
-1,null));
XxlJobHelper.log(logContent);
}
}

@ -53,7 +53,7 @@ public class XxlJobConfig {
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
xxlJobSpringExecutor.setVersion("master");//实际应用中应该从编译插件获得git分支号
return xxlJobSpringExecutor;
}

Loading…
Cancel
Save