refactor(core): 重构枚举类和返回类型以提升代码一致性

- 将 RegistryConfig 类重命名为 Const 并调整包路径
- 更新所有引用 RegistryConfig 的地方为 Const- 将 ReturnT 返回类型统一替换为 Response
- 调整相关静态常量引用路径
- 更新测试类中的客户端构建方式和参数引用
- 修改前端JS中对返回数据字段的访问方式
- 更新文档中关于枚举类的引用说明
3.3.0-release
xuxueli 1 month ago
parent fa7eec0693
commit 4ab5c54748

@ -1919,7 +1919,7 @@ Header
"jobId":1, // 任务ID "jobId":1, // 任务ID
"executorHandler":"demoJobHandler", // 任务标识 "executorHandler":"demoJobHandler", // 任务标识
"executorParams":"demoJobHandler", // 任务参数 "executorParams":"demoJobHandler", // 任务参数
"executorBlockStrategy":"COVER_EARLY", // 任务阻塞策略,可选值参考 com.xxl.job.core.enums.ExecutorBlockStrategyEnum "executorBlockStrategy":"COVER_EARLY", // 任务阻塞策略,可选值参考 com.xxl.job.core.constant.ExecutorBlockStrategyEnum
"executorTimeout":0, // 任务超时时间,单位秒,大于零时生效 "executorTimeout":0, // 任务超时时间,单位秒,大于零时生效
"logId":1, // 本次调度日志ID "logId":1, // 本次调度日志ID
"logDateTime":1586629003729, // 本次调度日志时间 "logDateTime":1586629003729, // 本次调度日志时间

