refactor(xxl-job): 重构错误处理和权限验证逻辑

- 使用 ReturnT.ofFail() 替代 new ReturnT<String>(ReturnT.FAIL_CODE, ...) 来返回错误信息
- 将权限验证相关方法移至 JobGroupPermissionUtil工具类中
- 优化了多个控制器中的错误处理和权限验证逻辑
- 统一了错误消息的返回格式
3.2.0-release
xuxueli 4 weeks ago
parent be44018394
commit 6fa72373f2

@ -7,6 +7,7 @@ import com.xxl.job.core.biz.model.RegistryParam;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.util.XxlJobRemotingUtil; import com.xxl.job.core.util.XxlJobRemotingUtil;
import com.xxl.sso.core.annotation.XxlSso; import com.xxl.sso.core.annotation.XxlSso;
import com.xxl.tool.core.StringTool;
import com.xxl.tool.gson.GsonTool; import com.xxl.tool.gson.GsonTool;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -42,15 +43,14 @@ public class JobApiController {
// valid // valid
if (!"POST".equalsIgnoreCase(request.getMethod())) { if (!"POST".equalsIgnoreCase(request.getMethod())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, HttpMethod not support."); return ReturnT.ofFail("invalid request, HttpMethod not support.");
} }
if (uri==null || uri.trim().length()==0) { if (StringTool.isBlank(uri)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping empty."); return ReturnT.ofFail("invalid request, uri-mapping empty.");
} }
if (XxlJobAdminConfig.getAdminConfig().getAccessToken()!=null if (StringTool.isNotBlank(XxlJobAdminConfig.getAdminConfig().getAccessToken())
&& XxlJobAdminConfig.getAdminConfig().getAccessToken().trim().length()>0
&& !XxlJobAdminConfig.getAdminConfig().getAccessToken().equals(request.getHeader(XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN))) { && !XxlJobAdminConfig.getAdminConfig().getAccessToken().equals(request.getHeader(XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN))) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "The access token is wrong."); return ReturnT.ofFail("The access token is wrong.");
} }
// services mapping // services mapping
@ -64,7 +64,7 @@ public class JobApiController {
RegistryParam registryParam = GsonTool.fromJson(data, RegistryParam.class); RegistryParam registryParam = GsonTool.fromJson(data, RegistryParam.class);
return adminBiz.registryRemove(registryParam); return adminBiz.registryRemove(registryParam);
} else { } else {
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping("+ uri +") not found."); return ReturnT.ofFail("invalid request, uri-mapping("+ uri +") not found.");
} }
} }

@ -5,6 +5,7 @@ import com.xxl.job.admin.mapper.XxlJobLogGlueMapper;
import com.xxl.job.admin.model.XxlJobInfo; import com.xxl.job.admin.model.XxlJobInfo;
import com.xxl.job.admin.model.XxlJobLogGlue; import com.xxl.job.admin.model.XxlJobLogGlue;
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.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -44,7 +45,7 @@ public class JobCodeController {
} }
// valid jobGroup permission // valid jobGroup permission
JobInfoController.validJobGroupPermission(request, jobInfo.getJobGroup()); JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup());
// Glue类型-字典 // Glue类型-字典
model.addAttribute("GlueTypeEnum", GlueTypeEnum.values()); model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());
@ -63,18 +64,18 @@ public class JobCodeController {
// valid // valid
if (glueRemark==null) { if (glueRemark==null) {
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) ); return ReturnT.ofFail( (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
} }
if (glueRemark.length()<4 || glueRemark.length()>100) { if (glueRemark.length()<4 || glueRemark.length()>100) {
return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit")); return ReturnT.ofFail(I18nUtil.getString("jobinfo_glue_remark_limit"));
} }
XxlJobInfo existsJobInfo = xxlJobInfoMapper.loadById(id); XxlJobInfo existsJobInfo = xxlJobInfoMapper.loadById(id);
if (existsJobInfo == null) { if (existsJobInfo == null) {
return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid")); return ReturnT.ofFail( I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
} }
// valid jobGroup permission // valid jobGroup permission
JobInfoController.validJobGroupPermission(request, existsJobInfo.getJobGroup()); JobGroupPermissionUtil.validJobGroupPermission(request, existsJobInfo.getJobGroup());
// update new code // update new code
existsJobInfo.setGlueSource(glueSource); existsJobInfo.setGlueSource(glueSource);

@ -69,32 +69,32 @@ public class JobGroupController {
// valid // valid
if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) { if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") ); return ReturnT.ofFail((I18nUtil.getString("system_please_input")+"AppName") );
} }
if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) { if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_field_appname_length") );
} }
if (xxlJobGroup.getAppname().contains(">") || xxlJobGroup.getAppname().contains("<")) { if (xxlJobGroup.getAppname().contains(">") || xxlJobGroup.getAppname().contains("<")) {
return new ReturnT<String>(500, "AppName"+I18nUtil.getString("system_unvalid") ); return ReturnT.ofFail( "AppName"+I18nUtil.getString("system_unvalid") );
} }
if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) { if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) ); return ReturnT.ofFail((I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
} }
if (xxlJobGroup.getTitle().contains(">") || xxlJobGroup.getTitle().contains("<")) { if (xxlJobGroup.getTitle().contains(">") || xxlJobGroup.getTitle().contains("<")) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_title")+I18nUtil.getString("system_unvalid") ); return ReturnT.ofFail(I18nUtil.getString("jobgroup_field_title")+I18nUtil.getString("system_unvalid") );
} }
if (xxlJobGroup.getAddressType()!=0) { if (xxlJobGroup.getAddressType()!=0) {
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) { if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_field_addressType_limit") );
} }
if (xxlJobGroup.getAddressList().contains(">") || xxlJobGroup.getAddressList().contains("<")) { if (xxlJobGroup.getAddressList().contains(">") || xxlJobGroup.getAddressList().contains("<")) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList")+I18nUtil.getString("system_unvalid") ); return ReturnT.ofFail(I18nUtil.getString("jobgroup_field_registryList")+I18nUtil.getString("system_unvalid") );
} }
String[] addresss = xxlJobGroup.getAddressList().split(","); String[] addresss = xxlJobGroup.getAddressList().split(",");
for (String item: addresss) { for (String item: addresss) {
if (item==null || item.trim().length()==0) { if (item==null || item.trim().length()==0) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_field_registryList_unvalid") );
} }
} }
} }
@ -112,13 +112,13 @@ public class JobGroupController {
public ReturnT<String> update(XxlJobGroup xxlJobGroup){ public ReturnT<String> update(XxlJobGroup xxlJobGroup){
// valid // valid
if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) { if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") ); return ReturnT.ofFail((I18nUtil.getString("system_please_input")+"AppName") );
} }
if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) { if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_field_appname_length") );
} }
if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) { if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) ); return ReturnT.ofFail( (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
} }
if (xxlJobGroup.getAddressType() == 0) { if (xxlJobGroup.getAddressType() == 0) {
// 0=自动注册 // 0=自动注册
@ -136,12 +136,12 @@ public class JobGroupController {
} else { } else {
// 1=手动录入 // 1=手动录入
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) { if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_field_addressType_limit") );
} }
String[] addresss = xxlJobGroup.getAddressList().split(","); String[] addresss = xxlJobGroup.getAddressList().split(",");
for (String item: addresss) { for (String item: addresss) {
if (item==null || item.trim().length()==0) { if (item==null || item.trim().length()==0) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") ); return ReturnT.ofFail(I18nUtil.getString("jobgroup_field_registryList_unvalid") );
} }
} }
} }
@ -183,12 +183,12 @@ public class JobGroupController {
// valid // valid
int count = xxlJobInfoMapper.pageListCount(0, 10, id, -1, null, null, null); int count = xxlJobInfoMapper.pageListCount(0, 10, id, -1, null, null, null);
if (count > 0) { if (count > 0) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_del_limit_0") );
} }
List<XxlJobGroup> allList = xxlJobGroupMapper.findAll(); List<XxlJobGroup> allList = xxlJobGroupMapper.findAll();
if (allList.size() == 1) { if (allList.size() == 1) {
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1") ); return ReturnT.ofFail( I18nUtil.getString("jobgroup_del_limit_1") );
} }
int ret = xxlJobGroupMapper.remove(id); int ret = xxlJobGroupMapper.remove(id);

