mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
bug fix (#2122)
* admin端口调整完成 * server端适配调整 * 调整部分功能 * 单机/集群admin调试完成 * 重新发布前端页面 * bug fix * 解决server端admin配置会被远程覆盖的问题 解决default-instance.xml无法加载远程zkServers配置的问题 * 集群模式下取活动实例的问题
This commit is contained in:
@@ -46,7 +46,7 @@ import com.google.common.collect.MigrateMap;
|
||||
*/
|
||||
public class CanalController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CanalController.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(CanalController.class);
|
||||
private Long cid;
|
||||
private String ip;
|
||||
private String registerIp;
|
||||
@@ -54,10 +54,11 @@ public class CanalController {
|
||||
private int adminPort;
|
||||
// 默认使用spring的方式载入
|
||||
private Map<String, InstanceConfig> instanceConfigs;
|
||||
private Map<String, String> runningInstances = new MapMaker().makeMap();
|
||||
private InstanceConfig globalInstanceConfig;
|
||||
private Map<String, PlainCanalConfigClient> managerClients;
|
||||
// 监听instance config的变化
|
||||
private boolean autoScan = true;
|
||||
private boolean autoScan = true;
|
||||
private InstanceAction defaultAction;
|
||||
private Map<InstanceMode, InstanceConfigMonitor> instanceConfigMonitors;
|
||||
private CanalServerWithEmbedded embededCanalServer;
|
||||
@@ -169,6 +170,7 @@ public class CanalController {
|
||||
if (canalMQStarter != null) {
|
||||
canalMQStarter.startDestination(destination);
|
||||
}
|
||||
runningInstances.put(destination, destination);
|
||||
} finally {
|
||||
MDC.remove(CanalConstants.MDC_DESTINATION);
|
||||
}
|
||||
@@ -181,6 +183,7 @@ public class CanalController {
|
||||
canalMQStarter.stopDestination(destination);
|
||||
}
|
||||
embededCanalServer.stop(destination);
|
||||
runningInstances.remove(destination);
|
||||
} finally {
|
||||
MDC.remove(CanalConstants.MDC_DESTINATION);
|
||||
}
|
||||
@@ -363,7 +366,7 @@ public class CanalController {
|
||||
}
|
||||
|
||||
if (config.getMode().isManager()) {
|
||||
PlainCanalInstanceGenerator instanceGenerator = new PlainCanalInstanceGenerator();
|
||||
PlainCanalInstanceGenerator instanceGenerator = new PlainCanalInstanceGenerator(properties);
|
||||
instanceGenerator.setCanalConfigClient(managerClients.get(config.getManagerAddress()));
|
||||
instanceGenerator.setSpringXml(config.getSpringXml());
|
||||
return instanceGenerator.generate(destination);
|
||||
@@ -592,4 +595,7 @@ public class CanalController {
|
||||
return instanceConfigs;
|
||||
}
|
||||
|
||||
public Map<String, String> getRunningInstances() {
|
||||
return runningInstances;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,45 +49,55 @@ public class CanalLauncher {
|
||||
if (StringUtils.isNotEmpty(managerAddress)) {
|
||||
String user = properties.getProperty(CanalConstants.CANAL_ADMIN_USER);
|
||||
String passwd = properties.getProperty(CanalConstants.CANAL_ADMIN_PASSWD);
|
||||
String adminPort = properties.getProperty(CanalConstants.CANAL_ADMIN_PORT);
|
||||
if (StringUtils.isEmpty(adminPort)) {
|
||||
adminPort = "11110";
|
||||
}
|
||||
String adminPort = properties.getProperty(CanalConstants.CANAL_ADMIN_PORT, "11110");
|
||||
final PlainCanalConfigClient configClient = new PlainCanalConfigClient(managerAddress,
|
||||
user,
|
||||
passwd,
|
||||
"",
|
||||
Integer.parseInt(adminPort));
|
||||
PlainCanal canalConfig = configClient.findServer(null);
|
||||
properties = canalConfig.getProperties();
|
||||
int scanIntervalInSecond = Integer
|
||||
.valueOf(properties.getProperty(CanalConstants.CANAL_AUTO_SCAN_INTERVAL, "5"));
|
||||
executor.scheduleWithFixedDelay(new Runnable() {
|
||||
if (canalConfig != null) {
|
||||
properties = canalConfig.getProperties();
|
||||
// 用本地配置覆盖
|
||||
properties.put(CanalConstants.CANAL_ADMIN_MANAGER, managerAddress);
|
||||
properties.put(CanalConstants.CANAL_ADMIN_USER, user);
|
||||
properties.put(CanalConstants.CANAL_ADMIN_PASSWD, passwd);
|
||||
properties.put(CanalConstants.CANAL_ADMIN_PORT, adminPort);
|
||||
int scanIntervalInSecond = Integer
|
||||
.parseInt(properties.getProperty(CanalConstants.CANAL_AUTO_SCAN_INTERVAL, "5"));
|
||||
executor.scheduleWithFixedDelay(new Runnable() {
|
||||
|
||||
private PlainCanal lastCanalConfig;
|
||||
private PlainCanal lastCanalConfig;
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
if (lastCanalConfig == null) {
|
||||
lastCanalConfig = configClient.findServer(null);
|
||||
} else {
|
||||
PlainCanal newCanalConfig = configClient.findServer(lastCanalConfig.getMd5());
|
||||
if (newCanalConfig != null) {
|
||||
// 远程配置canal.properties修改重新加载整个应用
|
||||
canalStater.stop();
|
||||
canalStater.setProperties(newCanalConfig.getProperties());
|
||||
canalStater.start();
|
||||
public void run() {
|
||||
try {
|
||||
if (lastCanalConfig == null) {
|
||||
lastCanalConfig = configClient.findServer(null);
|
||||
} else {
|
||||
PlainCanal newCanalConfig = configClient.findServer(lastCanalConfig.getMd5());
|
||||
if (newCanalConfig != null) {
|
||||
// 远程配置canal.properties修改重新加载整个应用
|
||||
canalStater.stop();
|
||||
Properties properties1 = newCanalConfig.getProperties();
|
||||
// 用本地配置覆盖
|
||||
properties1.put(CanalConstants.CANAL_ADMIN_MANAGER, managerAddress);
|
||||
properties1.put(CanalConstants.CANAL_ADMIN_USER, user);
|
||||
properties1.put(CanalConstants.CANAL_ADMIN_PASSWD, passwd);
|
||||
properties1.put(CanalConstants.CANAL_ADMIN_PORT, adminPort);
|
||||
canalStater.setProperties(properties1);
|
||||
canalStater.start();
|
||||
|
||||
lastCanalConfig = newCanalConfig;
|
||||
lastCanalConfig = newCanalConfig;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("scan failed", e);
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("scan failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
}, 0, scanIntervalInSecond, TimeUnit.SECONDS);
|
||||
}, 0, scanIntervalInSecond, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
canalStater.setProperties(properties);
|
||||
@@ -108,5 +118,4 @@ public class CanalLauncher {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.google.common.base.Joiner;
|
||||
|
||||
/**
|
||||
* 提供canal admin的管理操作
|
||||
*
|
||||
*
|
||||
* @author agapple 2019年8月24日 下午11:39:01
|
||||
* @since 1.1.4
|
||||
*/
|
||||
@@ -103,7 +103,7 @@ public class CanalAdminController implements CanalAdmin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRunningInstances() {
|
||||
public String getInstances() {
|
||||
try {
|
||||
CanalController controller = canalStater.getController();
|
||||
if (controller != null) {
|
||||
@@ -118,6 +118,22 @@ public class CanalAdminController implements CanalAdmin {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRunningInstances() {
|
||||
try {
|
||||
CanalController controller = canalStater.getController();
|
||||
if (controller != null) {
|
||||
Map<String, String> instanceConfigs = controller.getRunningInstances();
|
||||
if (instanceConfigs != null) {
|
||||
return Joiner.on(",").join(instanceConfigs.keySet());
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkInstance(String destination) {
|
||||
Map<String, CanalInstance> instances = CanalServerWithEmbedded.instance().getCanalInstances();
|
||||
|
||||
Reference in New Issue
Block a user