@ -7,7 +7,7 @@ import com.xxl.job.admin.util.I18nUtil;
import com.xxl.job.admin.mapper.XxlJobGroupMapper; import com.xxl.job.admin.mapper.XxlJobGroupMapper;
import com.xxl.job.admin.mapper.XxlJobInfoMapper; import com.xxl.job.admin.mapper.XxlJobInfoMapper;
import com.xxl.job.admin.mapper.XxlJobRegistryMapper; import com.xxl.job.admin.mapper.XxlJobRegistryMapper;
import com.xxl.job.core.enums.RegistryConfig; import com.xxl.job.core.constant.Const;
import com.xxl.sso.core.annotation.XxlSso; import com.xxl.sso.core.annotation.XxlSso;
import com.xxl.tool.core.CollectionTool; import com.xxl.tool.core.CollectionTool;
import com.xxl.tool.core.StringTool; import com.xxl.tool.core.StringTool;
@ -152,10 +152,10 @@ public class JobGroupController {
private List<String> findRegistryByAppName(String appnameParam){ private List<String> findRegistryByAppName(String appnameParam){
HashMap<String, List<String>> appAddressMap = new HashMap<>(); HashMap<String, List<String>> appAddressMap = new HashMap<>();
List<XxlJobRegistry> list = xxlJobRegistryMapper.findAll(RegistryConfig.DEAD_TIMEOUT, new Date()); List<XxlJobRegistry> list = xxlJobRegistryMapper.findAll(Const.DEAD_TIMEOUT, new Date());
if (CollectionTool.isNotEmpty(list)) { if (CollectionTool.isNotEmpty(list)) {
for (XxlJobRegistry item: list) { for (XxlJobRegistry item: list) {
if (!RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) { if (!Const.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
continue; continue;
} }

@ -10,8 +10,7 @@ import com.xxl.job.admin.scheduler.type.ScheduleTypeEnum;
import com.xxl.job.admin.service.XxlJobService; import com.xxl.job.admin.service.XxlJobService;
import com.xxl.job.admin.util.I18nUtil; import com.xxl.job.admin.util.I18nUtil;
import com.xxl.job.admin.util.JobGroupPermissionUtil; import com.xxl.job.admin.util.JobGroupPermissionUtil;
import com.xxl.job.core.openapi.model.ReturnT; import com.xxl.job.core.constant.ExecutorBlockStrategyEnum;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.sso.core.helper.XxlSsoHelper; import com.xxl.sso.core.helper.XxlSsoHelper;
import com.xxl.sso.core.model.LoginInfo; import com.xxl.sso.core.model.LoginInfo;
@ -32,7 +31,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* index controller * index controller
@ -93,7 +91,7 @@ public class JobInfoController {
@RequestMapping("/add") @RequestMapping("/add")
@ResponseBody @ResponseBody
public ReturnT<String> add(HttpServletRequest request, XxlJobInfo jobInfo) { public Response<String> add(HttpServletRequest request, XxlJobInfo jobInfo) {
// valid permission // valid permission
LoginInfo loginInfo = JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup()); LoginInfo loginInfo = JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup());
@ -103,7 +101,7 @@ public class JobInfoController {
@RequestMapping("/update") @RequestMapping("/update")
@ResponseBody @ResponseBody
public ReturnT<String> update(HttpServletRequest request, XxlJobInfo jobInfo) { public Response<String> update(HttpServletRequest request, XxlJobInfo jobInfo) {
// valid permission // valid permission
LoginInfo loginInfo = JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup()); LoginInfo loginInfo = JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup());
@ -113,28 +111,28 @@ public class JobInfoController {
@RequestMapping("/remove") @RequestMapping("/remove")
@ResponseBody @ResponseBody
public ReturnT<String> remove(HttpServletRequest request, @RequestParam("id") int id) { public Response<String> remove(HttpServletRequest request, @RequestParam("id") int id) {
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
return xxlJobService.remove(id, loginInfoResponse.getData()); return xxlJobService.remove(id, loginInfoResponse.getData());
} }
@RequestMapping("/stop") @RequestMapping("/stop")
@ResponseBody @ResponseBody
public ReturnT<String> pause(HttpServletRequest request, @RequestParam("id") int id) { public Response<String> pause(HttpServletRequest request, @RequestParam("id") int id) {
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
return xxlJobService.stop(id, loginInfoResponse.getData()); return xxlJobService.stop(id, loginInfoResponse.getData());
} }
@RequestMapping("/start") @RequestMapping("/start")
@ResponseBody @ResponseBody
public ReturnT<String> start(HttpServletRequest request, @RequestParam("id") int id) { public Response<String> start(HttpServletRequest request, @RequestParam("id") int id) {
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
return xxlJobService.start(id, loginInfoResponse.getData()); return xxlJobService.start(id, loginInfoResponse.getData());
} }
@RequestMapping("/trigger") @RequestMapping("/trigger")
@ResponseBody @ResponseBody
public ReturnT<String> triggerJob(HttpServletRequest request, public Response<String> triggerJob(HttpServletRequest request,
@RequestParam("id") int id, @RequestParam("id") int id,
@RequestParam("executorParam") String executorParam, @RequestParam("executorParam") String executorParam,
@RequestParam("addressList") String addressList) { @RequestParam("addressList") String addressList) {
@ -144,7 +142,7 @@ public class JobInfoController {
@RequestMapping("/nextTriggerTime") @RequestMapping("/nextTriggerTime")
@ResponseBody @ResponseBody
public ReturnT<List<String>> nextTriggerTime(@RequestParam("scheduleType") String scheduleType, public Response<List<String>> nextTriggerTime(@RequestParam("scheduleType") String scheduleType,
@RequestParam("scheduleConf") String scheduleConf) { @RequestParam("scheduleConf") String scheduleConf) {
XxlJobInfo paramXxlJobInfo = new XxlJobInfo(); XxlJobInfo paramXxlJobInfo = new XxlJobInfo();
@ -169,9 +167,9 @@ public class JobInfoController {
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(">>>>>>>>>>> nextTriggerTime error. scheduleType = {}, scheduleConf= {}", scheduleType, scheduleConf, e); logger.error(">>>>>>>>>>> nextTriggerTime error. scheduleType = {}, scheduleConf= {}", scheduleType, scheduleConf, e);
return ReturnT.ofFail((I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) + e.getMessage()); return Response.ofFail((I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) + e.getMessage());
} }
return ReturnT.ofSuccess(result); return Response.ofSuccess(result);
} }

@ -8,7 +8,7 @@ import com.xxl.job.admin.scheduler.trigger.JobTrigger;
import com.xxl.job.admin.util.I18nUtil; import com.xxl.job.admin.util.I18nUtil;
import com.xxl.job.core.openapi.ExecutorBiz; import com.xxl.job.core.openapi.ExecutorBiz;
import com.xxl.job.core.openapi.client.ExecutorBizClient; import com.xxl.job.core.openapi.client.ExecutorBizClient;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.constant.ExecutorBlockStrategyEnum;
import com.xxl.tool.core.StringTool; import com.xxl.tool.core.StringTool;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.slf4j.Logger; import org.slf4j.Logger;

@ -4,7 +4,7 @@ import com.xxl.job.admin.model.XxlJobGroup;
import com.xxl.job.admin.model.XxlJobRegistry; import com.xxl.job.admin.model.XxlJobRegistry;
import com.xxl.job.admin.scheduler.config.XxlJobAdminBootstrap; import com.xxl.job.admin.scheduler.config.XxlJobAdminBootstrap;
import com.xxl.job.core.openapi.model.RegistryRequest; import com.xxl.job.core.openapi.model.RegistryRequest;
import com.xxl.job.core.enums.RegistryConfig; import com.xxl.job.core.constant.Const;
import com.xxl.tool.core.StringTool; import com.xxl.tool.core.StringTool;
import com.xxl.tool.response.Response; import com.xxl.tool.response.Response;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -64,17 +64,17 @@ public class JobRegistryHelper {
if (groupList!=null && !groupList.isEmpty()) { if (groupList!=null && !groupList.isEmpty()) {
// remove dead address (admin/executor) // remove dead address (admin/executor)
List<Integer> ids = XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().findDead(RegistryConfig.DEAD_TIMEOUT, new Date()); List<Integer> ids = XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().findDead(Const.DEAD_TIMEOUT, new Date());
if (ids!=null && ids.size()>0) { if (ids!=null && ids.size()>0) {
XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().removeDead(ids); XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().removeDead(ids);
} }
// fresh online address (admin/executor) // fresh online address (admin/executor)
HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>(); HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>();
List<XxlJobRegistry> list = XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().findAll(RegistryConfig.DEAD_TIMEOUT, new Date()); List<XxlJobRegistry> list = XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().findAll(Const.DEAD_TIMEOUT, new Date());
if (list != null) { if (list != null) {
for (XxlJobRegistry item: list) { for (XxlJobRegistry item: list) {
if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) { if (Const.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
String appname = item.getRegistryKey(); String appname = item.getRegistryKey();
List<String> registryList = appAddressMap.get(appname); List<String> registryList = appAddressMap.get(appname);
if (registryList == null) { if (registryList == null) {
@ -114,7 +114,7 @@ public class JobRegistryHelper {
} }
} }
try { try {
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT); TimeUnit.SECONDS.sleep(Const.BEAT_TIMEOUT);
} catch (Throwable e) { } catch (Throwable e) {
if (!toStop) { if (!toStop) {
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e); logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);

@ -12,7 +12,7 @@ import com.xxl.job.admin.util.I18nUtil;
import com.xxl.job.core.openapi.ExecutorBiz; import com.xxl.job.core.openapi.ExecutorBiz;
import com.xxl.job.core.openapi.model.TriggerRequest; import com.xxl.job.core.openapi.model.TriggerRequest;
import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.context.XxlJobContext;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.constant.ExecutorBlockStrategyEnum;
import com.xxl.tool.core.StringTool; import com.xxl.tool.core.StringTool;
import com.xxl.tool.exception.ThrowableTool; import com.xxl.tool.exception.ThrowableTool;
import com.xxl.tool.http.IPTool; import com.xxl.tool.http.IPTool;

@ -1,7 +1,6 @@
package com.xxl.job.admin.service; package com.xxl.job.admin.service;
import com.xxl.job.admin.model.XxlJobInfo; import com.xxl.job.admin.model.XxlJobInfo;
import com.xxl.job.core.openapi.model.ReturnT;
import com.xxl.sso.core.model.LoginInfo; import com.xxl.sso.core.model.LoginInfo;
import com.xxl.tool.response.PageModel; import com.xxl.tool.response.PageModel;
import com.xxl.tool.response.Response; import com.xxl.tool.response.Response;
@ -24,32 +23,32 @@ public interface XxlJobService {
/** /**
* add job * add job
*/ */
public ReturnT<String> add(XxlJobInfo jobInfo, LoginInfo loginInfo); public Response<String> add(XxlJobInfo jobInfo, LoginInfo loginInfo);
/** /**
* update job * update job
*/ */
public ReturnT<String> update(XxlJobInfo jobInfo, LoginInfo loginInfo); public Response<String> update(XxlJobInfo jobInfo, LoginInfo loginInfo);
/** /**
* remove job * remove job
*/ */
public ReturnT<String> remove(int id, LoginInfo loginInfo); public Response<String> remove(int id, LoginInfo loginInfo);
/** /**
* start job * start job
*/ */
public ReturnT<String> start(int id, LoginInfo loginInfo); public Response<String> start(int id, LoginInfo loginInfo);
/** /**
* stop job * stop job
*/ */
public ReturnT<String> stop(int id, LoginInfo loginInfo); public Response<String> stop(int id, LoginInfo loginInfo);
/** /**
* trigger * trigger
*/ */
public ReturnT<String> trigger(LoginInfo loginInfo, int jobId, String executorParam, String addressList); public Response<String> trigger(LoginInfo loginInfo, int jobId, String executorParam, String addressList);
/** /**
* dashboard info * dashboard info

@ -14,8 +14,7 @@ import com.xxl.job.admin.scheduler.type.ScheduleTypeEnum;
import com.xxl.job.admin.service.XxlJobService; import com.xxl.job.admin.service.XxlJobService;
import com.xxl.job.admin.util.I18nUtil; import com.xxl.job.admin.util.I18nUtil;
import com.xxl.job.admin.util.JobGroupPermissionUtil; import com.xxl.job.admin.util.JobGroupPermissionUtil;
import com.xxl.job.core.openapi.model.ReturnT; import com.xxl.job.core.constant.ExecutorBlockStrategyEnum;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.sso.core.model.LoginInfo; import com.xxl.sso.core.model.LoginInfo;
import com.xxl.tool.core.DateTool; import com.xxl.tool.core.DateTool;
@ -64,49 +63,49 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
@Override @Override
public ReturnT<String> add(XxlJobInfo jobInfo, LoginInfo loginInfo) { public Response<String> add(XxlJobInfo jobInfo, LoginInfo loginInfo) {
// valid base // valid base
XxlJobGroup group = xxlJobGroupMapper.load(jobInfo.getJobGroup()); XxlJobGroup group = xxlJobGroupMapper.load(jobInfo.getJobGroup());
if (group == null) { if (group == null) {
return ReturnT.ofFail (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")); return Response.ofFail (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup"));
} }
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) {
return ReturnT.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); return Response.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
} }
if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) { if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) {
return ReturnT.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); return Response.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
} }
// valid trigger // valid trigger
ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(jobInfo.getScheduleType(), null); ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(jobInfo.getScheduleType(), null);
if (scheduleTypeEnum == null) { if (scheduleTypeEnum == null) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
if (scheduleTypeEnum == ScheduleTypeEnum.CRON) { if (scheduleTypeEnum == ScheduleTypeEnum.CRON) {
if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) { if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) {
return ReturnT.ofFail ( "Cron"+I18nUtil.getString("system_unvalid")); return Response.ofFail ( "Cron"+I18nUtil.getString("system_unvalid"));
} }
} else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE/* || scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) { } else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE/* || scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) {
if (jobInfo.getScheduleConf() == null) { if (jobInfo.getScheduleConf() == null) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")) );
} }
try { try {
int fixSecond = Integer.valueOf(jobInfo.getScheduleConf()); int fixSecond = Integer.valueOf(jobInfo.getScheduleConf());
if (fixSecond < 1) { if (fixSecond < 1) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} catch (Exception e) { } catch (Exception e) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} }
// valid job // valid job
if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) { if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) );
} }
if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && (jobInfo.getExecutorHandler()==null || jobInfo.getExecutorHandler().trim().length()==0) ) { if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && (jobInfo.getExecutorHandler()==null || jobInfo.getExecutorHandler().trim().length()==0) ) {
return ReturnT.ofFail ( (I18nUtil.getString("system_please_input")+"JobHandler") ); return Response.ofFail ( (I18nUtil.getString("system_please_input")+"JobHandler") );
} }
// 》fix "\r" in shell // 》fix "\r" in shell
if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) { if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) {
@ -115,13 +114,13 @@ public class XxlJobServiceImpl implements XxlJobService {
// valid advanced // valid advanced
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) { if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
} }
if (MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), null) == null) { if (MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), null) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) );
} }
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
} }
// 》ChildJobId valid // 》ChildJobId valid
@ -131,16 +130,16 @@ public class XxlJobServiceImpl implements XxlJobService {
if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) { if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) {
XxlJobInfo childJobInfo = xxlJobInfoMapper.loadById(Integer.parseInt(childJobIdItem)); XxlJobInfo childJobInfo = xxlJobInfoMapper.loadById(Integer.parseInt(childJobIdItem));
if (childJobInfo==null) { if (childJobInfo==null) {
return ReturnT.ofFail ( return Response.ofFail (
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem)); MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) {
return ReturnT.ofFail ( return Response.ofFail (
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_permission_limit")), childJobIdItem)); MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_permission_limit")), childJobIdItem));
} }
} else { } else {
return ReturnT.ofFail ( return Response.ofFail (
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem)); MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
} }
} }
@ -163,10 +162,10 @@ public class XxlJobServiceImpl implements XxlJobService {
jobInfo.setExecutorHandler(jobInfo.getExecutorHandler().trim()); jobInfo.setExecutorHandler(jobInfo.getExecutorHandler().trim());
xxlJobInfoMapper.save(jobInfo); xxlJobInfoMapper.save(jobInfo);
if (jobInfo.getId() < 1) { if (jobInfo.getId() < 1) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
} }
return ReturnT.ofSuccess(String.valueOf(jobInfo.getId())); return Response.ofSuccess(String.valueOf(jobInfo.getId()));
} }
private boolean isNumeric(String str){ private boolean isNumeric(String str){
@ -179,48 +178,48 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
@Override @Override
public ReturnT<String> update(XxlJobInfo jobInfo, LoginInfo loginInfo) { public Response<String> update(XxlJobInfo jobInfo, LoginInfo loginInfo) {
// valid base // valid base
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) {
return ReturnT.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); return Response.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
} }
if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) { if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) {
return ReturnT.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); return Response.ofFail ( (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
} }
// valid trigger // valid trigger
ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(jobInfo.getScheduleType(), null); ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(jobInfo.getScheduleType(), null);
if (scheduleTypeEnum == null) { if (scheduleTypeEnum == null) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
if (scheduleTypeEnum == ScheduleTypeEnum.CRON) { if (scheduleTypeEnum == ScheduleTypeEnum.CRON) {
if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) { if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) {
return ReturnT.ofFail ( "Cron"+I18nUtil.getString("system_unvalid") ); return Response.ofFail ( "Cron"+I18nUtil.getString("system_unvalid") );
} }
} else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE /*|| scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) { } else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE /*|| scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) {
if (jobInfo.getScheduleConf() == null) { if (jobInfo.getScheduleConf() == null) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
try { try {
int fixSecond = Integer.valueOf(jobInfo.getScheduleConf()); int fixSecond = Integer.valueOf(jobInfo.getScheduleConf());
if (fixSecond < 1) { if (fixSecond < 1) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} catch (Exception e) { } catch (Exception e) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} }
// valid advanced // valid advanced
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) { if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
} }
if (MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), null) == null) { if (MisfireStrategyEnum.match(jobInfo.getMisfireStrategy(), null) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) );
} }
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
} }
// 》ChildJobId valid // 》ChildJobId valid
@ -231,22 +230,22 @@ public class XxlJobServiceImpl implements XxlJobService {
// parse child // parse child
int childJobId = Integer.parseInt(childJobIdItem); int childJobId = Integer.parseInt(childJobIdItem);
if (childJobId == jobInfo.getId()) { if (childJobId == jobInfo.getId()) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_childJobId")+"("+childJobId+")"+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_childJobId")+"("+childJobId+")"+I18nUtil.getString("system_unvalid")) );
} }
// valid child // valid child
XxlJobInfo childJobInfo = xxlJobInfoMapper.loadById(childJobId); XxlJobInfo childJobInfo = xxlJobInfoMapper.loadById(childJobId);
if (childJobInfo==null) { if (childJobInfo==null) {
return ReturnT.ofFail ( return Response.ofFail (
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem)); MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) {
return ReturnT.ofFail ( return Response.ofFail (
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_permission_limit")), childJobIdItem)); MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_permission_limit")), childJobIdItem));
} }
} else { } else {
return ReturnT.ofFail ( return Response.ofFail (
MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem)); MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
} }
} }
@ -264,13 +263,13 @@ public class XxlJobServiceImpl implements XxlJobService {
// group valid // group valid
XxlJobGroup jobGroup = xxlJobGroupMapper.load(jobInfo.getJobGroup()); XxlJobGroup jobGroup = xxlJobGroupMapper.load(jobInfo.getJobGroup());
if (jobGroup == null) { if (jobGroup == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) );
} }
// stage job info // stage job info
XxlJobInfo exists_jobInfo = xxlJobInfoMapper.loadById(jobInfo.getId()); XxlJobInfo exists_jobInfo = xxlJobInfoMapper.loadById(jobInfo.getId());
if (exists_jobInfo == null) { if (exists_jobInfo == null) {
return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) ); return Response.ofFail ( (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
} }
// next trigger time (5s后生效避开预读周期) // next trigger time (5s后生效避开预读周期)
@ -282,12 +281,12 @@ public class XxlJobServiceImpl implements XxlJobService {
// generate next trigger time // generate next trigger time
Date nextValidTime = scheduleTypeEnum.getScheduleType().generateNextTriggerTime(jobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); Date nextValidTime = scheduleTypeEnum.getScheduleType().generateNextTriggerTime(jobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
if (nextValidTime == null) { if (nextValidTime == null) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
nextTriggerTime = nextValidTime.getTime(); nextTriggerTime = nextValidTime.getTime();
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} }
@ -311,46 +310,45 @@ public class XxlJobServiceImpl implements XxlJobService {
exists_jobInfo.setUpdateTime(new Date()); exists_jobInfo.setUpdateTime(new Date());
xxlJobInfoMapper.update(exists_jobInfo); xxlJobInfoMapper.update(exists_jobInfo);
return Response.ofSuccess();
return ReturnT.ofSuccess();
} }
@Override @Override
public ReturnT<String> remove(int id, LoginInfo loginInfo) { public Response<String> remove(int id, LoginInfo loginInfo) {
// valid job // valid job
XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(id); XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(id);
if (xxlJobInfo == null) { if (xxlJobInfo == null) {
return ReturnT.ofSuccess(); return Response.ofSuccess();
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return Response.ofFail(I18nUtil.getString("system_permission_limit"));
} }
xxlJobInfoMapper.delete(id); xxlJobInfoMapper.delete(id);
xxlJobLogMapper.delete(id); xxlJobLogMapper.delete(id);
xxlJobLogGlueMapper.deleteByJobId(id); xxlJobLogGlueMapper.deleteByJobId(id);
return ReturnT.ofSuccess(); return Response.ofSuccess();
} }
@Override @Override
public ReturnT<String> start(int id, LoginInfo loginInfo) { public Response<String> start(int id, LoginInfo loginInfo) {
// load and valid // load and valid
XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(id); XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(id);
if (xxlJobInfo == null) { if (xxlJobInfo == null) {
return ReturnT.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid")); return Response.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return Response.ofFail(I18nUtil.getString("system_permission_limit"));
} }
// valid ScheduleType: can not be none // valid ScheduleType: can not be none
ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(xxlJobInfo.getScheduleType(), ScheduleTypeEnum.NONE); ScheduleTypeEnum scheduleTypeEnum = ScheduleTypeEnum.match(xxlJobInfo.getScheduleType(), ScheduleTypeEnum.NONE);
if (ScheduleTypeEnum.NONE == scheduleTypeEnum) { if (ScheduleTypeEnum.NONE == scheduleTypeEnum) {
return ReturnT.ofFail(I18nUtil.getString("schedule_type_none_limit_start")); return Response.ofFail(I18nUtil.getString("schedule_type_none_limit_start"));
} }
// next trigger time (5s后生效避开预读周期) // next trigger time (5s后生效避开预读周期)
@ -360,12 +358,12 @@ public class XxlJobServiceImpl implements XxlJobService {
Date nextValidTime = scheduleTypeEnum.getScheduleType().generateNextTriggerTime(xxlJobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); Date nextValidTime = scheduleTypeEnum.getScheduleType().generateNextTriggerTime(xxlJobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
if (nextValidTime == null) { if (nextValidTime == null) {
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
nextTriggerTime = nextValidTime.getTime(); nextTriggerTime = nextValidTime.getTime();
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return Response.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
xxlJobInfo.setTriggerStatus(1); xxlJobInfo.setTriggerStatus(1);
@ -374,20 +372,20 @@ public class XxlJobServiceImpl implements XxlJobService {
xxlJobInfo.setUpdateTime(new Date()); xxlJobInfo.setUpdateTime(new Date());
xxlJobInfoMapper.update(xxlJobInfo); xxlJobInfoMapper.update(xxlJobInfo);
return ReturnT.ofSuccess(); return Response.ofSuccess();
} }
@Override @Override
public ReturnT<String> stop(int id, LoginInfo loginInfo) { public Response<String> stop(int id, LoginInfo loginInfo) {
// load and valid // load and valid
XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(id); XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(id);
if (xxlJobInfo == null) { if (xxlJobInfo == null) {
return ReturnT.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid")); return Response.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return Response.ofFail(I18nUtil.getString("system_permission_limit"));
} }
// stop // stop
@ -397,22 +395,20 @@ public class XxlJobServiceImpl implements XxlJobService {
xxlJobInfo.setUpdateTime(new Date()); xxlJobInfo.setUpdateTime(new Date());
xxlJobInfoMapper.update(xxlJobInfo); xxlJobInfoMapper.update(xxlJobInfo);
return ReturnT.ofSuccess(); return Response.ofSuccess();
} }
@Override @Override
public ReturnT<String> trigger(LoginInfo loginInfo, int jobId, String executorParam, String addressList) { public Response<String> trigger(LoginInfo loginInfo, int jobId, String executorParam, String addressList) {
// valid job // valid job
XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(jobId); XxlJobInfo xxlJobInfo = xxlJobInfoMapper.loadById(jobId);
if (xxlJobInfo == null) { if (xxlJobInfo == null) {
return ReturnT.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid")); return Response.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return Response.ofFail(I18nUtil.getString("system_permission_limit"));
} }
// force cover job param // force cover job param
@ -421,7 +417,7 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
XxlJobAdminBootstrap.getInstance().getJobTriggerPoolHelper().trigger(jobId, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList); XxlJobAdminBootstrap.getInstance().getJobTriggerPoolHelper().trigger(jobId, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList);
return ReturnT.ofSuccess(); return Response.ofSuccess();
} }
@Override @Override

@ -361,9 +361,9 @@ $(function() {
}); });
} else { } else {
var html = '<center>'; var html = '<center>';
if (data.code == 200 && data.content) { if (data.code == 200 && data.data) {
for (var index in data.content) { for (var index in data.data) {
html += '<span>' + data.content[index] + '</span><br>'; html += '<span>' + data.data[index] + '</span><br>';
} }
} }
html += '</center>'; html += '</center>';

@ -32,19 +32,19 @@ $(function() {
success : function(data){ success : function(data){
if (data.code == 200) { if (data.code == 200) {
if (!data.content) { if (!data.data) {
console.log('pullLog fail'); console.log('pullLog fail');
return; return;
} }
if (fromLineNum != data.content.fromLineNum) { if (fromLineNum != data.data.fromLineNum) {
console.log('pullLog fromLineNum not match'); console.log('pullLog fromLineNum not match');
return; return;
} }
if (fromLineNum > data.content.toLineNum ) { if (fromLineNum > data.data.toLineNum ) {
console.log('pullLog already line-end'); console.log('pullLog already line-end');
// valid end // valid end
if (data.content.end) { if (data.data.end) {
logRunStop('<br><span style="color: green;">[Rolling Log Finish]</span>'); logRunStop('<br><span style="color: green;">[Rolling Log Finish]</span>');
return; return;
} }
@ -53,8 +53,8 @@ $(function() {
} }
// append content // append content
fromLineNum = data.content.toLineNum + 1; fromLineNum = data.data.toLineNum + 1;
$('#logConsole').append(data.content.logContent); $('#logConsole').append(data.data.logContent);
pullFailCount = 0; pullFailCount = 0;
// scroll to bottom // scroll to bottom

@ -650,7 +650,7 @@
dataType : "json", dataType : "json",
success : function(data){ success : function(data){
if (data.code === 200) { if (data.code === 200) {
$('#runTime').val(data.content.join("\n")); $('#runTime').val(data.data.join("\n"));
} else { } else {
$('#runTime').val(data.msg); $('#runTime').val(data.msg);
} }

@ -647,7 +647,7 @@
dataType : "json", dataType : "json",
success : function(data){ success : function(data){
if (data.code === 200) { if (data.code === 200) {
$('#runTime').val(data.content.join("\n")); $('#runTime').val(data.data.join("\n"));
} else { } else {
$('#runTime').val(data.msg); $('#runTime').val(data.msg);
} }

@ -1,13 +1,15 @@
package com.xxl.job.adminbiz; package com.xxl.job.adminbiz;
import com.xxl.job.core.openapi.AdminBiz; import com.xxl.job.core.openapi.AdminBiz;
import com.xxl.job.core.openapi.client.AdminBizClient;
import com.xxl.job.core.openapi.model.HandleCallbackRequest; import com.xxl.job.core.openapi.model.HandleCallbackRequest;
import com.xxl.job.core.openapi.model.RegistryRequest; import com.xxl.job.core.openapi.model.RegistryRequest;
import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.context.XxlJobContext;
import com.xxl.job.core.enums.RegistryConfig; import com.xxl.job.core.constant.Const;
import com.xxl.tool.http.HttpTool;
import com.xxl.tool.response.Response; import com.xxl.tool.response.Response;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -20,16 +22,26 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author xuxueli 2017-07-28 22:14:52 * @author xuxueli 2017-07-28 22:14:52
*/ */
public class AdminBizTest { public class AdminBizTest {
private static final Logger logger = LoggerFactory.getLogger(AdminBizTest.class);
// admin-client // admin-client
private static String addressUrl = "http://127.0.0.1:8080/xxl-job-admin/"; private static String addressUrl = "http://127.0.0.1:8080/xxl-job-admin";
private static String accessToken = null; private static String accessToken = "default_token";
private static int timeoutSecond = 3;
private AdminBiz buildClient(){
String finalUrl = addressUrl + "/api";
return HttpTool.createClient()
.url(finalUrl)
.timeout(3 * 1000)
.header(Const.XXL_JOB_ACCESS_TOKEN, accessToken)
.proxy(AdminBiz.class);
}
@Test @Test
public void callback() throws Exception { public void callback() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken, timeoutSecond); AdminBiz adminBiz = buildClient();
HandleCallbackRequest param = new HandleCallbackRequest(); HandleCallbackRequest param = new HandleCallbackRequest();
param.setLogId(1); param.setLogId(1);
@ -38,7 +50,6 @@ public class AdminBizTest {
List<HandleCallbackRequest> callbackParamList = Arrays.asList(param); List<HandleCallbackRequest> callbackParamList = Arrays.asList(param);
Response<String> returnT = adminBiz.callback(callbackParamList); Response<String> returnT = adminBiz.callback(callbackParamList);
assertTrue(returnT.isSuccess()); assertTrue(returnT.isSuccess());
} }
@ -49,11 +60,11 @@ public class AdminBizTest {
*/ */
@Test @Test
public void registry() throws Exception { public void registry() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken, timeoutSecond); AdminBiz adminBiz = buildClient();
RegistryRequest registryParam = new RegistryRequest(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999"); RegistryRequest registryParam = new RegistryRequest(Const.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
Response<String> returnT = adminBiz.registry(registryParam);
Response<String> returnT = adminBiz.registry(registryParam);
assertTrue(returnT.isSuccess()); assertTrue(returnT.isSuccess());
} }
@ -64,11 +75,11 @@ public class AdminBizTest {
*/ */
@Test @Test
public void registryRemove() throws Exception { public void registryRemove() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken, timeoutSecond); AdminBiz adminBiz = buildClient();
RegistryRequest registryParam = new RegistryRequest(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999"); RegistryRequest registryParam = new RegistryRequest(Const.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
Response<String> returnT = adminBiz.registryRemove(registryParam);
Response<String> returnT = adminBiz.registryRemove(registryParam);
assertTrue(returnT.isSuccess()); assertTrue(returnT.isSuccess());
} }

@ -3,7 +3,7 @@ package com.xxl.job.executorbiz;
import com.xxl.job.core.openapi.ExecutorBiz; import com.xxl.job.core.openapi.ExecutorBiz;
import com.xxl.job.core.openapi.client.ExecutorBizClient; import com.xxl.job.core.openapi.client.ExecutorBizClient;
import com.xxl.job.core.openapi.model.*; import com.xxl.job.core.openapi.model.*;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.constant.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.tool.response.Response; import com.xxl.tool.response.Response;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;

@ -1,9 +1,19 @@
package com.xxl.job.core.enums; package com.xxl.job.core.constant;
/** /**
* Created by xuxueli on 17/5/10. * Created by xuxueli on 17/5/10.
*/ */
public class RegistryConfig { public class Const {
// ---------------------- for openapi ----------------------
/**
* access token
*/
public static final String XXL_JOB_ACCESS_TOKEN = "XXL-JOB-ACCESS-TOKEN";
// ---------------------- for registry ----------------------
/** /**
* registry beat interval, default 30s * registry beat interval, default 30s

@ -1,4 +1,4 @@
package com.xxl.job.core.enums; package com.xxl.job.core.constant;
/** /**
* Created by xuxueli on 17/5/9. * Created by xuxueli on 17/5/9.

@ -1,54 +0,0 @@
package com.xxl.job.core.openapi.client;
import com.xxl.job.core.openapi.AdminBiz;
import com.xxl.job.core.openapi.model.HandleCallbackRequest;
import com.xxl.job.core.openapi.model.RegistryRequest;
import com.xxl.job.core.util.XxlJobRemotingUtil;
import com.xxl.tool.response.Response;
import java.util.List;
/**
* admin api test
*
* @author xuxueli 2017-07-28 22:14:52
*/
public class AdminBizClient implements AdminBiz {
public AdminBizClient() {
}
public AdminBizClient(String addressUrl, String accessToken, int timeout) {
this.addressUrl = addressUrl;
this.accessToken = accessToken;
this.timeout = timeout;
// valid
if (!this.addressUrl.endsWith("/")) {
this.addressUrl = this.addressUrl + "/";
}
if (!(this.timeout >=1 && this.timeout <= 10)) {
this.timeout = 3;
}
}
private String addressUrl ;
private String accessToken;
private int timeout;
@Override
public Response<String> callback(List<HandleCallbackRequest> handleCallbackRequestList) {
return XxlJobRemotingUtil.postBody(addressUrl+"api/callback", accessToken, timeout, handleCallbackRequestList, String.class);
}
@Override
public Response<String> registry(RegistryRequest registryRequest) {
return XxlJobRemotingUtil.postBody(addressUrl + "api/registry", accessToken, timeout, registryRequest, String.class);
}
@Override
public Response<String> registryRemove(RegistryRequest registryRequest) {
return XxlJobRemotingUtil.postBody(addressUrl + "api/registryRemove", accessToken, timeout, registryRequest, String.class);
}
}

@ -3,7 +3,7 @@ package com.xxl.job.core.openapi.impl;
import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.context.XxlJobContext;
import com.xxl.job.core.openapi.ExecutorBiz; import com.xxl.job.core.openapi.ExecutorBiz;
import com.xxl.job.core.openapi.model.*; import com.xxl.job.core.openapi.model.*;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.constant.ExecutorBlockStrategyEnum;
import com.xxl.job.core.executor.XxlJobExecutor; import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.glue.GlueFactory; import com.xxl.job.core.glue.GlueFactory;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;

@ -1,103 +0,0 @@
package com.xxl.job.core.openapi.model;
import java.io.Serializable;
/**
* common return
*
* @author xuxueli 2015-12-4 16:32:31
* @param <T>
*/
public class ReturnT<T> implements Serializable {
public static final long serialVersionUID = 42L;
private int code;
private String msg;
private T content;
public ReturnT(){}
public ReturnT(int code, String msg) {
this.code = code;
this.msg = msg;
}
public ReturnT(int code, String msg, T content) {
this.code = code;
this.msg = msg;
this.content = content;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getContent() {
return content;
}
public void setContent(T content) {
this.content = content;
}
@Override
public String toString() {
return "ReturnT{" +
"code=" + code +
", msg='" + msg + '\'' +
", content=" + content +
'}';
}
// --------------------------- tool ---------------------------
public static final int SUCCESS_CODE = 200;
public static final int FAIL_CODE = 500;
/**
* is success
*
* @return
*/
public boolean isSuccess() {
return code == SUCCESS_CODE;
}
public static <T> ReturnT<T> of(int code, String msg, T data) {
return new ReturnT<T>(code, msg, data);
}
public static <T> ReturnT<T> of(int code, String msg) {
return new ReturnT<T>(code, msg, null);
}
public static <T> ReturnT<T> ofSuccess(T data) {
return new ReturnT<T>(SUCCESS_CODE, "Success", data);
}
public static <T> ReturnT<T> ofSuccess() {
return new ReturnT<T>(SUCCESS_CODE, "Success", null);
}
public static <T> ReturnT<T> ofFail(String msg) {
return new ReturnT<T>(FAIL_CODE, msg, null);
}
public static <T> ReturnT<T> ofFail() {
return new ReturnT<T>(FAIL_CODE, "Fail", null);
}
}

@ -7,6 +7,7 @@ import com.xxl.job.core.thread.ExecutorRegistryThread;
import com.xxl.job.core.util.XxlJobRemotingUtil; import com.xxl.job.core.util.XxlJobRemotingUtil;
import com.xxl.tool.exception.ThrowableTool; import com.xxl.tool.exception.ThrowableTool;
import com.xxl.tool.gson.GsonTool; import com.xxl.tool.gson.GsonTool;
import com.xxl.tool.response.Response;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.*; import io.netty.channel.*;
@ -169,15 +170,15 @@ public class EmbedServer {
private Object dispatchRequest(HttpMethod httpMethod, String uri, String requestData, String accessTokenReq) { private Object dispatchRequest(HttpMethod httpMethod, String uri, String requestData, String accessTokenReq) {
// valid // valid
if (HttpMethod.POST != httpMethod) { if (HttpMethod.POST != httpMethod) {
return ReturnT.ofFail("invalid request, HttpMethod not support."); return Response.ofFail("invalid request, HttpMethod not support.");
} }
if (uri == null || uri.trim().isEmpty()) { if (uri == null || uri.trim().isEmpty()) {
return ReturnT.ofFail( "invalid request, uri-mapping empty."); return Response.ofFail( "invalid request, uri-mapping empty.");
} }
if (accessToken != null if (accessToken != null
&& !accessToken.trim().isEmpty() && !accessToken.trim().isEmpty()
&& !accessToken.equals(accessTokenReq)) { && !accessToken.equals(accessTokenReq)) {
return ReturnT.ofFail("The access token is wrong."); return Response.ofFail("The access token is wrong.");
} }
// services mapping // services mapping
@ -198,11 +199,11 @@ public class EmbedServer {
LogRequest logParam = GsonTool.fromJson(requestData, LogRequest.class); LogRequest logParam = GsonTool.fromJson(requestData, LogRequest.class);
return executorBiz.log(logParam); return executorBiz.log(logParam);
default: default:
return ReturnT.ofFail( "invalid request, uri-mapping(" + uri + ") not found."); return Response.ofFail( "invalid request, uri-mapping(" + uri + ") not found.");
} }
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return ReturnT.ofFail("request error:" + ThrowableTool.toString(e)); return Response.ofFail("request error:" + ThrowableTool.toString(e));
} }
} }

@ -2,7 +2,7 @@ package com.xxl.job.core.thread;
import com.xxl.job.core.openapi.AdminBiz; import com.xxl.job.core.openapi.AdminBiz;
import com.xxl.job.core.openapi.model.RegistryRequest; import com.xxl.job.core.openapi.model.RegistryRequest;
import com.xxl.job.core.enums.RegistryConfig; import com.xxl.job.core.constant.Const;
import com.xxl.job.core.executor.XxlJobExecutor; import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.tool.response.Response; import com.xxl.tool.response.Response;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -42,7 +42,7 @@ public class ExecutorRegistryThread {
// registry // registry
while (!toStop) { while (!toStop) {
try { try {
RegistryRequest registryParam = new RegistryRequest(RegistryConfig.RegistType.EXECUTOR.name(), appname, address); RegistryRequest registryParam = new RegistryRequest(Const.RegistType.EXECUTOR.name(), appname, address);
for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) { for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
try { try {
Response<String> registryResult = adminBiz.registry(registryParam); Response<String> registryResult = adminBiz.registry(registryParam);
@ -67,7 +67,7 @@ public class ExecutorRegistryThread {
try { try {
if (!toStop) { if (!toStop) {
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT); TimeUnit.SECONDS.sleep(Const.BEAT_TIMEOUT);
} }
} catch (Throwable e) { } catch (Throwable e) {
if (!toStop) { if (!toStop) {
@ -78,7 +78,7 @@ public class ExecutorRegistryThread {
// registry remove // registry remove
try { try {
RegistryRequest registryParam = new RegistryRequest(RegistryConfig.RegistType.EXECUTOR.name(), appname, address); RegistryRequest registryParam = new RegistryRequest(Const.RegistType.EXECUTOR.name(), appname, address);
for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) { for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
try { try {
Response<String> registryResult = adminBiz.registryRemove(registryParam); Response<String> registryResult = adminBiz.registryRemove(registryParam);

@ -4,7 +4,7 @@ import com.xxl.job.core.openapi.AdminBiz;
import com.xxl.job.core.openapi.model.HandleCallbackRequest; import com.xxl.job.core.openapi.model.HandleCallbackRequest;
import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.context.XxlJobContext;
import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.enums.RegistryConfig; import com.xxl.job.core.constant.Const;
import com.xxl.job.core.executor.XxlJobExecutor; import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.log.XxlJobFileAppender; import com.xxl.job.core.log.XxlJobFileAppender;
import com.xxl.tool.core.ArrayTool; import com.xxl.tool.core.ArrayTool;
@ -132,7 +132,7 @@ public class TriggerCallbackThread {
} }
try { try {
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT); TimeUnit.SECONDS.sleep(Const.BEAT_TIMEOUT);
} catch (Throwable e) { } catch (Throwable e) {
if (!toStop) { if (!toStop) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);

@ -0,0 +1,54 @@
//package com.xxl.job.core.openapi.client;
//
//import com.xxl.job.core.openapi.AdminBiz;
//import com.xxl.job.core.openapi.model.HandleCallbackRequest;
//import com.xxl.job.core.openapi.model.RegistryRequest;
//import com.xxl.job.core.util.XxlJobRemotingUtil;
//import com.xxl.tool.response.Response;
//
//import java.util.List;
//
///**
// * admin api test
// *
// * @author xuxueli 2017-07-28 22:14:52
// */
//public class AdminBizClient implements AdminBiz {
//
// public AdminBizClient() {
// }
// public AdminBizClient(String addressUrl, String accessToken, int timeout) {
// this.addressUrl = addressUrl;
// this.accessToken = accessToken;
// this.timeout = timeout;
//
// // valid
// if (!this.addressUrl.endsWith("/")) {
// this.addressUrl = this.addressUrl + "/";
// }
// if (!(this.timeout >=1 && this.timeout <= 10)) {
// this.timeout = 3;
// }
// }
//
// private String addressUrl ;
// private String accessToken;
// private int timeout;
//
//
// @Override
// public Response<String> callback(List<HandleCallbackRequest> handleCallbackRequestList) {
// return XxlJobRemotingUtil.postBody(addressUrl+"api/callback", accessToken, timeout, handleCallbackRequestList, String.class);
// }
//
// @Override
// public Response<String> registry(RegistryRequest registryRequest) {
// return XxlJobRemotingUtil.postBody(addressUrl + "api/registry", accessToken, timeout, registryRequest, String.class);
// }
//
// @Override
// public Response<String> registryRemove(RegistryRequest registryRequest) {
// return XxlJobRemotingUtil.postBody(addressUrl + "api/registryRemove", accessToken, timeout, registryRequest, String.class);
// }
//
//}

@ -0,0 +1,103 @@
//package com.xxl.job.core.openapi.model;
//
//import java.io.Serializable;
//
///**
// * common return
// *
// * @author xuxueli 2015-12-4 16:32:31
// * @param <T>
// */
//public class ReturnT<T> implements Serializable {
// public static final long serialVersionUID = 42L;
//
// private int code;
//
// private String msg;
//
// private T content;
//
// public ReturnT(){}
//
// public ReturnT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
//
// public ReturnT(int code, String msg, T content) {
// this.code = code;
// this.msg = msg;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ReturnT{" +
// "code=" + code +
// ", msg='" + msg + '\'' +
// ", content=" + content +
// '}';
// }
//
//
// // --------------------------- tool ---------------------------
//
// public static final int SUCCESS_CODE = 200;
// public static final int FAIL_CODE = 500;
//
// /**
// * is success
// *
// * @return
// */
// public boolean isSuccess() {
// return code == SUCCESS_CODE;
// }
//
// public static <T> ReturnT<T> of(int code, String msg, T data) {
// return new ReturnT<T>(code, msg, data);
// }
// public static <T> ReturnT<T> of(int code, String msg) {
// return new ReturnT<T>(code, msg, null);
// }
//
// public static <T> ReturnT<T> ofSuccess(T data) {
// return new ReturnT<T>(SUCCESS_CODE, "Success", data);
// }
//
// public static <T> ReturnT<T> ofSuccess() {
// return new ReturnT<T>(SUCCESS_CODE, "Success", null);
// }
//
// public static <T> ReturnT<T> ofFail(String msg) {
// return new ReturnT<T>(FAIL_CODE, msg, null);
// }
// public static <T> ReturnT<T> ofFail() {
// return new ReturnT<T>(FAIL_CODE, "Fail", null);
// }
//
//}
Loading…
Cancel
Save