Skip to content

Commit

Permalink
Merge branch 'apache:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiele committed Jun 6, 2021
2 parents 0c73ad8 + 388d2bd commit 7d981d2
Show file tree
Hide file tree
Showing 147 changed files with 2,780 additions and 634 deletions.
8 changes: 0 additions & 8 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,3 @@ Please visit the Netty web site for more information:
* http://netty.io/

Copyright 2014 The Netty Project

The product contains code form the Google Protocol Buffers project:

Please visit the following site for more information:
https://developers.google.com/protocol-buffers/

Copyright 2008 Google Inc. All rights reserved.

24 changes: 22 additions & 2 deletions dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,27 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-redis</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-http</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper</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 @@ -328,6 +342,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-container-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-container-spring</artifactId>
Expand Down Expand Up @@ -638,6 +659,7 @@
<include>org.apache.dubbo:dubbo-remoting-mina</include>
<include>org.apache.dubbo:dubbo-remoting-grizzly</include>
<include>org.apache.dubbo:dubbo-remoting-p2p</include>
<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-rpc-api</include>
Expand Down Expand Up @@ -686,8 +708,6 @@
<include>org.apache.dubbo:dubbo-serialization-gson</include>
<include>org.apache.dubbo:dubbo-serialization-msgpack</include>
<include>org.apache.dubbo:dubbo-serialization-protobuf</include>
<include>org.apache.dubbo:dubbo-configcenter-api</include>
<include>org.apache.dubbo:dubbo-configcenter-definition</include>
<include>org.apache.dubbo:dubbo-configcenter-apollo</include>
<include>org.apache.dubbo:dubbo-configcenter-zookeeper</include>
<include>org.apache.dubbo:dubbo-configcenter-consul</include>
Expand Down
33 changes: 33 additions & 0 deletions dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@
<artifactId>dubbo-remoting-etcd3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-redis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
Expand Down Expand Up @@ -268,6 +278,11 @@
<artifactId>dubbo-registry-etcd3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-eureka</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-consul</artifactId>
Expand All @@ -293,6 +308,11 @@
<artifactId>dubbo-monitor-default</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-container-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-container-spring</artifactId>
Expand All @@ -308,11 +328,19 @@
<artifactId>dubbo-container-logback</artifactId>
<version>${project.version}</version>
</dependency>