@ -1,6 +1,5 @@
package com.xxl.job.admin.controller.biz; package com.xxl.job.admin.controller.biz;
import com.xxl.job.admin.constant.Consts;
import com.xxl.job.admin.mapper.XxlJobGroupMapper; import com.xxl.job.admin.mapper.XxlJobGroupMapper;
import com.xxl.job.admin.model.XxlJobGroup; import com.xxl.job.admin.model.XxlJobGroup;
import com.xxl.job.admin.model.XxlJobInfo; import com.xxl.job.admin.model.XxlJobInfo;
@ -11,6 +10,7 @@ import com.xxl.job.admin.scheduler.scheduler.ScheduleTypeEnum;
import com.xxl.job.admin.scheduler.thread.JobScheduleHelper; import com.xxl.job.admin.scheduler.thread.JobScheduleHelper;
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.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;
@ -62,7 +62,7 @@ public class JobInfoController {
List<XxlJobGroup> jobGroupListTotal = xxlJobGroupMapper.findAll(); List<XxlJobGroup> jobGroupListTotal = xxlJobGroupMapper.findAll();
// filter group // filter group
List<XxlJobGroup> jobGroupList = filterJobGroupByPermission(request, jobGroupListTotal); List<XxlJobGroup> jobGroupList = JobGroupPermissionUtil.filterJobGroupByPermission(request, jobGroupListTotal);
if (jobGroupList==null || jobGroupList.isEmpty()) { if (jobGroupList==null || jobGroupList.isEmpty()) {
throw new XxlJobException(I18nUtil.getString("jobgroup_empty")); throw new XxlJobException(I18nUtil.getString("jobgroup_empty"));
} }
@ -85,7 +85,7 @@ public class JobInfoController {
@RequestParam("author") String author) { @RequestParam("author") String author) {
// valid jobGroup permission // valid jobGroup permission
validJobGroupPermission(request, jobGroup); JobGroupPermissionUtil.validJobGroupPermission(request, jobGroup);
// page // page
return xxlJobService.pageList(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author); return xxlJobService.pageList(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author);
@ -95,7 +95,7 @@ public class JobInfoController {
@ResponseBody @ResponseBody
public ReturnT<String> add(HttpServletRequest request, XxlJobInfo jobInfo) { public ReturnT<String> add(HttpServletRequest request, XxlJobInfo jobInfo) {
// valid permission // valid permission
LoginInfo loginInfo = validJobGroupPermission(request, jobInfo.getJobGroup()); LoginInfo loginInfo = JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup());
// opt // opt
return xxlJobService.add(jobInfo, loginInfo); return xxlJobService.add(jobInfo, loginInfo);
@ -105,7 +105,7 @@ public class JobInfoController {
@ResponseBody @ResponseBody
public ReturnT<String> update(HttpServletRequest request, XxlJobInfo jobInfo) { public ReturnT<String> update(HttpServletRequest request, XxlJobInfo jobInfo) {
// valid permission // valid permission
LoginInfo loginInfo = validJobGroupPermission(request, jobInfo.getJobGroup()); LoginInfo loginInfo = JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup());
// opt // opt
return xxlJobService.update(jobInfo, loginInfo); return xxlJobService.update(jobInfo, loginInfo);
@ -164,56 +164,10 @@ 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 new ReturnT<List<String>>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) + e.getMessage()); return ReturnT.ofFail((I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) + e.getMessage());
} }
return ReturnT.ofSuccess(result); return ReturnT.ofSuccess(result);
} }
// -------------------- tool --------------------
/**
* check if has jobgroup permission
*/
public static boolean hasJobGroupPermission(LoginInfo loginInfo, int jobGroup){
if (XxlSsoHelper.hasRole(loginInfo, Consts.ADMIN_ROLE).isSuccess()) {
return true;
} else {
List<String> jobGroups = (loginInfo.getExtraInfo()!=null && loginInfo.getExtraInfo().containsKey("jobGroups"))
? List.of(StringTool.tokenizeToArray(loginInfo.getExtraInfo().get("jobGroups"), ",")) :new ArrayList<>();
return jobGroups.contains(String.valueOf(jobGroup));
}
}
/**
* valid jobGroup permission
*/
public static LoginInfo validJobGroupPermission(HttpServletRequest request, int jobGroup) {
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
if (!(loginInfoResponse.isSuccess() && hasJobGroupPermission(loginInfoResponse.getData(), jobGroup))) {
throw new RuntimeException(I18nUtil.getString("system_permission_limit") + "[username="+ loginInfoResponse.getData().getUserName() +"]");
}
return loginInfoResponse.getData();
}
/**
* filter jobGroupList by permission
*/
public static List<XxlJobGroup> filterJobGroupByPermission(HttpServletRequest request, List<XxlJobGroup> jobGroupListTotal){
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
if (XxlSsoHelper.hasRole(loginInfoResponse.getData(), Consts.ADMIN_ROLE).isSuccess()) {
return jobGroupListTotal;
} else {
List<String> jobGroups = (loginInfoResponse.getData().getExtraInfo()!=null && loginInfoResponse.getData().getExtraInfo().containsKey("jobGroups"))
? List.of(StringTool.tokenizeToArray(loginInfoResponse.getData().getExtraInfo().get("jobGroups"), ",")) :new ArrayList<>();
return jobGroupListTotal
.stream()
.filter(jobGroup -> jobGroups.contains(String.valueOf(jobGroup.getId())))
.toList();
}
}
} }

