You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/06/29 08:04:04 UTC

[GitHub] [incubator-eventmesh] VNBear opened a new pull request, #974: Feature/zookeeper registry

VNBear opened a new pull request, #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974

   Impl ISSUE #973 
   
   Motivation
   
   And zookeeper registry
   
   Modifications
   
   And zookeeper registry
   
   Documentation
   
   Does this pull request introduce a new feature?  yes
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] xwm1992 merged pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
xwm1992 merged PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] codecov[bot] commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1175719901

   # [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/974?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#974](https://codecov.io/gh/apache/incubator-eventmesh/pull/974?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (282ba6b) into [master](https://codecov.io/gh/apache/incubator-eventmesh/commit/dab10863a82a1828ea2e44b164086a1427abd8a3?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (dab1086) will **increase** coverage by `0.37%`.
   > The diff coverage is `76.92%`.
   
   ```diff
   @@             Coverage Diff             @@
   ##             master    #974      +/-   ##
   ===========================================
   + Coverage      8.42%   8.80%   +0.37%     
   - Complexity      534     552      +18     
   ===========================================
     Files           362     365       +3     
     Lines         23228   23376     +148     
     Branches       2546    2551       +5     
   ===========================================
   + Hits           1958    2059     +101     
   - Misses        21118   21158      +40     
   - Partials        152     159       +7     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-eventmesh/pull/974?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...registry/zookeeper/constant/ZookeeperConstant.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJlZ2lzdHJ5LXBsdWdpbi9ldmVudG1lc2gtcmVnaXN0cnktem9va2VlcGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvcmVnaXN0cnkvem9va2VlcGVyL2NvbnN0YW50L1pvb2tlZXBlckNvbnN0YW50LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...ry/zookeeper/service/ZookeeperRegistryService.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJlZ2lzdHJ5LXBsdWdpbi9ldmVudG1lc2gtcmVnaXN0cnktem9va2VlcGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvcmVnaXN0cnkvem9va2VlcGVyL3NlcnZpY2UvWm9va2VlcGVyUmVnaXN0cnlTZXJ2aWNlLmphdmE=) | `77.33% <77.33%> (ø)` | |
   | [...esh/registry/zookeeper/pojo/EventMeshInstance.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJlZ2lzdHJ5LXBsdWdpbi9ldmVudG1lc2gtcmVnaXN0cnktem9va2VlcGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvcmVnaXN0cnkvem9va2VlcGVyL3Bvam8vRXZlbnRNZXNoSW5zdGFuY2UuamF2YQ==) | `80.00% <80.00%> (ø)` | |
   | [...tandalone/broker/task/HistoryMessageClearTask.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL3Rhc2svSGlzdG9yeU1lc3NhZ2VDbGVhclRhc2suamF2YQ==) | `29.41% <0.00%> (-29.42%)` | :arrow_down: |
   | [...mesh/connector/standalone/broker/MessageQueue.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL01lc3NhZ2VRdWV1ZS5qYXZh) | `32.46% <0.00%> (-7.80%)` | :arrow_down: |
   | [...ava/org/apache/eventmesh/common/utils/IPUtils.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZXZlbnRtZXNoL2NvbW1vbi91dGlscy9JUFV0aWxzLmphdmE=) | `33.33% <0.00%> (-6.49%)` | :arrow_down: |
   | [...nnector/standalone/broker/model/MessageEntity.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL21vZGVsL01lc3NhZ2VFbnRpdHkuamF2YQ==) | `38.88% <0.00%> (-5.56%)` | :arrow_down: |
   | [...rg/apache/eventmesh/runtime/trace/LogExporter.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL3RyYWNlL0xvZ0V4cG9ydGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...core/protocol/http/consumer/EventMeshConsumer.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvaHR0cC9jb25zdW1lci9FdmVudE1lc2hDb25zdW1lci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../protocol/tcp/client/group/ClientGroupWrapper.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9ncm91cC9DbGllbnRHcm91cFdyYXBwZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | ... and [2 more](https://codecov.io/gh/apache/incubator-eventmesh/pull/974/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/974?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/974?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [dab1086...282ba6b](https://codecov.io/gh/apache/incubator-eventmesh/pull/974?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] VNBear commented on a diff in pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
VNBear commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r914704975


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,306 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   done, please approval again, tks !



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] ruanwenjun commented on a diff in pull request #974: Feature/zookeeper registry

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r910091389


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.eventmesh.registry.zookeeper.pojo;

Review Comment:
   Please add license header.



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.eventmesh.registry.zookeeper.pojo;
+
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class Instance implements Serializable {

Review Comment:
   It's better to rename to EventMeshInstance? 
   And please add lombok to this module, then you can move the get/set method of the pojo.
   ```
   compileOnly 'org.projectlombok:lombok:1.18.22'
   annotationProcessor 'org.projectlombok:lombok:1.18.22'
   ```



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle:
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+dependencies {
+    implementation 'log4j:log4j:1.2.17'
+    implementation 'org.apache.zookeeper:zookeeper:3.4.6'
+    implementation 'org.apache.curator:curator-client:4.0.1'
+    implementation 'org.apache.curator:curator-framework:4.0.1'
+    implementation 'org.apache.curator:curator-recipes:4.0.1'
+    implementation project(":eventmesh-registry-plugin:eventmesh-registry-api")
+    implementation project(":eventmesh-common")
+    testImplementation 'org.mockito:mockito-core'
+    testImplementation 'org.apache.curator:curator-test:2.12.0'

Review Comment:
   Please manage the dependency version in root/build.gradle, and I remember we already have log4j in our dependency.



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java:
##########
@@ -0,0 +1,26 @@
+package org.apache.eventmesh.registry.zookeeper.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class JsonUtils {
+
+    public static String toJSON(Object o) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        try {
+            return objectMapper.writeValueAsString(o);
+        } catch (JsonProcessingException e) {
+            return null;
+        }
+    }
+
+    public static <T> T parseJson(String json, Class<T> c) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        try {
+
+            return objectMapper.readValue(json, c);
+        } catch (JsonProcessingException e) {
+            return null;
+        }

Review Comment:
   I remember there is already a JsonUtils in EventMesh



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size());
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+            if (null == commonConfiguration) {
+                continue;
+            }
+            if (StringUtils.isBlank(commonConfiguration.namesrvAddr)) {
+                throw new RegistryException("namesrvAddr cannot be null");
+            }
+            this.serverAddr = commonConfiguration.namesrvAddr;
+            break;
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        boolean update = START_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        try {
+            RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
+            zkClient = CuratorFrameworkFactory.builder()
+                .connectString(serverAddr)
+                .retryPolicy(retryPolicy)
+                .namespace(ZookeeperConstant.NAMESPACE)
+                .build();
+            zkClient.start();
+
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][start] error", e);
+            throw new RegistryException(e.getMessage());
+        }
+    }
+
+    @Override
+    public void shutdown() throws RegistryException {
+        INIT_STATUS.compareAndSet(true, false);
+        START_STATUS.compareAndSet(true, false);
+        try {
+            zkClient.close();
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][shutdown] error", e);
+            throw new RegistryException(e.getMessage());
+        }
+        logger.info("ZookeeperRegistryService close");

Review Comment:
   ```suggestion
           logger.info("ZookeeperRegistryService closed");
   ```



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size());
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+            if (null == commonConfiguration) {
+                continue;
+            }
+            if (StringUtils.isBlank(commonConfiguration.namesrvAddr)) {
+                throw new RegistryException("namesrvAddr cannot be null");
+            }
+            this.serverAddr = commonConfiguration.namesrvAddr;
+            break;
+        }

Review Comment:
   If the `serverAddr` is null throw exception here?



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size());
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+            if (null == commonConfiguration) {
+                continue;
+            }
+            if (StringUtils.isBlank(commonConfiguration.namesrvAddr)) {
+                throw new RegistryException("namesrvAddr cannot be null");
+            }
+            this.serverAddr = commonConfiguration.namesrvAddr;
+            break;
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        boolean update = START_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        try {
+            RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
+            zkClient = CuratorFrameworkFactory.builder()
+                .connectString(serverAddr)
+                .retryPolicy(retryPolicy)
+                .namespace(ZookeeperConstant.NAMESPACE)
+                .build();
+            zkClient.start();
+
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][start] error", e);
+            throw new RegistryException(e.getMessage());
+        }
+    }
+
+    @Override
+    public void shutdown() throws RegistryException {
+        INIT_STATUS.compareAndSet(true, false);
+        START_STATUS.compareAndSet(true, false);
+        try {
+            zkClient.close();
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][shutdown] error", e);
+            throw new RegistryException(e.getMessage());
+        }
+        logger.info("ZookeeperRegistryService close");
+    }
+
+    @Override
+    public List<EventMeshDataInfo> findEventMeshInfoByCluster(String clusterName) throws RegistryException {
+        List<EventMeshDataInfo> eventMeshDataInfoList = new ArrayList<>();
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration configuration = ConfigurationContextUtil.get(key);
+            if (Objects.isNull(configuration)) {
+                continue;
+            }
+            String eventMeshName = configuration.eventMeshName;
+            try {
+                String serviceName = eventMeshName.concat("-").concat(key);
+                String servicePath = formatServicePath(clusterName, serviceName);
+
+                List<String> instances = zkClient.getChildren()
+                    .forPath(servicePath);
+
+                if (CollectionUtils.isEmpty(instances)) {
+                    continue;
+                }
+
+                for (String endpoint : instances) {
+                    String instancePath = servicePath.concat(ZookeeperConstant.PATH_SEPARATOR).concat(endpoint);
+
+                    Stat stat = new Stat();
+                    byte[] data = new byte[0];
+                    try {
+                        data = zkClient.getData()
+                            .storingStatIn(stat)
+                            .forPath(instancePath);
+                    } catch (Exception e) {
+                        logger.error("[ZookeeperRegistryService][findEventMeshInfoByCluster][findInstanceData] error", e);
+                    }
+
+                    Instance instance = JsonUtils.parseJson(new String(data, ZookeeperConstant.CHARSET_UTF8), Instance.class);
+
+                    EventMeshDataInfo eventMeshDataInfo =
+                        new EventMeshDataInfo(clusterName, serviceName, endpoint, stat.getMtime(), instance.getMetaData());
+
+                    eventMeshDataInfoList.add(eventMeshDataInfo);
+                }
+
+            } catch (Exception e) {
+                logger.error("[ZookeeperRegistryService][findEventMeshInfoByCluster] error", e);
+                throw new RegistryException(e.getMessage());
+            }
+
+        }
+        return eventMeshDataInfoList;
+    }
+
+    @Override
+    public List<EventMeshDataInfo> findAllEventMeshInfo() throws RegistryException {
+        List<EventMeshDataInfo> eventMeshDataInfoList = new ArrayList<>();
+
+        for (Map.Entry<String, EventMeshRegisterInfo> entry : eventMeshRegisterInfoMap.entrySet()) {
+
+            String serviceName = entry.getKey();
+            String clusterName = entry.getValue().getEventMeshClusterName();
+            try {
+                String servicePath = formatServicePath(clusterName, serviceName);
+
+                List<String> instances = zkClient.getChildren()
+                    .forPath(servicePath);
+
+                if (CollectionUtils.isEmpty(instances)) {
+                    continue;
+                }
+
+                for (String endpoint : instances) {
+                    String instancePath = servicePath.concat(ZookeeperConstant.PATH_SEPARATOR).concat(endpoint);
+
+                    Stat stat = new Stat();
+                    byte[] data = new byte[0];
+                    try {
+                        data = zkClient.getData()
+                            .storingStatIn(stat)
+                            .forPath(instancePath);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+
+                    Instance instance = JsonUtils.parseJson(new String(data, ZookeeperConstant.CHARSET_UTF8), Instance.class);
+
+                    EventMeshDataInfo eventMeshDataInfo =
+                        new EventMeshDataInfo(clusterName, serviceName, endpoint, stat.getMtime(), instance.getMetaData());
+
+                    eventMeshDataInfoList.add(eventMeshDataInfo);
+                }
+
+            } catch (Exception e) {
+                logger.error("[ZookeeperRegistryService][findAllEventMeshInfo] error", e);
+                throw new RegistryException(e.getMessage());
+            }
+        }
+        return eventMeshDataInfoList;
+    }
+
+    @Override
+    public Map<String, Map<String, Integer>> findEventMeshClientDistributionData(String clusterName, String group, String purpose)
+        throws RegistryException {
+        // todo find metadata
+        return null;
+    }
+
+    @Override
+    public void registerMetadata(Map<String, String> metadataMap) {
+        for (Map.Entry<String, EventMeshRegisterInfo> eventMeshRegisterInfo : eventMeshRegisterInfoMap.entrySet()) {
+            EventMeshRegisterInfo registerInfo = eventMeshRegisterInfo.getValue();
+            registerInfo.setMetadata(metadataMap);
+            this.register(registerInfo);
+        }
+    }
+
+    @Override
+    public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException {
+        try {
+
+            String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(ZookeeperConstant.IP_PORT_SEPARATOR);
+            String ip = ipPort[0];
+            Integer port = Integer.valueOf(ipPort[1]);
+            String eventMeshName = eventMeshRegisterInfo.getEventMeshName();
+            String eventMeshClusterName = eventMeshRegisterInfo.getEventMeshClusterName();
+            Map<String, Map<String, Integer>> instanceNumMap = eventMeshRegisterInfo.getEventMeshInstanceNumMap();
+            Map<String, String> metadata = eventMeshRegisterInfo.getMetadata();
+
+            // clusterName/eventMeshName/ip:port
+            String path = formatInstancePath(eventMeshClusterName, eventMeshName, eventMeshRegisterInfo.getEndPoint());
+
+            Instance instance = new Instance();
+            instance.setIp(ip);
+            instance.setPort(port);
+            instance.setInstanceNumMap(instanceNumMap);
+            instance.setMetaData(metadata);
+
+            Stat stat = zkClient.checkExists().forPath(path);
+            if (stat == null) {
+                //not exits,to create
+                zkClient.create()
+                    .creatingParentsIfNeeded()
+                    .withMode(CreateMode.EPHEMERAL)
+                    .forPath(path, JsonUtils.toJSON(instance).getBytes(ZookeeperConstant.CHARSET_UTF8));
+            } else {

Review Comment:
   This is not atomic operation, you can use `.create().orSetData()`



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;

Review Comment:
   Add a warning log here?



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size());
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+            if (null == commonConfiguration) {
+                continue;
+            }
+            if (StringUtils.isBlank(commonConfiguration.namesrvAddr)) {
+                throw new RegistryException("namesrvAddr cannot be null");
+            }
+            this.serverAddr = commonConfiguration.namesrvAddr;
+            break;
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        boolean update = START_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        try {
+            RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
+            zkClient = CuratorFrameworkFactory.builder()
+                .connectString(serverAddr)
+                .retryPolicy(retryPolicy)
+                .namespace(ZookeeperConstant.NAMESPACE)
+                .build();
+            zkClient.start();
+
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][start] error", e);
+            throw new RegistryException(e.getMessage());
+        }
+    }
+
+    @Override
+    public void shutdown() throws RegistryException {
+        INIT_STATUS.compareAndSet(true, false);
+        START_STATUS.compareAndSet(true, false);
+        try {
+            zkClient.close();
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][shutdown] error", e);
+            throw new RegistryException(e.getMessage());
+        }

Review Comment:
   ```suggestion
           try (CuratorFramework closedClient = zkClient){
   
           } catch (Exception e) {
               throw new RegistryException("ZookeeperRegistry shutdown failed" ,e);
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] Alonexc commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
Alonexc commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1174526465

   > Does anyone approve it?
   
   Well done!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] xwm1992 commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
