From afe774a779bb2e4166568162b08af56b2fd52a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=98=E6=98=9F?= Date: Fri, 17 Jun 2022 18:05:49 +0800 Subject: [PATCH 01/12] add registry by zookeeper --- .../eventmesh-registry-zookeeper/build.gradle | 26 ++ .../gradle.properties | 18 ++ .../zookeeper/constant/ZKConstant.java | 34 +++ .../zookeeper/service/ZKRegistryService.java | 228 ++++++++++++++++++ .../registry/zookeeper/util/JsonUtils.java | 23 ++ ...che.eventmesh.api.registry.RegistryService | 16 ++ .../service/ZKRegistryServiceTest.java | 149 ++++++++++++ .../src/test/resources/log4j.properties | 18 ++ eventmesh-runtime/build.gradle | 1 + settings.gradle | 1 + 10 files changed, 514 insertions(+) create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/gradle.properties create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.java create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle new file mode 100644 index 0000000000..72156b51c8 --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle @@ -0,0 +1,26 @@ +/* + * 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 '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" +} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/gradle.properties b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/gradle.properties new file mode 100644 index 0000000000..1743025814 --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/gradle.properties @@ -0,0 +1,18 @@ +# 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. +# + +pluginType=registry +pluginName=zookeeper \ No newline at end of file diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.java new file mode 100644 index 0000000000..337c879ac0 --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.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; + +/** + * ZookeeperConstant. + */ +public class ZKConstant { + + public static final String NAMESPACE = "eventmesh-zcy"; + + public static final String IP_PORT_SEPARATOR = ":"; + + public static final int SESSION_TIME_OUT = 2000; + + public static final String DEFAULT_GROUP = "DEFAULT_GROUP"; + + public static final String PATH_SEPARATOR = "/"; +} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java new file mode 100644 index 0000000000..ccbb4f0cbf --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java @@ -0,0 +1,228 @@ +/* + * 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 com.google.common.collect.Maps; + +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.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.ZKConstant; +import org.apache.eventmesh.registry.zookeeper.util.JsonUtils; +import org.apache.zookeeper.CreateMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.charset.Charset; +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 java.util.stream.Collectors; + +public class ZKRegistryService implements RegistryService { + + private static final Logger logger = LoggerFactory.getLogger(ZKRegistryService.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; + + + @Override + public void init() throws RegistryException { + boolean update = INIT_STATUS.compareAndSet(false, true); + if (!update) { + return; + } + + 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) + .sessionTimeoutMs(ZKConstant.SESSION_TIME_OUT) + .retryPolicy(retryPolicy) + .namespace(ZKConstant.NAMESPACE) + .build(); + zkClient.start(); + + } catch (Exception e) { + logger.error("[ZKRegistryService][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("[ZKRegistryService][shutdown] error", e); + throw new RegistryException(e.getMessage()); + } + logger.info("ZKRegistryService close"); + } + + @Override + public List findEventMeshInfoByCluster(String clusterName) throws RegistryException { + List 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 clusterPath = formatServicePath(clusterName,serviceName); + + List instances = zkClient.getChildren().forPath(clusterPath); + + if (CollectionUtils.isEmpty(instances)) { + continue; + } + + eventMeshDataInfoList = instances.stream() + .map(p -> new EventMeshDataInfo(clusterName, serviceName, p, 0L)) + .collect(Collectors.toList()); + + } catch (Exception e) { + logger.error("[ZKRegistryService][findEventMeshInfoByCluster] error", e); + throw new RegistryException(e.getMessage()); + } + + } + return eventMeshDataInfoList; + } + + @Override + public Map> findEventMeshClientDistributionData(String clusterName, String group, String purpose) + throws RegistryException { + // todo find metadata + return null; + } + + @Override + public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException { + try { + + String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(ZKConstant.IP_PORT_SEPARATOR); + String ip = ipPort[0]; + Integer port = Integer.valueOf(ipPort[1]); + String eventMeshName = eventMeshRegisterInfo.getEventMeshName(); + String eventMeshClusterName = eventMeshRegisterInfo.getEventMeshClusterName(); + Map> instanceNumMap = eventMeshRegisterInfo.getEventMeshInstanceNumMap(); + + // clusterName/eventMeshName/ip:port + String path = formatInstancePath(eventMeshClusterName,eventMeshName,eventMeshRegisterInfo.getEndPoint()); + + HashMap dataMap = Maps.newHashMap(); + dataMap.put("ip", ip); + dataMap.put("port", port); + dataMap.put("weight", 1.0); + dataMap.put("instanceNumMap", instanceNumMap); + + zkClient.create() + .creatingParentsIfNeeded() + .withMode(CreateMode.EPHEMERAL) + .forPath(path, JsonUtils.toJSON(dataMap).getBytes(Charset.forName("utf-8"))); + + } catch (Exception e) { + logger.error("[ZKRegistryService][register] error", e); + throw new RegistryException(e.getMessage()); + } + logger.info("EventMesh successfully registered to zookeeper"); + return true; + } + + @Override + public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws RegistryException { + try { + String eventMeshName = eventMeshUnRegisterInfo.getEventMeshName(); + String eventMeshClusterName = eventMeshUnRegisterInfo.getEventMeshClusterName(); + + String path = formatInstancePath(eventMeshClusterName,eventMeshName,eventMeshUnRegisterInfo.getEndPoint()); + + zkClient.delete().forPath(path); + } catch (Exception e) { + logger.error("[ZKRegistryService][unRegister] error", e); + throw new RegistryException(e.getMessage()); + } + logger.info("EventMesh successfully logout to zookeeper"); + return true; + } + + private String formatInstancePath(String clusterName, String serviceName, String endPoint){ + return ZKConstant.PATH_SEPARATOR.concat(clusterName) + .concat(ZKConstant.PATH_SEPARATOR).concat(serviceName) + .concat(ZKConstant.PATH_SEPARATOR).concat(endPoint); + } + + private String formatServicePath(String clusterName,String serviceName){ + return ZKConstant.PATH_SEPARATOR.concat(clusterName) + .concat(ZKConstant.PATH_SEPARATOR).concat(serviceName); + } + + public String getServerAddr() { + return serverAddr; + } + + public CuratorFramework getZkClient() { + return zkClient; + } +} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java new file mode 100644 index 0000000000..0893bc9c19 --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java @@ -0,0 +1,23 @@ +package org.apache.eventmesh.registry.zookeeper.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * @Author: moxing + * @Date: 2022/6/17 13:57 + * @Description: + */ +public class JsonUtils { + + public static String toJSON(Object o) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + String string = objectMapper.writeValueAsString(o); + return string; + } catch (JsonProcessingException e) { + return null; + } + } + +} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService new file mode 100644 index 0000000000..f6fddaa3da --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService @@ -0,0 +1,16 @@ +# 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. + +zk=ZKRegistryService \ No newline at end of file diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java new file mode 100644 index 0000000000..f273b989f6 --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java @@ -0,0 +1,149 @@ +/* + * 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 com.google.common.collect.Maps; + +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.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import java.lang.reflect.Field; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ZKRegistryServiceTest { + + @Mock + private EventMeshRegisterInfo eventMeshRegisterInfo; + @Mock + private EventMeshUnRegisterInfo eventMeshUnRegisterInfo; + + private ZKRegistryService zkRegistryService; + + @Before + public void setUp() { + zkRegistryService = new ZKRegistryService(); + CommonConfiguration configuration = new CommonConfiguration(null); + configuration.namesrvAddr = "10.11.12.66:1500"; + configuration.eventMeshRegistryPluginPassword = "zookeeper"; + configuration.eventMeshRegistryPluginUsername = "zookeeper"; + configuration.eventMeshName = "eventmesh"; + ConfigurationContextUtil.putIfAbsent(ConfigurationContextUtil.HTTP, configuration); + + + Mockito.when(eventMeshRegisterInfo.getEventMeshClusterName()).thenReturn("eventmeshCluster"); + Mockito.when(eventMeshRegisterInfo.getEventMeshName()).thenReturn("eventmesh-" + ConfigurationContextUtil.HTTP); + Mockito.when(eventMeshRegisterInfo.getEndPoint()).thenReturn("127.0.0.1:8848"); + Mockito.when(eventMeshRegisterInfo.getEventMeshInstanceNumMap()).thenReturn(Maps.newHashMap()); + + + Mockito.when(eventMeshUnRegisterInfo.getEventMeshClusterName()).thenReturn("eventmeshCluster"); + Mockito.when(eventMeshUnRegisterInfo.getEventMeshName()).thenReturn("eventmesh-" + ConfigurationContextUtil.HTTP); + Mockito.when(eventMeshUnRegisterInfo.getEndPoint()).thenReturn("127.0.0.1:8848"); + } + + @After + public void after() { + zkRegistryService.shutdown(); + } + + + @Test + public void testInit() { + zkRegistryService.init(); + zkRegistryService.start(); + Assert.assertNotNull(zkRegistryService.getServerAddr()); + } + + @Test + public void testStart() { + zkRegistryService.init(); + zkRegistryService.start(); + Assert.assertNotNull(zkRegistryService.getZkClient()); + + } + + @Test + public void testShutdown() throws NoSuchFieldException, IllegalAccessException { + zkRegistryService.init(); + zkRegistryService.start(); + zkRegistryService.shutdown(); + + Class zkRegistryServiceClass = ZKRegistryService.class; + Field initStatus = zkRegistryServiceClass.getDeclaredField("INIT_STATUS"); + initStatus.setAccessible(true); + Object initStatusField = initStatus.get(zkRegistryService); + + Field startStatus = zkRegistryServiceClass.getDeclaredField("START_STATUS"); + startStatus.setAccessible(true); + Object startStatusField = startStatus.get(zkRegistryService); + + + Assert.assertFalse((Boolean.parseBoolean(initStatusField.toString()))); + Assert.assertFalse((Boolean.parseBoolean(startStatusField.toString()))); + } + + + @Test + public void testFindEventMeshInfoByCluster() { + zkRegistryService.init(); + zkRegistryService.start(); + zkRegistryService.register(eventMeshRegisterInfo); + // Setup + // Run the test + + final List result = zkRegistryService.findEventMeshInfoByCluster(eventMeshRegisterInfo.getEventMeshClusterName()); + + // Verify the results + Assert.assertNotNull(result); + } + + @Test() + public void testRegister() { + zkRegistryService.init(); + zkRegistryService.start(); + zkRegistryService.register(eventMeshRegisterInfo); + } + + @Test() + public void testUnRegister() { + zkRegistryService.init(); + zkRegistryService.start(); + boolean register = zkRegistryService.register(eventMeshRegisterInfo); + + Assert.assertTrue(register); + + boolean unRegister = zkRegistryService.unRegister(eventMeshUnRegisterInfo); + + Assert.assertTrue(unRegister); + } + + + +} \ No newline at end of file diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties new file mode 100644 index 0000000000..746168484d --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties @@ -0,0 +1,18 @@ +log4j.rootLogger=info, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=example.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=5 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n + diff --git a/eventmesh-runtime/build.gradle b/eventmesh-runtime/build.gradle index 1963b60927..599c4c90aa 100644 --- a/eventmesh-runtime/build.gradle +++ b/eventmesh-runtime/build.gradle @@ -42,6 +42,7 @@ dependencies { implementation project(":eventmesh-registry-plugin:eventmesh-registry-nacos") + implementation project(":eventmesh-registry-plugin:eventmesh-registry-zookeeper") implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-api") diff --git a/settings.gradle b/settings.gradle index 310c789254..41deef71f6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -30,6 +30,7 @@ include 'eventmesh-security-plugin:eventmesh-security-api' include 'eventmesh-security-plugin:eventmesh-security-acl' include 'eventmesh-registry-plugin:eventmesh-registry-api' include 'eventmesh-registry-plugin:eventmesh-registry-nacos' +include 'eventmesh-registry-plugin:eventmesh-registry-zookeeper' include 'eventmesh-admin' include 'eventmesh-protocol-plugin' include 'eventmesh-protocol-plugin:eventmesh-protocol-api' From 2d724cd74a06dc208f617f212f6339b0a41b144d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=B8=A3?= Date: Mon, 20 Jun 2022 10:13:20 +0800 Subject: [PATCH 02/12] Zookeeper registry classes renamed. --- ...ZKConstant.java => ZookeeperConstant.java} | 2 +- ...ice.java => ZookeeperRegistryService.java} | 34 +++++++++---------- ...che.eventmesh.api.registry.RegistryService | 2 +- ...java => ZookeeperRegistryServiceTest.java} | 8 ++--- 4 files changed, 23 insertions(+), 23 deletions(-) rename eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/{ZKConstant.java => ZookeeperConstant.java} (97%) rename eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/{ZKRegistryService.java => ZookeeperRegistryService.java} (86%) rename eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/{ZKRegistryServiceTest.java => ZookeeperRegistryServiceTest.java} (95%) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java similarity index 97% rename from eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.java rename to eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java index 337c879ac0..9d0ba356ad 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZKConstant.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java @@ -20,7 +20,7 @@ /** * ZookeeperConstant. */ -public class ZKConstant { +public class ZookeeperConstant { public static final String NAMESPACE = "eventmesh-zcy"; diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java similarity index 86% rename from eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java rename to eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index ccbb4f0cbf..569510ee20 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -33,7 +33,7 @@ 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.ZKConstant; +import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant; import org.apache.eventmesh.registry.zookeeper.util.JsonUtils; import org.apache.zookeeper.CreateMode; import org.slf4j.Logger; @@ -48,9 +48,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -public class ZKRegistryService implements RegistryService { +public class ZookeeperRegistryService implements RegistryService { - private static final Logger logger = LoggerFactory.getLogger(ZKRegistryService.class); + private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryService.class); private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false); @@ -92,14 +92,14 @@ public void start() throws RegistryException { zkClient = CuratorFrameworkFactory.builder() .connectString(serverAddr) - .sessionTimeoutMs(ZKConstant.SESSION_TIME_OUT) + .sessionTimeoutMs(ZookeeperConstant.SESSION_TIME_OUT) .retryPolicy(retryPolicy) - .namespace(ZKConstant.NAMESPACE) + .namespace(ZookeeperConstant.NAMESPACE) .build(); zkClient.start(); } catch (Exception e) { - logger.error("[ZKRegistryService][start] error", e); + logger.error("[ZookeeperRegistryService][start] error", e); throw new RegistryException(e.getMessage()); } } @@ -111,10 +111,10 @@ public void shutdown() throws RegistryException { try { zkClient.close(); } catch (Exception e) { - logger.error("[ZKRegistryService][shutdown] error", e); + logger.error("[ZookeeperRegistryService][shutdown] error", e); throw new RegistryException(e.getMessage()); } - logger.info("ZKRegistryService close"); + logger.info("ZookeeperRegistryService close"); } @Override @@ -142,7 +142,7 @@ public List findEventMeshInfoByCluster(String clusterName) th .collect(Collectors.toList()); } catch (Exception e) { - logger.error("[ZKRegistryService][findEventMeshInfoByCluster] error", e); + logger.error("[ZookeeperRegistryService][findEventMeshInfoByCluster] error", e); throw new RegistryException(e.getMessage()); } @@ -161,7 +161,7 @@ public Map> findEventMeshClientDistributionData(Str public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException { try { - String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(ZKConstant.IP_PORT_SEPARATOR); + String[] ipPort = eventMeshRegisterInfo.getEndPoint().split(ZookeeperConstant.IP_PORT_SEPARATOR); String ip = ipPort[0]; Integer port = Integer.valueOf(ipPort[1]); String eventMeshName = eventMeshRegisterInfo.getEventMeshName(); @@ -183,7 +183,7 @@ public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Regi .forPath(path, JsonUtils.toJSON(dataMap).getBytes(Charset.forName("utf-8"))); } catch (Exception e) { - logger.error("[ZKRegistryService][register] error", e); + logger.error("[ZookeeperRegistryService][register] error", e); throw new RegistryException(e.getMessage()); } logger.info("EventMesh successfully registered to zookeeper"); @@ -200,7 +200,7 @@ public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throw zkClient.delete().forPath(path); } catch (Exception e) { - logger.error("[ZKRegistryService][unRegister] error", e); + logger.error("[ZookeeperRegistryService][unRegister] error", e); throw new RegistryException(e.getMessage()); } logger.info("EventMesh successfully logout to zookeeper"); @@ -208,14 +208,14 @@ public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throw } private String formatInstancePath(String clusterName, String serviceName, String endPoint){ - return ZKConstant.PATH_SEPARATOR.concat(clusterName) - .concat(ZKConstant.PATH_SEPARATOR).concat(serviceName) - .concat(ZKConstant.PATH_SEPARATOR).concat(endPoint); + return ZookeeperConstant.PATH_SEPARATOR.concat(clusterName) + .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName) + .concat(ZookeeperConstant.PATH_SEPARATOR).concat(endPoint); } private String formatServicePath(String clusterName,String serviceName){ - return ZKConstant.PATH_SEPARATOR.concat(clusterName) - .concat(ZKConstant.PATH_SEPARATOR).concat(serviceName); + return ZookeeperConstant.PATH_SEPARATOR.concat(clusterName) + .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName); } public String getServerAddr() { diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService index f6fddaa3da..82909f46a9 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.registry.RegistryService @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -zk=ZKRegistryService \ No newline at end of file +zookeeper=org.apache.eventmesh.registry.zookeeper.service.ZookeeperRegistryService \ No newline at end of file diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java similarity index 95% rename from eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java rename to eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java index f273b989f6..0fd4776b23 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZKRegistryServiceTest.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java @@ -37,18 +37,18 @@ import java.util.List; @RunWith(MockitoJUnitRunner.class) -public class ZKRegistryServiceTest { +public class ZookeeperRegistryServiceTest { @Mock private EventMeshRegisterInfo eventMeshRegisterInfo; @Mock private EventMeshUnRegisterInfo eventMeshUnRegisterInfo; - private ZKRegistryService zkRegistryService; + private ZookeeperRegistryService zkRegistryService; @Before public void setUp() { - zkRegistryService = new ZKRegistryService(); + zkRegistryService = new ZookeeperRegistryService(); CommonConfiguration configuration = new CommonConfiguration(null); configuration.namesrvAddr = "10.11.12.66:1500"; configuration.eventMeshRegistryPluginPassword = "zookeeper"; @@ -95,7 +95,7 @@ public void testShutdown() throws NoSuchFieldException, IllegalAccessException { zkRegistryService.start(); zkRegistryService.shutdown(); - Class zkRegistryServiceClass = ZKRegistryService.class; + Class zkRegistryServiceClass = ZookeeperRegistryService.class; Field initStatus = zkRegistryServiceClass.getDeclaredField("INIT_STATUS"); initStatus.setAccessible(true); Object initStatusField = initStatus.get(zkRegistryService); From 5a77dd3dc84f356330435af9365903572fb1c9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=B8=A3?= Date: Mon, 20 Jun 2022 11:00:26 +0800 Subject: [PATCH 03/12] Zookeeper NAMESPACE update. --- .../registry/zookeeper/constant/ZookeeperConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java index 9d0ba356ad..518ab608d1 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java @@ -22,7 +22,7 @@ */ public class ZookeeperConstant { - public static final String NAMESPACE = "eventmesh-zcy"; + public static final String NAMESPACE = "eventmesh"; public static final String IP_PORT_SEPARATOR = ":"; From dfb6bc803d0f9652204f8ff792585a833870a6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=B8=A3?= Date: Mon, 20 Jun 2022 13:44:11 +0800 Subject: [PATCH 04/12] 1. Zookeeper registry build error fix; 2. Zookeeper registry test case normalization: remove external system dependencies. --- .../eventmesh-registry-zookeeper/build.gradle | 4 ++- .../service/ZookeeperRegistryServiceTest.java | 25 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle index 72156b51c8..006f9a1812 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle @@ -16,11 +16,13 @@ */ 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.mockito:mockito-core' + testImplementation 'org.apache.curator:curator-test:2.12.0' } diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java index 0fd4776b23..17d30400d9 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java @@ -24,6 +24,9 @@ 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.curator.test.TestingServer; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -46,34 +49,35 @@ public class ZookeeperRegistryServiceTest { private ZookeeperRegistryService zkRegistryService; + private TestingServer testingServer; + @Before - public void setUp() { + public void setUp() throws Exception { + testingServer = new TestingServer(1500, true); + testingServer.start(); + zkRegistryService = new ZookeeperRegistryService(); CommonConfiguration configuration = new CommonConfiguration(null); - configuration.namesrvAddr = "10.11.12.66:1500"; - configuration.eventMeshRegistryPluginPassword = "zookeeper"; - configuration.eventMeshRegistryPluginUsername = "zookeeper"; + configuration.namesrvAddr = "127.0.0.1:1500"; configuration.eventMeshName = "eventmesh"; ConfigurationContextUtil.putIfAbsent(ConfigurationContextUtil.HTTP, configuration); - Mockito.when(eventMeshRegisterInfo.getEventMeshClusterName()).thenReturn("eventmeshCluster"); Mockito.when(eventMeshRegisterInfo.getEventMeshName()).thenReturn("eventmesh-" + ConfigurationContextUtil.HTTP); Mockito.when(eventMeshRegisterInfo.getEndPoint()).thenReturn("127.0.0.1:8848"); Mockito.when(eventMeshRegisterInfo.getEventMeshInstanceNumMap()).thenReturn(Maps.newHashMap()); - Mockito.when(eventMeshUnRegisterInfo.getEventMeshClusterName()).thenReturn("eventmeshCluster"); Mockito.when(eventMeshUnRegisterInfo.getEventMeshName()).thenReturn("eventmesh-" + ConfigurationContextUtil.HTTP); Mockito.when(eventMeshUnRegisterInfo.getEndPoint()).thenReturn("127.0.0.1:8848"); } @After - public void after() { + public void after() throws Exception { zkRegistryService.shutdown(); + testingServer.close(); } - @Test public void testInit() { zkRegistryService.init(); @@ -86,7 +90,6 @@ public void testStart() { zkRegistryService.init(); zkRegistryService.start(); Assert.assertNotNull(zkRegistryService.getZkClient()); - } @Test @@ -104,7 +107,6 @@ public void testShutdown() throws NoSuchFieldException, IllegalAccessException { startStatus.setAccessible(true); Object startStatusField = startStatus.get(zkRegistryService); - Assert.assertFalse((Boolean.parseBoolean(initStatusField.toString()))); Assert.assertFalse((Boolean.parseBoolean(startStatusField.toString()))); } @@ -143,7 +145,4 @@ public void testUnRegister() { Assert.assertTrue(unRegister); } - - - } \ No newline at end of file From a7fcdb9fb88cd32b4077116ab7cba66dba08cc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=B8=A3?= Date: Tue, 21 Jun 2022 18:51:01 +0800 Subject: [PATCH 05/12] Use default sessionTimeoutMs. --- .../registry/zookeeper/service/ZookeeperRegistryService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index 569510ee20..1d732111e2 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -92,7 +92,6 @@ public void start() throws RegistryException { zkClient = CuratorFrameworkFactory.builder() .connectString(serverAddr) - .sessionTimeoutMs(ZookeeperConstant.SESSION_TIME_OUT) .retryPolicy(retryPolicy) .namespace(ZookeeperConstant.NAMESPACE) .build(); From 3dcee5c5a86359a0f5894a2794c088fdef4ef459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=B8=A3?= Date: Wed, 22 Jun 2022 20:37:24 +0800 Subject: [PATCH 06/12] Doc tag problem fix. --- .../eventmesh/registry/zookeeper/util/JsonUtils.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java index 0893bc9c19..95a01d0bac 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java @@ -3,21 +3,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -/** - * @Author: moxing - * @Date: 2022/6/17 13:57 - * @Description: - */ public class JsonUtils { public static String toJSON(Object o) { ObjectMapper objectMapper = new ObjectMapper(); try { - String string = objectMapper.writeValueAsString(o); - return string; + return objectMapper.writeValueAsString(o); } catch (JsonProcessingException e) { return null; } } - } From b41ac2d6c42b23d7c733fcaa26a6e863fcf65bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=98=E6=98=9F?= Date: Wed, 29 Jun 2022 15:18:22 +0800 Subject: [PATCH 07/12] Add the eventmesh metadata to zookeeper registry --- .../zookeeper/constant/ZookeeperConstant.java | 8 +- .../registry/zookeeper/pojo/Instance.java | 50 ++++++ .../service/ZookeeperRegistryService.java | 166 +++++++++++++----- .../registry/zookeeper/util/JsonUtils.java | 10 ++ .../service/ZookeeperRegistryServiceTest.java | 42 ++++- 5 files changed, 224 insertions(+), 52 deletions(-) create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java index 518ab608d1..4cf31c94f4 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.registry.zookeeper.constant; +import java.nio.charset.Charset; + /** * ZookeeperConstant. */ @@ -26,9 +28,7 @@ public class ZookeeperConstant { public static final String IP_PORT_SEPARATOR = ":"; - public static final int SESSION_TIME_OUT = 2000; - - public static final String DEFAULT_GROUP = "DEFAULT_GROUP"; - public static final String PATH_SEPARATOR = "/"; + + public static final Charset CHARSET_UTF8 = Charset.forName("utf-8"); } diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java new file mode 100644 index 0000000000..754393ba34 --- /dev/null +++ b/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 { + + private static final long serialVersionUID = -7953085707514834697L; + + private String ip; + + private int port; + + private Map> instanceNumMap; + + private Map metaData; + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public Map> getInstanceNumMap() { + return instanceNumMap; + } + + public void setInstanceNumMap(Map> instanceNumMap) { + this.instanceNumMap = instanceNumMap; + } + + public Map getMetaData() { + return metaData; + } + + public void setMetaData(Map metaData) { + this.metaData = metaData; + } +} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index 1d732111e2..d4c606b64b 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -18,14 +18,6 @@ package org.apache.eventmesh.registry.zookeeper.service; -import com.google.common.collect.Maps; - -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.eventmesh.api.exception.RegistryException; import org.apache.eventmesh.api.registry.RegistryService; import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo; @@ -34,19 +26,28 @@ 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.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.zookeeper.data.Stat; -import java.nio.charset.Charset; 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 java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ZookeeperRegistryService implements RegistryService { @@ -60,6 +61,7 @@ public class ZookeeperRegistryService implements RegistryService { public CuratorFramework zkClient = null; + private Map eventMeshRegisterInfoMap; @Override public void init() throws RegistryException { @@ -67,7 +69,7 @@ public void init() throws RegistryException { if (!update) { return; } - + eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size()); for (String key : ConfigurationContextUtil.KEYS) { CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key); if (null == commonConfiguration) { @@ -89,12 +91,11 @@ public void start() throws RegistryException { } try { RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5); - zkClient = CuratorFrameworkFactory.builder() - .connectString(serverAddr) - .retryPolicy(retryPolicy) - .namespace(ZookeeperConstant.NAMESPACE) - .build(); + .connectString(serverAddr) + .retryPolicy(retryPolicy) + .namespace(ZookeeperConstant.NAMESPACE) + .build(); zkClient.start(); } catch (Exception e) { @@ -126,19 +127,36 @@ public List findEventMeshInfoByCluster(String clusterName) th } String eventMeshName = configuration.eventMeshName; try { - String serviceName = eventMeshName.concat("-").concat(key); - String clusterPath = formatServicePath(clusterName,serviceName); + String servicePath = formatServicePath(clusterName, serviceName); - List instances = zkClient.getChildren().forPath(clusterPath); + List instances = zkClient.getChildren() + .forPath(servicePath); if (CollectionUtils.isEmpty(instances)) { continue; } - eventMeshDataInfoList = instances.stream() - .map(p -> new EventMeshDataInfo(clusterName, serviceName, p, 0L)) - .collect(Collectors.toList()); + 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); @@ -149,13 +167,69 @@ public List findEventMeshInfoByCluster(String clusterName) th return eventMeshDataInfoList; } + @Override + public List findAllEventMeshInfo() throws RegistryException { + List eventMeshDataInfoList = new ArrayList<>(); + + for (Map.Entry entry : eventMeshRegisterInfoMap.entrySet()) { + + String serviceName = entry.getKey(); + String clusterName = entry.getValue().getEventMeshClusterName(); + try { + String servicePath = formatServicePath(clusterName, serviceName); + + List 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> findEventMeshClientDistributionData(String clusterName, String group, String purpose) - throws RegistryException { + throws RegistryException { // todo find metadata return null; } + @Override + public void registerMetadata(Map metadataMap) { + for (Map.Entry eventMeshRegisterInfo : eventMeshRegisterInfoMap.entrySet()) { + EventMeshRegisterInfo registerInfo = eventMeshRegisterInfo.getValue(); + registerInfo.setMetadata(metadataMap); + this.register(registerInfo); + } + } + @Override public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException { try { @@ -166,21 +240,30 @@ public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Regi String eventMeshName = eventMeshRegisterInfo.getEventMeshName(); String eventMeshClusterName = eventMeshRegisterInfo.getEventMeshClusterName(); Map> instanceNumMap = eventMeshRegisterInfo.getEventMeshInstanceNumMap(); + Map metadata = eventMeshRegisterInfo.getMetadata(); // clusterName/eventMeshName/ip:port - String path = formatInstancePath(eventMeshClusterName,eventMeshName,eventMeshRegisterInfo.getEndPoint()); - - HashMap dataMap = Maps.newHashMap(); - dataMap.put("ip", ip); - dataMap.put("port", port); - dataMap.put("weight", 1.0); - dataMap.put("instanceNumMap", instanceNumMap); - - zkClient.create() + 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(dataMap).getBytes(Charset.forName("utf-8"))); + .forPath(path, JsonUtils.toJSON(instance).getBytes(ZookeeperConstant.CHARSET_UTF8)); + } else { + zkClient.setData() + .forPath(path, JsonUtils.toJSON(instance).getBytes(ZookeeperConstant.CHARSET_UTF8)); + } + eventMeshRegisterInfoMap.put(eventMeshName, eventMeshRegisterInfo); } catch (Exception e) { logger.error("[ZookeeperRegistryService][register] error", e); throw new RegistryException(e.getMessage()); @@ -189,13 +272,14 @@ public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Regi return true; } + @Override public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws RegistryException { try { String eventMeshName = eventMeshUnRegisterInfo.getEventMeshName(); String eventMeshClusterName = eventMeshUnRegisterInfo.getEventMeshClusterName(); - String path = formatInstancePath(eventMeshClusterName,eventMeshName,eventMeshUnRegisterInfo.getEndPoint()); + String path = formatInstancePath(eventMeshClusterName, eventMeshName, eventMeshUnRegisterInfo.getEndPoint()); zkClient.delete().forPath(path); } catch (Exception e) { @@ -206,15 +290,15 @@ public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throw return true; } - private String formatInstancePath(String clusterName, String serviceName, String endPoint){ + private String formatInstancePath(String clusterName, String serviceName, String endPoint) { return ZookeeperConstant.PATH_SEPARATOR.concat(clusterName) - .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName) - .concat(ZookeeperConstant.PATH_SEPARATOR).concat(endPoint); + .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName) + .concat(ZookeeperConstant.PATH_SEPARATOR).concat(endPoint); } - private String formatServicePath(String clusterName,String serviceName){ + private String formatServicePath(String clusterName, String serviceName) { return ZookeeperConstant.PATH_SEPARATOR.concat(clusterName) - .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName); + .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName); } public String getServerAddr() { diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java index 95a01d0bac..f07a77cf67 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java @@ -13,4 +13,14 @@ public static String toJSON(Object o) { return null; } } + + public static T parseJson(String json, Class c) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + + return objectMapper.readValue(json, c); + } catch (JsonProcessingException e) { + return null; + } + } } diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java index 17d30400d9..36e4b763c3 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java @@ -17,8 +17,6 @@ package org.apache.eventmesh.registry.zookeeper.service; -import com.google.common.collect.Maps; - import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo; import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo; import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo; @@ -27,6 +25,11 @@ import org.apache.curator.test.TestingServer; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -36,8 +39,7 @@ import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import java.lang.reflect.Field; -import java.util.List; +import com.google.common.collect.Maps; @RunWith(MockitoJUnitRunner.class) public class ZookeeperRegistryServiceTest { @@ -66,6 +68,10 @@ public void setUp() throws Exception { Mockito.when(eventMeshRegisterInfo.getEventMeshName()).thenReturn("eventmesh-" + ConfigurationContextUtil.HTTP); Mockito.when(eventMeshRegisterInfo.getEndPoint()).thenReturn("127.0.0.1:8848"); Mockito.when(eventMeshRegisterInfo.getEventMeshInstanceNumMap()).thenReturn(Maps.newHashMap()); + HashMap metaData = Maps.newHashMap(); + metaData.put("test","a"); + Mockito.when(eventMeshRegisterInfo.getMetadata()).thenReturn(metaData); + Mockito.when(eventMeshUnRegisterInfo.getEventMeshClusterName()).thenReturn("eventmeshCluster"); Mockito.when(eventMeshUnRegisterInfo.getEventMeshName()).thenReturn("eventmesh-" + ConfigurationContextUtil.HTTP); @@ -117,15 +123,37 @@ public void testFindEventMeshInfoByCluster() { zkRegistryService.init(); zkRegistryService.start(); zkRegistryService.register(eventMeshRegisterInfo); - // Setup - // Run the test final List result = zkRegistryService.findEventMeshInfoByCluster(eventMeshRegisterInfo.getEventMeshClusterName()); - // Verify the results Assert.assertNotNull(result); } + @Test + public void testFindAllEventMeshInfo() { + zkRegistryService.init(); + zkRegistryService.start(); + zkRegistryService.register(eventMeshRegisterInfo); + + List result = zkRegistryService.findAllEventMeshInfo(); + + Assert.assertNotNull(result); + } + + @Test + public void testRegisterMetadata(){ + zkRegistryService.init(); + zkRegistryService.start(); + zkRegistryService.register(eventMeshRegisterInfo); + Map metaData = Maps.newConcurrentMap(); + metaData.put("test","a"); + zkRegistryService.registerMetadata(metaData); + List infoList = + zkRegistryService.findEventMeshInfoByCluster(eventMeshRegisterInfo.getEventMeshClusterName()); + + Assert.assertNotNull(infoList); + } + @Test() public void testRegister() { zkRegistryService.init(); From ebdc7bd381843e62db7f9d98e3a14bc7697b277b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=98=E6=98=9F?= Date: Thu, 30 Jun 2022 16:18:01 +0800 Subject: [PATCH 08/12] optimize zookeeper registry --- build.gradle | 6 ++ .../eventmesh-registry-zookeeper/build.gradle | 17 ++-- .../zookeeper/constant/ZookeeperConstant.java | 5 -- .../zookeeper/pojo/EventMeshInstance.java | 39 +++++++++ .../registry/zookeeper/pojo/Instance.java | 50 ------------ .../service/ZookeeperRegistryService.java | 79 +++++++++---------- .../registry/zookeeper/util/JsonUtils.java | 26 ------ 7 files changed, 92 insertions(+), 130 deletions(-) create mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java delete mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java delete mode 100644 eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java diff --git a/build.gradle b/build.gradle index e49ea7bbe9..84054493f4 100644 --- a/build.gradle +++ b/build.gradle @@ -481,6 +481,12 @@ subprojects { dependency "javax.annotation:javax.annotation-api:1.3.2" dependency "com.github.seancfoley:ipaddress:5.3.3" + + dependency 'org.apache.zookeeper:zookeeper:3.4.6' + dependency 'org.apache.curator:curator-client:4.0.1' + dependency 'org.apache.curator:curator-framework:4.0.1' + dependency 'org.apache.curator:curator-recipes:4.0.1' + dependency 'org.apache.curator:curator-test:2.12.0' } } } diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle index 006f9a1812..0056539960 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/build.gradle @@ -16,13 +16,18 @@ */ 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' + + compileOnly 'org.projectlombok:lombok:1.18.22' + annotationProcessor 'org.projectlombok:lombok:1.18.22' + + implementation 'org.apache.zookeeper:zookeeper' + implementation 'org.apache.curator:curator-client' + implementation 'org.apache.curator:curator-framework' + implementation 'org.apache.curator:curator-recipes' + 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' + testImplementation 'org.apache.curator:curator-test' } diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java index 4cf31c94f4..4369ff14fa 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java @@ -17,11 +17,7 @@ package org.apache.eventmesh.registry.zookeeper.constant; -import java.nio.charset.Charset; -/** - * ZookeeperConstant. - */ public class ZookeeperConstant { public static final String NAMESPACE = "eventmesh"; @@ -30,5 +26,4 @@ public class ZookeeperConstant { public static final String PATH_SEPARATOR = "/"; - public static final Charset CHARSET_UTF8 = Charset.forName("utf-8"); } diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java new file mode 100644 index 0000000000..c64b1fcf8d --- /dev/null +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java @@ -0,0 +1,39 @@ +/* + * 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.pojo; + + +import java.io.Serializable; +import java.util.Map; + +import lombok.Data; + +@Data +public class EventMeshInstance implements Serializable { + + private static final long serialVersionUID = -7953085707514834697L; + + private String ip; + + private int port; + + private Map> instanceNumMap; + + private Map metaData; + + +} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java deleted file mode 100644 index 754393ba34..0000000000 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/Instance.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.eventmesh.registry.zookeeper.pojo; - - -import java.io.Serializable; -import java.util.Map; - -public class Instance implements Serializable { - - private static final long serialVersionUID = -7953085707514834697L; - - private String ip; - - private int port; - - private Map> instanceNumMap; - - private Map metaData; - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public Map> getInstanceNumMap() { - return instanceNumMap; - } - - public void setInstanceNumMap(Map> instanceNumMap) { - this.instanceNumMap = instanceNumMap; - } - - public Map getMetaData() { - return metaData; - } - - public void setMetaData(Map metaData) { - this.metaData = metaData; - } -} diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index d4c606b64b..dafd407664 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -25,9 +25,9 @@ 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.common.utils.JsonUtils; 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.eventmesh.registry.zookeeper.pojo.EventMeshInstance; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -38,6 +38,7 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.data.Stat; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -67,6 +68,7 @@ public class ZookeeperRegistryService implements RegistryService { public void init() throws RegistryException { boolean update = INIT_STATUS.compareAndSet(false, true); if (!update) { + logger.warn("[ZookeeperRegistryService] has been init"); return; } eventMeshRegisterInfoMap = new HashMap<>(ConfigurationContextUtil.KEYS.size()); @@ -87,6 +89,7 @@ public void init() throws RegistryException { public void start() throws RegistryException { boolean update = START_STATUS.compareAndSet(false, true); if (!update) { + logger.warn("[ZookeeperRegistryService] has been start"); return; } try { @@ -99,8 +102,7 @@ public void start() throws RegistryException { zkClient.start(); } catch (Exception e) { - logger.error("[ZookeeperRegistryService][start] error", e); - throw new RegistryException(e.getMessage()); + throw new RegistryException("ZookeeperRegistry starting failed", e); } } @@ -108,13 +110,12 @@ public void start() throws RegistryException { public void shutdown() throws RegistryException { INIT_STATUS.compareAndSet(true, false); START_STATUS.compareAndSet(true, false); - try { - zkClient.close(); + try (CuratorFramework closedClient = zkClient) { + } catch (Exception e) { - logger.error("[ZookeeperRegistryService][shutdown] error", e); - throw new RegistryException(e.getMessage()); + throw new RegistryException("ZookeeperRegistry shutdown failed", e); } - logger.info("ZookeeperRegistryService close"); + logger.info("ZookeeperRegistryService closed"); } @Override @@ -141,26 +142,26 @@ public List findEventMeshInfoByCluster(String clusterName) th String instancePath = servicePath.concat(ZookeeperConstant.PATH_SEPARATOR).concat(endpoint); Stat stat = new Stat(); - byte[] data = new byte[0]; + byte[] data; try { data = zkClient.getData() .storingStatIn(stat) .forPath(instancePath); } catch (Exception e) { - logger.error("[ZookeeperRegistryService][findEventMeshInfoByCluster][findInstanceData] error", e); + logger.warn("[ZookeeperRegistryService][findEventMeshInfoByCluster] failed for path: {}", instancePath, e); + continue; } - Instance instance = JsonUtils.parseJson(new String(data, ZookeeperConstant.CHARSET_UTF8), Instance.class); + EventMeshInstance eventMeshInstance = JsonUtils.deserialize(new String(data, StandardCharsets.UTF_8), EventMeshInstance.class); EventMeshDataInfo eventMeshDataInfo = - new EventMeshDataInfo(clusterName, serviceName, endpoint, stat.getMtime(), instance.getMetaData()); + new EventMeshDataInfo(clusterName, serviceName, endpoint, stat.getMtime(), eventMeshInstance.getMetaData()); eventMeshDataInfoList.add(eventMeshDataInfo); } } catch (Exception e) { - logger.error("[ZookeeperRegistryService][findEventMeshInfoByCluster] error", e); - throw new RegistryException(e.getMessage()); + throw new RegistryException("ZookeeperRegistry findEventMeshInfoByCluster failed",e); } } @@ -189,31 +190,32 @@ public List findAllEventMeshInfo() throws RegistryException { String instancePath = servicePath.concat(ZookeeperConstant.PATH_SEPARATOR).concat(endpoint); Stat stat = new Stat(); - byte[] data = new byte[0]; + byte[] data; try { data = zkClient.getData() .storingStatIn(stat) .forPath(instancePath); } catch (Exception e) { - e.printStackTrace(); + logger.warn("[ZookeeperRegistryService][findAllEventMeshInfo] failed for path: {}", instancePath, e); + continue; } - Instance instance = JsonUtils.parseJson(new String(data, ZookeeperConstant.CHARSET_UTF8), Instance.class); + EventMeshInstance eventMeshInstance = JsonUtils.deserialize(new String(data, StandardCharsets.UTF_8), EventMeshInstance.class); EventMeshDataInfo eventMeshDataInfo = - new EventMeshDataInfo(clusterName, serviceName, endpoint, stat.getMtime(), instance.getMetaData()); + new EventMeshDataInfo(clusterName, serviceName, endpoint, stat.getMtime(), eventMeshInstance.getMetaData()); eventMeshDataInfoList.add(eventMeshDataInfo); } } catch (Exception e) { - logger.error("[ZookeeperRegistryService][findAllEventMeshInfo] error", e); - throw new RegistryException(e.getMessage()); + throw new RegistryException("ZookeeperRegistry findAllEventMeshInfo failed", e); } } return eventMeshDataInfoList; } + @Override public Map> findEventMeshClientDistributionData(String clusterName, String group, String purpose) throws RegistryException { @@ -233,7 +235,6 @@ public void registerMetadata(Map metadataMap) { @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]); @@ -245,28 +246,21 @@ public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Regi // 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 { - zkClient.setData() - .forPath(path, JsonUtils.toJSON(instance).getBytes(ZookeeperConstant.CHARSET_UTF8)); - } + EventMeshInstance eventMeshInstance = new EventMeshInstance(); + eventMeshInstance.setIp(ip); + eventMeshInstance.setPort(port); + eventMeshInstance.setInstanceNumMap(instanceNumMap); + eventMeshInstance.setMetaData(metadata); + + zkClient.create() + .orSetData() + .creatingParentsIfNeeded() + .withMode(CreateMode.EPHEMERAL) + .forPath(path, JsonUtils.serialize(eventMeshInstance).getBytes(StandardCharsets.UTF_8)); eventMeshRegisterInfoMap.put(eventMeshName, eventMeshRegisterInfo); } catch (Exception e) { - logger.error("[ZookeeperRegistryService][register] error", e); - throw new RegistryException(e.getMessage()); + throw new RegistryException("ZookeeperRegistry register failed", e); } logger.info("EventMesh successfully registered to zookeeper"); return true; @@ -283,8 +277,7 @@ public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throw zkClient.delete().forPath(path); } catch (Exception e) { - logger.error("[ZookeeperRegistryService][unRegister] error", e); - throw new RegistryException(e.getMessage()); + throw new RegistryException("ZookeeperRegistry unRegister failed", e); } logger.info("EventMesh successfully logout to zookeeper"); return true; diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java deleted file mode 100644 index f07a77cf67..0000000000 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/util/JsonUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -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 parseJson(String json, Class c) { - ObjectMapper objectMapper = new ObjectMapper(); - try { - - return objectMapper.readValue(json, c); - } catch (JsonProcessingException e) { - return null; - } - } -} From cddabe108559d7253b2642bf3cbf10ea3b3f3e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=98=E6=98=9F?= Date: Fri, 1 Jul 2022 10:26:16 +0800 Subject: [PATCH 09/12] optimize zookeeper registry checkstyle --- .../zookeeper/pojo/EventMeshInstance.java | 27 +++++++------- .../service/ZookeeperRegistryService.java | 36 ++++++++++--------- .../service/ZookeeperRegistryServiceTest.java | 34 +++++++++--------- .../src/test/resources/log4j.properties | 24 ++++++++++--- 4 files changed, 71 insertions(+), 50 deletions(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java index c64b1fcf8d..691272a32a 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java @@ -1,19 +1,22 @@ /* - * 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 + * * 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. * - * 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.pojo; diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index dafd407664..bbed6dc434 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -1,18 +1,20 @@ /* - * 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 + * * 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. * - * 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; @@ -111,7 +113,7 @@ public void shutdown() throws RegistryException { INIT_STATUS.compareAndSet(true, false); START_STATUS.compareAndSet(true, false); try (CuratorFramework closedClient = zkClient) { - + // } catch (Exception e) { throw new RegistryException("ZookeeperRegistry shutdown failed", e); } @@ -161,7 +163,7 @@ public List findEventMeshInfoByCluster(String clusterName) th } } catch (Exception e) { - throw new RegistryException("ZookeeperRegistry findEventMeshInfoByCluster failed",e); + throw new RegistryException("ZookeeperRegistry findEventMeshInfoByCluster failed", e); } } @@ -243,15 +245,15 @@ public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Regi Map> instanceNumMap = eventMeshRegisterInfo.getEventMeshInstanceNumMap(); Map metadata = eventMeshRegisterInfo.getMetadata(); - // clusterName/eventMeshName/ip:port - String path = formatInstancePath(eventMeshClusterName, eventMeshName, eventMeshRegisterInfo.getEndPoint()); - EventMeshInstance eventMeshInstance = new EventMeshInstance(); eventMeshInstance.setIp(ip); eventMeshInstance.setPort(port); eventMeshInstance.setInstanceNumMap(instanceNumMap); eventMeshInstance.setMetaData(metadata); + // clusterName/eventMeshName/ip:port + final String path = formatInstancePath(eventMeshClusterName, eventMeshName, eventMeshRegisterInfo.getEndPoint()); + zkClient.create() .orSetData() .creatingParentsIfNeeded() diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java index 36e4b763c3..8a30c5a02d 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java @@ -1,18 +1,20 @@ /* - * 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 + * * 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. * - * 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; @@ -69,7 +71,7 @@ public void setUp() throws Exception { Mockito.when(eventMeshRegisterInfo.getEndPoint()).thenReturn("127.0.0.1:8848"); Mockito.when(eventMeshRegisterInfo.getEventMeshInstanceNumMap()).thenReturn(Maps.newHashMap()); HashMap metaData = Maps.newHashMap(); - metaData.put("test","a"); + metaData.put("test", "a"); Mockito.when(eventMeshRegisterInfo.getMetadata()).thenReturn(metaData); @@ -135,18 +137,18 @@ public void testFindAllEventMeshInfo() { zkRegistryService.start(); zkRegistryService.register(eventMeshRegisterInfo); - List result = zkRegistryService.findAllEventMeshInfo(); + List result = zkRegistryService.findAllEventMeshInfo(); Assert.assertNotNull(result); } @Test - public void testRegisterMetadata(){ + public void testRegisterMetadata() { zkRegistryService.init(); zkRegistryService.start(); zkRegistryService.register(eventMeshRegisterInfo); Map metaData = Maps.newConcurrentMap(); - metaData.put("test","a"); + metaData.put("test", "a"); zkRegistryService.registerMetadata(metaData); List infoList = zkRegistryService.findEventMeshInfoByCluster(eventMeshRegisterInfo.getEventMeshClusterName()); diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties index 746168484d..862b487732 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties @@ -1,18 +1,32 @@ -log4j.rootLogger=info, stdout, R +# +# /* +# * 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. +# */ +# +log4j.rootLogger=info, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout - # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n - log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log - log4j.appender.R.MaxFileSize=100KB # Keep one backup file log4j.appender.R.MaxBackupIndex=5 - log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n From 3c62fd164c8219bb36e7a398e0b508aaaffa12dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=98=E6=98=9F?= Date: Wed, 6 Jul 2022 17:55:17 +0800 Subject: [PATCH 10/12] format licenses & add know-dependencies --- .../zookeeper/pojo/EventMeshInstance.java | 27 ++++++++------- .../service/ZookeeperRegistryService.java | 27 ++++++++------- .../service/ZookeeperRegistryServiceTest.java | 27 ++++++++------- .../src/test/resources/log4j.properties | 33 ++++++++++--------- tools/dependency-check/known-dependencies.txt | 10 +++++- 5 files changed, 65 insertions(+), 59 deletions(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java index 691272a32a..a6825e7017 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java @@ -1,19 +1,18 @@ /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * his 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 * - * * 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. + * 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. * */ diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index bbed6dc434..9476569cb9 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -1,19 +1,18 @@ /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * his 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 * - * * 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. + * 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. * */ diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java index 8a30c5a02d..5bcc6e73a7 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java @@ -1,19 +1,18 @@ /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * his 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 * - * * 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. + * 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. * */ diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties index 862b487732..43960f03f9 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties @@ -1,21 +1,22 @@ # -# /* -# * 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. -# */ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# his 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. +# +# + + log4j.rootLogger=info, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender diff --git a/tools/dependency-check/known-dependencies.txt b/tools/dependency-check/known-dependencies.txt index 7179efd38c..258c3edf60 100644 --- a/tools/dependency-check/known-dependencies.txt +++ b/tools/dependency-check/known-dependencies.txt @@ -131,4 +131,12 @@ snakeyaml-1.23.jar snakeyaml-1.30.jar bcpkix-jdk15on-1.69.jar bcprov-jdk15on-1.69.jar -bcutil-jdk15on-1.69.jar \ No newline at end of file +bcutil-jdk15on-1.69.jar +curator-client-4.0.1.jar +curator-framework-4.0.1.jar +curator-recipes-4.0.1.jar +zookeeper-3.4.6.jar +jline-0.9.94.jar +log4j-1.2.16.jar +netty-3.7.0.Final.jar +slf4j-log4j12-1.6.1.jar \ No newline at end of file From 63d17735f45796e3ce77688adc028688234a0e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=98=E6=98=9F?= Date: Fri, 8 Jul 2022 09:55:26 +0800 Subject: [PATCH 11/12] format licenses --- .../zookeeper/pojo/EventMeshInstance.java | 25 +++++++++---------- .../service/ZookeeperRegistryService.java | 25 +++++++++---------- .../service/ZookeeperRegistryServiceTest.java | 25 +++++++++---------- .../src/test/resources/log4j.properties | 25 +++++++++---------- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java index a6825e7017..46f0eb27e8 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/pojo/EventMeshInstance.java @@ -1,19 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * his 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 + * 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. + * 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.pojo; diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java index 9476569cb9..d5da2126fa 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java @@ -1,19 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * his 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 + * 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. + * 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; diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java index 5bcc6e73a7..1d04746399 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryServiceTest.java @@ -1,19 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * his 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 + * 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. + * 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; diff --git a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties index 43960f03f9..6a06772a50 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties +++ b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/test/resources/log4j.properties @@ -1,19 +1,18 @@ # -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# his 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 +# 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. +# 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. # From 4dd5e893cd84bfaa77649259024c5ba7be4c9e9b Mon Sep 17 00:00:00 2001 From: xwm1992 Date: Tue, 8 Nov 2022 00:30:00 +0800 Subject: [PATCH 12/12] update known-dependencies --- tools/dependency-check/known-dependencies.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/dependency-check/known-dependencies.txt b/tools/dependency-check/known-dependencies.txt index e4f31926b8..8ff673c037 100644 --- a/tools/dependency-check/known-dependencies.txt +++ b/tools/dependency-check/known-dependencies.txt @@ -105,6 +105,7 @@ metrics-json-4.1.0.jar nacos-auth-plugin-2.1.0.jar nacos-client-2.1.0.jar nacos-encryption-plugin-2.1.0.jar +netty-3.7.0.Final.jar netty-3.10.6.Final.jar netty-all-4.1.79.Final.jar netty-buffer-4.1.79.Final.jar