@ -10,6 +10,7 @@ import com.xxl.job.admin.scheduler.complete.XxlJobCompleter;
import com.xxl.job.admin.scheduler.exception.XxlJobException; import com.xxl.job.admin.scheduler.exception.XxlJobException;
import com.xxl.job.admin.scheduler.scheduler.XxlJobScheduler; import com.xxl.job.admin.scheduler.scheduler.XxlJobScheduler;
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.core.biz.ExecutorBiz; import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.KillParam; import com.xxl.job.core.biz.model.KillParam;
import com.xxl.job.core.biz.model.LogParam; import com.xxl.job.core.biz.model.LogParam;
@ -57,7 +58,7 @@ public class JobLogController {
// find jobGroup // find jobGroup
List<XxlJobGroup> jobGroupListTotal = xxlJobGroupMapper.findAll(); List<XxlJobGroup> jobGroupListTotal = xxlJobGroupMapper.findAll();
// filter jobGroup // filter jobGroup
List<XxlJobGroup> jobGroupList = JobInfoController.filterJobGroupByPermission(request, jobGroupListTotal); List<XxlJobGroup> jobGroupList = JobGroupPermissionUtil.filterJobGroupByPermission(request, jobGroupListTotal);
if (jobGroupList==null || jobGroupList.isEmpty()) { if (jobGroupList==null || jobGroupList.isEmpty()) {
throw new XxlJobException(I18nUtil.getString("jobgroup_empty")); throw new XxlJobException(I18nUtil.getString("jobgroup_empty"));
} }
@ -76,7 +77,7 @@ public class JobLogController {
} }
jobGroup = jobGroup > 0 ? jobGroup : jobGroupList.get(0).getId(); jobGroup = jobGroup > 0 ? jobGroup : jobGroupList.get(0).getId();
// valid permission // valid permission
JobInfoController.validJobGroupPermission(request, jobGroup); JobGroupPermissionUtil.validJobGroupPermission(request, jobGroup);
// find jobList // find jobList
List<XxlJobInfo> jobInfoList = xxlJobInfoMapper.getJobsByGroup(jobGroup); List<XxlJobInfo> jobInfoList = xxlJobInfoMapper.getJobsByGroup(jobGroup);
@ -112,7 +113,7 @@ public class JobLogController {
@RequestParam("filterTime") String filterTime) { @RequestParam("filterTime") String filterTime) {
// valid jobGroup permission // valid jobGroup permission
JobInfoController.validJobGroupPermission(request, jobGroup); JobGroupPermissionUtil.validJobGroupPermission(request, jobGroup);
// parse param // parse param
Date triggerTimeStart = null; Date triggerTimeStart = null;
@ -147,7 +148,7 @@ public class JobLogController {
} }
// valid permission // valid permission
JobInfoController.validJobGroupPermission(request, jobLog.getJobGroup()); JobGroupPermissionUtil.validJobGroupPermission(request, jobLog.getJobGroup());
// data // data
model.addAttribute("triggerCode", jobLog.getTriggerCode()); model.addAttribute("triggerCode", jobLog.getTriggerCode());
@ -163,7 +164,7 @@ public class JobLogController {
// valid // valid
XxlJobLog jobLog = xxlJobLogMapper.load(logId); // todo, need to improve performance XxlJobLog jobLog = xxlJobLogMapper.load(logId); // todo, need to improve performance
if (jobLog == null) { if (jobLog == null) {
return new ReturnT<LogResult>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_logid_unvalid")); return ReturnT.ofFail(I18nUtil.getString("joblog_logid_unvalid"));
} }
// log cat // log cat
@ -186,7 +187,7 @@ public class JobLogController {
return logResult; return logResult;
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return new ReturnT<LogResult>(ReturnT.FAIL_CODE, e.getMessage()); return ReturnT.ofFail(e.getMessage());
} }
} }
@ -229,14 +230,14 @@ public class JobLogController {
XxlJobLog log = xxlJobLogMapper.load(id); XxlJobLog log = xxlJobLogMapper.load(id);
XxlJobInfo jobInfo = xxlJobInfoMapper.loadById(log.getJobId()); XxlJobInfo jobInfo = xxlJobInfoMapper.loadById(log.getJobId());
if (jobInfo==null) { if (jobInfo==null) {
return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid")); return ReturnT.ofFail(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
} }
if (ReturnT.SUCCESS_CODE != log.getTriggerCode()) { if (ReturnT.SUCCESS_CODE != log.getTriggerCode()) {
return new ReturnT<String>(500, I18nUtil.getString("joblog_kill_log_limit")); return ReturnT.ofFail( I18nUtil.getString("joblog_kill_log_limit"));
} }
// valid JobGroup permission // valid JobGroup permission
JobInfoController.validJobGroupPermission(request, jobInfo.getJobGroup()); JobGroupPermissionUtil.validJobGroupPermission(request, jobInfo.getJobGroup());
// request of kill // request of kill
ReturnT<String> runResult = null; ReturnT<String> runResult = null;
@ -245,7 +246,7 @@ public class JobLogController {
runResult = executorBiz.kill(new KillParam(jobInfo.getId())); runResult = executorBiz.kill(new KillParam(jobInfo.getId()));
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
runResult = new ReturnT<String>(500, e.getMessage()); runResult = ReturnT.ofFail( e.getMessage());
} }
if (ReturnT.SUCCESS_CODE == runResult.getCode()) { if (ReturnT.SUCCESS_CODE == runResult.getCode()) {
@ -266,7 +267,7 @@ public class JobLogController {
@RequestParam("jobId") int jobId, @RequestParam("jobId") int jobId,
@RequestParam("type") int type){ @RequestParam("type") int type){
// valid JobGroup permission // valid JobGroup permission
JobInfoController.validJobGroupPermission(request, jobGroup); JobGroupPermissionUtil.validJobGroupPermission(request, jobGroup);
// opt // opt
Date clearBeforeTime = null; Date clearBeforeTime = null;
@ -290,7 +291,7 @@ public class JobLogController {
} else if (type == 9) { } else if (type == 9) {
clearBeforeNum = 0; // 清理所有日志数据 clearBeforeNum = 0; // 清理所有日志数据
} else { } else {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid")); return ReturnT.ofFail(I18nUtil.getString("joblog_clean_type_unvalid"));
} }
List<Long> logIds = null; List<Long> logIds = null;

@ -82,19 +82,19 @@ public class JobUserController {
// valid username // valid username
if (!StringUtils.hasText(xxlJobUser.getUsername())) { if (!StringUtils.hasText(xxlJobUser.getUsername())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_please_input")+I18nUtil.getString("user_username") ); return ReturnT.ofFail(I18nUtil.getString("system_please_input")+I18nUtil.getString("user_username") );
} }
xxlJobUser.setUsername(xxlJobUser.getUsername().trim()); xxlJobUser.setUsername(xxlJobUser.getUsername().trim());
if (!(xxlJobUser.getUsername().length()>=4 && xxlJobUser.getUsername().length()<=20)) { if (!(xxlJobUser.getUsername().length()>=4 && xxlJobUser.getUsername().length()<=20)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" ); return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" );
} }
// valid password // valid password
if (!StringUtils.hasText(xxlJobUser.getPassword())) { if (!StringUtils.hasText(xxlJobUser.getPassword())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_please_input")+I18nUtil.getString("user_password") ); return ReturnT.ofFail(I18nUtil.getString("system_please_input")+I18nUtil.getString("user_password") );
} }
xxlJobUser.setPassword(xxlJobUser.getPassword().trim()); xxlJobUser.setPassword(xxlJobUser.getPassword().trim());
if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) { if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" ); return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" );
} }
// md5 password // md5 password
String passwordHash = SHA256Tool.sha256(xxlJobUser.getPassword()); String passwordHash = SHA256Tool.sha256(xxlJobUser.getPassword());
@ -103,7 +103,7 @@ public class JobUserController {
// check repeat // check repeat
XxlJobUser existUser = xxlJobUserMapper.loadByUserName(xxlJobUser.getUsername()); XxlJobUser existUser = xxlJobUserMapper.loadByUserName(xxlJobUser.getUsername());
if (existUser != null) { if (existUser != null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("user_username_repeat") ); return ReturnT.ofFail( I18nUtil.getString("user_username_repeat") );
} }
// write // write
@ -126,7 +126,7 @@ public class JobUserController {
if (StringUtils.hasText(xxlJobUser.getPassword())) { if (StringUtils.hasText(xxlJobUser.getPassword())) {
xxlJobUser.setPassword(xxlJobUser.getPassword().trim()); xxlJobUser.setPassword(xxlJobUser.getPassword().trim());
if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) { if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" ); return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" );
} }
// md5 password // md5 password
String passwordHash = SHA256Tool.sha256(xxlJobUser.getPassword()); String passwordHash = SHA256Tool.sha256(xxlJobUser.getPassword());

