com.alibaba.dubbo.registry.common.domain.Route Java Examples

The following examples show how to use com.alibaba.dubbo.registry.common.domain.Route. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters) {
    RouteRule rule = RouteRule.parseQuitely(route);
    Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
            rule.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
    Map<String, String> consumerSample = ParseUtils.parseQuery("consumer.", consumerQueryUrl);
    
    final int index = consumerAddress.lastIndexOf(":");
    String consumerHost = null;
    if(index != -1){
        consumerHost = consumerAddress.substring(0, index);
    }
    else {
        consumerHost = consumerAddress;
    }
    consumerSample.put("consumer.host", consumerHost);
    
    return RouteRuleUtils.isMatchCondition(when, consumerSample, consumerSample);
}
 
Example #2
Source File: Routes.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 路由模块首页
 * @param context
 */
public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    String address = (String) context.get("address");
    address = Tool.getIP(address);
    List<Route> routes;
    if (service != null && service.length() > 0
    		&& address != null && address.length() > 0) {
        routes = routeService.findByServiceAndAddress(service, address);
    } else if (service != null && service.length() > 0) {
        routes = routeService.findByService(service);
    } else if (address != null && address.length() > 0) {
        routes = routeService.findByAddress(address);
    } else {
        routes = routeService.findAll();
    }
    context.put("routes", routes);
}
 
Example #3
Source File: Routes.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 选择消费者
 * @param context
 */
public void routeselect(Map<String, Object> context){
	long rid = Long.valueOf((String)context.get("id"));
    context.put("id", rid);
    
    Route route = routeService.findRoute(rid);
    if (route == null) {
        throw new IllegalStateException("Route(id=" + rid + ") is not existed!");
    }
    
    context.put("route", route);
    // 获取数据
    List<Consumer> consumers = consumerService.findByService(route.getService());
    context.put("consumers", consumers);
    
    Map<String, Boolean> matchRoute = new HashMap<String, Boolean>();
    for(Consumer c : consumers) {
        matchRoute.put(c.getAddress(), RouteUtils.matchRoute(c.getAddress(), null, route, null));
    }
    context.put("matchRoute", matchRoute);
}
 
Example #4
Source File: Routes.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
/**
 * 路由模块首页
 * @param context
 */
public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    String address = (String) context.get("address");
    address = Tool.getIP(address);
    List<Route> routes;
    if (service != null && service.length() > 0
    		&& address != null && address.length() > 0) {
        routes = routeService.findByServiceAndAddress(service, address);
    } else if (service != null && service.length() > 0) {
        routes = routeService.findByService(service);
    } else if (address != null && address.length() > 0) {
        routes = routeService.findByAddress(address);
    } else {
        routes = routeService.findAll();
    }
    context.put("routes", routes);
}
 
Example #5
Source File: RouteUtils.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
static Route getFirstRouteMatchedWhenConditionOfRule(String serviceName, Map<String, String> consumerSample, List<Route> routes, Map<Long, RouteRule> routeRuleMap) {
    if (serviceName == null || serviceName.length() == 0) {
        return null;
    }
    if (routes != null && routes.size() > 0) {
        for (Route route : routes) {
            if (isSerivceNameMatched(route.getService(), serviceName)) {
                RouteRule rule = routeRuleMap.get(route.getId());
                // 当满足when条件时
                if (rule != null && RouteRuleUtils.isMatchCondition(
                        rule.getWhenCondition(), consumerSample, consumerSample)) {
                    return route; // 第一个满足即返回
                }
            }
        }
    }
    return null;
}
 
Example #6
Source File: Routes.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 路由模块首页
 * @param context
 */
public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    String address = (String) context.get("address");
    address = Tool.getIP(address);
    List<Route> routes;
    if (service != null && service.length() > 0
    		&& address != null && address.length() > 0) {
        routes = routeService.findByServiceAndAddress(service, address);
    } else if (service != null && service.length() > 0) {
        routes = routeService.findByService(service);
    } else if (address != null && address.length() > 0) {
        routes = routeService.findByAddress(address);
    } else {
        routes = routeService.findAll();
    }
    context.put("routes", routes);
}
 
Example #7
Source File: Routes.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 选择消费者
 * @param context
 */
