Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3069 #3075

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
683af85
fix #3069
CrazyHZM Dec 27, 2018
b4dd0cf
Add comment
chickenlj Dec 27, 2018
cdee4a2
Fix UT
chickenlj Dec 27, 2018
0282a42
Revert demo changes
chickenlj Dec 27, 2018
c18b1cf
Revert code to avoid NPE in RPC wire after providers are cleared.
chickenlj Dec 27, 2018
4cf3e38
make ListenableRouter code thread safe
chickenlj Dec 27, 2018
dc1dec5
Fix UT
chickenlj Dec 27, 2018
0b700a7
Remove assert check to continue with execute.
chickenlj Dec 27, 2018
9c0e3ef
solve compile error
chickenlj Dec 27, 2018
c255ad6
Merge pull request #3077, Code review around AbstractConfiguratorList…
beiwei30 Dec 27, 2018
7aa0717
add Apache license
chickenlj Dec 27, 2018
5cfb963
edit comments , edit metadata identify path
cvictory Dec 27, 2018
d0033d1
Merge branch 'master' of github.com:apache/incubator-dubbo
cvictory Dec 27, 2018
70b8d0c
temporarily ignore UT ZookeeperMetadataReportTest
chickenlj Dec 27, 2018
ca7d641
temporarily ignore UT RegistryDataConfigTest
chickenlj Dec 27, 2018
5ea4fa5
add license and reformat
chickenlj Dec 27, 2018
cd56069
add unit test to dubbo-registry/dubbo-registry-api and dubbo-registry…
lixiaojiee Dec 28, 2018
2fbdecf
fix async store test fail issue
cvictory Dec 28, 2018
09cbf8f
fix async store test fail issue
cvictory Dec 28, 2018
5c54c68
Change the configurtion to work default with multicast address (#3092)
khanimteyaz Dec 29, 2018
50afb87
Merge pull request #3083 beiwei30/incubator-dubbo, more code review.
beiwei30 Dec 29, 2018
7c72a36
Use regular expressions to judge
CrazyHZM Dec 29, 2018
f99f015
change @AsyncFor annotation from TYPE to METHOD
chickenlj Dec 29, 2018
cba6642
fix #3069
CrazyHZM Dec 27, 2018
e9e7277
Use regular expressions to judge
CrazyHZM Dec 29, 2018
0fd8140
Merge branch 'emptyInput' of https://github.com/CrazyHZM/incubator-du…
CrazyHZM Dec 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;

Expand Down Expand Up @@ -66,10 +67,6 @@ public void initWithRouters(List<Router> builtinRouters) {
this.sort();
}

public void addRouter(Router router) {
this.routers.add(router);
}

/**
* If we use route:// protocol in version before 2.7.0, each URL will generate a Router instance, so we should
* keep the routers up to date, that is, each time router URLs changes, we should update the routers list, only
Expand All @@ -79,12 +76,11 @@ public void addRouter(Router router) {
* @param routers routers from 'router://' rules in 2.6.x or before.
*/
public void addRouters(List<Router> routers) {
// FIXME will sort cause concurrent problem? since it's kind of a write operation.
List<Router> newRouters = new CopyOnWriteArrayList<>();
newRouters.addAll(builtinRouters);
newRouters.addAll(routers);
CollectionUtils.sort(routers);
this.routers = newRouters;
this.sort();
}

private void sort() {
Expand All @@ -110,9 +106,7 @@ public List<Invoker<T>> route(URL url, Invocation invocation) {
* Notify whenever addresses in registry change.
*/
public void setInvokers(List<Invoker<T>> invokers) {
if (invokers != null) {
this.invokers = invokers;
routers.forEach(router -> router.notify(invokers));
}
this.invokers = (invokers == null ? Collections.emptyList() : invokers);
routers.forEach(router -> router.notify(this.invokers));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.dubbo.rpc.cluster.Router;
import org.apache.dubbo.rpc.cluster.RouterChain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -96,8 +96,7 @@ public void setRouterChain(RouterChain<T> routerChain) {
}

protected void addRouters(List<Router> routers) {
// copy list
routers = routers == null ? new ArrayList<>() : new ArrayList<>(routers);
routers = routers == null ? Collections.emptyList() : routers;
routerChain.addRouters(routers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class AppRouterFactory implements RouterFactory {
public static final String NAME = "app";

private Router router;
private volatile Router router;

@Override
public Router getRouter(URL url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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.Assert;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.configcenter.ConfigChangeEvent;
import org.apache.dubbo.configcenter.ConfigChangeType;
import org.apache.dubbo.configcenter.ConfigurationListener;
Expand Down Expand Up @@ -124,14 +124,15 @@ private void generateConditions(ConditionRouterRule rule, List<ConditionRouter>
}
}

private void init(String ruleKey) {
Assert.notEmptyString(ruleKey, "router rule's name cannot be null");
String router = ruleKey + Constants.ROUTERS_SUFFIX;
String rule = configuration.getConfig(router);
private synchronized void init(String ruleKey) {
if (StringUtils.isEmpty(ruleKey)) {
return;
}
String routerKey = ruleKey + Constants.ROUTERS_SUFFIX;
configuration.addListener(routerKey, this);
String rule = configuration.getConfig(routerKey);
if (rule != null) {
this.process(new ConfigChangeEvent(router, rule));
this.process(new ConfigChangeEvent(routerKey, rule));
}

configuration.addListener(router, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ public Router getRouter(URL url) {
}
String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath())));

// FIXME: this code looks useless
boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false);
URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameter(Constants.RUNTIME_KEY, runtime).addParameterAndEncoded(Constants.RULE_KEY, rule);
URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type)
.addParameter(Constants.RUNTIME_KEY, runtime)
.addParameterAndEncoded(Constants.RULE_KEY, rule);

return routerFactory.getRouter(script);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ScriptRouter extends AbstractRouter {
public static final String NAME = "SCRIPT_ROUTER";
private static final Logger logger = LoggerFactory.getLogger(ScriptRouter.class);

private static final Map<String, ScriptEngine> engines = new ConcurrentHashMap<String, ScriptEngine>();
private static final Map<String, ScriptEngine> engines = new ConcurrentHashMap<>();

private final ScriptEngine engine;

Expand All @@ -62,13 +62,13 @@ public ScriptRouter(URL url) {
type = Constants.DEFAULT_SCRIPT_TYPE_KEY;
}
if (rule == null || rule.length() == 0) {
throw new IllegalStateException(new IllegalStateException("route rule can not be empty. rule:" + rule));
throw new IllegalStateException("route rule can not be empty. rule:" + rule);
}
ScriptEngine engine = engines.get(type);
if (engine == null) {
engine = new ScriptEngineManager().getEngineByName(type);
if (engine == null) {
throw new IllegalStateException(new IllegalStateException("Unsupported route rule type: " + type + ", rule: " + rule));
throw new IllegalStateException("unsupported route rule type: " + type + ", rule: " + rule);
}
engines.put(type, engine);
}
Expand All @@ -85,7 +85,7 @@ public URL getUrl() {
@SuppressWarnings("unchecked")
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
try {
List<Invoker<T>> invokersCopy = new ArrayList<Invoker<T>>(invokers);
List<Invoker<T>> invokersCopy = new ArrayList<>(invokers);
Compilable compilable = (Compilable) engine;
Bindings bindings = engine.createBindings();
bindings.put("invokers", invokersCopy);
Expand All @@ -105,8 +105,8 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}
return invokersCopy;
} catch (ScriptException e) {
//fail then ignore rule .invokers.
logger.error("route error , rule has been ignored. rule: " + rule + ", method:" + invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e);
logger.error("route error, rule has been ignored. rule: " + rule + ", method:" +
invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e);
return invokers;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static org.apache.dubbo.common.Constants.TAG_KEY;

/**
*
* TagRouter
*/
public class TagRouter extends AbstractRouter implements Comparable<Router>, ConfigurationListener {
public static final String NAME = "TAG_ROUTER";
Expand Down Expand Up @@ -117,10 +117,9 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}
// FAILOVER: return all Providers without any tags.
else {
List<Invoker<T>> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(), tagRouterRule
.getAddresses()));
return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl()
.getParameter(TAG_KEY)));
List<Invoker<T>> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(),
tagRouterRule.getAddresses()));
return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY)));
}
} else {
// List<String> addresses = tagRouterRule.filter(providerApp);
Expand All @@ -137,10 +136,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}
return filterInvoker(result, invoker -> {
String localTag = invoker.getUrl().getParameter(TAG_KEY);
if (StringUtils.isEmpty(localTag) || !tagRouterRule.getTagNames().contains(localTag)) {
return true;
}
return false;
return StringUtils.isEmpty(localTag) || !tagRouterRule.getTagNames().contains(localTag);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ private void initInvokers(URL url, boolean invoker1Status, boolean invoker2Statu

private void initDic(URL url) {
// FIXME: this exposes the design flaw in RouterChain
dic = new StaticDirectory<>(url, invokers);
URL dicInitUrl = URL.valueOf("consumer://localhost:20880/org.apache.dubbo.rpc.cluster.router.file.FileRouterEngineTest?application=FileRouterEngineTest");
dic = new StaticDirectory<>(dicInitUrl, invokers);
dic.buildRouterChain();
dic.getRouterChain().initWithRouters(Arrays.asList(routerFactory.getRouter(url)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class AbstractClusterInvokerTest {
AbstractClusterInvoker<IHelloService> cluster_nocheck;
StaticDirectory<IHelloService> dic;
RpcInvocation invocation = new RpcInvocation();
URL url = URL.valueOf("registry://localhost:9090/org.apache.dubbo.rpc.cluster.support.AbstractClusterInvokerTest.IHelloService");
URL url = URL.valueOf("registry://localhost:9090/org.apache.dubbo.rpc.cluster.support.AbstractClusterInvokerTest.IHelloService?refer=" + URL.encode("application=abstractClusterInvokerTest"));

Invoker<IHelloService> invoker1;
Invoker<IHelloService> invoker2;
Expand Down Expand Up @@ -221,8 +222,9 @@ public void testSelect_multiInvokers() throws Exception {
@Test
public void testCloseAvailablecheck() {
LoadBalance lb = mock(LoadBalance.class);
given(lb.select(invokers, url, invocation)).willReturn(invoker1);

Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
URL tmpUrl = url.clearParameters().addParameters(queryMap).removeParameter(Constants.MONITOR_KEY);
given(lb.select(invokers, tmpUrl, invocation)).willReturn(invoker1);
initlistsize5();

Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

/**
* TODO This definition should better be placed in module 'dubbo-config-api', but only can be done when "rpc" dependencies are removed from "dubbo-config-api"
* If an interface is annotated with AsyncFor, it will be treated as an async counterpart for the sync one.
* If a method is annotated with AsyncFor, it will be treated as an async counterpart for the sync specified in value.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Target({ElementType.METHOD})
public @interface AsyncFor {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public static ClassLoader getClassLoader(Class<?> clazz) {
// getClassLoader() returning null indicates the bootstrap ClassLoader
try {
cl = ClassLoader.getSystemClassLoader();
}
catch (Throwable ex) {
} catch (Throwable ex) {
// Cannot access system ClassLoader - oh well, maybe the caller can live with null...
}
}
Expand Down Expand Up @@ -265,10 +264,14 @@ public static boolean isPrimitive(Class<?> type) {
}

public static Object convertPrimitive(Class<?> type, String value) {
if (type == char.class || type == Character.class) {
if (value == null) {
return null;
} else if (type == char.class || type == Character.class) {
return value.length() > 0 ? value.charAt(0) : '\0';
} else if (type == boolean.class || type == Boolean.class) {
return Boolean.valueOf(value);
} else if (!isNumber(value)) {
return null;
} else if (type == byte.class || type == Byte.class) {
return Byte.valueOf(value);
} else if (type == short.class || type == Short.class) {
Expand All @@ -285,6 +288,11 @@ public static Object convertPrimitive(Class<?> type, String value) {
return value;
}

public static boolean isNumber(String str) {
String reg = "^[0-9]+(.[0-9]+)?$";
return str.matches(reg);
}

/**
* We only check boolean value at this moment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.apache.dubbo.common.Constants.CATEGORY_KEY;
import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY;
import static org.apache.dubbo.common.Constants.DEFAULT_CATEGORY;
import static org.apache.dubbo.common.Constants.OVERRIDE_PROTOCOL;
import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.common.Constants.ROUTERS_CATEGORY;
import static org.apache.dubbo.common.Constants.ROUTE_PROTOCOL;

public class UrlUtils {

/**
Expand Down Expand Up @@ -343,14 +351,14 @@ public static URL getEmptyUrl(String service, String category) {
service = service.substring(0, i);
}
return URL.valueOf(Constants.EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL
+ Constants.CATEGORY_KEY + "=" + category
+ CATEGORY_KEY + "=" + category
+ (group == null ? "" : "&" + Constants.GROUP_KEY + "=" + group)
+ (version == null ? "" : "&" + Constants.VERSION_KEY + "=" + version));
}

public static boolean isMatchCategory(String category, String categories) {
if (categories == null || categories.length() == 0) {
return Constants.DEFAULT_CATEGORY.equals(category);
return DEFAULT_CATEGORY.equals(category);
} else if (categories.contains(Constants.ANY_VALUE)) {
return true;
} else if (categories.contains(Constants.REMOVE_VALUE_PREFIX)) {
Expand All @@ -370,8 +378,8 @@ public static boolean isMatch(URL consumerUrl, URL providerUrl) {
return false;
}

if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY),
consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) {
if (!isMatchCategory(providerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY),
consumerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY))) {
return false;
}
if (!providerUrl.getParameter(Constants.ENABLED_KEY, true)
Expand Down Expand Up @@ -445,6 +453,22 @@ public static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate) {
return urls.stream().filter(predicate).collect(Collectors.toList());
}

public static boolean isConfigurator(URL url) {
return OVERRIDE_PROTOCOL.equals(url.getProtocol()) ||
CONFIGURATORS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY));
}

public static boolean isRoute(URL url) {
return ROUTE_PROTOCOL.equals(url.getProtocol()) ||
ROUTERS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY));
}

public static boolean isProvider(URL url) {
return !OVERRIDE_PROTOCOL.equals(url.getProtocol()) &&
!ROUTE_PROTOCOL.equals(url.getProtocol()) &&
PROVIDERS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, PROVIDERS_CATEGORY));
}

/**
* Check if the given value matches the given pattern. The pattern supports wildcard "*".
*
Expand All @@ -459,4 +483,4 @@ static boolean isItemMatch(String pattern, String value) {
return "*".equals(pattern) || pattern.equals(value);
}
}
}
}
Loading