@ -26,7 +26,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
idleBeatResult = executorBiz.idleBeat(new IdleBeatParam(triggerParam.getJobId())); idleBeatResult = executorBiz.idleBeat(new IdleBeatParam(triggerParam.getJobId()));
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
idleBeatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e ); idleBeatResult = ReturnT.ofFail( ""+e );
} }
idleBeatResultSB.append( (idleBeatResultSB.length()>0)?"<br><br>":"") idleBeatResultSB.append( (idleBeatResultSB.length()>0)?"<br><br>":"")
.append(I18nUtil.getString("jobconf_idleBeat") + "") .append(I18nUtil.getString("jobconf_idleBeat") + "")
@ -42,7 +42,7 @@ public class ExecutorRouteBusyover extends ExecutorRouter {
} }
} }
return new ReturnT<String>(ReturnT.FAIL_CODE, idleBeatResultSB.toString()); return ReturnT.ofFail( idleBeatResultSB.toString());
} }
} }

@ -26,7 +26,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
beatResult = executorBiz.beat(); beatResult = executorBiz.beat();
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
beatResult = new ReturnT<String>(ReturnT.FAIL_CODE, ""+e ); beatResult = ReturnT.ofFail(e.getMessage() );
} }
beatResultSB.append( (beatResultSB.length()>0)?"<br><br>":"") beatResultSB.append( (beatResultSB.length()>0)?"<br><br>":"")
.append(I18nUtil.getString("jobconf_beat") + "") .append(I18nUtil.getString("jobconf_beat") + "")
@ -42,7 +42,7 @@ public class ExecutorRouteFailover extends ExecutorRouter {
return beatResult; return beatResult;
} }
} }
return new ReturnT<String>(ReturnT.FAIL_CODE, beatResultSB.toString()); return ReturnT.ofFail( beatResultSB.toString());
} }
} }

