@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()); }
public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if(null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if(p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; }
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if(null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if(p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } }
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if(null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if(p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private  RouteRuleUtils(); }
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if(null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if(p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private  RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
            Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
            Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
            Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if(null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if(p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private  RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
            Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
            Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
            Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule);  }