public void routeselect(Map<String, Object> context){
	long rid = Long.valueOf((String)context.get("id"));
    context.put("id", rid);
    
    Route route = routeService.findRoute(rid);
    if (route == null) {
        throw new IllegalStateException("Route(id=" + rid + ") is not existed!");
    }
    
    context.put("route", route);
    // 获取数据
    List<Consumer> consumers = consumerService.findByService(route.getService());
    context.put("consumers", consumers);
    
    Map<String, Boolean> matchRoute = new HashMap<String, Boolean>();
    for(Consumer c : consumers) {
        matchRoute.put(c.getAddress(), RouteUtils.matchRoute(c.getAddress(), null, route, null));
    }
    context.put("matchRoute", matchRoute);
}
 
Example #8
Source File: SyncUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public static Route url2Route(Pair<Long, URL> pair) {
	if (pair == null) {
		return null;
	}
	
    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    Route r = new Route();
    r.setId(id);
    r.setName(url.getParameter("name"));
    r.setService(url.getServiceKey());
    r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
    r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
    r.setForce(url.getParameter(Constants.FORCE_KEY, false));
    r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
    return r;
}
 
Example #9
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
static Map<Long, RouteRule> route2RouteRule(List<Route> routes,
                                            Map<String, List<String>> clusters) {
    Map<Long, RouteRule> rules = new HashMap<Long, RouteRule>();
    // route -> RouteRule
    if (routes != null && routes.size() > 0) {
        for(Route route: routes) {
            rules.put(route.getId(), RouteRule.parseQuitely(route));
        }
    }
    // expand the cluster parameters into conditions of routerule
    if (clusters != null && clusters.size() > 0) {
        Map<Long, RouteRule> rrs = new HashMap<Long, RouteRule>();
        for (Map.Entry<Long, RouteRule> entry : rules.entrySet()) {
            RouteRule rr = entry.getValue();

            Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
                    rr.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
            Map<String, RouteRule.MatchPair> then = RouteRuleUtils.expandCondition(
                    rr.getThenCondition(), "provider.cluster", "provider.host", clusters);

            rrs.put(entry.getKey(), RouteRule.createFromCondition(when, then));
        }
        rules = rrs;
    }
    return rules;
}
 
Example #10
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
static Route getFirstRouteMatchedWhenConditionOfRule(String serviceName, Map<String, String> consumerSample, List<Route> routes, Map<Long, RouteRule> routeRuleMap) {
    if (serviceName == null || serviceName.length() == 0) {
        return null;
    }
    if (routes != null && routes.size() > 0) {
        for (Route route : routes) {
            if (isSerivceNameMatched(route.getService(), serviceName)) {
                RouteRule rule = routeRuleMap.get(route.getId());
                // 当满足when条件时
                if (rule != null && RouteRuleUtils.isMatchCondition(
                        rule.getWhenCondition(), consumerSample, consumerSample)) {
                    return route; // 第一个满足即返回
                }
            }
        }
    }
    return null;
}
 
Example #11
Source File: SyncUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public static Route url2Route(Pair<Long, URL> pair) {
	if (pair == null) {
		return null;
	}
	
    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    Route r = new Route();
    r.setId(id);
    r.setName(url.getParameter("name"));
    r.setService(url.getServiceKey());
    r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
    r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
    r.setForce(url.getParameter(Constants.FORCE_KEY, false));
    r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
    return r;
}
 
Example #12
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
static Route getFirstRouteMatchedWhenConditionOfRule(String serviceName, Map<String, String> consumerSample, List<Route> routes, Map<Long, RouteRule> routeRuleMap) {
    if (serviceName == null || serviceName.length() == 0) {
        return null;
    }
    if (routes != null && routes.size() > 0) {
        for (Route route : routes) {
            if (isSerivceNameMatched(route.getService(), serviceName)) {
                RouteRule rule = routeRuleMap.get(route.getId());
                // 当满足when条件时
                if (rule != null && RouteRuleUtils.isMatchCondition(
                        rule.getWhenCondition(), consumerSample, consumerSample)) {
                    return route; // 第一个满足即返回
                }
            }
        }
    }
    return null;
}
 
Example #13
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
static Route getFirstRouteMatchedWhenConditionOfRule(String serviceName, Map<String, String> consumerSample, List<Route> routes, Map<Long, RouteRule> routeRuleMap) {
    if (serviceName == null || serviceName.length() == 0) {
        return null;
    }
    if (routes != null && routes.size() > 0) {
        for (Route route : routes) {
            if (isSerivceNameMatched(route.getService(), serviceName)) {
                RouteRule rule = routeRuleMap.get(route.getId());
                // 当满足when条件时
                if (rule != null && RouteRuleUtils.isMatchCondition(
                        rule.getWhenCondition(), consumerSample, consumerSample)) {
                    return route; // 第一个满足即返回
                }
            }
        }
    }
    return null;
}
 