@ -155,10 +155,10 @@ public class JobCompleteHelper {
// valid log item // valid log item
XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogMapper().load(handleCallbackParam.getLogId()); XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogMapper().load(handleCallbackParam.getLogId());
if (log == null) { if (log == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "log item not found."); return ReturnT.ofFail( "log item not found.");
} }
if (log.getHandleCode() > 0) { if (log.getHandleCode() > 0) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "log repeate callback."); // avoid repeat callback, trigger child job etc return ReturnT.ofFail("log repeate callback."); // avoid repeat callback, trigger child job etc
} }
// handle msg // handle msg

@ -152,7 +152,7 @@ public class JobRegistryHelper {
if (!StringUtils.hasText(registryParam.getRegistryGroup()) if (!StringUtils.hasText(registryParam.getRegistryGroup())
|| !StringUtils.hasText(registryParam.getRegistryKey()) || !StringUtils.hasText(registryParam.getRegistryKey())
|| !StringUtils.hasText(registryParam.getRegistryValue())) { || !StringUtils.hasText(registryParam.getRegistryValue())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "Illegal Argument."); return ReturnT.ofFail("Illegal Argument.");
} }
// async execute // async execute
@ -184,7 +184,7 @@ public class JobRegistryHelper {
if (!StringUtils.hasText(registryParam.getRegistryGroup()) if (!StringUtils.hasText(registryParam.getRegistryGroup())
|| !StringUtils.hasText(registryParam.getRegistryKey()) || !StringUtils.hasText(registryParam.getRegistryKey())
|| !StringUtils.hasText(registryParam.getRegistryValue())) { || !StringUtils.hasText(registryParam.getRegistryValue())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "Illegal Argument."); return ReturnT.ofFail("Illegal Argument.");
} }
// async execute // async execute

@ -155,7 +155,7 @@ public class XxlJobTrigger {
} }
} }
} else { } else {
routeAddressResult = new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobconf_trigger_address_empty")); routeAddressResult = ReturnT.ofFail( I18nUtil.getString("jobconf_trigger_address_empty"));
} }
// 4、trigger remote executor // 4、trigger remote executor
@ -163,7 +163,7 @@ public class XxlJobTrigger {
if (address != null) { if (address != null) {
triggerResult = runExecutor(triggerParam, address); triggerResult = runExecutor(triggerParam, address);
} else { } else {
triggerResult = new ReturnT<String>(ReturnT.FAIL_CODE, null); triggerResult = ReturnT.ofFail(null);
} }
// 5、collection trigger info // 5、collection trigger info
@ -211,7 +211,7 @@ public class XxlJobTrigger {
runResult = executorBiz.run(triggerParam); runResult = executorBiz.run(triggerParam);
} catch (Exception e) { } catch (Exception e) {
logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e); logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e);
runResult = new ReturnT<String>(ReturnT.FAIL_CODE, ThrowableUtil.toString(e)); runResult = ReturnT.ofFail(ThrowableUtil.toString(e));
} }
StringBuffer runResultSB = new StringBuffer(I18nUtil.getString("jobconf_trigger_run") + ""); StringBuffer runResultSB = new StringBuffer(I18nUtil.getString("jobconf_trigger_run") + "");

