【fix sonar】微服务修改文件
This commit is contained in:
+3
-45
@@ -60,8 +60,9 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
|
||||
|
||||
public DynamicRouteLoader(InMemoryRouteDefinitionRepository repository, DynamicRouteService dynamicRouteService, RedisUtil redisUtil) {
|
||||
|
||||
this.repository = repository;
|
||||
if(this.repository == null){
|
||||
this.repository = repository;
|
||||
}
|
||||
this.dynamicRouteService = dynamicRouteService;
|
||||
this.redisUtil = redisUtil;
|
||||
}
|
||||
@@ -234,49 +235,6 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
}
|
||||
|
||||
|
||||
// private void loadRoutesByDataBase() {
|
||||
// List<GatewayRouteVo> routeList = jdbcTemplate.query(SELECT_ROUTES, new RowMapper<GatewayRouteVo>() {
|
||||
// @Override
|
||||
// public GatewayRouteVo mapRow(ResultSet rs, int i) throws SQLException {
|
||||
// GatewayRouteVo result = new GatewayRouteVo();
|
||||
// result.setId(rs.getString("id"));
|
||||
// result.setName(rs.getString("name"));
|
||||
// result.setUri(rs.getString("uri"));
|
||||
// result.setStatus(rs.getInt("status"));
|
||||
// result.setRetryable(rs.getInt("retryable"));
|
||||
// result.setPredicates(rs.getString("predicates"));
|
||||
// result.setStripPrefix(rs.getInt("strip_prefix"));
|
||||
// result.setPersist(rs.getInt("persist"));
|
||||
// return result;
|
||||
// }
|
||||
// });
|
||||
// if (ObjectUtil.isNotEmpty(routeList)) {
|
||||
// // 加载路由
|
||||
// routeList.forEach(route -> {
|
||||
// RouteDefinition definition = new RouteDefinition();
|
||||
// List<PredicateDefinition> predicatesList = Lists.newArrayList();
|
||||
// List<FilterDefinition> filtersList = Lists.newArrayList();
|
||||
// definition.setId(route.getId());
|
||||
// String predicates = route.getPredicates();
|
||||
// String filters = route.getFilters();
|
||||
// if (StringUtils.isNotEmpty(predicates)) {
|
||||
// predicatesList = JSON.parseArray(predicates, PredicateDefinition.class);
|
||||
// definition.setPredicates(predicatesList);
|
||||
// }
|
||||
// if (StringUtils.isNotEmpty(filters)) {
|
||||
// filtersList = JSON.parseArray(filters, FilterDefinition.class);
|
||||
// definition.setFilters(filtersList);
|
||||
// }
|
||||
// URI uri = UriComponentsBuilder.fromUriString(route.getUri()).build().toUri();
|
||||
// definition.setUri(uri);
|
||||
// this.repository.save(Mono.just(definition)).subscribe();
|
||||
// });
|
||||
// log.info("加载路由:{}==============", routeList.size());
|
||||
// Mono.empty();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 监听Nacos下发的动态路由配置
|
||||
*
|
||||
|
||||
-5
@@ -73,11 +73,6 @@ public class IndexController {
|
||||
|
||||
@RequestMapping("/help")
|
||||
public String help() {
|
||||
|
||||
/*if (!PermissionInterceptor.ifLogin(request)) {
|
||||
return "redirect:/toLogin";
|
||||
}*/
|
||||
|
||||
return "help";
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -36,10 +36,10 @@ public class JobCodeController {
|
||||
List<XxlJobLogGlue> jobLogGlues = xxlJobLogGlueDao.findByJobId(jobId);
|
||||
|
||||
if (jobInfo == null) {
|
||||
throw new RuntimeException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
|
||||
throw new IllegalArgumentException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
|
||||
}
|
||||
if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType())) {
|
||||
throw new RuntimeException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
|
||||
throw new IllegalArgumentException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
|
||||
}
|
||||
|
||||
// valid permission
|
||||
|
||||
+42
-23
@@ -74,14 +74,9 @@ public class JobGroupController {
|
||||
return new ReturnT<>(500, (I18nUtil.getString(systemPleaseInput) + I18nUtil.getString("jobgroup_field_title")) );
|
||||
}
|
||||
if (xxlJobGroup.getAddressType()!=0) {
|
||||
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
||||
}
|
||||
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
||||
for (String item: addresss) {
|
||||
if (item==null || item.trim().length()==0) {
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
||||
}
|
||||
ReturnT<String> x = getStringReturnT(xxlJobGroup);
|
||||
if (x != null) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +84,19 @@ public class JobGroupController {
|
||||
return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
|
||||
}
|
||||
|
||||
private ReturnT<String> getStringReturnT(XxlJobGroup xxlJobGroup) {
|
||||
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
||||
}
|
||||
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
||||
for (String item: addresss) {
|
||||
if (item==null || item.trim().length()==0) {
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@ResponseBody
|
||||
public ReturnT<String> update(XxlJobGroup xxlJobGroup){
|
||||
@@ -105,33 +113,44 @@ public class JobGroupController {
|
||||
if (xxlJobGroup.getAddressType() == 0) {
|
||||
// 0=自动注册
|
||||
List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppname());
|
||||
StringBuilder addressListStr = new StringBuilder();
|
||||
if (registryList!=null && !registryList.isEmpty()) {
|
||||
Collections.sort(registryList);
|
||||
addressListStr = new StringBuilder();
|
||||
for (String item:registryList) {
|
||||
addressListStr.append(item).append(",");
|
||||
}
|
||||
addressListStr = new StringBuilder(addressListStr.substring(0, addressListStr.length() - 1));
|
||||
}
|
||||
StringBuilder addressListStr = getStringBuilder(registryList);
|
||||
xxlJobGroup.setAddressList(addressListStr.toString());
|
||||
} else {
|
||||
// 1=手动录入
|
||||
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
||||
}
|
||||
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
||||
for (String item: addresss) {
|
||||
if (item==null || item.trim().length()==0) {
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
||||
}
|
||||
}
|
||||
if (getAddresss(xxlJobGroup))
|
||||
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid"));
|
||||
}
|
||||
|
||||
int ret = xxlJobGroupDao.update(xxlJobGroup);
|
||||
return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
|
||||
}
|
||||
|
||||
private boolean getAddresss(XxlJobGroup xxlJobGroup) {
|
||||
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
||||
for (String item : addresss) {
|
||||
if (item == null || item.trim().length() == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private StringBuilder getStringBuilder(List<String> registryList) {
|
||||
StringBuilder addressListStr = new StringBuilder();
|
||||
if (registryList!=null && !registryList.isEmpty()) {
|
||||
Collections.sort(registryList);
|
||||
addressListStr = new StringBuilder();
|
||||
for (String item:registryList) {
|
||||
addressListStr.append(item).append(",");
|
||||
}
|
||||
addressListStr = new StringBuilder(addressListStr.substring(0, addressListStr.length() - 1));
|
||||
}
|
||||
return addressListStr;
|
||||
}
|
||||
|
||||
private List<String> findRegistryByAppName(String appnameParam){
|
||||
HashMap<String, List<String>> appAddressMap = new HashMap<>();
|
||||
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
|
||||
|
||||
+9
-4
@@ -75,18 +75,23 @@ public class JobInfoController {
|
||||
groupIdStrs = Arrays.asList(loginUser.getPermission().trim().split(","));
|
||||
}
|
||||
for (XxlJobGroup groupItem:jobGroupListAll) {
|
||||
if (groupIdStrs.contains(String.valueOf(groupItem.getId()))) {
|
||||
jobGroupList.add(groupItem);
|
||||
}
|
||||
getAdd(jobGroupList, groupIdStrs, groupItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return jobGroupList;
|
||||
}
|
||||
|
||||
private static void getAdd(List<XxlJobGroup> jobGroupList, List<String> groupIdStrs, XxlJobGroup groupItem) {
|
||||
if (groupIdStrs.contains(String.valueOf(groupItem.getId()))) {
|
||||
jobGroupList.add(groupItem);
|
||||
}
|
||||
}
|
||||
|
||||
public static void validPermission(HttpServletRequest request, int jobGroup) {
|
||||
XxlJobUser loginUser = (XxlJobUser) request.getAttribute(LoginService.LOGIN_IDENTITY_KEY);
|
||||
if (!loginUser.validPermission(jobGroup)) {
|
||||
throw new RuntimeException(I18nUtil.getString("system_permission_limit") + "[username="+ loginUser.getUsername() +"]");
|
||||
throw new IllegalArgumentException(I18nUtil.getString("system_permission_limit") + "[username="+ loginUser.getUsername() +"]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -64,7 +64,7 @@ public class JobLogController {
|
||||
if (jobId > 0) {
|
||||
XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
|
||||
if (jobInfo == null) {
|
||||
throw new RuntimeException(I18nUtil.getString("jobinfo_field_id") + I18nUtil.getString("system_unvalid"));
|
||||
throw new IllegalArgumentException(I18nUtil.getString("jobinfo_field_id") + I18nUtil.getString("system_unvalid"));
|
||||
}
|
||||
|
||||
model.addAttribute("jobInfo", jobInfo);
|
||||
@@ -120,10 +120,9 @@ public class JobLogController {
|
||||
public String logDetailPage(int id, Model model){
|
||||
|
||||
// base check
|
||||
// ReturnT<String> logStatue = ReturnT.SUCCESS;
|
||||
XxlJobLog jobLog = xxlJobLogDao.load(id);
|
||||
if (jobLog == null) {
|
||||
throw new RuntimeException(I18nUtil.getString("joblog_logid_unvalid"));
|
||||
throw new IllegalArgumentException(I18nUtil.getString("joblog_logid_unvalid"));
|
||||
}
|
||||
|
||||
model.addAttribute("triggerCode", jobLog.getTriggerCode());
|
||||
|
||||
+3
-4
@@ -25,7 +25,7 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
|
||||
if (!(handler instanceof HandlerMethod)) {
|
||||
return super.preHandle(request, response, handler);
|
||||
}
|
||||
@@ -44,16 +44,15 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
||||
XxlJobUser loginUser = loginService.ifLogin(request, response);
|
||||
if (loginUser == null) {
|
||||
response.sendRedirect(request.getContextPath() + "/toLogin");
|
||||
//request.getRequestDispatcher("/toLogin").forward(request, response);
|
||||
return false;
|
||||
}
|
||||
if (needAdminuser && loginUser.getRole()!=1) {
|
||||
throw new RuntimeException(I18nUtil.getString("system_permission_limit"));
|
||||
throw new IllegalArgumentException(I18nUtil.getString("system_permission_limit"));
|
||||
}
|
||||
request.setAttribute(LoginService.LOGIN_IDENTITY_KEY, loginUser);
|
||||
}
|
||||
|
||||
return super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+5
-6
@@ -1,10 +1,9 @@
|
||||
package com.xxl.job.admin.controller.resolver;
|
||||
|
||||
import com.xxl.job.admin.core.exception.XxlJobException;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.admin.core.util.JacksonUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
@@ -20,16 +19,16 @@ import java.io.IOException;
|
||||
*
|
||||
* @author xuxueli 2016-1-6 19:22:18
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WebExceptionResolver implements HandlerExceptionResolver {
|
||||
private static Logger logger = LoggerFactory.getLogger(WebExceptionResolver.class);
|
||||
|
||||
@Override
|
||||
public ModelAndView resolveException(HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler, Exception ex) {
|
||||
|
||||
if (!(ex instanceof XxlJobException)) {
|
||||
logger.error("WebExceptionResolver:{}", ex);
|
||||
log.error("WebExceptionResolver:{}", ex);
|
||||
}
|
||||
|
||||
// if json
|
||||
@@ -50,7 +49,7 @@ public class WebExceptionResolver implements HandlerExceptionResolver {
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
response.getWriter().print(JacksonUtil.writeValueAsString(errorResult));
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return mv;
|
||||
} else {
|
||||
|
||||
+8
-6
@@ -27,6 +27,8 @@ import java.util.Set;
|
||||
public class EmailJobAlarm implements JobAlarm {
|
||||
private static Logger logger = LoggerFactory.getLogger(EmailJobAlarm.class);
|
||||
|
||||
private static final String TD = "</td>\n";
|
||||
|
||||
/**
|
||||
* fail alarm
|
||||
*
|
||||
@@ -94,11 +96,11 @@ public class EmailJobAlarm implements JobAlarm {
|
||||
"<table border=\"1\" cellpadding=\"3\" style=\"border-collapse:collapse; width:80%;\" >\n" +
|
||||
" <thead style=\"font-weight: bold;color: #ffffff;background-color: #ff8c00;\" >" +
|
||||
" <tr>\n" +
|
||||
" <td width=\"20%\" >"+ I18nUtil.getString("jobinfo_field_jobgroup") +"</td>\n" +
|
||||
" <td width=\"10%\" >"+ I18nUtil.getString("jobinfo_field_id") +"</td>\n" +
|
||||
" <td width=\"20%\" >"+ I18nUtil.getString("jobinfo_field_jobdesc") +"</td>\n" +
|
||||
" <td width=\"10%\" >"+ I18nUtil.getString("jobconf_monitor_alarm_title") +"</td>\n" +
|
||||
" <td width=\"40%\" >"+ I18nUtil.getString("jobconf_monitor_alarm_content") +"</td>\n" +
|
||||
" <td width=\"20%\" >"+ I18nUtil.getString("jobinfo_field_jobgroup") +TD +
|
||||
" <td width=\"10%\" >"+ I18nUtil.getString("jobinfo_field_id") +TD +
|
||||
" <td width=\"20%\" >"+ I18nUtil.getString("jobinfo_field_jobdesc") +TD +
|
||||
" <td width=\"10%\" >"+ I18nUtil.getString("jobconf_monitor_alarm_title") +TD +
|
||||
" <td width=\"40%\" >"+ I18nUtil.getString("jobconf_monitor_alarm_content") +TD +
|
||||
" </tr>\n" +
|
||||
" </thead>\n" +
|
||||
" <tbody>\n" +
|
||||
@@ -106,7 +108,7 @@ public class EmailJobAlarm implements JobAlarm {
|
||||
" <td>{0}</td>\n" +
|
||||
" <td>{1}</td>\n" +
|
||||
" <td>{2}</td>\n" +
|
||||
" <td>"+ I18nUtil.getString("jobconf_monitor_alarm_type") +"</td>\n" +
|
||||
" <td>"+ I18nUtil.getString("jobconf_monitor_alarm_type") +TD +
|
||||
" <td>{3}</td>\n" +
|
||||
" </tr>\n" +
|
||||
" </tbody>\n" +
|
||||
|
||||
-2
@@ -34,8 +34,6 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean {
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
adminConfig = this;
|
||||
|
||||
xxlJobScheduler = new XxlJobScheduler();
|
||||
xxlJobScheduler.init();
|
||||
}
|
||||
|
||||
+579
-448
File diff suppressed because it is too large
Load Diff
-32
@@ -1,32 +0,0 @@
|
||||
//package com.xxl.job.admin.core.jobbean;
|
||||
//
|
||||
//import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
//import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
|
||||
//import org.quartz.JobExecutionContext;
|
||||
//import org.quartz.JobExecutionException;
|
||||
//import org.quartz.JobKey;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
//
|
||||
///**
|
||||
// * http job bean
|
||||
// * “@DisallowConcurrentExecution” disable concurrent, thread size can not be only one, better given more
|
||||
// * @author xuxueli 2015-12-17 18:20:34
|
||||
// */
|
||||
////@DisallowConcurrentExecution
|
||||
//public class RemoteHttpJobBean extends QuartzJobBean {
|
||||
// private static Logger logger = LoggerFactory.getLogger(RemoteHttpJobBean.class);
|
||||
//
|
||||
// @Override
|
||||
// protected void executeInternal(JobExecutionContext context)
|
||||
// throws JobExecutionException {
|
||||
//
|
||||
// // load jobId
|
||||
// JobKey jobKey = context.getTrigger().getJobKey();
|
||||
// Integer jobId = Integer.valueOf(jobKey.getName());
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
-413
@@ -1,413 +0,0 @@
|
||||
//package com.xxl.job.admin.core.schedule;
|
||||
//
|
||||
//import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
//import com.xxl.job.admin.core.jobbean.RemoteHttpJobBean;
|
||||
//import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
//import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
|
||||
//import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
|
||||
//import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
//import com.xxl.job.admin.core.util.I18nUtil;
|
||||
//import com.xxl.job.core.biz.AdminBiz;
|
||||
//import com.xxl.job.core.biz.ExecutorBiz;
|
||||
//import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
||||
//import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
||||
//import com.xxl.rpc.remoting.invoker.call.CallType;
|
||||
//import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
||||
//import com.xxl.rpc.remoting.invoker.route.LoadBalance;
|
||||
//import com.xxl.rpc.remoting.net.NetEnum;
|
||||
//import com.xxl.rpc.remoting.net.impl.servlet.server.ServletServerHandler;
|
||||
//import com.xxl.rpc.remoting.provider.XxlRpcProviderFactory;
|
||||
//import com.xxl.rpc.serialize.Serializer;
|
||||
//import org.quartz.*;
|
||||
//import org.quartz.Trigger.TriggerState;
|
||||
//import org.quartz.impl.triggers.CronTriggerImpl;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.util.Assert;
|
||||
//
|
||||
//import javax.servlet.ServletException;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.IOException;
|
||||
//import java.util.Date;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
///**
|
||||
// * base quartz scheduler util
|
||||
// * @author xuxueli 2015-12-19 16:13:53
|
||||
// */
|
||||
//public final class XxlJobDynamicScheduler {
|
||||
// private static final Logger logger = LoggerFactory.getLogger(XxlJobDynamicScheduler_old.class);
|
||||
//
|
||||
// // ---------------------- param ----------------------
|
||||
//
|
||||
// // scheduler
|
||||
// private static Scheduler scheduler;
|
||||
// public void setScheduler(Scheduler scheduler) {
|
||||
// XxlJobDynamicScheduler_old.scheduler = scheduler;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- init + destroy ----------------------
|
||||
// public void start() throws Exception {
|
||||
// // valid
|
||||
// Assert.notNull(scheduler, "quartz scheduler is null");
|
||||
//
|
||||
// // init i18n
|
||||
// initI18n();
|
||||
//
|
||||
// // admin registry monitor run
|
||||
// JobRegistryMonitorHelper.getInstance().start();
|
||||
//
|
||||
// // admin monitor run
|
||||
// JobFailMonitorHelper.getInstance().start();
|
||||
//
|
||||
// // admin-server
|
||||
// initRpcProvider();
|
||||
//
|
||||
// logger.info(">>>>>>>>> init xxl-job admin success.");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void destroy() throws Exception {
|
||||
// // admin trigger pool stop
|
||||
// JobTriggerPoolHelper.toStop();
|
||||
//
|
||||
// // admin registry stop
|
||||
// JobRegistryMonitorHelper.getInstance().toStop();
|
||||
//
|
||||
// // admin monitor stop
|
||||
// JobFailMonitorHelper.getInstance().toStop();
|
||||
//
|
||||
// // admin-server
|
||||
// stopRpcProvider();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- I18n ----------------------
|
||||
//
|
||||
// private void initI18n(){
|
||||
// for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
|
||||
// item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- admin rpc provider (no server version) ----------------------
|
||||
// private static ServletServerHandler servletServerHandler;
|
||||
// private void initRpcProvider(){
|
||||
// // init
|
||||
// XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
|
||||
// xxlRpcProviderFactory.initConfig(
|
||||
// NetEnum.NETTY_HTTP,
|
||||
// Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
// null,
|
||||
// 0,
|
||||
// XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
// null,
|
||||
// null);
|
||||
//
|
||||
// // add services
|
||||
// xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());
|
||||
//
|
||||
// // servlet handler
|
||||
// servletServerHandler = new ServletServerHandler(xxlRpcProviderFactory);
|
||||
// }
|
||||
// private void stopRpcProvider() throws Exception {
|
||||
// XxlRpcInvokerFactory.getInstance().stop();
|
||||
// }
|
||||
// public static void invokeAdminService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
// servletServerHandler.handle(null, request, response);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- executor-client ----------------------
|
||||
// private static ConcurrentHashMap<String, ExecutorBiz> executorBizRepository = new ConcurrentHashMap<String, ExecutorBiz>();
|
||||
// public static ExecutorBiz getExecutorBiz(String address) throws Exception {
|
||||
// // valid
|
||||
// if (address==null || address.trim().length()==0) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // load-cache
|
||||
// address = address.trim();
|
||||
// ExecutorBiz executorBiz = executorBizRepository.get(address);
|
||||
// if (executorBiz != null) {
|
||||
// return executorBiz;
|
||||
// }
|
||||
//
|
||||
// // set-cache
|
||||
// executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
|
||||
// NetEnum.NETTY_HTTP,
|
||||
// Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
// CallType.SYNC,
|
||||
// LoadBalance.ROUND,
|
||||
// ExecutorBiz.class,
|
||||
// null,
|
||||
// 5000,
|
||||
// address,
|
||||
// XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
// null,
|
||||
// null).getObject();
|
||||
//
|
||||
// executorBizRepository.put(address, executorBiz);
|
||||
// return executorBiz;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- schedule util ----------------------
|
||||
//
|
||||
// /**
|
||||
// * fill job info
|
||||
// *
|
||||
// * @param jobInfo
|
||||
// */
|
||||
// public static void fillJobInfo(XxlJobInfo jobInfo) {
|
||||
//
|
||||
// String name = String.valueOf(jobInfo.getId());
|
||||
//
|
||||
// // trigger key
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(name);
|
||||
// try {
|
||||
//
|
||||
// // trigger cron
|
||||
// Trigger trigger = scheduler.getTrigger(triggerKey);
|
||||
// if (trigger!=null && trigger instanceof CronTriggerImpl) {
|
||||
// String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
|
||||
// jobInfo.setJobCron(cronExpression);
|
||||
// }
|
||||
//
|
||||
// // trigger state
|
||||
// TriggerState triggerState = scheduler.getTriggerState(triggerKey);
|
||||
// if (triggerState!=null) {
|
||||
// jobInfo.setJobStatus(triggerState.name());
|
||||
// }
|
||||
//
|
||||
// //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
|
||||
// //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
// //String jobClass = jobDetail.getJobClass().getName();
|
||||
//
|
||||
// } catch (SchedulerException e) {
|
||||
// logger.error(e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * add trigger + job
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @param cronExpression
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// public static boolean addJob(String jobName, String cronExpression) throws SchedulerException {
|
||||
// // 1、job key
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
//
|
||||
// // 2、valid
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// return true; // PASS
|
||||
// }
|
||||
//
|
||||
// // 3、corn trigger
|
||||
// CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing(); // withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度
|
||||
// CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
|
||||
//
|
||||
// // 4、job detail
|
||||
// Class<? extends Job> jobClass_ = RemoteHttpJobBean.class; // Class.forName(jobInfo.getJobClass());
|
||||
// JobDetail jobDetail = JobBuilder.newJob(jobClass_).withIdentity(jobKey).build();
|
||||
//
|
||||
// /*if (jobInfo.getJobData()!=null) {
|
||||
// JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
||||
// jobDataMap.putAll(JacksonUtil.readValue(jobInfo.getJobData(), Map.class));
|
||||
// // JobExecutionContext context.getMergedJobDataMap().get("mailGuid");
|
||||
// }*/
|
||||
//
|
||||
// // 5、schedule job
|
||||
// Date date = scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> addJob success(quartz), jobDetail:{}, cronTrigger:{}, date:{}", jobDetail, cronTrigger, date);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * remove trigger + job
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// public static boolean removeJob(String jobName) throws SchedulerException {
|
||||
//
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
// scheduler.deleteJob(jobKey);
|
||||
//
|
||||
// /*TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.unscheduleJob(triggerKey); // trigger + job
|
||||
// }*/
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> removeJob success(quartz), jobKey:{}", jobKey);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * updateJobCron
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @param cronExpression
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// public static boolean updateJobCron(String jobName, String cronExpression) throws SchedulerException {
|
||||
//
|
||||
// // 1、job key
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// // 2、valid
|
||||
// if (!scheduler.checkExists(triggerKey)) {
|
||||
// return true; // PASS
|
||||
// }
|
||||
//
|
||||
// CronTrigger oldTrigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||
//
|
||||
// // 3、avoid repeat cron
|
||||
// String oldCron = oldTrigger.getCronExpression();
|
||||
// if (oldCron.equals(cronExpression)){
|
||||
// return true; // PASS
|
||||
// }
|
||||
//
|
||||
// // 4、new cron trigger
|
||||
// CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
|
||||
// oldTrigger = oldTrigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
|
||||
//
|
||||
// // 5、rescheduleJob
|
||||
// scheduler.rescheduleJob(triggerKey, oldTrigger);
|
||||
//
|
||||
// /*
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
//
|
||||
// // old job detail
|
||||
// JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
//
|
||||
// // new trigger
|
||||
// HashSet<Trigger> triggerSet = new HashSet<Trigger>();
|
||||
// triggerSet.add(cronTrigger);
|
||||
// // cover trigger of job detail
|
||||
// scheduler.scheduleJob(jobDetail, triggerSet, true);*/
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> resumeJob success, JobName:{}", jobName);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * pause
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// /*public static boolean pauseJob(String jobName) throws SchedulerException {
|
||||
//
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// boolean result = false;
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.pauseTrigger(triggerKey);
|
||||
// result = true;
|
||||
// }
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> pauseJob {}, triggerKey:{}", (result?"success":"fail"),triggerKey);
|
||||
// return result;
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * resume
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// /*public static boolean resumeJob(String jobName) throws SchedulerException {
|
||||
//
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// boolean result = false;
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.resumeTrigger(triggerKey);
|
||||
// result = true;
|
||||
// }
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> resumeJob {}, triggerKey:{}", (result?"success":"fail"), triggerKey);
|
||||
// return result;
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * run
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// /*public static boolean triggerJob(String jobName) throws SchedulerException {
|
||||
// // TriggerKey : name + group
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// boolean result = false;
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.triggerJob(jobKey);
|
||||
// result = true;
|
||||
// logger.info(">>>>>>>>>>> runJob success, jobKey:{}", jobKey);
|
||||
// } else {
|
||||
// logger.info(">>>>>>>>>>> runJob fail, jobKey:{}", jobKey);
|
||||
// }
|
||||
// return result;
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * finaAllJobList
|
||||
// *
|
||||
// * @return
|
||||
// *//*
|
||||
// @Deprecated
|
||||
// public static List<Map<String, Object>> finaAllJobList(){
|
||||
// List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
|
||||
//
|
||||
// try {
|
||||
// if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) {
|
||||
// return null;
|
||||
// }
|
||||
// String groupName = scheduler.getJobGroupNames().get(0);
|
||||
// Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
|
||||
// if (jobKeys!=null && jobKeys.size()>0) {
|
||||
// for (JobKey jobKey : jobKeys) {
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
|
||||
// Trigger trigger = scheduler.getTrigger(triggerKey);
|
||||
// JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
// TriggerState triggerState = scheduler.getTriggerState(triggerKey);
|
||||
// Map<String, Object> jobMap = new HashMap<String, Object>();
|
||||
// jobMap.put("TriggerKey", triggerKey);
|
||||
// jobMap.put("Trigger", trigger);
|
||||
// jobMap.put("JobDetail", jobDetail);
|
||||
// jobMap.put("TriggerState", triggerState);
|
||||
// jobList.add(jobMap);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } catch (SchedulerException e) {
|
||||
// logger.error(e.getMessage(), e);
|
||||
// return null;
|
||||
// }
|
||||
// return jobList;
|
||||
// }*/
|
||||
//
|
||||
//}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
//package com.xxl.job.admin.core.quartz;
|
||||
//
|
||||
//import org.quartz.SchedulerConfigException;
|
||||
//import org.quartz.spi.ThreadPool;
|
||||
//
|
||||
///**
|
||||
// * single thread pool, for async trigger
|
||||
// *
|
||||
// * @author xuxueli 2019-03-06
|
||||
// */
|
||||
//public class XxlJobThreadPool implements ThreadPool {
|
||||
//
|
||||
// @Override
|
||||
// public boolean runInThread(Runnable runnable) {
|
||||
//
|
||||
// // async run
|
||||
// runnable.run();
|
||||
// return true;
|
||||
//
|
||||
// //return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int blockForAvailableThreads() {
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void initialize() throws SchedulerConfigException {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void shutdown(boolean waitForJobsToComplete) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getPoolSize() {
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setInstanceId(String schedInstId) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setInstanceName(String schedName) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // support
|
||||
// public void setThreadCount(int count) {
|
||||
// //
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class ExecutorRouteConsistentHash extends ExecutorRouter {
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("MD5 not supported", e);
|
||||
throw new IllegalArgumentException("MD5 not supported", e);
|
||||
}
|
||||
md5.reset();
|
||||
byte[] keyBytes = null;
|
||||
|
||||
+16
-9
@@ -3,7 +3,10 @@ package com.xxl.job.admin.core.route.strategy;
|
||||
import com.xxl.job.admin.core.route.ExecutorRouter;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.biz.model.TriggerParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
@@ -15,11 +18,21 @@ import java.util.concurrent.ConcurrentMap;
|
||||
*
|
||||
* Created by xuxueli on 17/3/10.
|
||||
*/
|
||||
@Slf4j
|
||||
public class ExecutorRouteLFU extends ExecutorRouter {
|
||||
|
||||
private static ConcurrentMap<Integer, HashMap<String, Integer>> jobLfuMap = new ConcurrentHashMap<>();
|
||||
private long cacheValidTime = 0;
|
||||
|
||||
private static Random rand;
|
||||
static {
|
||||
try {
|
||||
rand = SecureRandom.getInstanceStrong();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.info("Exception:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String route(int jobId, List<String> addressList) {
|
||||
|
||||
// cache clear
|
||||
@@ -38,7 +51,8 @@ public class ExecutorRouteLFU extends ExecutorRouter {
|
||||
// put new
|
||||
for (String address: addressList) {
|
||||
if (!lfuItemMap.containsKey(address) || lfuItemMap.get(address) >1000000 ) {
|
||||
lfuItemMap.put(address, new Random().nextInt(addressList.size())); // 初始化时主动Random一次,缓解首次压力
|
||||
// 初始化时主动Random一次,缓解首次压力
|
||||
lfuItemMap.put(address, rand.nextInt(addressList.size()));
|
||||
}
|
||||
}
|
||||
// remove old
|
||||
@@ -56,16 +70,9 @@ public class ExecutorRouteLFU extends ExecutorRouter {
|
||||
|
||||
// load least userd count address
|
||||
List<Map.Entry<String, Integer>> lfuItemList = new ArrayList<>(lfuItemMap.entrySet());
|
||||
/* Collections.sort(lfuItemList, new Comparator<Map.Entry<String, Integer>>() {
|
||||
@Override
|
||||
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
|
||||
return o1.getValue().compareTo(o2.getValue());
|
||||
}
|
||||
});*/
|
||||
Collections.sort(lfuItemList, (o1,o2)-> o1.getValue().compareTo(o2.getValue()));
|
||||
Collections.sort(lfuItemList, Comparator.comparing(Map.Entry::getValue));
|
||||
|
||||
Map.Entry<String, Integer> addressItem = lfuItemList.get(0);
|
||||
// String minAddress = addressItem.getKey();
|
||||
addressItem.setValue(addressItem.getValue() + 1);
|
||||
|
||||
return addressItem.getKey();
|
||||
|
||||
-3
@@ -44,9 +44,6 @@ public class ExecutorRouteLRU extends ExecutorRouter {
|
||||
|
||||
// put new
|
||||
for (String address: addressList) {
|
||||
/*if (!lruItem.containsKey(address)) {
|
||||
lruItem.put(address, address);
|
||||
}*/
|
||||
lruItem.computeIfAbsent(address,key->address);
|
||||
}
|
||||
// remove old
|
||||
|
||||
+15
-1
@@ -3,7 +3,10 @@ package com.xxl.job.admin.core.route.strategy;
|
||||
import com.xxl.job.admin.core.route.ExecutorRouter;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.biz.model.TriggerParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -12,10 +15,21 @@ import java.util.concurrent.ConcurrentMap;
|
||||
/**
|
||||
* Created by xuxueli on 17/3/10.
|
||||
*/
|
||||
@Slf4j
|
||||
public class ExecutorRouteRound extends ExecutorRouter {
|
||||
|
||||
private static ConcurrentMap<Integer, Integer> routeCountEachJob = new ConcurrentHashMap<>();
|
||||
private static long cacheValidTime = 0;
|
||||
|
||||
private static Random rand;
|
||||
static {
|
||||
try {
|
||||
rand = SecureRandom.getInstanceStrong();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.info("Exception:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static int count(int jobId) {
|
||||
// cache clear
|
||||
if (System.currentTimeMillis() > cacheValidTime) {
|
||||
@@ -25,7 +39,7 @@ public class ExecutorRouteRound extends ExecutorRouter {
|
||||
|
||||
// count++
|
||||
Integer count = routeCountEachJob.get(jobId);
|
||||
count = (count==null || count>1000000)?(new Random().nextInt(100)):++count; // 初始化时主动Random一次,缓解首次压力
|
||||
count = (count==null || count>1000000)?(rand.nextInt(100)):++count; // 初始化时主动Random一次,缓解首次压力
|
||||
routeCountEachJob.put(jobId, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
+86
-76
@@ -5,6 +5,7 @@ import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import com.xxl.job.admin.core.model.XxlJobLog;
|
||||
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -16,93 +17,102 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @author xuxueli 2015-9-1 18:05:56
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobFailMonitorHelper {
|
||||
private static Logger logger = LoggerFactory.getLogger(JobFailMonitorHelper.class);
|
||||
|
||||
private static JobFailMonitorHelper instance = new JobFailMonitorHelper();
|
||||
public static JobFailMonitorHelper getInstance(){
|
||||
return instance;
|
||||
}
|
||||
private static JobFailMonitorHelper instance = new JobFailMonitorHelper();
|
||||
|
||||
// ---------------------- monitor ----------------------
|
||||
public static JobFailMonitorHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Thread monitorThread;
|
||||
private volatile boolean toStop = false;
|
||||
public void start(){
|
||||
monitorThread = new Thread(()-> {
|
||||
// ---------------------- monitor ----------------------
|
||||
|
||||
private Thread monitorThread;
|
||||
private volatile boolean toStop = false;
|
||||
|
||||
public void start() {
|
||||
monitorThread = new Thread(() -> {
|
||||
// monitor
|
||||
getWhile();
|
||||
|
||||
log.info(">>>>>>>>>>> xxl-job, job fail monitor thread stop");
|
||||
|
||||
|
||||
// monitor
|
||||
while (!toStop) {
|
||||
try {
|
||||
|
||||
List<Long> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(1000);
|
||||
if (failLogIds!=null && !failLogIds.isEmpty()) {
|
||||
for (long failLogId: failLogIds) {
|
||||
|
||||
// lock log
|
||||
int lockRet = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, 0, -1);
|
||||
if (lockRet < 1) {
|
||||
continue;
|
||||
}
|
||||
XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().load(failLogId);
|
||||
XxlJobInfo info = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(log.getJobId());
|
||||
|
||||
// 1、fail retry monitor
|
||||
if (log.getExecutorFailRetryCount() > 0) {
|
||||
JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount()-1), log.getExecutorShardingParam(), log.getExecutorParam(), null);
|
||||
String retryMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_type_retry") +"<<<<<<<<<<< </span><br>";
|
||||
log.setTriggerMsg(log.getTriggerMsg() + retryMsg);
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(log);
|
||||
}
|
||||
|
||||
// 2、fail alarm monitor
|
||||
int newAlarmStatus = 0; // 告警状态:0-默认、-1=锁定状态、1-无需告警、2-告警成功、3-告警失败
|
||||
if (info!=null && info.getAlarmEmail()!=null && info.getAlarmEmail().trim().length()>0) {
|
||||
boolean alarmResult = XxlJobAdminConfig.getAdminConfig().getJobAlarmer().alarm(info, log);
|
||||
newAlarmStatus = alarmResult?2:3;
|
||||
} else {
|
||||
newAlarmStatus = 1;
|
||||
}
|
||||
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, -1, newAlarmStatus);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
monitorThread.setDaemon(true);
|
||||
monitorThread.setName("xxl-job, admin JobFailMonitorHelper");
|
||||
monitorThread.start();
|
||||
}
|
||||
|
||||
private void getWhile() {
|
||||
while (!toStop) {
|
||||
try {
|
||||
List<Long> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(1000);
|
||||
if (failLogIds != null && !failLogIds.isEmpty()) {
|
||||
getFor(failLogIds);
|
||||
}
|
||||
|
||||
logger.info(">>>>>>>>>>> xxl-job, job fail monitor thread stop");
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
});
|
||||
monitorThread.setDaemon(true);
|
||||
monitorThread.setName("xxl-job, admin JobFailMonitorHelper");
|
||||
monitorThread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void toStop(){
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
monitorThread.interrupt();
|
||||
try {
|
||||
monitorThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
private void getFor(List<Long> failLogIds) {
|
||||
for (long failLogId : failLogIds) {
|
||||
|
||||
// lock log
|
||||
int lockRet = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, 0, -1);
|
||||
if (lockRet < 1) {
|
||||
continue;
|
||||
}
|
||||
XxlJobLog log = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().load(failLogId);
|
||||
XxlJobInfo info = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().loadById(log.getJobId());
|
||||
|
||||
// 1、fail retry monitor
|
||||
if (log.getExecutorFailRetryCount() > 0) {
|
||||
JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount() - 1), log.getExecutorShardingParam(), log.getExecutorParam(), null);
|
||||
String retryMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>" + I18nUtil.getString("jobconf_trigger_type_retry") + "<<<<<<<<<<< </span><br>";
|
||||
log.setTriggerMsg(log.getTriggerMsg() + retryMsg);
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(log);
|
||||
}
|
||||
|
||||
// 2、fail alarm monitor
|
||||
int newAlarmStatus = 0; // 告警状态:0-默认、-1=锁定状态、1-无需告警、2-告警成功、3-告警失败
|
||||
if (info != null && info.getAlarmEmail() != null && info.getAlarmEmail().trim().length() > 0) {
|
||||
boolean alarmResult = XxlJobAdminConfig.getAdminConfig().getJobAlarmer().alarm(info, log);
|
||||
newAlarmStatus = alarmResult ? 2 : 3;
|
||||
} else {
|
||||
newAlarmStatus = 1;
|
||||
}
|
||||
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, -1, newAlarmStatus);
|
||||
}
|
||||
}
|
||||
|
||||
public void toStop() {
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
monitorThread.interrupt();
|
||||
try {
|
||||
monitorThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+114
-104
@@ -2,8 +2,7 @@ package com.xxl.job.admin.core.thread;
|
||||
|
||||
import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import com.xxl.job.admin.core.model.XxlJobLogReport;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -16,131 +15,142 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @author xuxueli 2019-11-22
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobLogReportHelper {
|
||||
private static Logger logger = LoggerFactory.getLogger(JobLogReportHelper.class);
|
||||
|
||||
private static JobLogReportHelper instance = new JobLogReportHelper();
|
||||
public static JobLogReportHelper getInstance(){
|
||||
|
||||
public static JobLogReportHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private Thread logrThread;
|
||||
private volatile boolean toStop = false;
|
||||
public void start(){
|
||||
logrThread = new Thread(()-> {
|
||||
|
||||
// last clean log time
|
||||
long lastCleanLogTime = 0;
|
||||
public void start() {
|
||||
logrThread = new Thread(() -> {
|
||||
// last clean log time
|
||||
long lastCleanLogTime = 0;
|
||||
getWhile(lastCleanLogTime);
|
||||
|
||||
|
||||
while (!toStop) {
|
||||
|
||||
// 1、log-report refresh: refresh log report in 3 days
|
||||
try {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
// today
|
||||
Calendar itemDay = Calendar.getInstance();
|
||||
itemDay.add(Calendar.DAY_OF_MONTH, -i);
|
||||
itemDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||
itemDay.set(Calendar.MINUTE, 0);
|
||||
itemDay.set(Calendar.SECOND, 0);
|
||||
itemDay.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Date todayFrom = itemDay.getTime();
|
||||
|
||||
itemDay.set(Calendar.HOUR_OF_DAY, 23);
|
||||
itemDay.set(Calendar.MINUTE, 59);
|
||||
itemDay.set(Calendar.SECOND, 59);
|
||||
itemDay.set(Calendar.MILLISECOND, 999);
|
||||
|
||||
Date todayTo = itemDay.getTime();
|
||||
|
||||
// refresh log-report every minute
|
||||
XxlJobLogReport xxlJobLogReport = new XxlJobLogReport();
|
||||
xxlJobLogReport.setTriggerDay(todayFrom);
|
||||
xxlJobLogReport.setRunningCount(0);
|
||||
xxlJobLogReport.setSucCount(0);
|
||||
xxlJobLogReport.setFailCount(0);
|
||||
|
||||
Map<String, Object> triggerCountMap = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLogReport(todayFrom, todayTo);
|
||||
if (triggerCountMap!=null && triggerCountMap.size()>0) {
|
||||
int triggerDayCount = triggerCountMap.containsKey("triggerDayCount")?Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCount"))):0;
|
||||
int triggerDayCountRunning = triggerCountMap.containsKey("triggerDayCountRunning")?Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCountRunning"))):0;
|
||||
int triggerDayCountSuc = triggerCountMap.containsKey("triggerDayCountSuc")?Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCountSuc"))):0;
|
||||
int triggerDayCountFail = triggerDayCount - triggerDayCountRunning - triggerDayCountSuc;
|
||||
|
||||
xxlJobLogReport.setRunningCount(triggerDayCountRunning);
|
||||
xxlJobLogReport.setSucCount(triggerDayCountSuc);
|
||||
xxlJobLogReport.setFailCount(triggerDayCountFail);
|
||||
}
|
||||
|
||||
// do refresh
|
||||
int ret = XxlJobAdminConfig.getAdminConfig().getXxlJobLogReportDao().update(xxlJobLogReport);
|
||||
if (ret < 1) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogReportDao().save(xxlJobLogReport);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, job log report thread error:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 2、log-clean: switch open & once each day
|
||||
if (XxlJobAdminConfig.getAdminConfig().getLogretentiondays()>0
|
||||
&& System.currentTimeMillis() - lastCleanLogTime > 24*60*60*1000) {
|
||||
|
||||
// expire-time
|
||||
Calendar expiredDay = Calendar.getInstance();
|
||||
expiredDay.add(Calendar.DAY_OF_MONTH, -1 * XxlJobAdminConfig.getAdminConfig().getLogretentiondays());
|
||||
expiredDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||
expiredDay.set(Calendar.MINUTE, 0);
|
||||
expiredDay.set(Calendar.SECOND, 0);
|
||||
expiredDay.set(Calendar.MILLISECOND, 0);
|
||||
Date clearBeforeTime = expiredDay.getTime();
|
||||
|
||||
// clean expired log
|
||||
List<Long> logIds = null;
|
||||
do {
|
||||
logIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findClearLogIds(0, 0, clearBeforeTime, 0, 1000);
|
||||
if (logIds!=null && !logIds.isEmpty()) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().clearLog(logIds);
|
||||
}
|
||||
} while (logIds!=null && !logIds.isEmpty());
|
||||
|
||||
// update clean time
|
||||
lastCleanLogTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.MINUTES.sleep(1);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logger.info(">>>>>>>>>>> xxl-job, job log report thread stop");
|
||||
log.info(">>>>>>>>>>> xxl-job, job log report thread stop");
|
||||
});
|
||||
logrThread.setDaemon(true);
|
||||
logrThread.setName("xxl-job, admin JobLogReportHelper");
|
||||
logrThread.start();
|
||||
}
|
||||
|
||||
public void toStop(){
|
||||
private void getWhile(long lastCleanLogTime) {
|
||||
while (!toStop) {
|
||||
// 1、log-report refresh: refresh log report in 3 days
|
||||
try {
|
||||
getFor();
|
||||
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, job log report thread error:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 2、log-clean: switch open & once each day
|
||||
lastCleanLogTime = getLastCleanLogTime(lastCleanLogTime);
|
||||
|
||||
try {
|
||||
TimeUnit.MINUTES.sleep(1);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private long getLastCleanLogTime(long lastCleanLogTime) {
|
||||
if (XxlJobAdminConfig.getAdminConfig().getLogretentiondays() > 0
|
||||
&& System.currentTimeMillis() - lastCleanLogTime > 24 * 60 * 60 * 1000) {
|
||||
|
||||
// expire-time
|
||||
Calendar expiredDay = Calendar.getInstance();
|
||||
expiredDay.add(Calendar.DAY_OF_MONTH, -1 * XxlJobAdminConfig.getAdminConfig().getLogretentiondays());
|
||||
expiredDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||
expiredDay.set(Calendar.MINUTE, 0);
|
||||
expiredDay.set(Calendar.SECOND, 0);
|
||||
expiredDay.set(Calendar.MILLISECOND, 0);
|
||||
Date clearBeforeTime = expiredDay.getTime();
|
||||
|
||||
// clean expired log
|
||||
List<Long> logIds = null;
|
||||
do {
|
||||
logIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findClearLogIds(0, 0, clearBeforeTime, 0, 1000);
|
||||
if (logIds != null && !logIds.isEmpty()) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().clearLog(logIds);
|
||||
}
|
||||
} while (logIds != null && !logIds.isEmpty());
|
||||
|
||||
// update clean time
|
||||
lastCleanLogTime = System.currentTimeMillis();
|
||||
}
|
||||
return lastCleanLogTime;
|
||||
}
|
||||
|
||||
private void getFor() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// today
|
||||
Calendar itemDay = Calendar.getInstance();
|
||||
itemDay.add(Calendar.DAY_OF_MONTH, -i);
|
||||
itemDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||
itemDay.set(Calendar.MINUTE, 0);
|
||||
itemDay.set(Calendar.SECOND, 0);
|
||||
itemDay.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Date todayFrom = itemDay.getTime();
|
||||
|
||||
itemDay.set(Calendar.HOUR_OF_DAY, 23);
|
||||
itemDay.set(Calendar.MINUTE, 59);
|
||||
itemDay.set(Calendar.SECOND, 59);
|
||||
itemDay.set(Calendar.MILLISECOND, 999);
|
||||
|
||||
Date todayTo = itemDay.getTime();
|
||||
|
||||
// refresh log-report every minute
|
||||
XxlJobLogReport xxlJobLogReport = new XxlJobLogReport();
|
||||
xxlJobLogReport.setTriggerDay(todayFrom);
|
||||
xxlJobLogReport.setRunningCount(0);
|
||||
xxlJobLogReport.setSucCount(0);
|
||||
xxlJobLogReport.setFailCount(0);
|
||||
|
||||
Map<String, Object> triggerCountMap = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLogReport(todayFrom, todayTo);
|
||||
if (triggerCountMap != null && triggerCountMap.size() > 0) {
|
||||
int triggerDayCount = triggerCountMap.containsKey("triggerDayCount") ? Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCount"))) : 0;
|
||||
int triggerDayCountRunning = triggerCountMap.containsKey("triggerDayCountRunning") ? Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCountRunning"))) : 0;
|
||||
int triggerDayCountSuc = triggerCountMap.containsKey("triggerDayCountSuc") ? Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCountSuc"))) : 0;
|
||||
int triggerDayCountFail = triggerDayCount - triggerDayCountRunning - triggerDayCountSuc;
|
||||
|
||||
xxlJobLogReport.setRunningCount(triggerDayCountRunning);
|
||||
xxlJobLogReport.setSucCount(triggerDayCountSuc);
|
||||
xxlJobLogReport.setFailCount(triggerDayCountFail);
|
||||
}
|
||||
|
||||
// do refresh
|
||||
int ret = XxlJobAdminConfig.getAdminConfig().getXxlJobLogReportDao().update(xxlJobLogReport);
|
||||
if (ret < 1) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogReportDao().save(xxlJobLogReport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void toStop() {
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
logrThread.interrupt();
|
||||
try {
|
||||
logrThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+67
-57
@@ -5,8 +5,7 @@ import com.xxl.job.admin.core.model.XxlJobLog;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.util.DateUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -17,70 +16,81 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @author xuxueli 2015-9-1 18:05:56
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobLosedMonitorHelper {
|
||||
private static Logger logger = LoggerFactory.getLogger(JobLosedMonitorHelper.class);
|
||||
|
||||
private static JobLosedMonitorHelper instance = new JobLosedMonitorHelper();
|
||||
public static JobLosedMonitorHelper getInstance(){
|
||||
return instance;
|
||||
}
|
||||
private static JobLosedMonitorHelper instance = new JobLosedMonitorHelper();
|
||||
|
||||
// ---------------------- monitor ----------------------
|
||||
public static JobLosedMonitorHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Thread monitorThread;
|
||||
private volatile boolean toStop = false;
|
||||
public void start(){
|
||||
monitorThread = new Thread(()->{
|
||||
// monitor
|
||||
while (!toStop) {
|
||||
try {
|
||||
// 任务结果丢失处理:调度记录停留在 "运行中" 状态超过10min,且对应执行器心跳注册失败不在线,则将本地调度主动标记失败;
|
||||
Date losedTime = DateUtil.addMinutes(new Date(), -10);
|
||||
List<Long> losedJobIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLostJobIds(losedTime);
|
||||
// ---------------------- monitor ----------------------
|
||||
|
||||
if (losedJobIds!=null && !losedJobIds.isEmpty()) {
|
||||
for (Long logId: losedJobIds) {
|
||||
private Thread monitorThread;
|
||||
private volatile boolean toStop = false;
|
||||
|
||||
XxlJobLog jobLog = new XxlJobLog();
|
||||
jobLog.setId(logId);
|
||||
public void start() {
|
||||
monitorThread = new Thread(() -> {
|
||||
// monitor
|
||||
getWhile();
|
||||
log.info(">>>>>>>>>>> xxl-job, JobLosedMonitorHelper stop");
|
||||
});
|
||||
monitorThread.setDaemon(true);
|
||||
monitorThread.setName("xxl-job, admin JobLosedMonitorHelper");
|
||||
monitorThread.start();
|
||||
}
|
||||
|
||||
jobLog.setHandleTime(new Date());
|
||||
jobLog.setHandleCode(ReturnT.FAIL_CODE);
|
||||
jobLog.setHandleMsg( I18nUtil.getString("joblog_lost_fail") );
|
||||
private void getWhile() {
|
||||
while (!toStop) {
|
||||
try {
|
||||
// 任务结果丢失处理:调度记录停留在 "运行中" 状态超过10min,且对应执行器心跳注册失败不在线,则将本地调度主动标记失败;
|
||||
Date losedTime = DateUtil.addMinutes(new Date(), -10);
|
||||
List<Long> losedJobIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLostJobIds(losedTime);
|
||||
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateHandleInfo(jobLog);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(60);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (losedJobIds != null && !losedJobIds.isEmpty()) {
|
||||
getFor(losedJobIds);
|
||||
}
|
||||
logger.info(">>>>>>>>>>> xxl-job, JobLosedMonitorHelper stop");
|
||||
});
|
||||
monitorThread.setDaemon(true);
|
||||
monitorThread.setName("xxl-job, admin JobLosedMonitorHelper");
|
||||
monitorThread.start();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(60);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void toStop(){
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
monitorThread.interrupt();
|
||||
try {
|
||||
monitorThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
private void getFor(List<Long> losedJobIds) {
|
||||
for (Long logId : losedJobIds) {
|
||||
|
||||
XxlJobLog jobLog = new XxlJobLog();
|
||||
jobLog.setId(logId);
|
||||
|
||||
jobLog.setHandleTime(new Date());
|
||||
jobLog.setHandleCode(ReturnT.FAIL_CODE);
|
||||
jobLog.setHandleMsg(I18nUtil.getString("joblog_lost_fail"));
|
||||
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateHandleInfo(jobLog);
|
||||
}
|
||||
}
|
||||
|
||||
public void toStop() {
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
monitorThread.interrupt();
|
||||
try {
|
||||
monitorThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+103
-84
@@ -4,105 +4,124 @@ import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import com.xxl.job.admin.core.model.XxlJobGroup;
|
||||
import com.xxl.job.admin.core.model.XxlJobRegistry;
|
||||
import com.xxl.job.core.enums.RegistryConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* job registry instance
|
||||
*
|
||||
* @author xuxueli 2016-10-02 19:10:24
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobRegistryMonitorHelper {
|
||||
private static Logger logger = LoggerFactory.getLogger(JobRegistryMonitorHelper.class);
|
||||
|
||||
private static JobRegistryMonitorHelper instance = new JobRegistryMonitorHelper();
|
||||
public static JobRegistryMonitorHelper getInstance(){
|
||||
return instance;
|
||||
}
|
||||
private static JobRegistryMonitorHelper instance = new JobRegistryMonitorHelper();
|
||||
|
||||
private Thread registryThread;
|
||||
private volatile boolean toStop = false;
|
||||
public void start(){
|
||||
registryThread = new Thread(()-> {
|
||||
while (!toStop) {
|
||||
try {
|
||||
// auto registry group
|
||||
List<XxlJobGroup> groupList = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().findByAddressType(0);
|
||||
if (groupList!=null && !groupList.isEmpty()) {
|
||||
public static JobRegistryMonitorHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
// remove dead address (admin/executor)
|
||||
List<Integer> ids = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findDead(RegistryConfig.DEAD_TIMEOUT, new Date());
|
||||
if (ids!=null && !ids.isEmpty()) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().removeDead(ids);
|
||||
}
|
||||
private Thread registryThread;
|
||||
private volatile boolean toStop = false;
|
||||
|
||||
// fresh online address (admin/executor)
|
||||
HashMap<String, List<String>> appAddressMap = new HashMap<>();
|
||||
List<XxlJobRegistry> list = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
|
||||
if (list != null) {
|
||||
for (XxlJobRegistry item: list) {
|
||||
if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
|
||||
String appname = item.getRegistryKey();
|
||||
List<String> registryList = appAddressMap.get(appname);
|
||||
if (registryList == null) {
|
||||
registryList = new ArrayList<>();
|
||||
}
|
||||
public void start() {
|
||||
registryThread = new Thread(() -> {
|
||||
getWhile();
|
||||
log.info(">>>>>>>>>>> xxl-job, job registry monitor thread stop");
|
||||
});
|
||||
registryThread.setDaemon(true);
|
||||
registryThread.setName("xxl-job, admin JobRegistryMonitorHelper");
|
||||
registryThread.start();
|
||||
}
|
||||
|
||||
if (!registryList.contains(item.getRegistryValue())) {
|
||||
registryList.add(item.getRegistryValue());
|
||||
}
|
||||
appAddressMap.put(appname, registryList);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void getWhile() {
|
||||
while (!toStop) {
|
||||
try {
|
||||
// auto registry group
|
||||
List<XxlJobGroup> groupList = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().findByAddressType(0);
|
||||
getGroupList(groupList);
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
if (!toStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fresh group address
|
||||
for (XxlJobGroup group: groupList) {
|
||||
List<String> registryList = appAddressMap.get(group.getAppname());
|
||||
StringBuilder addressListStr = null;
|
||||
if (registryList!=null && !registryList.isEmpty()) {
|
||||
Collections.sort(registryList);
|
||||
addressListStr = new StringBuilder();
|
||||
for (String item:registryList) {
|
||||
addressListStr.append(item).append(",");
|
||||
}
|
||||
addressListStr = new StringBuilder(addressListStr.substring(0, addressListStr.length() - 1));
|
||||
}
|
||||
group.setAddressList(addressListStr.toString());
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().update(group);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!toStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
if (!toStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info(">>>>>>>>>>> xxl-job, job registry monitor thread stop");
|
||||
});
|
||||
registryThread.setDaemon(true);
|
||||
registryThread.setName("xxl-job, admin JobRegistryMonitorHelper");
|
||||
registryThread.start();
|
||||
}
|
||||
private void getGroupList(List<XxlJobGroup> groupList) {
|
||||
if (groupList != null && !groupList.isEmpty()) {
|
||||
|
||||
public void toStop(){
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
registryThread.interrupt();
|
||||
try {
|
||||
registryThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
// remove dead address (admin/executor)
|
||||
List<Integer> ids = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findDead(RegistryConfig.DEAD_TIMEOUT, new Date());
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().removeDead(ids);
|
||||
}
|
||||
|
||||
// fresh online address (admin/executor)
|
||||
HashMap<String, List<String>> appAddressMap = new HashMap<>();
|
||||
List<XxlJobRegistry> list = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
|
||||
if (list != null) {
|
||||
getFor(appAddressMap, list);
|
||||
}
|
||||
|
||||
// fresh group address
|
||||
getFreshGroupAddress(groupList, appAddressMap);
|
||||
}
|
||||
}
|
||||
|
||||
private void getFreshGroupAddress(List<XxlJobGroup> groupList, HashMap<String, List<String>> appAddressMap) {
|
||||
for (XxlJobGroup group : groupList) {
|
||||
List<String> registryList = appAddressMap.get(group.getAppname());
|
||||
StringBuilder addressListStr = new StringBuilder();
|
||||
if (registryList != null && !registryList.isEmpty()) {
|
||||
Collections.sort(registryList);
|
||||
for (String item : registryList) {
|
||||
addressListStr.append(item).append(",");
|
||||
}
|
||||
addressListStr = new StringBuilder(addressListStr.substring(0, addressListStr.length() - 1));
|
||||
}
|
||||
group.setAddressList(addressListStr.toString());
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().update(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void getFor(HashMap<String, List<String>> appAddressMap, List<XxlJobRegistry> list) {
|
||||
for (XxlJobRegistry item : list) {
|
||||
if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
|
||||
String appname = item.getRegistryKey();
|
||||
List<String> registryList = appAddressMap.get(appname);
|
||||
if (registryList == null) {
|
||||
registryList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!registryList.contains(item.getRegistryValue())) {
|
||||
registryList.add(item.getRegistryValue());
|
||||
}
|
||||
appAddressMap.put(appname, registryList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void toStop() {
|
||||
toStop = true;
|
||||
// interrupt and wait
|
||||
registryThread.interrupt();
|
||||
try {
|
||||
registryThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+270
-244
@@ -4,8 +4,7 @@ import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import com.xxl.job.admin.core.cron.CronExpression;
|
||||
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -18,11 +17,12 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* @author xuxueli 2019-05-21
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobScheduleHelper {
|
||||
private static Logger logger = LoggerFactory.getLogger(JobScheduleHelper.class);
|
||||
|
||||
private static JobScheduleHelper instance = new JobScheduleHelper();
|
||||
public static JobScheduleHelper getInstance(){
|
||||
|
||||
public static JobScheduleHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -32,169 +32,14 @@ public class JobScheduleHelper {
|
||||
private Thread ringThread;
|
||||
private volatile boolean scheduleThreadToStop = false;
|
||||
private volatile boolean ringThreadToStop = false;
|
||||
private static volatile Map<Integer, List<Integer>> ringData = new ConcurrentHashMap<>();
|
||||
private static Map<Integer, List<Integer>> ringData = new ConcurrentHashMap<>();
|
||||
|
||||
public void start(){
|
||||
public void start() {
|
||||
|
||||
// schedule thread
|
||||
scheduleThread = new Thread(()-> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(5000 - System.currentTimeMillis()%1000 );
|
||||
} catch (InterruptedException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
logger.info(">>>>>>>>> init xxl-job admin scheduler success.");
|
||||
// pre-read count: treadpool-size * trigger-qps (each trigger cost 50ms, qps = 1000/50 = 20)
|
||||
int preReadCount = (XxlJobAdminConfig.getAdminConfig().getTriggerPoolFastMax() + XxlJobAdminConfig.getAdminConfig().getTriggerPoolSlowMax()) * 20;
|
||||
|
||||
while (!scheduleThreadToStop) {
|
||||
// Scan Job
|
||||
long start = System.currentTimeMillis();
|
||||
Connection conn = null;
|
||||
Boolean connAutoCommit = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
boolean preReadSuc = true;
|
||||
try {
|
||||
|
||||
conn = XxlJobAdminConfig.getAdminConfig().getDataSource().getConnection();
|
||||
connAutoCommit = conn.getAutoCommit();
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
preparedStatement = conn.prepareStatement( "select * from xxl_job_lock where lock_name = 'schedule_lock' for update" );
|
||||
preparedStatement.execute();
|
||||
|
||||
// tx start
|
||||
|
||||
// 1、pre read
|
||||
long nowTime = System.currentTimeMillis();
|
||||
List<XxlJobInfo> scheduleList = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleJobQuery(nowTime + PRE_READ_MS, preReadCount);
|
||||
if (scheduleList!=null && !scheduleList.isEmpty()) {
|
||||
// 2、push time-ring
|
||||
for (XxlJobInfo jobInfo: scheduleList) {
|
||||
|
||||
// time-ring jump
|
||||
if (nowTime > jobInfo.getTriggerNextTime() + PRE_READ_MS) {
|
||||
// 2.1、trigger-expire > 5s:pass && make next-trigger-time
|
||||
logger.warn(">>>>>>>>>>> xxl-job, schedule misfire, jobId = " + jobInfo.getId());
|
||||
|
||||
// fresh next
|
||||
refreshNextValidTime(jobInfo, new Date());
|
||||
|
||||
} else if (nowTime > jobInfo.getTriggerNextTime()) {
|
||||
// 2.2、trigger-expire < 5s:direct-trigger && make next-trigger-time
|
||||
|
||||
// 1、trigger
|
||||
JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.CRON, -1, null, null, null);
|
||||
logger.debug(">>>>>>>>>>> xxl-job, schedule push trigger : jobId = {}" , jobInfo.getId() );
|
||||
|
||||
// 2、fresh next
|
||||
refreshNextValidTime(jobInfo, new Date());
|
||||
|
||||
// next-trigger-time in 5s, pre-read again
|
||||
if (jobInfo.getTriggerStatus()==1 && nowTime + PRE_READ_MS > jobInfo.getTriggerNextTime()) {
|
||||
|
||||
// 1、make ring second
|
||||
int ringSecond = (int)((jobInfo.getTriggerNextTime()/1000)%60);
|
||||
|
||||
// 2、push time ring
|
||||
pushTimeRing(ringSecond, jobInfo.getId());
|
||||
|
||||
// 3、fresh next
|
||||
refreshNextValidTime(jobInfo, new Date(jobInfo.getTriggerNextTime()));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// 2.3、trigger-pre-read:time-ring trigger && make next-trigger-time
|
||||
|
||||
// 1、make ring second
|
||||
int ringSecond = (int)((jobInfo.getTriggerNextTime()/1000)%60);
|
||||
|
||||
// 2、push time ring
|
||||
pushTimeRing(ringSecond, jobInfo.getId());
|
||||
|
||||
// 3、fresh next
|
||||
refreshNextValidTime(jobInfo, new Date(jobInfo.getTriggerNextTime()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 3、update trigger info
|
||||
for (XxlJobInfo jobInfo: scheduleList) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleUpdate(jobInfo);
|
||||
}
|
||||
|
||||
} else {
|
||||
preReadSuc = false;
|
||||
}
|
||||
|
||||
// tx stop
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread error:{}", e);
|
||||
}
|
||||
} finally {
|
||||
|
||||
// commit
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.commit();
|
||||
} catch (SQLException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
conn.setAutoCommit(connAutoCommit);
|
||||
} catch (SQLException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close PreparedStatement
|
||||
if (null != preparedStatement) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
long cost = System.currentTimeMillis()-start;
|
||||
|
||||
|
||||
// Wait seconds, align second
|
||||
if (cost < 1000) { // scan-overtime, not wait
|
||||
try {
|
||||
// pre-read period: success > scan each second; fail > skip this period;
|
||||
TimeUnit.MILLISECONDS.sleep((preReadSuc?1000:PRE_READ_MS) - System.currentTimeMillis()%1000);
|
||||
} catch (InterruptedException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread stop");
|
||||
scheduleThread = new Thread(() -> {
|
||||
getThread();
|
||||
log.info(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread stop");
|
||||
});
|
||||
scheduleThread.setDaemon(true);
|
||||
scheduleThread.setName("xxl-job, admin JobScheduleHelper#scheduleThread");
|
||||
@@ -202,65 +47,245 @@ public class JobScheduleHelper {
|
||||
|
||||
|
||||
// ring thread
|
||||
ringThread = new Thread(()-> {
|
||||
// align second
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000 );
|
||||
} catch (InterruptedException e) {
|
||||
if (!ringThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
while (!ringThreadToStop) {
|
||||
|
||||
try {
|
||||
// second data
|
||||
List<Integer> ringItemData = new ArrayList<>();
|
||||
int nowSecond = Calendar.getInstance().get(Calendar.SECOND); // 避免处理耗时太长,跨过刻度,向前校验一个刻度;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
List<Integer> tmpData = ringData.remove( (nowSecond+60-i)%60 );
|
||||
if (tmpData != null) {
|
||||
ringItemData.addAll(tmpData);
|
||||
}
|
||||
}
|
||||
|
||||
// ring trigger
|
||||
logger.debug(">>>>>>>>>>> xxl-job, time-ring beat : " + nowSecond + " = " + Arrays.asList(ringItemData) );
|
||||
if (!ringItemData.isEmpty()) {
|
||||
// do trigger
|
||||
for (int jobId: ringItemData) {
|
||||
// do trigger
|
||||
JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null, null, null);
|
||||
}
|
||||
// clear
|
||||
ringItemData.clear();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!ringThreadToStop) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread error:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// next second, align second
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000);
|
||||
} catch (InterruptedException e) {
|
||||
if (!ringThreadToStop) {
|
||||
logger.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
logger.info(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread stop");
|
||||
ringThread = new Thread(() -> {
|
||||
// align second
|
||||
getThread1();
|
||||
log.info(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread stop");
|
||||
});
|
||||
ringThread.setDaemon(true);
|
||||
ringThread.setName("xxl-job, admin JobScheduleHelper#ringThread");
|
||||
ringThread.start();
|
||||
}
|
||||
|
||||
private void getThread1() {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis() % 1000);
|
||||
} catch (InterruptedException e) {
|
||||
if (!ringThreadToStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
while (!ringThreadToStop) {
|
||||
|
||||
try {
|
||||
// second data
|
||||
getSecondData();
|
||||
} catch (Exception e) {
|
||||
if (!ringThreadToStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread error:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// next second, align second
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis() % 1000);
|
||||
} catch (InterruptedException e) {
|
||||
if (!ringThreadToStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getSecondData() {
|
||||
List<Integer> ringItemData = new ArrayList<>();
|
||||
int nowSecond = Calendar.getInstance().get(Calendar.SECOND); // 避免处理耗时太长,跨过刻度,向前校验一个刻度;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
List<Integer> tmpData = ringData.remove((nowSecond + 60 - i) % 60);
|
||||
if (tmpData != null) {
|
||||
ringItemData.addAll(tmpData);
|
||||
}
|
||||
}
|
||||
|
||||
// ring trigger
|
||||
log.debug(">>>>>>>>>>> xxl-job, time-ring beat : " + nowSecond + " = " + Arrays.asList(ringItemData));
|
||||
if (!ringItemData.isEmpty()) {
|
||||
// do trigger
|
||||
for (int jobId : ringItemData) {
|
||||
// do trigger
|
||||
JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null, null, null);
|
||||
}
|
||||
// clear
|
||||
ringItemData.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void getThread() {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(5000 - System.currentTimeMillis() % 1000);
|
||||
} catch (InterruptedException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
log.info(">>>>>>>>> init xxl-job admin scheduler success.");
|
||||
// pre-read count: treadpool-size * trigger-qps (each trigger cost 50ms, qps = 1000/50 = 20)
|
||||
int preReadCount = (XxlJobAdminConfig.getAdminConfig().getTriggerPoolFastMax() + XxlJobAdminConfig.getAdminConfig().getTriggerPoolSlowMax()) * 20;
|
||||
|
||||
while (!scheduleThreadToStop) {
|
||||
// Scan Job
|
||||
getWhile(preReadCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void getWhile(int preReadCount) {
|
||||
long start = System.currentTimeMillis();
|
||||
Connection conn = null;
|
||||
Boolean connAutoCommit = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
boolean preReadSuc = true;
|
||||
try {
|
||||
|
||||
conn = XxlJobAdminConfig.getAdminConfig().getDataSource().getConnection();
|
||||
connAutoCommit = conn.getAutoCommit();
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
preparedStatement = conn.prepareStatement("select * from xxl_job_lock where lock_name = 'schedule_lock' for update");
|
||||
preparedStatement.execute();
|
||||
|
||||
// tx start
|
||||
|
||||
// 1、pre read
|
||||
long nowTime = System.currentTimeMillis();
|
||||
List<XxlJobInfo> scheduleList = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleJobQuery(nowTime + PRE_READ_MS, preReadCount);
|
||||
if (scheduleList != null && !scheduleList.isEmpty()) {
|
||||
// 2、push time-ring
|
||||
getFor(nowTime, scheduleList);
|
||||
|
||||
// 3、update trigger info
|
||||
for (XxlJobInfo jobInfo : scheduleList) {
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleUpdate(jobInfo);
|
||||
}
|
||||
|
||||
} else {
|
||||
preReadSuc = false;
|
||||
}
|
||||
|
||||
// tx stop
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
log.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread error:{}", e);
|
||||
}
|
||||
} finally {
|
||||
|
||||
// commit
|
||||
getFinally(conn, connAutoCommit, preparedStatement);
|
||||
}
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
|
||||
|
||||
// Wait seconds, align second
|
||||
getCost(preReadSuc, cost);
|
||||
}
|
||||
|
||||
private void getCost(boolean preReadSuc, long cost) {
|
||||
if (cost < 1000) { // scan-overtime, not wait
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep((preReadSuc ? 1000 : PRE_READ_MS) - System.currentTimeMillis() % 1000);
|
||||
} catch (InterruptedException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getFinally(Connection conn, Boolean connAutoCommit, PreparedStatement preparedStatement) {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.commit();
|
||||
} catch (SQLException e) {
|
||||
getScheduleThreadToStop(e);
|
||||
}
|
||||
try {
|
||||
conn.setAutoCommit(connAutoCommit);
|
||||
} catch (SQLException e) {
|
||||
getScheduleThreadToStop(e);
|
||||
}
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
getScheduleThreadToStop(e);
|
||||
}
|
||||
}
|
||||
|
||||
// close PreparedStatement
|
||||
if (null != preparedStatement) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) {
|
||||
getScheduleThreadToStop(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getScheduleThreadToStop(SQLException e) {
|
||||
if (!scheduleThreadToStop) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void getFor(long nowTime, List<XxlJobInfo> scheduleList) throws ParseException {
|
||||
for (XxlJobInfo jobInfo : scheduleList) {
|
||||
|
||||
// time-ring jump
|
||||
if (nowTime > jobInfo.getTriggerNextTime() + PRE_READ_MS) {
|
||||
// 2.1、trigger-expire > 5s:pass && make next-trigger-time
|
||||
log.warn(">>>>>>>>>>> xxl-job, schedule misfire, jobId = " + jobInfo.getId());
|
||||
|
||||
// fresh next
|
||||
refreshNextValidTime(jobInfo, new Date());
|
||||
|
||||
} else if (nowTime > jobInfo.getTriggerNextTime()) {
|
||||
// 2.2、trigger-expire < 5s:direct-trigger && make next-trigger-time
|
||||
|
||||
// 1、trigger
|
||||
JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.CRON, -1, null, null, null);
|
||||
log.debug(">>>>>>>>>>> xxl-job, schedule push trigger : jobId = {}", jobInfo.getId());
|
||||
|
||||
// 2、fresh next
|
||||
refreshNextValidTime(jobInfo, new Date());
|
||||
|
||||
// next-trigger-time in 5s, pre-read again
|
||||
if (jobInfo.getTriggerStatus() == 1 && nowTime + PRE_READ_MS > jobInfo.getTriggerNextTime()) {
|
||||
|
||||
// 1、make ring second
|
||||
int ringSecond = (int) ((jobInfo.getTriggerNextTime() / 1000) % 60);
|
||||
|
||||
// 2、push time ring
|
||||
pushTimeRing(ringSecond, jobInfo.getId());
|
||||
|
||||
// 3、fresh next
|
||||
refreshNextValidTime(jobInfo, new Date(jobInfo.getTriggerNextTime()));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// 2.3、trigger-pre-read:time-ring trigger && make next-trigger-time
|
||||
|
||||
// 1、make ring second
|
||||
int ringSecond = (int) ((jobInfo.getTriggerNextTime() / 1000) % 60);
|
||||
|
||||
// 2、push time ring
|
||||
pushTimeRing(ringSecond, jobInfo.getId());
|
||||
|
||||
// 3、fresh next
|
||||
refreshNextValidTime(jobInfo, new Date(jobInfo.getTriggerNextTime()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshNextValidTime(XxlJobInfo jobInfo, Date fromTime) throws ParseException {
|
||||
Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(fromTime);
|
||||
if (nextValidTime != null) {
|
||||
@@ -273,56 +298,42 @@ public class JobScheduleHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private void pushTimeRing(int ringSecond, int jobId){
|
||||
private void pushTimeRing(int ringSecond, int jobId) {
|
||||
// push async ring
|
||||
List<Integer> ringItemData = ringData.get(ringSecond);
|
||||
if (ringItemData == null) {
|
||||
ringItemData = new ArrayList<>();
|
||||
ringData.put(ringSecond, ringItemData);
|
||||
}
|
||||
List<Integer> ringItemData = ringData.computeIfAbsent(ringSecond, k -> new ArrayList<>());
|
||||
ringItemData.add(jobId);
|
||||
|
||||
logger.debug(">>>>>>>>>>> xxl-job, schedule push time-ring : " + ringSecond + " = " + Arrays.asList(ringItemData) );
|
||||
log.debug(">>>>>>>>>>> xxl-job, schedule push time-ring : " + ringSecond + " = " + Arrays.asList(ringItemData));
|
||||
}
|
||||
|
||||
public void toStop(){
|
||||
public void toStop() {
|
||||
|
||||
// 1、stop schedule
|
||||
scheduleThreadToStop = true;
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(1); // wait
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
if (scheduleThread.getState() != Thread.State.TERMINATED){
|
||||
if (scheduleThread.getState() != Thread.State.TERMINATED) {
|
||||
// interrupt and wait
|
||||
scheduleThread.interrupt();
|
||||
try {
|
||||
scheduleThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
// if has ring data
|
||||
boolean hasRingData = false;
|
||||
if (!ringData.isEmpty()) {
|
||||
Set<Map.Entry<Integer, List<Integer>>> entries = ringData.entrySet();
|
||||
for (Map.Entry<Integer, List<Integer>> e : entries) {
|
||||
List<Integer> tmpData = e.getValue();
|
||||
if (tmpData!=null && !tmpData.isEmpty()) {
|
||||
hasRingData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean hasRingData = isHasRingData();
|
||||
if (hasRingData) {
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(8);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
@@ -332,21 +343,36 @@ public class JobScheduleHelper {
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
if (ringThread.getState() != Thread.State.TERMINATED){
|
||||
if (ringThread.getState() != Thread.State.TERMINATED) {
|
||||
// interrupt and wait
|
||||
ringThread.interrupt();
|
||||
try {
|
||||
ringThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
log.error(e.getMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(">>>>>>>>>>> xxl-job, JobScheduleHelper stop");
|
||||
log.info(">>>>>>>>>>> xxl-job, JobScheduleHelper stop");
|
||||
}
|
||||
|
||||
private boolean isHasRingData() {
|
||||
boolean hasRingData = false;
|
||||
if (!ringData.isEmpty()) {
|
||||
Set<Map.Entry<Integer, List<Integer>>> entries = ringData.entrySet();
|
||||
for (Map.Entry<Integer, List<Integer>> e : entries) {
|
||||
List<Integer> tmpData = e.getValue();
|
||||
if (tmpData != null && !tmpData.isEmpty()) {
|
||||
hasRingData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasRingData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-14
@@ -32,12 +32,6 @@ public class JobTriggerPoolHelper {
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(1000),
|
||||
r-> new Thread(r, "xxl-job, admin JobTriggerPoolHelper-fastTriggerPool-" + r.hashCode()));
|
||||
/*new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "xxl-job, admin JobTriggerPoolHelper-fastTriggerPool-" + r.hashCode());
|
||||
}
|
||||
});*/
|
||||
|
||||
slowTriggerPool = new ThreadPoolExecutor(
|
||||
10,
|
||||
@@ -46,17 +40,10 @@ public class JobTriggerPoolHelper {
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(2000),
|
||||
r-> new Thread(r, "xxl-job, admin JobTriggerPoolHelper-slowTriggerPool-" + r.hashCode()));
|
||||
/*new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "xxl-job, admin JobTriggerPoolHelper-slowTriggerPool-" + r.hashCode());
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
|
||||
public void stop() {
|
||||
//triggerPool.shutdown();
|
||||
fastTriggerPool.shutdownNow();
|
||||
slowTriggerPool.shutdownNow();
|
||||
logger.info(">>>>>>>>> xxl-job trigger thread pool shutdown success.");
|
||||
@@ -65,7 +52,7 @@ public class JobTriggerPoolHelper {
|
||||
|
||||
// job timeout count
|
||||
private volatile long minTim = System.currentTimeMillis()/60000; // ms > min
|
||||
private volatile ConcurrentMap<Integer, AtomicInteger> jobTimeoutCountMap = new ConcurrentHashMap<>();
|
||||
private ConcurrentMap<Integer, AtomicInteger> jobTimeoutCountMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+42
-22
@@ -71,14 +71,7 @@ public class XxlJobTrigger {
|
||||
|
||||
// sharding param
|
||||
int[] shardingParam = null;
|
||||
if (executorShardingParam!=null){
|
||||
String[] shardingArr = executorShardingParam.split("/");
|
||||
if (shardingArr.length==2 && isNumeric(shardingArr[0]) && isNumeric(shardingArr[1])) {
|
||||
shardingParam = new int[2];
|
||||
shardingParam[0] = Integer.valueOf(shardingArr[0]);
|
||||
shardingParam[1] = Integer.valueOf(shardingArr[1]);
|
||||
}
|
||||
}
|
||||
shardingParam = getInts(executorShardingParam, shardingParam);
|
||||
if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null)
|
||||
&& group.getRegistryList()!=null && !group.getRegistryList().isEmpty()
|
||||
&& shardingParam==null) {
|
||||
@@ -94,6 +87,18 @@ public class XxlJobTrigger {
|
||||
|
||||
}
|
||||
|
||||
private static int[] getInts(String executorShardingParam, int[] shardingParam) {
|
||||
if (executorShardingParam!=null){
|
||||
String[] shardingArr = executorShardingParam.split("/");
|
||||
if (shardingArr.length==2 && isNumeric(shardingArr[0]) && isNumeric(shardingArr[1])) {
|
||||
shardingParam = new int[2];
|
||||
shardingParam[0] = Integer.valueOf(shardingArr[0]);
|
||||
shardingParam[1] = Integer.valueOf(shardingArr[1]);
|
||||
}
|
||||
}
|
||||
return shardingParam;
|
||||
}
|
||||
|
||||
private static boolean isNumeric(String str){
|
||||
try {
|
||||
Integer.valueOf(str);
|
||||
@@ -146,11 +151,7 @@ public class XxlJobTrigger {
|
||||
ReturnT<String> routeAddressResult = null;
|
||||
if (group.getRegistryList()!=null && !group.getRegistryList().isEmpty()) {
|
||||
if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) {
|
||||
if (index < group.getRegistryList().size()) {
|
||||
address = group.getRegistryList().get(index);
|
||||
} else {
|
||||
address = group.getRegistryList().get(0);
|
||||
}
|
||||
address = getString(group, index);
|
||||
} else {
|
||||
routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, group.getRegistryList());
|
||||
if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) {
|
||||
@@ -163,11 +164,7 @@ public class XxlJobTrigger {
|
||||
|
||||
// 4、trigger remote executor
|
||||
ReturnT<String> triggerResult = null;
|
||||
if (address != null) {
|
||||
triggerResult = runExecutor(triggerParam, address);
|
||||
} else {
|
||||
triggerResult = new ReturnT<>(ReturnT.FAIL_CODE, null);
|
||||
}
|
||||
triggerResult = getTriggerResult(triggerParam, address);
|
||||
|
||||
// 5、collection trigger info
|
||||
StringBuilder triggerMsgSb = new StringBuilder();
|
||||
@@ -177,9 +174,7 @@ public class XxlJobTrigger {
|
||||
.append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") );
|
||||
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList());
|
||||
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle());
|
||||
if (shardingParam != null) {
|
||||
triggerMsgSb.append("("+shardingParam+")");
|
||||
}
|
||||
triggerMsgSbAppend(shardingParam, triggerMsgSb);
|
||||
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle());
|
||||
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout());
|
||||
triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount);
|
||||
@@ -193,7 +188,6 @@ public class XxlJobTrigger {
|
||||
jobLog.setExecutorParam(jobInfo.getExecutorParam());
|
||||
jobLog.setExecutorShardingParam(shardingParam);
|
||||
jobLog.setExecutorFailRetryCount(finalFailRetryCount);
|
||||
//jobLog.setTriggerTime();
|
||||
jobLog.setTriggerCode(triggerResult.getCode());
|
||||
jobLog.setTriggerMsg(triggerMsgSb.toString());
|
||||
XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(jobLog);
|
||||
@@ -201,6 +195,32 @@ public class XxlJobTrigger {
|
||||
logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
|
||||
}
|
||||
|
||||
private static ReturnT<String> getTriggerResult(TriggerParam triggerParam, String address) {
|
||||
ReturnT<String> triggerResult;
|
||||
if (address != null) {
|
||||
triggerResult = runExecutor(triggerParam, address);
|
||||
} else {
|
||||
triggerResult = new ReturnT<>(ReturnT.FAIL_CODE, null);
|
||||
}
|
||||
return triggerResult;
|
||||
}
|
||||
|
||||
private static String getString(XxlJobGroup group, int index) {
|
||||
String address;
|
||||
if (index < group.getRegistryList().size()) {
|
||||
address = group.getRegistryList().get(index);
|
||||
} else {
|
||||
address = group.getRegistryList().get(0);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
private static void triggerMsgSbAppend(String shardingParam, StringBuilder triggerMsgSb) {
|
||||
if (shardingParam != null) {
|
||||
triggerMsgSb.append("("+shardingParam+")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* run executor
|
||||
* @param triggerParam
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class FtlUtil {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(FtlUtil.class);
|
||||
|
||||
private static BeansWrapper wrapper = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build(); //BeansWrapper.getDefaultInstance();
|
||||
private static BeansWrapper wrapper = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();
|
||||
|
||||
public static TemplateHashModel generateStaticModel(String packageName) {
|
||||
try {
|
||||
|
||||
+6
-1
@@ -6,6 +6,7 @@ import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import com.xxl.job.admin.core.util.JacksonUtil;
|
||||
import com.xxl.job.admin.dao.XxlJobUserDao;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
@@ -13,10 +14,12 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2019-05-04 22:13:264
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class LoginService {
|
||||
|
||||
@@ -41,7 +44,9 @@ public class LoginService {
|
||||
|
||||
|
||||
public ReturnT<String> login(HttpServletRequest request, HttpServletResponse response, String username, String password, boolean ifRemember){
|
||||
|
||||
if(Objects.isNull(request)){
|
||||
log.info("未使用参数");
|
||||
}
|
||||
// param
|
||||
if (username==null || username.trim().length()==0 || password==null || password.trim().length()==0){
|
||||
return new ReturnT<>(500, I18nUtil.getString("login_param_empty"));
|
||||
|
||||
+32
-24
@@ -14,6 +14,7 @@ import com.xxl.job.core.biz.model.HandleCallbackParam;
|
||||
import com.xxl.job.core.biz.model.RegistryParam;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -23,10 +24,12 @@ import javax.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2017-07-27 21:54:20
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AdminBizImpl implements AdminBiz {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AdminBizImpl.class);
|
||||
@@ -68,30 +71,7 @@ public class AdminBizImpl implements AdminBiz {
|
||||
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
|
||||
if (xxlJobInfo!=null && xxlJobInfo.getChildJobId()!=null && xxlJobInfo.getChildJobId().trim().length()>0) {
|
||||
callbackMsg = new StringBuilder("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>" + I18nUtil.getString("jobconf_trigger_child_run") + "<<<<<<<<<<< </span><br>");
|
||||
|
||||
String[] childJobIds = xxlJobInfo.getChildJobId().split(",");
|
||||
for (int i = 0; i < childJobIds.length; i++) {
|
||||
int childJobId = (childJobIds[i]!=null && childJobIds[i].trim().length()>0 && isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1;
|
||||
if (childJobId > 0) {
|
||||
|
||||
JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null, null);
|
||||
ReturnT<String> triggerChildResult = ReturnT.SUCCESS;
|
||||
|
||||
// add msg
|
||||
callbackMsg.append(MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg1"),
|
||||
(i + 1),
|
||||
childJobIds.length,
|
||||
childJobIds[i],
|
||||
(triggerChildResult.getCode() == ReturnT.SUCCESS_CODE ? I18nUtil.getString("system_success") : I18nUtil.getString("system_fail")),
|
||||
triggerChildResult.getMsg()));
|
||||
} else {
|
||||
callbackMsg.append(MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg2"),
|
||||
(i + 1),
|
||||
childJobIds.length,
|
||||
childJobIds[i]));
|
||||
}
|
||||
}
|
||||
|
||||
appendCallbackMsg(callbackMsg, xxlJobInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +100,31 @@ public class AdminBizImpl implements AdminBiz {
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
private void appendCallbackMsg(StringBuilder callbackMsg, XxlJobInfo xxlJobInfo) {
|
||||
String[] childJobIds = xxlJobInfo.getChildJobId().split(",");
|
||||
for (int i = 0; i < childJobIds.length; i++) {
|
||||
int childJobId = (childJobIds[i]!=null && childJobIds[i].trim().length()>0 && isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1;
|
||||
if (childJobId > 0) {
|
||||
|
||||
JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null, null);
|
||||
ReturnT<String> triggerChildResult = ReturnT.SUCCESS;
|
||||
|
||||
// add msg
|
||||
callbackMsg.append(MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg1"),
|
||||
(i + 1),
|
||||
childJobIds.length,
|
||||
childJobIds[i],
|
||||
(triggerChildResult.getCode() == ReturnT.SUCCESS_CODE ? I18nUtil.getString("system_success") : I18nUtil.getString("system_fail")),
|
||||
triggerChildResult.getMsg()));
|
||||
} else {
|
||||
callbackMsg.append(MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg2"),
|
||||
(i + 1),
|
||||
childJobIds.length,
|
||||
childJobIds[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNumeric(String str){
|
||||
try {
|
||||
Integer.valueOf(str);
|
||||
@@ -169,6 +174,9 @@ public class AdminBizImpl implements AdminBiz {
|
||||
}
|
||||
|
||||
private void freshGroupRegistryInfo(RegistryParam registryParam){
|
||||
if(Objects.isNull(registryParam)){
|
||||
log.info("未使用参数");
|
||||
}
|
||||
// Under consideration, prevent affecting core tables
|
||||
}
|
||||
|
||||
|
||||
+65
-41
@@ -91,14 +91,35 @@ public class XxlJobServiceImpl implements XxlJobService {
|
||||
if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && (jobInfo.getExecutorHandler()==null || jobInfo.getExecutorHandler().trim().length()==0) ) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+"JobHandler") );
|
||||
}
|
||||
getGlueTypeEnum(jobInfo);
|
||||
|
||||
// ChildJobId valid
|
||||
ReturnT<String> childJobIdItem = getChildJobId(jobInfo);
|
||||
if (childJobIdItem != null) {
|
||||
return childJobIdItem;
|
||||
}
|
||||
|
||||
// add in db
|
||||
jobInfo.setAddTime(new Date());
|
||||
jobInfo.setUpdateTime(new Date());
|
||||
jobInfo.setGlueUpdatetime(new Date());
|
||||
xxlJobInfoDao.save(jobInfo);
|
||||
if (jobInfo.getId() < 1) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
|
||||
}
|
||||
|
||||
return new ReturnT<>(String.valueOf(jobInfo.getId()));
|
||||
}
|
||||
|
||||
private void getGlueTypeEnum(XxlJobInfo jobInfo) {
|
||||
// fix "\r" in shell
|
||||
if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) {
|
||||
jobInfo.setGlueSource(jobInfo.getGlueSource().replace("\r", ""));
|
||||
}
|
||||
}
|
||||
|
||||
// ChildJobId valid
|
||||
if (jobInfo.getChildJobId()!=null && jobInfo.getChildJobId().trim().length()>0) {
|
||||
private ReturnT<String> getChildJobId(XxlJobInfo jobInfo) {
|
||||
if (jobInfo.getChildJobId()!=null && jobInfo.getChildJobId().trim().length()>0) {
|
||||
String[] childJobIds = jobInfo.getChildJobId().split(",");
|
||||
for (String childJobIdItem: childJobIds) {
|
||||
if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) {
|
||||
@@ -122,17 +143,7 @@ public class XxlJobServiceImpl implements XxlJobService {
|
||||
|
||||
jobInfo.setChildJobId(temp.toString());
|
||||
}
|
||||
|
||||
// add in db
|
||||
jobInfo.setAddTime(new Date());
|
||||
jobInfo.setUpdateTime(new Date());
|
||||
jobInfo.setGlueUpdatetime(new Date());
|
||||
xxlJobInfoDao.save(jobInfo);
|
||||
if (jobInfo.getId() < 1) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) );
|
||||
}
|
||||
|
||||
return new ReturnT<>(String.valueOf(jobInfo.getId()));
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isNumeric(String str){
|
||||
@@ -146,39 +157,16 @@ public class XxlJobServiceImpl implements XxlJobService {
|
||||
|
||||
@Override
|
||||
public ReturnT<String> update(XxlJobInfo jobInfo) {
|
||||
|
||||
// valid
|
||||
if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString(jobinfoFieldCronUnvalid) );
|
||||
}
|
||||
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_jobdesc")) );
|
||||
}
|
||||
if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_author")) );
|
||||
}
|
||||
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString(systemUnvalid)) );
|
||||
}
|
||||
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString(systemUnvalid)) );
|
||||
ReturnT<String> x = getStringReturnT(jobInfo);
|
||||
if (x != null) {
|
||||
return x;
|
||||
}
|
||||
|
||||
// ChildJobId valid
|
||||
if (jobInfo.getChildJobId()!=null && jobInfo.getChildJobId().trim().length()>0) {
|
||||
String[] childJobIds = jobInfo.getChildJobId().split(",");
|
||||
for (String childJobIdItem: childJobIds) {
|
||||
if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) {
|
||||
XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(childJobIdItem));
|
||||
if (childJobInfo==null) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,
|
||||
MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemNotFound)), childJobIdItem));
|
||||
}
|
||||
} else {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,
|
||||
MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemUnvalid)), childJobIdItem));
|
||||
}
|
||||
}
|
||||
ReturnT<String> childJobIdItem = getStringReturnT(childJobIds);
|
||||
if (childJobIdItem != null) return childJobIdItem;
|
||||
|
||||
// join , avoid "xxx,,"
|
||||
StringBuilder temp = new StringBuilder();
|
||||
@@ -238,6 +226,42 @@ public class XxlJobServiceImpl implements XxlJobService {
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
private ReturnT<String> getStringReturnT(String[] childJobIds) {
|
||||
for (String childJobIdItem: childJobIds) {
|
||||
if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) {
|
||||
XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(childJobIdItem));
|
||||
if (childJobInfo==null) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,
|
||||
MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemNotFound)), childJobIdItem));
|
||||
}
|
||||
} else {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,
|
||||
MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemUnvalid)), childJobIdItem));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ReturnT<String> getStringReturnT(XxlJobInfo jobInfo) {
|
||||
// valid
|
||||
if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString(jobinfoFieldCronUnvalid) );
|
||||
}
|
||||
if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_jobdesc")) );
|
||||
}
|
||||
if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_author")) );
|
||||
}
|
||||
if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString(systemUnvalid)) );
|
||||
}
|
||||
if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString(systemUnvalid)) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnT<String> remove(int id) {
|
||||
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
|
||||
|
||||
Reference in New Issue
Block a user