Example #14
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
static Map<Long, RouteRule> route2RouteRule(List<Route> routes,
                                            Map<String, List<String>> clusters) {
    Map<Long, RouteRule> rules = new HashMap<Long, RouteRule>();
    // route -> RouteRule
    if (routes != null && routes.size() > 0) {
        for(Route route: routes) {
            rules.put(route.getId(), RouteRule.parseQuitely(route));
        }
    }
    // expand the cluster parameters into conditions of routerule
    if (clusters != null && clusters.size() > 0) {
        Map<Long, RouteRule> rrs = new HashMap<Long, RouteRule>();
        for (Map.Entry<Long, RouteRule> entry : rules.entrySet()) {
            RouteRule rr = entry.getValue();

            Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
                    rr.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
            Map<String, RouteRule.MatchPair> then = RouteRuleUtils.expandCondition(
                    rr.getThenCondition(), "provider.cluster", "provider.host", clusters);

            rrs.put(entry.getKey(), RouteRule.createFromCondition(when, then));
        }
        rules = rrs;
    }
    return rules;
}
 
Example #15
Source File: RouteUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
static Map<Long, RouteRule> route2RouteRule(List<Route> routes,
                                            Map<String, List<String>> clusters) {
    Map<Long, RouteRule> rules = new HashMap<Long, RouteRule>();
    // route -> RouteRule
    if (routes != null && routes.size() > 0) {
        for(Route route: routes) {
            rules.put(route.getId(), RouteRule.parseQuitely(route));
        }
    }
    // expand the cluster parameters into conditions of routerule
    if (clusters != null && clusters.size() > 0) {
        Map<Long, RouteRule> rrs = new HashMap<Long, RouteRule>();
        for (Map.Entry<Long, RouteRule> entry : rules.entrySet()) {
            RouteRule rr = entry.getValue();

            Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
                    rr.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
            Map<String, RouteRule.MatchPair> then = RouteRuleUtils.expandCondition(
                    rr.getThenCondition(), "provider.cluster", "provider.host", clusters);

            rrs.put(entry.getKey(), RouteRule.createFromCondition(when, then));
        }
        rules = rrs;
    }
    return rules;
}
 
Example #16
Source File: RouteRule.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
/**
 * @see #parse(String)
 * @throws RuntimeException 解析出错时,Wrap了{@link #parse(String)}方法的抛出的{@link ParseException}的异常。
 */
public static RouteRule parseQuitely(Route route) {
    try {
        return parse(route);
    } catch (ParseException e) {
       throw new RuntimeException(e);
    }
}
 
Example #17
Source File: RouteUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_matchRoute() throws Exception {
    Route route = new Route();
    route.setId(1L);
    route.setPriority(3);
    route.setMatchRule("consumer.host = 1.1.2.2");
    route.setFilterRule("xxx = yyy");
    routes.add(route);

    {
        assertTrue(RouteUtils.matchRoute("1.1.2.2:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));

        assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));

        route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = kylin");
        assertTrue(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));

        route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = notExstied");
        assertFalse(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters));
    }
    
    {
        route.setMatchRule("consumer.cluster = cluster1");
        
        assertTrue(RouteUtils.matchRoute("7.7.7.7:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));
        
        assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));
        
        route.setMatchRule("consumer.cluster = cluster1 & consumer.application = kylin");
        assertTrue(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));
        
        route.setMatchRule("consumer.cluster = cluster1 & consumer.application = notExstied");
        assertFalse(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters));
    }
}
 
Example #18
Source File: RouteUtils.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public 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) {
    if(null == route) {
        throw new IllegalArgumentException("Route is null.");
    }
    List<Route> routes = new ArrayList<Route>();
    routes.add(route);
    return route(serviceName, consumerAddress, queryUrl, serviceUrls, routes, clusters, routed);
}
 