@ -1,11 +1,9 @@
package com.xxl.job.admin.service.impl; package com.xxl.job.admin.service.impl;
import com.xxl.job.admin.controller.biz.JobInfoController;
import com.xxl.job.admin.mapper.*; import com.xxl.job.admin.mapper.*;
import com.xxl.job.admin.model.XxlJobGroup; import com.xxl.job.admin.model.XxlJobGroup;
import com.xxl.job.admin.model.XxlJobInfo; import com.xxl.job.admin.model.XxlJobInfo;
import com.xxl.job.admin.model.XxlJobLogReport; import com.xxl.job.admin.model.XxlJobLogReport;
import com.xxl.job.admin.model.XxlJobUser;
import com.xxl.job.admin.scheduler.cron.CronExpression; import com.xxl.job.admin.scheduler.cron.CronExpression;
import com.xxl.job.admin.scheduler.route.ExecutorRouteStrategyEnum; import com.xxl.job.admin.scheduler.route.ExecutorRouteStrategyEnum;
import com.xxl.job.admin.scheduler.scheduler.MisfireStrategyEnum; import com.xxl.job.admin.scheduler.scheduler.MisfireStrategyEnum;
@ -15,6 +13,7 @@ import com.xxl.job.admin.scheduler.thread.JobTriggerPoolHelper;
import com.xxl.job.admin.scheduler.trigger.TriggerTypeEnum; import com.xxl.job.admin.scheduler.trigger.TriggerTypeEnum;
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.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.glue.GlueTypeEnum;
@ -68,44 +67,44 @@ public class XxlJobServiceImpl implements XxlJobService {
// valid base // valid base
XxlJobGroup group = xxlJobGroupMapper.load(jobInfo.getJobGroup()); XxlJobGroup group = xxlJobGroupMapper.load(jobInfo.getJobGroup());
if (group == null) { if (group == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, "Cron"+I18nUtil.getString("system_unvalid")); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} catch (Exception e) { } catch (Exception e) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+"JobHandler") ); return ReturnT.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) {
@ -114,13 +113,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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) );
} }
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
} }
// 》ChildJobId valid // 》ChildJobId valid
@ -130,16 +129,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 new ReturnT<String>(ReturnT.FAIL_CODE, return ReturnT.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 (!JobInfoController.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, return ReturnT.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));
} }
} }
@ -162,7 +161,7 @@ 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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) ); return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
} }
return ReturnT.ofSuccess(String.valueOf(jobInfo.getId())); return ReturnT.ofSuccess(String.valueOf(jobInfo.getId()));
@ -182,44 +181,44 @@ public class XxlJobServiceImpl implements XxlJobService {
// valid base // valid base
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, "Cron"+I18nUtil.getString("system_unvalid") ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} catch (Exception e) { } catch (Exception e) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("misfire_strategy")+I18nUtil.getString("system_unvalid")) );
} }
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
} }
// 》ChildJobId valid // 》ChildJobId valid
@ -230,22 +229,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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_childJobId")+"("+childJobId+")"+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, return ReturnT.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 (!JobInfoController.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, childJobInfo.getJobGroup())) {
return new ReturnT<String>(ReturnT.FAIL_CODE, return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, return ReturnT.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));
} }
} }
@ -263,13 +262,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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) ); return ReturnT.ofFail ( (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
} }
// next trigger time (5s后生效避开预读周期) // next trigger time (5s后生效避开预读周期)
@ -279,12 +278,12 @@ public class XxlJobServiceImpl implements XxlJobService {
try { try {
Date nextValidTime = JobScheduleHelper.generateNextValidTime(jobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); Date nextValidTime = JobScheduleHelper.generateNextValidTime(jobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
if (nextValidTime == null) { if (nextValidTime == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
} }
@ -321,7 +320,7 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobInfoController.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return ReturnT.ofFail(I18nUtil.getString("system_permission_limit"));
} }
@ -340,7 +339,7 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobInfoController.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return ReturnT.ofFail(I18nUtil.getString("system_permission_limit"));
} }
@ -355,12 +354,12 @@ public class XxlJobServiceImpl implements XxlJobService {
try { try {
Date nextValidTime = JobScheduleHelper.generateNextValidTime(xxlJobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); Date nextValidTime = JobScheduleHelper.generateNextValidTime(xxlJobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
if (nextValidTime == null) { if (nextValidTime == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); return ReturnT.ofFail ( (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
} }
xxlJobInfo.setTriggerStatus(1); xxlJobInfo.setTriggerStatus(1);
@ -381,7 +380,7 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobInfoController.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return ReturnT.ofFail(I18nUtil.getString("system_permission_limit"));
} }
@ -406,7 +405,7 @@ public class XxlJobServiceImpl implements XxlJobService {
} }
// valid jobGroup permission // valid jobGroup permission
if (!JobInfoController.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) { if (!JobGroupPermissionUtil.hasJobGroupPermission(loginInfo, xxlJobInfo.getJobGroup())) {
return ReturnT.ofFail(I18nUtil.getString("system_permission_limit")); return ReturnT.ofFail(I18nUtil.getString("system_permission_limit"));
} }

@ -1,98 +0,0 @@
package com.xxl.job.admin.util;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* Cookie.Util
*
* @author xuxueli 2015-12-12 18:01:06
*/
public class CookieUtil {
// 默认缓存时间,单位/秒, 2H
private static final int COOKIE_MAX_AGE = Integer.MAX_VALUE;
// 保存路径,根路径
private static final String COOKIE_PATH = "/";
/**
*
*
* @param response
* @param key
* @param value
* @param ifRemember
*/
public static void set(HttpServletResponse response, String key, String value, boolean ifRemember) {
int age = ifRemember?COOKIE_MAX_AGE:-1;
set(response, key, value, null, COOKIE_PATH, age, true);
}
/**
*
*
* @param response
* @param key
* @param value
* @param maxAge
*/
private static void set(HttpServletResponse response, String key, String value, String domain, String path, int maxAge, boolean isHttpOnly) {
Cookie cookie = new Cookie(key, value);
if (domain != null) {
cookie.setDomain(domain);
}
cookie.setPath(path);
cookie.setMaxAge(maxAge);
cookie.setHttpOnly(isHttpOnly);
response.addCookie(cookie);
}
/**
* value
*
* @param request
* @param key
* @return
*/
public static String getValue(HttpServletRequest request, String key) {
Cookie cookie = get(request, key);
if (cookie != null) {
return cookie.getValue();
}
return null;
}
/**
* Cookie
*
* @param request
* @param key
*/
private static Cookie get(HttpServletRequest request, String key) {
Cookie[] arr_cookie = request.getCookies();
if (arr_cookie != null && arr_cookie.length > 0) {
for (Cookie cookie : arr_cookie) {
if (cookie.getName().equals(key)) {
return cookie;
}
}
}
return null;
}
/**
* Cookie
*
* @param request
* @param response
* @param key
*/
public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
Cookie cookie = get(request, key);
if (cookie != null) {
set(response, key, "", null, COOKIE_PATH, 0, true);
}
}
}

@ -0,0 +1,64 @@
package com.xxl.job.admin.util;
import com.xxl.job.admin.constant.Consts;
import com.xxl.job.admin.model.XxlJobGroup;
import com.xxl.sso.core.helper.XxlSsoHelper;
import com.xxl.sso.core.model.LoginInfo;
import com.xxl.tool.core.StringTool;
import com.xxl.tool.response.Response;
import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* jobGroup permission util
*
* @author xuxueli 2025-08-24
*/
public class JobGroupPermissionUtil {
/**
* check if has jobgroup permission
*/
public static boolean hasJobGroupPermission(LoginInfo loginInfo, int jobGroup){
if (XxlSsoHelper.hasRole(loginInfo, Consts.ADMIN_ROLE).isSuccess()) {
return true;
} else {
List<String> jobGroups = (loginInfo.getExtraInfo()!=null && loginInfo.getExtraInfo().containsKey("jobGroups"))
? List.of(StringTool.tokenizeToArray(loginInfo.getExtraInfo().get("jobGroups"), ",")) :new ArrayList<>();
return jobGroups.contains(String.valueOf(jobGroup));
}
}
/**
* valid jobGroup permission
*/
public static LoginInfo validJobGroupPermission(HttpServletRequest request, int jobGroup) {
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
if (!(loginInfoResponse.isSuccess() && hasJobGroupPermission(loginInfoResponse.getData(), jobGroup))) {
throw new RuntimeException(I18nUtil.getString("system_permission_limit") + "[username="+ loginInfoResponse.getData().getUserName() +"]");
}
return loginInfoResponse.getData();
}
/**
* filter jobGroupList by permission
*/
public static List<XxlJobGroup> filterJobGroupByPermission(HttpServletRequest request, List<XxlJobGroup> jobGroupListTotal){
Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
if (XxlSsoHelper.hasRole(loginInfoResponse.getData(), Consts.ADMIN_ROLE).isSuccess()) {
return jobGroupListTotal;
} else {
List<String> jobGroups = (loginInfoResponse.getData().getExtraInfo()!=null && loginInfoResponse.getData().getExtraInfo().containsKey("jobGroups"))
? List.of(StringTool.tokenizeToArray(loginInfoResponse.getData().getExtraInfo().get("jobGroups"), ",")) :new ArrayList<>();
return jobGroupListTotal
.stream()
.filter(jobGroup -> jobGroups.contains(String.valueOf(jobGroup.getId())))
.toList();
}
}
}

@ -0,0 +1,98 @@
//package com.xxl.job.admin.util;
//
//import jakarta.servlet.http.Cookie;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//
///**
// * Cookie.Util
// *
// * @author xuxueli 2015-12-12 18:01:06
// */
//public class CookieUtil {
//
// // 默认缓存时间,单位/秒, 2H
// private static final int COOKIE_MAX_AGE = Integer.MAX_VALUE;
// // 保存路径,根路径
// private static final String COOKIE_PATH = "/";
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param ifRemember
// */
// public static void set(HttpServletResponse response, String key, String value, boolean ifRemember) {
// int age = ifRemember?COOKIE_MAX_AGE:-1;
// set(response, key, value, null, COOKIE_PATH, age, true);
// }
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param maxAge
// */
// private static void set(HttpServletResponse response, String key, String value, String domain, String path, int maxAge, boolean isHttpOnly) {
// Cookie cookie = new Cookie(key, value);
// if (domain != null) {
// cookie.setDomain(domain);
// }
// cookie.setPath(path);
// cookie.setMaxAge(maxAge);
// cookie.setHttpOnly(isHttpOnly);
// response.addCookie(cookie);
// }
//
// /**
// * 查询value
// *
// * @param request
// * @param key
// * @return
// */
// public static String getValue(HttpServletRequest request, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// return cookie.getValue();
// }
// return null;
// }
//
// /**
// * 查询Cookie
// *
// * @param request
// * @param key
// */
// private static Cookie get(HttpServletRequest request, String key) {
// Cookie[] arr_cookie = request.getCookies();
// if (arr_cookie != null && arr_cookie.length > 0) {
// for (Cookie cookie : arr_cookie) {
// if (cookie.getName().equals(key)) {
// return cookie;
// }
// }
// }
// return null;
// }
//
// /**
// * 删除Cookie
// *
// * @param request
// * @param response
// * @param key
// */
// public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// set(response, key, "", null, COOKIE_PATH, 0, true);
// }
// }
//
//}

@ -38,7 +38,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
} }
if (isRunningOrHasQueue) { if (isRunningOrHasQueue) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "job thread is running or has trigger queue."); return ReturnT.ofFail("job thread is running or has trigger queue.");
} }
return ReturnT.ofSuccess(); return ReturnT.ofSuccess();
} }
@ -70,7 +70,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
if (jobHandler == null) { if (jobHandler == null) {
jobHandler = newJobHandler; jobHandler = newJobHandler;
if (jobHandler == null) { if (jobHandler == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "job handler [" + triggerParam.getExecutorHandler() + "] not found."); return ReturnT.ofFail( "job handler [" + triggerParam.getExecutorHandler() + "] not found.");
} }
} }
@ -94,7 +94,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
jobHandler = new GlueJobHandler(originJobHandler, triggerParam.getGlueUpdatetime()); jobHandler = new GlueJobHandler(originJobHandler, triggerParam.getGlueUpdatetime());
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage()); return ReturnT.ofFail( e.getMessage());
} }
} }
} else if (glueTypeEnum!=null && glueTypeEnum.isScript()) { } else if (glueTypeEnum!=null && glueTypeEnum.isScript()) {
@ -115,7 +115,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
jobHandler = new ScriptJobHandler(triggerParam.getJobId(), triggerParam.getGlueUpdatetime(), triggerParam.getGlueSource(), GlueTypeEnum.match(triggerParam.getGlueType())); jobHandler = new ScriptJobHandler(triggerParam.getJobId(), triggerParam.getGlueUpdatetime(), triggerParam.getGlueSource(), GlueTypeEnum.match(triggerParam.getGlueType()));
} }
} else { } else {
return new ReturnT<String>(ReturnT.FAIL_CODE, "glueType[" + triggerParam.getGlueType() + "] is not valid."); return ReturnT.ofFail("glueType[" + triggerParam.getGlueType() + "] is not valid.");
} }
// executor block strategy // executor block strategy
@ -124,7 +124,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
if (ExecutorBlockStrategyEnum.DISCARD_LATER == blockStrategy) { if (ExecutorBlockStrategyEnum.DISCARD_LATER == blockStrategy) {
// discard when running // discard when running
if (jobThread.isRunningOrHasQueue()) { if (jobThread.isRunningOrHasQueue()) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "block strategy effect"+ExecutorBlockStrategyEnum.DISCARD_LATER.getTitle()); return ReturnT.ofFail("block strategy effect"+ExecutorBlockStrategyEnum.DISCARD_LATER.getTitle());
} }
} else if (ExecutorBlockStrategyEnum.COVER_EARLY == blockStrategy) { } else if (ExecutorBlockStrategyEnum.COVER_EARLY == blockStrategy) {
// kill running jobThread // kill running jobThread

@ -169,15 +169,15 @@ public class EmbedServer {
private Object process(HttpMethod httpMethod, String uri, String requestData, String accessTokenReq) { private Object process(HttpMethod httpMethod, String uri, String requestData, String accessTokenReq) {
// valid // valid
if (HttpMethod.POST != httpMethod) { if (HttpMethod.POST != httpMethod) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, HttpMethod not support."); return ReturnT.ofFail("invalid request, HttpMethod not support.");
} }
if (uri == null || uri.trim().length() == 0) { if (uri == null || uri.trim().length() == 0) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping empty."); return ReturnT.ofFail( "invalid request, uri-mapping empty.");
} }
if (accessToken != null if (accessToken != null
&& accessToken.trim().length() > 0 && accessToken.trim().length() > 0
&& !accessToken.equals(accessTokenReq)) { && !accessToken.equals(accessTokenReq)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "The access token is wrong."); return ReturnT.ofFail("The access token is wrong.");
} }
// services mapping // services mapping
@ -198,11 +198,11 @@ public class EmbedServer {
LogParam logParam = GsonTool.fromJson(requestData, LogParam.class); LogParam logParam = GsonTool.fromJson(requestData, LogParam.class);
return executorBiz.log(logParam); return executorBiz.log(logParam);
default: default:
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping(" + uri + ") not found."); return ReturnT.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 new ReturnT<String>(ReturnT.FAIL_CODE, "request error:" + ThrowableUtil.toString(e)); return ReturnT.ofFail("request error:" + ThrowableUtil.toString(e));
} }
} }

