Skip to content

Commit

Permalink
Compatible with curator5 (#8264)
Browse files Browse the repository at this point in the history
* compatible for curator5.

* dependency fix.

* fix ut.

* for compatible.

* ut fix.

* dependency fix.

* ut fix.

* remove useless import.

* ZookeeperTransporter remove adaptive mechanism.

* code clean. make ZookeeperTransporter inject at constructor.
  • Loading branch information
horizonzy committed Jul 13, 2021
1 parent daf6f25 commit 352a0df
Show file tree
Hide file tree
Showing 29 changed files with 1,051 additions and 48 deletions.
8 changes: 8 additions & 0 deletions dubbo-all/pom.xml
Expand Up @@ -143,6 +143,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
Expand Down Expand Up @@ -662,6 +669,7 @@
<include>org.apache.dubbo:dubbo-remoting-redis</include>
<include>org.apache.dubbo:dubbo-remoting-http</include>
<include>org.apache.dubbo:dubbo-remoting-zookeeper</include>
<include>org.apache.dubbo:dubbo-remoting-zookeeper-curator5</include>
<include>org.apache.dubbo:dubbo-rpc-api</include>
<include>org.apache.dubbo:dubbo-rpc-dubbo</include>
<include>org.apache.dubbo:dubbo-rpc-injvm</include>
Expand Down
5 changes: 5 additions & 0 deletions dubbo-bom/pom.xml
Expand Up @@ -173,6 +173,11 @@
<artifactId>dubbo-remoting-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions dubbo-compatible/pom.xml
Expand Up @@ -78,6 +78,11 @@
<artifactId>dubbo-remoting-zookeeper</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-rest</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml
Expand Up @@ -38,6 +38,11 @@
<artifactId>dubbo-remoting-zookeeper</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;

/**
Expand All @@ -28,6 +29,11 @@ public class ZookeeperDynamicConfigurationFactory extends AbstractDynamicConfigu

private ZookeeperTransporter zookeeperTransporter;

public ZookeeperDynamicConfigurationFactory() {
this.zookeeperTransporter = ZookeeperTransporter.getExtension();
}

@DisableInject
public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) {
this.zookeeperTransporter = zookeeperTransporter;
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.metadata.store.zookeeper;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.metadata.report.MetadataReport;
import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
Expand All @@ -28,6 +29,11 @@ public class ZookeeperMetadataReportFactory extends AbstractMetadataReportFactor

private ZookeeperTransporter zookeeperTransporter;

public ZookeeperMetadataReportFactory() {
this.zookeeperTransporter = ZookeeperTransporter.getExtension();
}

@DisableInject
public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) {
this.zookeeperTransporter = zookeeperTransporter;
}
Expand Down
7 changes: 6 additions & 1 deletion dubbo-registry/dubbo-registry-zookeeper/pom.xml
Expand Up @@ -40,6 +40,11 @@
<artifactId>dubbo-remoting-zookeeper</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
Expand All @@ -50,4 +55,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Expand Up @@ -17,22 +17,28 @@
package org.apache.dubbo.registry.zookeeper;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;

/**
* ZookeeperRegistryFactory.
*
*/
public class ZookeeperRegistryFactory extends AbstractRegistryFactory {

private ZookeeperTransporter zookeeperTransporter;

public ZookeeperRegistryFactory() {
this.zookeeperTransporter = ZookeeperTransporter.getExtension();
}

/**
* Invisible injection of zookeeper client via IOC/SPI
*
* @param zookeeperTransporter
*/
@DisableInject
public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) {
this.zookeeperTransporter = zookeeperTransporter;
}
Expand Down
2 changes: 1 addition & 1 deletion dubbo-remoting/dubbo-remoting-api/pom.xml
Expand Up @@ -47,4 +47,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Expand Up @@ -14,16 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.zookeeper.support;
package org.apache.dubbo.remoting.zookeeper;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.remoting.zookeeper.ChildListener;
import org.apache.dubbo.remoting.zookeeper.DataListener;
import org.apache.dubbo.remoting.zookeeper.StateListener;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;

import java.util.List;
import java.util.Set;
Expand Down
Expand Up @@ -14,15 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.zookeeper.support;
package org.apache.dubbo.remoting.zookeeper;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -90,7 +88,7 @@ public ZookeeperClient connect(URL url) {
* @param addressList
* @return
*/
ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) {
public ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) {

ZookeeperClient zookeeperClient = null;
for (String address : addressList) {
Expand All @@ -110,7 +108,7 @@ ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) {
* @param url such as:zookeeper://127.0.0.1:2181?127.0.0.1:8989,127.0.0.1:9999
* @return such as 127.0.0.1:2181,127.0.0.1:8989,127.0.0.1:9999
*/
List<String> getURLBackupAddress(URL url) {
public List<String> getURLBackupAddress(URL url) {
List<String> addressList = new ArrayList<String>();
addressList.add(url.getAddress());
addressList.addAll(url.getParameter(RemotingConstants.BACKUP_KEY, Collections.EMPTY_LIST));
Expand Down Expand Up @@ -176,7 +174,7 @@ URL toClientURL(URL url) {
*
* @return
*/
Map<String, ZookeeperClient> getZookeeperClientMap() {
public Map<String, ZookeeperClient> getZookeeperClientMap() {
return zookeeperClientMap;
}
}
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.dubbo.remoting.zookeeper;

import org.apache.zookeeper.Watcher;

/**
* 2019-02-26
*/
Expand All @@ -32,8 +30,6 @@ public enum EventType {
CONNECTION_LOST(12),
INITIALIZED(10);



private final int intValue; // Integer representation of value
// for sending over wire

Expand All @@ -45,21 +41,4 @@ public int getIntValue() {
return intValue;
}

public static Watcher.Event.EventType fromInt(int intValue) {
switch (intValue) {
case -1:
return Watcher.Event.EventType.None;
case 1:
return Watcher.Event.EventType.NodeCreated;
case 2:
return Watcher.Event.EventType.NodeDeleted;
case 3:
return Watcher.Event.EventType.NodeDataChanged;
case 4:
return Watcher.Event.EventType.NodeChildrenChanged;

default:
throw new RuntimeException("Invalid integer value for conversion to EventType");
}
}
}
@@ -0,0 +1,52 @@
/*
* 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.dubbo.remoting.zookeeper;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.SPI;

import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;

@SPI
public interface ZookeeperTransporter {

String CURATOR_5 = "curator5";

String CURATOR = "curator";

ZookeeperClient connect(URL url);

static ZookeeperTransporter getExtension() {
ExtensionLoader<ZookeeperTransporter> extensionLoader = getExtensionLoader(ZookeeperTransporter.class);
boolean isHighVersion = isHighVersionCurator();
if (isHighVersion) {
return extensionLoader.getExtension(CURATOR_5);
}
return extensionLoader.getExtension(CURATOR);
}

static boolean isHighVersionCurator() {
try {
Class.forName("org.apache.curator.framework.recipes.cache.CuratorCache");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

}
67 changes: 67 additions & 0 deletions dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
@@ -0,0 +1,67 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>The zookeeper curator5 remoting module of dubbo project</description>
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
<curator5_version>5.0.0</curator5_version>
<zookeeper_version>3.6.0</zookeeper_version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator5_version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator5_version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper_version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>${curator5_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

0 comments on commit 352a0df

Please sign in to comment.