@Test public void testRoute() throws Exception { { Map<String, String> result = RouteUtils.route("hello.HelloService:1.0.0", "1.1.2.2:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); Map<String, String> expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("cn/hello.HelloService", "1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("cn/hello.HelloService:2.0.0", "1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_starMethods, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_ghostMethods, result); } { routes.get(0).setMatchRule("consumer.cluster = cluster1"); Map<String, String> result = RouteUtils.route("hello.HelloService", "7.7.7.7:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); Map<String, String> expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_starMethods, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_ghostMethods, result); } }
public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; }
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; } }
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; }  }
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; }  static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); static Map<String, String> previewRoute(String serviceName, String consumerAddress, String queryUrl, Map<String, String> serviceUrls,
            Route route, Map<String, List<String>> clusters, List<Route> routed); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
            List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
    		List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
            List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; }  static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); static Map<String, String> previewRoute(String serviceName, String consumerAddress, String queryUrl, Map<String, String> serviceUrls,
            Route route, Map<String, List<String>> clusters, List<Route> routed); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
            List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
    		List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
            List<Route> routes, Map<String, List<String>> clusters, List<Route> routed);  }