xwm1992 commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1182692960

   @VNBear Hi, please merge this pr into `registry-zookeeper` branch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] Alonexc commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
Alonexc commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1178454975

   > copyright is a real headache o(╥﹏╥)o
   
   Take it easy. It's gonna work this time.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] Alonexc commented on a diff in pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
Alonexc commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r914372203


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java:
##########
@@ -0,0 +1,42 @@
+/*

Review Comment:
   The license seems to have an extra column of asterisks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] VNBear commented on a diff in pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
VNBear commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r914704975


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,306 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   done, please approval again, thk !



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] Alonexc commented on a diff in pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
Alonexc commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r914374457


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,306 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   @VNBear Some licenses are not in the right format, please check!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] VNBear commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
VNBear commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1173598505

   Does anyone approve it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] Alonexc commented on a diff in pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
Alonexc commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r914372936


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,306 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   Same as above!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] xwm1992 commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
xwm1992 commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1175722917

   ![image](https://user-images.githubusercontent.com/13237619/177458240-8897c959-4d13-4d09-ab6e-f4fafca76ca4.png)
   please add the header for these files. @VNBear 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] ruanwenjun commented on a diff in pull request #974: Feature/zookeeper registry

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r910087220


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.constant;
+
+import java.nio.charset.Charset;
+
+/**
+ * ZookeeperConstant.
+ */
+public class ZookeeperConstant {
+
+    public static final String NAMESPACE = "eventmesh";
+
+    public static final String IP_PORT_SEPARATOR = ":";
+
+    public static final String PATH_SEPARATOR = "/";
+
+    public static final Charset CHARSET_UTF8 = Charset.forName("utf-8");

Review Comment:
   You can directly use `StandardCharsets.UTF_8` rather than define it again in this class.



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size());
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key);
+            if (null == commonConfiguration) {
+                continue;
+            }
+            if (StringUtils.isBlank(commonConfiguration.namesrvAddr)) {
+                throw new RegistryException("namesrvAddr cannot be null");
+            }
+            this.serverAddr = commonConfiguration.namesrvAddr;
+            break;
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        boolean update = START_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        try {
+            RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
+            zkClient = CuratorFrameworkFactory.builder()
+                .connectString(serverAddr)
+                .retryPolicy(retryPolicy)
+                .namespace(ZookeeperConstant.NAMESPACE)
+                .build();
+            zkClient.start();
+
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][start] error", e);
+            throw new RegistryException(e.getMessage());