Example #19
Source File: RouteRuleUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #20
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #21
Source File: Consumers.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void show(Long id, Map<String, Object> context) {
	Consumer consumer = consumerService.findConsumer(id);
	List<Provider> providers = providerService.findByService(consumer.getService());
	List<Route> routes = routeService.findByService(consumer.getService());
	List<Override> overrides = overrideService.findByService(consumer.getService());
	List<Route> routed = new ArrayList<Route>();
    consumer.setProviders(RouteUtils.route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
	consumer.setRoutes(routed);
	OverrideUtils.setConsumerOverrides(consumer, overrides);
	context.put("consumer", consumer);
	context.put("providers", consumer.getProviders());
	context.put("routes", consumer.getRoutes());
	context.put("overrides", consumer.getOverrides());
}
 
Example #22
Source File: SyncUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static List<Route> url2RouteList(Map<Long, URL> cs) {
    List<Route> list = new ArrayList<Route>();
    if(cs == null) return list;
    for(Map.Entry<Long, URL> entry : cs.entrySet()) {
        list.add(url2Route(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
    }
    return list;
}
 
Example #23
Source File: RouteRule.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 把字符串形式的RouteRule的解析成对象。
 * 
 * @throws ParseException RouteRule字符串格式不对了。以下输入的情况,RouteRule都是非法的。
 * <ul> <li> 输入是<code>null</code>。
 * <li> 输入是空串,或是空白串。
 * <li> 输入的Rule,没有When条件
 * <li> 输入的Rule,没有Then条件
 * </ul>
 */
public static RouteRule parse(Route route) throws ParseException {
    if(route == null) 
        throw new ParseException("null route!", 0);
    
    if(route.getMatchRule() == null && route.getFilterRule() == null) {
        return parse(route.getRule());
    }
    
    return parse(route == null ? null : route.getMatchRule(), route == null ? null : route.getFilterRule());
}
 
Example #24
Source File: RouteUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_matchRoute() throws Exception {
    Route route = new Route();
    route.setId(1L);
    route.setPriority(3);
    route.setMatchRule("consumer.host = 1.1.2.2");
    route.setFilterRule("xxx = yyy");
    routes.add(route);

    {
        assertTrue(RouteUtils.matchRoute("1.1.2.2:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));

        assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));

        route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = kylin");
        assertTrue(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));

        route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = notExstied");
        assertFalse(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters));
    }
    
    {
        route.setMatchRule("consumer.cluster = cluster1");
        
        assertTrue(RouteUtils.matchRoute("7.7.7.7:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));
        
        assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));
        
        route.setMatchRule("consumer.cluster = cluster1 & consumer.application = kylin");
        assertTrue(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters));
        
        route.setMatchRule("consumer.cluster = cluster1 & consumer.application = notExstied");
        assertFalse(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters));
    }
}
 
Example #25
Source File: RouteUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public 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) {
    if(null == route) {
        throw new IllegalArgumentException("Route is null.");
    }
    List<Route> routes = new ArrayList<Route>();
    routes.add(route);
    return route(serviceName, consumerAddress, queryUrl, serviceUrls, routes, clusters, routed);
}
 
Example #26
Source File: SyncUtils.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static List<Route> url2RouteList(Map<Long, URL> cs) {
    List<Route> list = new ArrayList<Route>();
    if(cs == null) return list;
    for(Map.Entry<Long, URL> entry : cs.entrySet()) {
        list.add(url2Route(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
    }
    return list;
}
 
Example #27
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #28
Source File: Consumers.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void show(Long id, Map<String, Object> context) {
	Consumer consumer = consumerService.findConsumer(id);
	List<Provider> providers = providerService.findByService(consumer.getService());
	List<Route> routes = routeService.findByService(consumer.getService());
	List<Override> overrides = overrideService.findByService(consumer.getService());
	List<Route> routed = new ArrayList<Route>();
    consumer.setProviders(RouteUtils.route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
	consumer.setRoutes(routed);
	OverrideUtils.setConsumerOverrides(consumer, overrides);
	context.put("consumer", consumer);
	context.put("providers", consumer.getProviders());
	context.put("routes", consumer.getRoutes());
	context.put("overrides", consumer.getOverrides());
}
 
Example #29
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #30
Source File: Consumers.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void show(Long id, Map<String, Object> context) {
	Consumer consumer = consumerService.findConsumer(id);
	List<Provider> providers = providerService.findByService(consumer.getService());
	List<Route> routes = routeService.findByService(consumer.getService());
	List<Override> overrides = overrideService.findByService(consumer.getService());
	List<Route> routed = new ArrayList<Route>();
    consumer.setProviders(RouteUtils.route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
	consumer.setRoutes(routed);
	OverrideUtils.setConsumerOverrides(consumer, overrides);
	context.put("consumer", consumer);
	context.put("providers", consumer.getProviders());
	context.put("routes", consumer.getRoutes());
	context.put("overrides", consumer.getOverrides());
}