<!-- dubbo plugin -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-qos</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-auth</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-api</artifactId>
Expand Down Expand Up @@ -368,6 +396,11 @@
<artifactId>dubbo-serialization-protobuf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-msgpack</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-compatible</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ public interface Constants {
* prefix of arguments router key
*/
String ARGUMENTS = "arguments";

/**
* Url merge processor key
*/
String URL_MERGE_PROCESSOR_KEY = "urlmergeprocessor";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster.support;
package org.apache.dubbo.rpc.cluster;

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

import java.util.Map;

@SPI
public interface ProviderURLMergeProcessor {
URL mergeProviderUrl(URL providerUrl, Map<String, String> localParametersMap);
@SPI("default")
public interface UrlMergeProcessor {

/**
* Merging the URL parameters of provider and consumer
* @param remoteUrl providerUrl
* @param localParametersMap consumer url parameters
* @return
*/
URL mergeUrl(URL remoteUrl, Map<String, String> localParametersMap);

boolean accept(URL providerUrl, Map<String, String> localParametersMap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,26 @@ private URL configureIfMatch(String host, URL url) {
String currentApplication = url.getParameter(APPLICATION_KEY, url.getUsername());
if (configApplication == null || ANY_VALUE.equals(configApplication)
|| configApplication.equals(currentApplication)) {
Set<String> conditionKeys = new HashSet<String>();

Set<String> tildeKeys = new HashSet<>();
for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
String tildeKey = StringUtils.isNotEmpty(key) && key.startsWith(TILDE) ? key : null;

if (tildeKey != null || APPLICATION_KEY.equals(key) || SIDE_KEY.equals(key)) {
if (value != null && !ANY_VALUE.equals(value)
&& !value.equals(url.getParameter(tildeKey != null ? key.substring(1) : key))) {
return url;
}
}

if (tildeKey != null) {
tildeKeys.add(tildeKey);
}
}

Set<String> conditionKeys = new HashSet<>();
conditionKeys.add(CATEGORY_KEY);
conditionKeys.add(Constants.CHECK_KEY);
conditionKeys.add(DYNAMIC_KEY);
Expand All @@ -138,34 +157,15 @@ private URL configureIfMatch(String host, URL url) {
conditionKeys.add(CONFIG_VERSION_KEY);
conditionKeys.add(COMPATIBLE_CONFIG_KEY);
conditionKeys.add(INTERFACES);
for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
boolean startWithTilde = startWithTilde(key);
if (startWithTilde || APPLICATION_KEY.equals(key) || SIDE_KEY.equals(key)) {
if (startWithTilde) {
conditionKeys.add(key);
}
if (value != null && !ANY_VALUE.equals(value)
&& !value.equals(url.getParameter(startWithTilde ? key.substring(1) : key))) {
return url;
}
}
}
conditionKeys.addAll(tildeKeys);

return doConfigure(url, configuratorUrl.removeParameters(conditionKeys));
}
}
}
return url;
}

private boolean startWithTilde(String key) {
if (StringUtils.isNotEmpty(key) && key.startsWith(TILDE)) {
return true;
}
return false;
}

protected abstract URL doConfigure(URL currentUrl, URL configUrl);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,12 @@

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.cluster.UrlMergeProcessor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INVOKER_LISTENER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.URL_MERGE_PROCESSOR_KEY;

/**
* ClusterUtils
Expand All @@ -53,93 +34,17 @@ private ClusterUtils() {
}

public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
Map<String, String> map = new HashMap<String, String>();
Map<String, String> remoteMap = remoteUrl.getParameters();

if (remoteMap != null && remoteMap.size() > 0) {
map.putAll(remoteMap);
String ump = localMap.get(URL_MERGE_PROCESSOR_KEY);
UrlMergeProcessor urlMergeProcessor;

// Remove configurations from provider, some items should be affected by provider.
map.remove(THREAD_NAME_KEY);
map.remove(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY);

map.remove(THREADPOOL_KEY);
map.remove(DEFAULT_KEY_PREFIX + THREADPOOL_KEY);

map.remove(CORE_THREADS_KEY);
map.remove(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY);

map.remove(THREADS_KEY);
map.remove(DEFAULT_KEY_PREFIX + THREADS_KEY);

map.remove(QUEUES_KEY);
map.remove(DEFAULT_KEY_PREFIX + QUEUES_KEY);

map.remove(ALIVE_KEY);
map.remove(DEFAULT_KEY_PREFIX + ALIVE_KEY);

map.remove(Constants.TRANSPORTER_KEY);
map.remove(DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY);
}

if (localMap != null && localMap.size() > 0) {
Map<String, String> copyOfLocalMap = new HashMap<>(localMap);

if(map.containsKey(GROUP_KEY)){
copyOfLocalMap.remove(GROUP_KEY);
}
if(map.containsKey(VERSION_KEY)){
copyOfLocalMap.remove(VERSION_KEY);
}
if (map.containsKey(GENERIC_KEY)) {
copyOfLocalMap.remove(GENERIC_KEY);
}

copyOfLocalMap.remove(RELEASE_KEY);
copyOfLocalMap.remove(DUBBO_VERSION_KEY);
copyOfLocalMap.remove(METHODS_KEY);
copyOfLocalMap.remove(TIMESTAMP_KEY);
copyOfLocalMap.remove(TAG_KEY);

map.putAll(copyOfLocalMap);

if (remoteMap != null) {
map.put(REMOTE_APPLICATION_KEY, remoteMap.get(APPLICATION_KEY));

// Combine filters and listeners on Provider and Consumer
String remoteFilter = remoteMap.get(REFERENCE_FILTER_KEY);
String localFilter = copyOfLocalMap.get(REFERENCE_FILTER_KEY);
if (remoteFilter != null && remoteFilter.length() > 0
&& localFilter != null && localFilter.length() > 0) {
map.put(REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
}
String remoteListener = remoteMap.get(INVOKER_LISTENER_KEY);
String localListener = copyOfLocalMap.get(INVOKER_LISTENER_KEY);
if (remoteListener != null && remoteListener.length() > 0
&& localListener != null && localListener.length() > 0) {
map.put(INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
}
}
}

return remoteUrl.clearParameters().addParameters(map);
}

public static URL mergeProviderUrl(URL remoteUrl, Map<String, String> localMap) {

//urlprocessor => upc
List<ProviderURLMergeProcessor> providerURLMergeProcessors = ExtensionLoader.getExtensionLoader(ProviderURLMergeProcessor.class)
.getActivateExtension(remoteUrl, "upc");

if (providerURLMergeProcessors != null && providerURLMergeProcessors.size() > 0) {
for (ProviderURLMergeProcessor providerURLMergeProcessor : providerURLMergeProcessors) {
if (providerURLMergeProcessor.accept(remoteUrl, localMap)) {
return providerURLMergeProcessor.mergeProviderUrl(remoteUrl, localMap);
}
}
if (StringUtils.isNotEmpty(ump)) {
urlMergeProcessor = ExtensionLoader.getExtensionLoader(UrlMergeProcessor.class).getExtension(ump);
} else {
urlMergeProcessor = ExtensionLoader.getExtensionLoader(UrlMergeProcessor.class).getExtension("default");
}

return mergeUrl(remoteUrl, localMap);
return urlMergeProcessor.mergeUrl(remoteUrl, localMap);
}

}
Loading

0 comments on commit 7d981d2

Please sign in to comment.