|
|
@ -1,14 +1,17 @@
|
|
|
|
package com.xxl.job.admin.core.thread;
|
|
|
|
package com.xxl.job.admin.core.thread;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobGroup;
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobRegistry;
|
|
|
|
import com.xxl.job.admin.core.model.XxlJobRegistry;
|
|
|
|
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
|
|
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
|
|
import com.xxl.job.core.enums.RegistryConfig;
|
|
|
|
import com.xxl.job.core.enums.RegistryConfig;
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -23,8 +26,6 @@ public class JobRegistryMonitorHelper {
|
|
|
|
return instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ConcurrentHashMap<String, List<String>> registMap = new ConcurrentHashMap<String, List<String>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Thread registryThread;
|
|
|
|
private Thread registryThread;
|
|
|
|
private boolean toStop = false;
|
|
|
|
private boolean toStop = false;
|
|
|
|
public void start(){
|
|
|
|
public void start(){
|
|
|
@ -33,26 +34,42 @@ public class JobRegistryMonitorHelper {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
while (!toStop) {
|
|
|
|
while (!toStop) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// remove dead admin/executor
|
|
|
|
// auto registry group
|
|
|
|
XxlJobDynamicScheduler.xxlJobRegistryDao.removeDead(RegistryConfig.DEAD_TIMEOUT);
|
|
|
|
List<XxlJobGroup> groupList = XxlJobDynamicScheduler.xxlJobGroupDao.findByAddressType(0);
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(groupList)) {
|
|
|
|
|
|
|
|
|
|
|
|
// fresh registry map
|
|
|
|
// remove dead address (admin/executor)
|
|
|
|
ConcurrentHashMap<String, List<String>> temp = new ConcurrentHashMap<String, List<String>>();
|
|
|
|
XxlJobDynamicScheduler.xxlJobRegistryDao.removeDead(RegistryConfig.DEAD_TIMEOUT);
|
|
|
|
List<XxlJobRegistry> list = XxlJobDynamicScheduler.xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT);
|
|
|
|
|
|
|
|
if (list != null) {
|
|
|
|
// fresh online address (admin/executor)
|
|
|
|
for (XxlJobRegistry item: list) {
|
|
|
|
HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>();
|
|
|
|
String groupKey = makeGroupKey(item.getRegistryGroup(), item.getRegistryKey());
|
|
|
|
List<XxlJobRegistry> list = XxlJobDynamicScheduler.xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT);
|
|
|
|
List<String> registryList = temp.get(groupKey);
|
|
|
|
if (list != null) {
|
|
|
|
if (registryList == null) {
|
|
|
|
for (XxlJobRegistry item: list) {
|
|
|
|
registryList = new ArrayList<String>();
|
|
|
|
if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
|
|
|
|
}
|
|
|
|
String appName = item.getRegistryKey();
|
|
|
|
if (!registryList.contains(item.getRegistryValue())) {
|
|
|
|
List<String> registryList = appAddressMap.get(appName);
|
|
|
|
registryList.add(item.getRegistryValue());
|
|
|
|
if (registryList == null) {
|
|
|
|
|
|
|
|
registryList = new ArrayList<String>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!registryList.contains(item.getRegistryValue())) {
|
|
|
|
|
|
|
|
registryList.add(item.getRegistryValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
appAddressMap.put(appName, registryList);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp.put(groupKey, registryList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fresh group address
|
|
|
|
|
|
|
|
for (XxlJobGroup group: groupList) {
|
|
|
|
|
|
|
|
List<String> registryList = appAddressMap.get(group.getAppName());
|
|
|
|
|
|
|
|
String addressListStr = StringUtils.join(registryList, ",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group.setAddressList(addressListStr);
|
|
|
|
|
|
|
|
XxlJobDynamicScheduler.xxlJobGroupDao.update(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
registMap = temp;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("job registry instance error:{}", e);
|
|
|
|
logger.error("job registry instance error:{}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,13 +90,4 @@ public class JobRegistryMonitorHelper {
|
|
|
|
//registryThread.interrupt();
|
|
|
|
//registryThread.interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String makeGroupKey(String registryGroup, String registryKey){
|
|
|
|
|
|
|
|
return registryGroup.concat("_").concat(registryKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<String> discover(String registryGroup, String registryKey){
|
|
|
|
|
|
|
|
String groupKey = makeGroupKey(registryGroup, registryKey);
|
|
|
|
|
|
|
|
return instance.registMap.get(groupKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|