@ -63,7 +63,7 @@ public class JobThread extends Thread{
// avoid repeat // avoid repeat
if (!triggerLogIdSet.add(triggerParam.getLogId())) { if (!triggerLogIdSet.add(triggerParam.getLogId())) {
logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId()); logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId());
return new ReturnT<String>(ReturnT.FAIL_CODE, "repeate trigger job, logId:" + triggerParam.getLogId()); return ReturnT.ofFail("repeate trigger job, logId:" + triggerParam.getLogId());
} }
// push trigger queue // push trigger queue

@ -119,7 +119,7 @@ public class XxlJobRemotingUtil {
// valid StatusCode // valid StatusCode
int statusCode = connection.getResponseCode(); int statusCode = connection.getResponseCode();
if (statusCode != 200) { if (statusCode != 200) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "xxl-job remoting fail, StatusCode("+ statusCode +") invalid. for url : " + url); return ReturnT.ofFail("xxl-job remoting fail, StatusCode("+ statusCode +") invalid. for url : " + url);
} }
// result // result
@ -137,12 +137,12 @@ public class XxlJobRemotingUtil {
return returnT; return returnT;
} catch (Exception e) { } catch (Exception e) {
logger.error("xxl-job remoting (url="+url+") response content invalid("+ resultJson +").", e); logger.error("xxl-job remoting (url="+url+") response content invalid("+ resultJson +").", e);
return new ReturnT<String>(ReturnT.FAIL_CODE, "xxl-job remoting (url="+url+") response content invalid("+ resultJson +")."); return ReturnT.ofFail("xxl-job remoting (url="+url+") response content invalid("+ resultJson +").");
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return new ReturnT<String>(ReturnT.FAIL_CODE, "xxl-job remoting error("+ e.getMessage() +"), for url : " + url); return ReturnT.ofFail("xxl-job remoting error("+ e.getMessage() +"), for url : " + url);
} finally { } finally {
try { try {
if (dataOutputStream != null) { if (dataOutputStream != null) {

Loading…
Cancel
Save