From 04ce01d50362f7f9f4917904d85db0b3425d3ba5 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Wed, 8 Aug 2018 17:00:34 +0800 Subject: [PATCH 01/12] tagRouter feature --- all/pom.xml | 58 +++++----- .../cluster/directory/AbstractDirectory.java | 3 + .../rpc/cluster/router/tag/TagRouter.java | 103 ++++++++++++++++++ .../cluster/router/tag/TagRouterFactory.java | 19 ++++ ...org.apache.dubbo.rpc.cluster.RouterFactory | 3 +- .../org/apache/dubbo/common/Constants.java | 4 + .../dubbo/config/AbstractInterfaceConfig.java | 1 - .../dubbo/config/AbstractReferenceConfig.java | 10 ++ .../dubbo/config/AbstractServiceConfig.java | 10 ++ .../dubbo/config/annotation/Reference.java | 5 + .../dubbo/config/annotation/Service.java | 2 + .../src/main/resources/META-INF/dubbo.xsd | 12 ++ .../integration/RegistryDirectory.java | 31 ++---- pom.xml | 81 +++++++++----- 14 files changed, 262 insertions(+), 80 deletions(-) create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java diff --git a/all/pom.xml b/all/pom.xml index a9febb59210..e36d153dd4e 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -554,35 +554,35 @@ - - maven-javadoc-plugin - ${maven_javadoc_version} - - - attach-javadoc - - jar - - - none - - - - - true - - org.apache.dubbo:dubbo-* - com.alibaba:hessian-* - - public - UTF-8 - UTF-8 - UTF-8 - - http://docs.oracle.com/javase/7/docs/api - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index 085094df228..2261fd613f9 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -28,6 +28,7 @@ import org.apache.dubbo.rpc.cluster.Router; import org.apache.dubbo.rpc.cluster.RouterFactory; import org.apache.dubbo.rpc.cluster.router.MockInvokersSelector; +import org.apache.dubbo.rpc.cluster.router.tag.TagRouter; import java.util.ArrayList; import java.util.Collections; @@ -108,6 +109,8 @@ protected void setRouters(List routers) { // append mock invoker selector routers.add(new MockInvokersSelector()); Collections.sort(routers); + // 2018-8-4 all request route by tag + routers.add(new TagRouter()); this.routers = routers; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java new file mode 100644 index 00000000000..537707dd05c --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -0,0 +1,103 @@ +package org.apache.dubbo.rpc.cluster.router.tag; + + +import org.apache.dubbo.common.Constants; +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.StringUtils; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.cluster.Router; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author kirito.moe@foxmail.com + * Date 2018-08-03 + */ +public class TagRouter implements Router, Comparable { + + private static final Logger logger = LoggerFactory.getLogger(TagRouter.class); + + private final int priority; + private final URL url; + + public static final URL ROUTER_URL = + new URL("tag" + , Constants.ANYHOST_VALUE, 0 + , Constants.ANY_VALUE) + .addParameters( + Constants.RUNTIME_KEY, "true" + ); + + public TagRouter(URL url) { + this.url = url; + this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); + } + + public TagRouter() { + this.url = ROUTER_URL; + this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); + } + + @Override + public URL getUrl() { + return url; + } + + @Override + public List> route(List> invokers, URL url, Invocation invocation) throws RpcException { + // filter + List> result = new ArrayList<>(); + try { + // static config + String tag = url.getParameter(Constants.REQUEST_TAG_KEY); + // dynamic param + if (!StringUtils.isEmpty(RpcContext.getContext().getAttachment(Constants.REQUEST_TAG_KEY))) { + tag = RpcContext.getContext().getAttachment(Constants.REQUEST_TAG_KEY); + } + // Tag request + if (!StringUtils.isEmpty(tag)) { + // Select tag invokers first + for (Invoker invoker : invokers) { + if (tag.equals(invoker.getUrl().getParameter(Constants.TAG_KEY))) { + result.add(invoker); + } + } + // If no invoker be selected, downgrade to normal invokers + if (result.isEmpty()) { + for (Invoker invoker : invokers) { + if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) { + result.add(invoker); + } + } + } + // Normal request + } else { + for (Invoker invoker : invokers) { + if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) { + result.add(invoker); + } + } + } + return result; + } catch (Exception e) { + logger.error("Route by tag error,return all invokers.", e); + } + // Downgrade to all invokers + return invokers; + } + + @Override + public int compareTo(Router o) { + if (o == null || o.getClass() != TagRouter.class) { + return 1; + } + TagRouter c = (TagRouter) o; + return this.priority == c.priority ? url.toFullString().compareTo(c.url.toFullString()) : (this.priority > c.priority ? 1 : -1); + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java new file mode 100644 index 00000000000..9b170ed1dd0 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java @@ -0,0 +1,19 @@ +package org.apache.dubbo.rpc.cluster.router.tag; + + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.cluster.Router; +import org.apache.dubbo.rpc.cluster.RouterFactory; + +/** + * @author kirito.moe@foxmail.com + * Date 2018-08-03 + */ +public class TagRouterFactory implements RouterFactory { + + public static final String NAME = "tag"; + + public Router getRouter(URL url) { + return new TagRouter(url); + } +} diff --git a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory index 0ada9c3be9c..e13851365af 100644 --- a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory +++ b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory @@ -1,3 +1,4 @@ file=org.apache.dubbo.rpc.cluster.router.file.FileRouterFactory script=org.apache.dubbo.rpc.cluster.router.script.ScriptRouterFactory -condition=org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory \ No newline at end of file +condition=org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory +tag=org.apache.dubbo.rpc.cluster.router.condition.TagRouterFactory \ No newline at end of file diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index a1c8fac34c6..95069306907 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -641,6 +641,10 @@ public class Constants { public static final String MULTICAST = "multicast"; + public static final String TAG_KEY = "tag"; + + public static final String REQUEST_TAG_KEY = "request.tag"; + /* * private Constants(){ } */ diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index 91a4a1641d6..70ab62e4493 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -522,5 +522,4 @@ public String getScope() { public void setScope(String scope) { this.scope = scope; } - } \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java index 08f3ad5e97b..db3219ae2c1 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java @@ -61,6 +61,9 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig { // group protected String group; + // requestTag + protected String requestTag; + public Boolean isCheck() { return check; } @@ -198,4 +201,11 @@ public void setGroup(String group) { this.group = group; } + public String getRequestTag() { + return requestTag; + } + + public void setRequestTag(String requestTag) { + this.requestTag = requestTag; + } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java index f23341fff17..4da1ffa89db 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java @@ -73,6 +73,9 @@ public abstract class AbstractServiceConfig extends AbstractInterfaceConfig { // serialization private String serialization; + // provider tag + protected String tag; + public String getVersion() { return version; } @@ -240,4 +243,11 @@ public void setSerialization(String serialization) { this.serialization = serialization; } + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java index 3a2fe03046b..53385932a34 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java @@ -256,4 +256,9 @@ * Protocol spring bean names */ String protocol() default ""; + + /** + * Request tag + */ + String requestTag() default ""; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java index bee838745e4..241000df0ac 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java @@ -263,4 +263,6 @@ * Registry spring bean name */ String[] registry() default {}; + + String tag() default ""; } diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd index adaa9369dfb..a766421b0be 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd @@ -216,6 +216,12 @@ + + + + + + @@ -307,6 +313,12 @@ + + + + + + diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 727bca297e2..c08feaf8c42 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -26,36 +26,18 @@ import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.Protocol; -import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.rpc.cluster.Cluster; -import org.apache.dubbo.rpc.cluster.Configurator; -import org.apache.dubbo.rpc.cluster.ConfiguratorFactory; -import org.apache.dubbo.rpc.cluster.Router; -import org.apache.dubbo.rpc.cluster.RouterFactory; +import org.apache.dubbo.rpc.*; +import org.apache.dubbo.rpc.cluster.*; import org.apache.dubbo.rpc.cluster.directory.AbstractDirectory; import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; import org.apache.dubbo.rpc.cluster.support.ClusterUtils; import org.apache.dubbo.rpc.protocol.InvokerWrapper; import org.apache.dubbo.rpc.support.RpcUtils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * RegistryDirectory - * */ public class RegistryDirectory extends AbstractDirectory implements NotifyListener { @@ -445,7 +427,8 @@ private List> route(List> invokers, String method) { List routers = getRouters(); if (routers != null) { for (Router router : routers) { - if (router.getUrl() != null) { + // If router's url not null and is not route by runtime,we filter invokers here + if (router.getUrl() != null && !router.getUrl().getParameter(Constants.RUNTIME_KEY, false)) { invokers = router.route(invokers, getConsumerUrl(), invocation); } } @@ -573,8 +556,8 @@ public List> doList(Invocation invocation) { if (forbidden) { // 1. No service provider 2. Service providers are disabled throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, - "No provider available from registry " + getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " + NetUtils.getLocalHost() - + " use dubbo version " + Version.getVersion() + ", please check status of providers(disabled, not registered or in blacklist)."); + "No provider available from registry " + getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " + NetUtils.getLocalHost() + + " use dubbo version " + Version.getVersion() + ", please check status of providers(disabled, not registered or in blacklist)."); } List> invokers = null; Map>> localMethodInvokerMap = this.methodInvokerMap; // local reference diff --git a/pom.xml b/pom.xml index 37d1f5e2799..54c54a08a0d 100644 --- a/pom.xml +++ b/pom.xml @@ -41,12 +41,18 @@ + + + + + + - https://github.com/apache/incubator-dubbo - scm:git:https://github.com/apache/incubator-dubbo.git - scm:git:https://github.com/apache/incubator-dubbo.git - HEAD - + http://git.dev.qianmi.com/commons/dubbo.git + scm:git:http://git.dev.qianmi.com/tda/freez-vcenter.git + http://git.dev.qianmi.com/commons/dubbo + freez-vcenter-1.0.0 + Development List @@ -542,18 +548,18 @@ - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - false - release - deploy - ${arguments} - - + + + + + + + + + + + + @@ -572,11 +578,11 @@ maven-clean-plugin 3.0.0 - - org.ops4j.pax.exam - maven-paxexam-plugin - 1.2.4 - + + + + + maven-dependency-plugin 2.10 @@ -603,10 +609,11 @@ org.apache.maven.plugins - maven-shade-plugin - 2.4.3 + maven-release-plugin + 2.5.2 - false + ${git.username} + ${git.password} @@ -617,4 +624,28 @@ + + + + nexus repository + intranet public groups + http://nexus.dev.qianmi.com/nexus/content/groups/public + + false + + + + + + + qianmi-releases + releases + http://nexus.dev.qianmi.com/nexus/content/repositories/releases + + + qianmi-snapshots + snapshots + http://nexus.dev.qianmi.com/nexus/content/repositories/snapshots + + From c3c9d48f594bb8b544034745fcee270791b0072c Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Wed, 8 Aug 2018 17:01:27 +0800 Subject: [PATCH 02/12] update dubbo.xsd --- .../dubbo/config/annotation/Service.java | 3 +++ .../main/resources/META-INF/compat/dubbo.xsd | 21 +++++++++++++++++-- pom.xml | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java index 241000df0ac..6f956f50c05 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java @@ -264,5 +264,8 @@ */ String[] registry() default {}; + /** + * Service tag name + */ String tag() default ""; } diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd index 30558cc7afe..ab4091aa8c9 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd @@ -2,8 +2,8 @@ + xmlns="http://dubbo.apache.org/schema/dubbo" + targetNamespace="http://dubbo.apache.org/schema/dubbo"> @@ -216,6 +216,12 @@ + + + + + + @@ -307,6 +313,12 @@ + + + + + + @@ -809,6 +821,11 @@ + + + + + diff --git a/pom.xml b/pom.xml index 54c54a08a0d..990e934c533 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ http://git.dev.qianmi.com/commons/dubbo.git - scm:git:http://git.dev.qianmi.com/tda/freez-vcenter.git + scm:git:http://git.dev.qianmi.com/commons/dubbo.git http://git.dev.qianmi.com/commons/dubbo freez-vcenter-1.0.0 From 307dcd2803de5ccdf83ff25050a14bb7a9653c46 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Thu, 9 Aug 2018 11:16:12 +0800 Subject: [PATCH 03/12] remove reference router param --- .../rpc/cluster/router/tag/TagRouter.java | 9 ++--- .../dubbo/config/AbstractReferenceConfig.java | 11 ------ .../dubbo/config/annotation/Reference.java | 5 --- .../dubbo/config/spring/AnnotationBean.java | 35 ++++++++----------- .../main/resources/META-INF/compat/dubbo.xsd | 6 ---- .../src/main/resources/META-INF/dubbo.xsd | 6 ---- 6 files changed, 17 insertions(+), 55 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index 537707dd05c..cb498db2f67 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -54,12 +54,8 @@ public List> route(List> invokers, URL url, Invocation // filter List> result = new ArrayList<>(); try { - // static config - String tag = url.getParameter(Constants.REQUEST_TAG_KEY); - // dynamic param - if (!StringUtils.isEmpty(RpcContext.getContext().getAttachment(Constants.REQUEST_TAG_KEY))) { - tag = RpcContext.getContext().getAttachment(Constants.REQUEST_TAG_KEY); - } + // Dynamic param + String tag = RpcContext.getContext().getAttachment(Constants.REQUEST_TAG_KEY); // Tag request if (!StringUtils.isEmpty(tag)) { // Select tag invokers first @@ -79,6 +75,7 @@ public List> route(List> invokers, URL url, Invocation // Normal request } else { for (Invoker invoker : invokers) { + // Can't access tag invoker,only normal invoker should be selected if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) { result.add(invoker); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java index db3219ae2c1..552ccf1e4a7 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java @@ -61,9 +61,6 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig { // group protected String group; - // requestTag - protected String requestTag; - public Boolean isCheck() { return check; } @@ -200,12 +197,4 @@ public void setGroup(String group) { checkKey("group", group); this.group = group; } - - public String getRequestTag() { - return requestTag; - } - - public void setRequestTag(String requestTag) { - this.requestTag = requestTag; - } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java index 53385932a34..3a2fe03046b 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java @@ -256,9 +256,4 @@ * Protocol spring bean names */ String protocol() default ""; - - /** - * Request tag - */ - String requestTag() default ""; } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java index 61513547c15..5a55aa6a301 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java @@ -21,19 +21,9 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.ReflectUtils; -import org.apache.dubbo.config.AbstractConfig; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ConsumerConfig; -import org.apache.dubbo.config.ModuleConfig; -import org.apache.dubbo.config.MonitorConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.ProviderConfig; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.config.*; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Service; - import org.springframework.beans.BeansException; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; @@ -76,7 +66,7 @@ public String getPackage() { public void setPackage(String annotationPackage) { this.annotationPackage = annotationPackage; this.annotationPackages = (annotationPackage == null || annotationPackage.length() == 0) ? null - : Constants.COMMA_SPLIT_PATTERN.split(annotationPackage); + : Constants.COMMA_SPLIT_PATTERN.split(annotationPackage); } @Override @@ -86,7 +76,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) - throws BeansException { + throws BeansException { if (annotationPackage == null || annotationPackage.length() == 0) { return; } @@ -135,7 +125,7 @@ public void destroy() { @Override public Object postProcessAfterInitialization(Object bean, String beanName) - throws BeansException { + throws BeansException { if (!isMatchPackage(bean)) { return bean; } @@ -144,7 +134,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) ServiceBean serviceConfig = new ServiceBean(service); serviceConfig.setRef(bean); if (void.class.equals(service.interfaceClass()) - && "".equals(service.interfaceName())) { + && "".equals(service.interfaceName())) { if (bean.getClass().getInterfaces().length > 0) { serviceConfig.setInterface(bean.getClass().getInterfaces()[0]); } else { @@ -186,6 +176,9 @@ public Object postProcessAfterInitialization(Object bean, String beanName) } serviceConfig.setProtocols(protocolConfigs); } + if (service.tag().length() > 0) { + serviceConfig.setTag(service.tag()); + } try { serviceConfig.afterPropertiesSet(); } catch (RuntimeException e) { @@ -202,7 +195,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) @Override public Object postProcessBeforeInitialization(Object bean, String beanName) - throws BeansException { + throws BeansException { if (!isMatchPackage(bean)) { return bean; } @@ -210,9 +203,9 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) for (Method method : methods) { String name = method.getName(); if (name.length() > 3 && name.startsWith("set") - && method.getParameterTypes().length == 1 - && Modifier.isPublic(method.getModifiers()) - && !Modifier.isStatic(method.getModifiers())) { + && method.getParameterTypes().length == 1 + && Modifier.isPublic(method.getModifiers()) + && !Modifier.isStatic(method.getModifiers())) { try { Reference reference = method.getAnnotation(Reference.class); if (reference != null) { @@ -262,8 +255,8 @@ private Object refer(Reference reference, Class referenceClass) { //method.ge if (referenceConfig == null) { referenceConfig = new ReferenceBean(reference); if (void.class.equals(reference.interfaceClass()) - && "".equals(reference.interfaceName()) - && referenceClass.isInterface()) { + && "".equals(reference.interfaceName()) + && referenceClass.isInterface()) { referenceConfig.setInterface(referenceClass); } if (applicationContext != null) { diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd index ab4091aa8c9..e1449545e68 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd @@ -216,12 +216,6 @@ - - - - - - diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd index a766421b0be..89966365a29 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd @@ -216,12 +216,6 @@ - - - - - - From fc4ef14596ca7e799fd3def0b5b1be8ef0812faa Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Sat, 11 Aug 2018 09:34:19 +0800 Subject: [PATCH 04/12] add Unit Test --- .../cluster/router/tag/TagRouterFactory.java | 1 + ...org.apache.dubbo.rpc.cluster.RouterFactory | 2 +- .../rpc/cluster/router/tag/TagRouterTest.java | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java index 9b170ed1dd0..f6e4393dafd 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java @@ -13,6 +13,7 @@ public class TagRouterFactory implements RouterFactory { public static final String NAME = "tag"; + @Override public Router getRouter(URL url) { return new TagRouter(url); } diff --git a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory index e13851365af..2d4717cfaa3 100644 --- a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory +++ b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory @@ -1,4 +1,4 @@ file=org.apache.dubbo.rpc.cluster.router.file.FileRouterFactory script=org.apache.dubbo.rpc.cluster.router.script.ScriptRouterFactory condition=org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory -tag=org.apache.dubbo.rpc.cluster.router.condition.TagRouterFactory \ No newline at end of file +tag=org.apache.dubbo.rpc.cluster.router.tag.TagRouterFactory \ No newline at end of file diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java new file mode 100644 index 00000000000..d58aebd60b2 --- /dev/null +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java @@ -0,0 +1,22 @@ +package org.apache.dubbo.rpc.cluster.router.tag; + +import org.junit.Before; +import org.junit.BeforeClass; + +/** + * @author kirito.moe@foxmail.com + * Date 2018-08-11 + */ +public class TagRouterTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + + +} From 4f73d773c36da3033cd41942347a70fd601ed252 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Sat, 11 Aug 2018 15:46:05 +0800 Subject: [PATCH 05/12] rollback pom.xml for merge --- all/pom.xml | 58 ++++---- .../cluster/directory/AbstractDirectory.java | 2 - .../rpc/cluster/router/tag/TagRouterTest.java | 131 ++++++++++++++++++ 3 files changed, 160 insertions(+), 31 deletions(-) diff --git a/all/pom.xml b/all/pom.xml index e36d153dd4e..a9febb59210 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -554,35 +554,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + maven-javadoc-plugin + ${maven_javadoc_version} + + + attach-javadoc + + jar + + + none + + + + + true + + org.apache.dubbo:dubbo-* + com.alibaba:hessian-* + + public + UTF-8 + UTF-8 + UTF-8 + + http://docs.oracle.com/javase/7/docs/api + + + \ No newline at end of file diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index 2261fd613f9..61fafc101f7 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -109,8 +109,6 @@ protected void setRouters(List routers) { // append mock invoker selector routers.add(new MockInvokersSelector()); Collections.sort(routers); - // 2018-8-4 all request route by tag - routers.add(new TagRouter()); this.routers = routers; } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java index d58aebd60b2..a52d5e4d78c 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java @@ -1,7 +1,22 @@ package org.apache.dubbo.rpc.cluster.router.tag; +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.cluster.Router; +import org.apache.dubbo.rpc.cluster.RouterFactory; +import org.apache.dubbo.rpc.cluster.router.MockInvoker; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; /** * @author kirito.moe@foxmail.com @@ -9,6 +24,13 @@ */ public class TagRouterTest { + private URL tagUrl = new URL("tag" + , Constants.ANYHOST_VALUE, 0 + , Constants.ANY_VALUE) + .addParameters( + Constants.RUNTIME_KEY, "true" + ); + @BeforeClass public static void setUpBeforeClass() throws Exception { } @@ -17,6 +39,115 @@ public static void setUpBeforeClass() throws Exception { public void setUp() throws Exception { } + @Test + public void testRoute_matchTag() { + + RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, "red"); + + List> invokers = new ArrayList>(); + Invoker redInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + Invoker yellowInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + Invoker blueInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + Invoker defaultInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.4:20880/com.foo.BarService")); + + invokers.add(redInvoker); + invokers.add(yellowInvoker); + invokers.add(blueInvoker); + invokers.add(defaultInvoker); + + Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); + Assert.assertTrue(filteredInvokers.contains(redInvoker)); + Assert.assertFalse(filteredInvokers.contains(yellowInvoker)); + Assert.assertFalse(filteredInvokers.contains(blueInvoker)); + Assert.assertFalse(filteredInvokers.contains(defaultInvoker)); + } + + @Test + public void testRoute_matchDefault() { + + List> invokers = new ArrayList>(); + Invoker redInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + Invoker yellowInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + Invoker blueInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + Invoker defaultInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.4:20880/com.foo.BarService")); + + invokers.add(redInvoker); + invokers.add(yellowInvoker); + invokers.add(blueInvoker); + invokers.add(defaultInvoker); + + Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); + Assert.assertTrue(filteredInvokers.contains(defaultInvoker)); + Assert.assertFalse(filteredInvokers.contains(yellowInvoker)); + Assert.assertFalse(filteredInvokers.contains(blueInvoker)); + Assert.assertFalse(filteredInvokers.contains(redInvoker)); + } + + @Test + public void testRoute_requestWithTag_shouldDowngrade() { + + RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, "black"); + + List> invokers = new ArrayList>(); + Invoker redInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + Invoker yellowInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + Invoker blueInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + Invoker defaultInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.4:20880/com.foo.BarService")); + + invokers.add(redInvoker); + invokers.add(yellowInvoker); + invokers.add(blueInvoker); + invokers.add(defaultInvoker); + + Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); + Assert.assertTrue(filteredInvokers.contains(defaultInvoker)); + Assert.assertFalse(filteredInvokers.contains(yellowInvoker)); + Assert.assertFalse(filteredInvokers.contains(blueInvoker)); + Assert.assertFalse(filteredInvokers.contains(redInvoker)); + } + + @Test + public void testRoute_requestWithoutTag_shouldNotDowngrade() { + + List> invokers = new ArrayList>(); + Invoker redInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + Invoker yellowInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + Invoker blueInvoker = new MockInvoker(URL.valueOf( + "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + + invokers.add(redInvoker); + invokers.add(yellowInvoker); + invokers.add(blueInvoker); + Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); + Assert.assertEquals(0, filteredInvokers.size()); + } + + @Test + public void testRoute_createBySpi() { + URL zkProvider = URL.valueOf("zookeeper://10.20.3.1:20880/com.foo.BarService?router=tag"); + String parameter = zkProvider.getParameter(Constants.ROUTER_KEY); + RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class).getExtension(parameter); + Router tagRouter = routerFactory.getRouter(zkProvider); + Assert.assertTrue(tagRouter instanceof TagRouter); + } } From 5d6677cdd341f330a6fa95bed87f66a957522110 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Sat, 11 Aug 2018 16:01:03 +0800 Subject: [PATCH 06/12] rollback pom.xml for merge --- pom.xml | 79 ++++++++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index 990e934c533..b55210bf5ec 100644 --- a/pom.xml +++ b/pom.xml @@ -41,17 +41,11 @@ - - - - - - - http://git.dev.qianmi.com/commons/dubbo.git - scm:git:http://git.dev.qianmi.com/commons/dubbo.git - http://git.dev.qianmi.com/commons/dubbo - freez-vcenter-1.0.0 + https://github.com/apache/incubator-dubbo + scm:git:https://github.com/apache/incubator-dubbo.git + scm:git:https://github.com/apache/incubator-dubbo.git + HEAD @@ -548,18 +542,18 @@ - - - - - - - - - - - - + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + true + false + release + deploy + ${arguments} + + @@ -578,11 +572,11 @@ maven-clean-plugin 3.0.0 - - - - - + + org.ops4j.pax.exam + maven-paxexam-plugin + 1.2.4 + maven-dependency-plugin 2.10 @@ -609,11 +603,10 @@ org.apache.maven.plugins - maven-release-plugin - 2.5.2 + maven-shade-plugin + 2.4.3 - ${git.username} - ${git.password} + false @@ -624,28 +617,4 @@ - - - - nexus repository - intranet public groups - http://nexus.dev.qianmi.com/nexus/content/groups/public - - false - - - - - - - qianmi-releases - releases - http://nexus.dev.qianmi.com/nexus/content/repositories/releases - - - qianmi-snapshots - snapshots - http://nexus.dev.qianmi.com/nexus/content/repositories/snapshots - - From b3cc0387eb4a308fbdd4c2a18aa04ac38cbc11d0 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Mon, 13 Aug 2018 09:21:53 +0800 Subject: [PATCH 07/12] fix checkstyle --- .../apache/dubbo/rpc/cluster/directory/AbstractDirectory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index 61fafc101f7..085094df228 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -28,7 +28,6 @@ import org.apache.dubbo.rpc.cluster.Router; import org.apache.dubbo.rpc.cluster.RouterFactory; import org.apache.dubbo.rpc.cluster.router.MockInvokersSelector; -import org.apache.dubbo.rpc.cluster.router.tag.TagRouter; import java.util.ArrayList; import java.util.Collections; From c887624ab805d53d7ed9d47159e4ab20ea6b36c0 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Mon, 13 Aug 2018 09:36:09 +0800 Subject: [PATCH 08/12] fix checkstyle --- .../integration/RegistryDirectory.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index c08feaf8c42..6b366b2921b 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -26,15 +26,32 @@ import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; -import org.apache.dubbo.rpc.*; -import org.apache.dubbo.rpc.cluster.*; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Protocol; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.cluster.Cluster; +import org.apache.dubbo.rpc.cluster.Configurator; +import org.apache.dubbo.rpc.cluster.ConfiguratorFactory; +import org.apache.dubbo.rpc.cluster.Router; +import org.apache.dubbo.rpc.cluster.RouterFactory; import org.apache.dubbo.rpc.cluster.directory.AbstractDirectory; import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; import org.apache.dubbo.rpc.cluster.support.ClusterUtils; import org.apache.dubbo.rpc.protocol.InvokerWrapper; import org.apache.dubbo.rpc.support.RpcUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * RegistryDirectory From be39988ac0463c36270a2f46cbdb2ce43ce3521a Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Mon, 13 Aug 2018 10:12:39 +0800 Subject: [PATCH 09/12] fix unit test --- .../rpc/cluster/router/tag/TagRouterTest.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java index a52d5e4d78c..5d81446fd16 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java @@ -44,14 +44,14 @@ public void testRoute_matchTag() { RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, "red"); - List> invokers = new ArrayList>(); - Invoker redInvoker = new MockInvoker(URL.valueOf( + List> invokers = new ArrayList<>(); + Invoker redInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); - Invoker yellowInvoker = new MockInvoker(URL.valueOf( + Invoker yellowInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); - Invoker blueInvoker = new MockInvoker(URL.valueOf( + Invoker blueInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); - Invoker defaultInvoker = new MockInvoker(URL.valueOf( + Invoker defaultInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.4:20880/com.foo.BarService")); invokers.add(redInvoker); @@ -70,14 +70,16 @@ public void testRoute_matchTag() { @Test public void testRoute_matchDefault() { - List> invokers = new ArrayList>(); - Invoker redInvoker = new MockInvoker(URL.valueOf( + RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, ""); + + List> invokers = new ArrayList<>(); + Invoker redInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); - Invoker yellowInvoker = new MockInvoker(URL.valueOf( + Invoker yellowInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); - Invoker blueInvoker = new MockInvoker(URL.valueOf( + Invoker blueInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); - Invoker defaultInvoker = new MockInvoker(URL.valueOf( + Invoker defaultInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.4:20880/com.foo.BarService")); invokers.add(redInvoker); @@ -98,14 +100,14 @@ public void testRoute_requestWithTag_shouldDowngrade() { RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, "black"); - List> invokers = new ArrayList>(); - Invoker redInvoker = new MockInvoker(URL.valueOf( + List> invokers = new ArrayList<>(); + Invoker redInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); - Invoker yellowInvoker = new MockInvoker(URL.valueOf( + Invoker yellowInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); - Invoker blueInvoker = new MockInvoker(URL.valueOf( + Invoker blueInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); - Invoker defaultInvoker = new MockInvoker(URL.valueOf( + Invoker defaultInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.4:20880/com.foo.BarService")); invokers.add(redInvoker); @@ -124,12 +126,14 @@ public void testRoute_requestWithTag_shouldDowngrade() { @Test public void testRoute_requestWithoutTag_shouldNotDowngrade() { - List> invokers = new ArrayList>(); - Invoker redInvoker = new MockInvoker(URL.valueOf( + RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, ""); + + List> invokers = new ArrayList<>(); + Invoker redInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); - Invoker yellowInvoker = new MockInvoker(URL.valueOf( + Invoker yellowInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); - Invoker blueInvoker = new MockInvoker(URL.valueOf( + Invoker blueInvoker = new MockInvoker<>(URL.valueOf( "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); invokers.add(redInvoker); From b70c32cf6a90ad3cb59a0138876097380c22dab3 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Mon, 13 Aug 2018 10:57:54 +0800 Subject: [PATCH 10/12] format import style --- .../apache/dubbo/config/spring/AnnotationBean.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java index 5a55aa6a301..7612c3302a3 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java @@ -21,7 +21,16 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.ReflectUtils; -import org.apache.dubbo.config.*; +import org.apache.dubbo.config.AbstractConfig; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ConsumerConfig; +import org.apache.dubbo.config.ModuleConfig; +import org.apache.dubbo.config.MonitorConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.ProviderConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Service; import org.springframework.beans.BeansException; From 8a2092575ad30667f4f32572d39c71304d745c1f Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Tue, 21 Aug 2018 14:01:00 +0800 Subject: [PATCH 11/12] add license&remove author info --- .../rpc/cluster/router/tag/TagRouter.java | 27 ++++++++++++------- .../cluster/router/tag/TagRouterFactory.java | 20 +++++++++++--- .../rpc/cluster/router/tag/TagRouterTest.java | 20 +++++++++++--- .../main/resources/META-INF/compat/dubbo.xsd | 6 +++++ 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index cb498db2f67..a7de9f135a5 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -1,3 +1,19 @@ +/* + * 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.rpc.cluster.router.tag; @@ -16,8 +32,7 @@ import java.util.List; /** - * @author kirito.moe@foxmail.com - * Date 2018-08-03 + * TagRouter */ public class TagRouter implements Router, Comparable { @@ -26,13 +41,7 @@ public class TagRouter implements Router, Comparable { private final int priority; private final URL url; - public static final URL ROUTER_URL = - new URL("tag" - , Constants.ANYHOST_VALUE, 0 - , Constants.ANY_VALUE) - .addParameters( - Constants.RUNTIME_KEY, "true" - ); + public static final URL ROUTER_URL = new URL("tag", Constants.ANYHOST_VALUE, 0, Constants.ANY_VALUE).addParameters(Constants.RUNTIME_KEY, "true"); public TagRouter(URL url) { this.url = url; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java index f6e4393dafd..05ad427ce6e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterFactory.java @@ -1,3 +1,19 @@ +/* + * 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.rpc.cluster.router.tag; @@ -5,10 +21,6 @@ import org.apache.dubbo.rpc.cluster.Router; import org.apache.dubbo.rpc.cluster.RouterFactory; -/** - * @author kirito.moe@foxmail.com - * Date 2018-08-03 - */ public class TagRouterFactory implements RouterFactory { public static final String NAME = "tag"; diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java index 5d81446fd16..839af44efe9 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouterTest.java @@ -1,3 +1,19 @@ +/* + * 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.rpc.cluster.router.tag; import org.apache.dubbo.common.Constants; @@ -18,10 +34,6 @@ import java.util.ArrayList; import java.util.List; -/** - * @author kirito.moe@foxmail.com - * Date 2018-08-11 - */ public class TagRouterTest { private URL tagUrl = new URL("tag" diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd index 6206048311b..290c750c93b 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd @@ -307,6 +307,12 @@ + + + + + + From 376c0ca9578315e9a3917339b180cea220d00bc3 Mon Sep 17 00:00:00 2001 From: kirito <250577914@qq.com> Date: Tue, 21 Aug 2018 15:04:34 +0800 Subject: [PATCH 12/12] trigger again --- .../java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index a7de9f135a5..38fd6166eff 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -81,7 +81,7 @@ public List> route(List> invokers, URL url, Invocation } } } - // Normal request + // Normal request } else { for (Invoker invoker : invokers) { // Can't access tag invoker,only normal invoker should be selected