From 17f4ee13e76bee5eb73a85b58d4c867b8621de19 Mon Sep 17 00:00:00 2001 From: zoemak Date: Mon, 19 Apr 2021 10:18:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89node=20server=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8Ccanal.properties#canal.admin.register.name?= =?UTF-8?q?=EF=BC=8C=E4=B8=BA=E7=A9=BA=E5=88=99=E4=BD=BF=E7=94=A8canal.reg?= =?UTF-8?q?ister.ip=20(#3459)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../canal/admin/controller/PollingConfigController.java | 5 +++-- .../otter/canal/admin/service/PollingConfigService.java | 2 +- .../canal/admin/service/impl/PollingConfigServiceImpl.java | 5 +++-- .../admin-web/src/main/resources/canal-template.properties | 4 ++++ .../com/alibaba/otter/canal/deployer/CanalConstants.java | 1 + .../com/alibaba/otter/canal/deployer/CanalLauncher.java | 4 +++- deployer/src/main/resources/canal_local.properties | 3 ++- .../instance/manager/plain/PlainCanalConfigClient.java | 6 ++++-- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/controller/PollingConfigController.java b/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/controller/PollingConfigController.java index 32da8425ca..01b8f1aba8 100644 --- a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/controller/PollingConfigController.java +++ b/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/controller/PollingConfigController.java @@ -46,14 +46,15 @@ public class PollingConfigController { public BaseModel canalConfigPoll(@RequestHeader String user, @RequestHeader String passwd, @RequestParam String ip, @RequestParam Integer port, @RequestParam String md5, @RequestParam boolean register, - @RequestParam String cluster, @PathVariable String env) { + @RequestParam String cluster, @RequestParam String name, + @PathVariable String env) { if (!auth(user, passwd)) { throw new RuntimeException("auth :" + user + " is failed"); } if (StringUtils.isEmpty(md5) && register) { // do something - pollingConfigService.autoRegister(ip, port, cluster); + pollingConfigService.autoRegister(ip, port, cluster, StringUtils.trimToNull(name)); } CanalConfig canalConfig = pollingConfigService.getChangedConfig(ip, port, md5); diff --git a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/PollingConfigService.java b/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/PollingConfigService.java index a5ce0a958c..e76302ce7d 100644 --- a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/PollingConfigService.java +++ b/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/PollingConfigService.java @@ -5,7 +5,7 @@ public interface PollingConfigService { - public boolean autoRegister(String ip, Integer adminPort, String cluster); + public boolean autoRegister(String ip, Integer adminPort, String cluster, String name); CanalConfig getChangedConfig(String ip, Integer port, String md5); diff --git a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/impl/PollingConfigServiceImpl.java b/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/impl/PollingConfigServiceImpl.java index 882f27ec17..f76648a4ca 100644 --- a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/impl/PollingConfigServiceImpl.java +++ b/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/service/impl/PollingConfigServiceImpl.java @@ -2,6 +2,7 @@ import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; @@ -28,11 +29,11 @@ public class PollingConfigServiceImpl implements PollingConfigService { @Autowired CanalClusterService canalClusterService; - public boolean autoRegister(String ip, Integer adminPort, String cluster) { + public boolean autoRegister(String ip, Integer adminPort, String cluster, String name) { NodeServer server = NodeServer.find.query().where().eq("ip", ip).eq("adminPort", adminPort).findOne(); if (server == null) { server = new NodeServer(); - server.setName(ip); + server.setName(Optional.ofNullable(name).orElse(ip)); server.setIp(ip); server.setAdminPort(adminPort); server.setTcpPort(adminPort + 1); diff --git a/admin/admin-web/src/main/resources/canal-template.properties b/admin/admin-web/src/main/resources/canal-template.properties index 8a104e68bb..bf43de9900 100644 --- a/admin/admin-web/src/main/resources/canal-template.properties +++ b/admin/admin-web/src/main/resources/canal-template.properties @@ -16,6 +16,10 @@ canal.metrics.pull.port = 11112 canal.admin.port = 11110 canal.admin.user = admin canal.admin.passwd = 4ACFE3202A5FF5CF467898FC58AAB1D615029441 +# admin auto register +#canal.admin.register.auto = true +#canal.admin.register.cluster = +#canal.admin.register.name = canal.zkServers = # flush data to zk diff --git a/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalConstants.java b/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalConstants.java index 5e691d4030..ad41ef31ae 100644 --- a/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalConstants.java +++ b/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalConstants.java @@ -25,6 +25,7 @@ public class CanalConstants { public static final String CANAL_ADMIN_PASSWD = ROOT + "." + "admin.passwd"; public static final String CANAL_ADMIN_AUTO_REGISTER = ROOT + "." + "admin.register.auto"; public static final String CANAL_ADMIN_AUTO_CLUSTER = ROOT + "." + "admin.register.cluster"; + public static final String CANAL_ADMIN_REGISTER_NAME = ROOT + "." + "admin.register.name"; public static final String CANAL_ZKSERVERS = ROOT + "." + "zkServers"; public static final String CANAL_WITHOUT_NETTY = ROOT + "." + "withoutNetty"; diff --git a/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalLauncher.java b/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalLauncher.java index add34634cd..2bc78994c3 100644 --- a/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalLauncher.java +++ b/deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalLauncher.java @@ -55,6 +55,7 @@ public static void main(String[] args) { boolean autoRegister = BooleanUtils.toBoolean(CanalController.getProperty(properties, CanalConstants.CANAL_ADMIN_AUTO_REGISTER)); String autoCluster = CanalController.getProperty(properties, CanalConstants.CANAL_ADMIN_AUTO_CLUSTER); + String name = CanalController.getProperty(properties, CanalConstants.CANAL_ADMIN_REGISTER_NAME); String registerIp = CanalController.getProperty(properties, CanalConstants.CANAL_REGISTER_IP); if (StringUtils.isEmpty(registerIp)) { registerIp = AddressUtils.getHostIp(); @@ -65,7 +66,8 @@ public static void main(String[] args) { registerIp, Integer.parseInt(adminPort), autoRegister, - autoCluster); + autoCluster, + name); PlainCanal canalConfig = configClient.findServer(null); if (canalConfig == null) { throw new IllegalArgumentException("managerAddress:" + managerAddress diff --git a/deployer/src/main/resources/canal_local.properties b/deployer/src/main/resources/canal_local.properties index c6d30a4203..f92b8f3c90 100644 --- a/deployer/src/main/resources/canal_local.properties +++ b/deployer/src/main/resources/canal_local.properties @@ -8,4 +8,5 @@ canal.admin.user = admin canal.admin.passwd = 4ACFE3202A5FF5CF467898FC58AAB1D615029441 # admin auto register canal.admin.register.auto = true -canal.admin.register.cluster = \ No newline at end of file +canal.admin.register.cluster = +canal.admin.register.name = \ No newline at end of file diff --git a/instance/manager/src/main/java/com/alibaba/otter/canal/instance/manager/plain/PlainCanalConfigClient.java b/instance/manager/src/main/java/com/alibaba/otter/canal/instance/manager/plain/PlainCanalConfigClient.java index 4cc5684799..ed87bdc4af 100644 --- a/instance/manager/src/main/java/com/alibaba/otter/canal/instance/manager/plain/PlainCanalConfigClient.java +++ b/instance/manager/src/main/java/com/alibaba/otter/canal/instance/manager/plain/PlainCanalConfigClient.java @@ -35,12 +35,14 @@ public class PlainCanalConfigClient extends AbstractCanalLifeCycle implements Ca private int adminPort; private boolean autoRegister; private String autoCluster; + private String name; public PlainCanalConfigClient(String configURL, String user, String passwd, String localIp, int adminPort, - boolean autoRegister, String autoCluster){ + boolean autoRegister, String autoCluster, String name){ this(configURL, user, passwd, localIp, adminPort); this.autoCluster = autoCluster; this.autoRegister = autoRegister; + this.name = name; } public PlainCanalConfigClient(String configURL, String user, String passwd, String localIp, int adminPort){ @@ -71,7 +73,7 @@ public PlainCanal findServer(String md5) { md5 = ""; } String url = configURL + "/api/v1/config/server_polling?ip=" + localIp + "&port=" + adminPort + "&md5=" + md5 - + "®ister=" + (autoRegister ? 1 : 0) + "&cluster=" + autoCluster; + + "®ister=" + (autoRegister ? 1 : 0) + "&cluster=" + autoCluster + "&name=" + name; return queryConfig(url); }