Review Comment:
   You can directly throw the exception to upper layer, since you don't need to log here, this may cause the exception boom.
   ```suggestion
               throw new RegistryException("ZookeeperRegistry starting failed", e);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] VNBear commented on a diff in pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
VNBear commented on code in PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#discussion_r910575323


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java:
##########
@@ -0,0 +1,26 @@
+package org.apache.eventmesh.registry.zookeeper.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class JsonUtils {
+
+    public static String toJSON(Object o) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        try {
+            return objectMapper.writeValueAsString(o);
+        } catch (JsonProcessingException e) {
+            return null;
+        }
+    }
+
+    public static <T> T parseJson(String json, Class<T> c) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        try {
+
+            return objectMapper.readValue(json, c);
+        } catch (JsonProcessingException e) {
+            return null;
+        }

Review Comment:
   tks, i will be  optimize



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] VNBear commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
VNBear commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1178452511

   copyright is a real headache o(╥﹏╥)o


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] VNBear commented on pull request #974: [ISSUE #973] zookeeper registry

Posted by GitBox <gi...@apache.org>.
VNBear commented on PR #974:
URL: https://github.com/apache/incubator-eventmesh/pull/974#issuecomment-1182803577

   > @VNBear Hi, please merge this pr into `registry-zookeeper` branch.
   
   ok, done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org