Package com.alibaba.dubbo.registry.common.route.RouteRule

Examples of com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair


            context.put("accesses", accesses);
            return;
        }
        for(Route route :routes){
            Map<String, MatchPair> rule = RouteRule.parseRule(route.getMatchRule());
            MatchPair pair = rule.get("consumer.host");
            if(pair != null){
                for(String host : pair.getMatches()){
                    Access access = new Access();
                    access.setAddress(host);
                    access.setService(route.getService());
                    access.setAllow(false);
                    accesses.add(access);
                }
                for(String host : pair.getUnmatches()){
                    Access access = new Access();
                    access.setAddress(host);
                    access.setService(route.getService());
                    access.setAllow(true);
                    accesses.add(access);
View Full Code Here


                route.setEnabled(true);
            }else{
                route = routes.get(0);
            }
            Map<String, MatchPair> when = null;
            MatchPair matchPair = null;
            if(isFirst){
                when = new HashMap<String, MatchPair>();
                matchPair = new MatchPair(new HashSet<String>(),new HashSet<String>());
                when.put("consumer.host", matchPair);
            }else{
                when = RouteRule.parseRule(route.getMatchRule());
                matchPair = when.get("consumer.host");
            }
            for (String consumerAddress : consumerAddresses) {
                if(Boolean.valueOf((String) context.get("allow"))){
                    matchPair.getUnmatches().add(Tool.getIP(consumerAddress));
                   
                }else{
                    matchPair.getMatches().add(Tool.getIP(consumerAddress));
                }
            }
            StringBuilder sb = new StringBuilder();
            RouteRule.contidionToString(sb,when);
            route.setMatchRule(sb.toString());
View Full Code Here

            List<Route> routes = routeService.findForceRouteByService(service);
            if(routes == null || routes.size() == 0){
                continue;
            }
            for(Route blackwhitelist : routes){
                MatchPair pairs = RouteRule.parseRule(blackwhitelist.getMatchRule()).get("consumer.host");
                Set<String> matches = new HashSet<String>();
                matches.addAll(pairs.getMatches());
                Set<String> unmatches = new HashSet<String>();
                unmatches.addAll(pairs.getUnmatches());
                for(String pair : pairs.getMatches()){
                  for(String address : entry.getValue()){
                    if(pair.equals(address)){
                            matches.remove(pair);
                            break;
                        }
                  }
                }
                for(String pair : pairs.getUnmatches()){
                  for(String address : entry.getValue()){
                     if(pair.equals(address)){
                             unmatches.remove(pair);
                             break;
                         }
                  }
                }
                if(matches.size()==0 && unmatches.size()==0){
                    routeService.deleteRoute(blackwhitelist.getId());
                }else{
                    Map<String, MatchPair> condition = new HashMap<String, MatchPair>();
                    condition.put("consumer.host", new MatchPair(matches,unmatches));
                    StringBuilder sb = new StringBuilder();
                    RouteRule.contidionToString(sb,condition);
                    blackwhitelist.setMatchRule(sb.toString());
                    routeService.updateRoute(blackwhitelist);
                }
View Full Code Here

                route.setEnabled(true);
            } else {
                route = routes.get(0);
            }
            Map<String, MatchPair> when = null;
            MatchPair matchPair = null;
            if(isFirst){
                when = new HashMap<String, MatchPair>();
                matchPair = new MatchPair(new HashSet<String>(),new HashSet<String>());
                when.put("consumer.host", matchPair);
            }else{
                when = RouteRule.parseRule(route.getMatchRule());
                matchPair = when.get("consumer.host");
            }
            if (only) {
              matchPair.getUnmatches().clear();
              matchPair.getMatches().clear();
              if (allow) {
                matchPair.getUnmatches().addAll(entry.getValue());
              } else {
                matchPair.getMatches().addAll(entry.getValue());
              }
            } else {
              for (String consumerAddress : entry.getValue()) {
                  if(matchPair.getUnmatches().size() > 0) { // 白名单优先
                    matchPair.getMatches().remove(consumerAddress); // 去掉黑名单中相同数据
                    if (allow) { // 如果允许访问
                      matchPair.getUnmatches().add(consumerAddress); // 加入白名单
                    } else { // 如果禁止访问
                      matchPair.getUnmatches().remove(consumerAddress); // 从白名单中去除
                    }
                    } else { // 黑名单生效
                      if (allow) { // 如果允许访问
                        matchPair.getMatches().remove(consumerAddress); // 从黑名单中去除
                      } else { // 如果禁止访问
                        matchPair.getMatches().add(consumerAddress); // 加入黑名单
                      }
                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            RouteRule.contidionToString(sb,when);
            route.setMatchRule(sb.toString());
            route.setUsername(operator);
            if (matchPair.getMatches().size() > 0 || matchPair.getUnmatches().size() > 0) {
              if(isFirst) {
                  routeService.createRoute(route);
                } else {
                  routeService.updateRoute(route);
                }
View Full Code Here

          continue;
        }
        String filterRule = route.getFilterRule();
        if (filterRule == null || filterRule.length() == 0 || "false".equals(filterRule)) {
          Map<String, MatchPair> rule = RouteRule.parseRule(route.getMatchRule());
          MatchPair pair = rule.get("consumer.host");
                if (pair == null) {
                  pair = rule.get("host");
                }
                if(pair != null){
                  if (pair.getMatches() != null && pair.getMatches().size() > 0) {
                      for(String host : pair.getMatches()){
                        if (ParseUtils.isMatchGlobPattern(host, ip)) {
                          return true;
                        }
                      }
                  }
                  if (pair.getUnmatches() != null && pair.getUnmatches().size() > 0) {
                      boolean forbid = true;
                      for(String host : pair.getUnmatches()){
                        if (ParseUtils.isMatchGlobPattern(host, ip)) {
                          forbid = false;
                        }
                      }
                      if (forbid) {
View Full Code Here

        pair = new RouteRule.MatchPair(matches, unmatches);
    }
   
    @org.junit.Test
    public void test_MatchPair_copy() throws Exception {
        MatchPair copy = pair.copy();
        assertEquals(pair, copy);
       
        copy.matches.remove("+a");
        assertFalse(pair.equals(copy));
       
View Full Code Here

        RouteRule r = RouteRule.parse("when1 = valueW1 & when3 != valueWx,valueWy & when2 = valueW4,valueW2,valueW3 & when2 != valueWu,valueWv",
        "then2 = valueT2,valueT4,valueT3 & then1 = valueT1");
       
        {
            Map<String, RouteRule.MatchPair> whenCondition = new HashMap<String, RouteRule.MatchPair>();
            RouteRule.MatchPair p = new MatchPair();
            p.matches.add("w1a");
            p.matches.add("w1b");
            p.matches.add("w1c");
            p.unmatches.add("w1-a");
            whenCondition.put("when1", p);
           
            p = new MatchPair();
            p.matches.add("w9a");
            p.matches.add("w9b");
            whenCondition.put("when9", p);
           
            RouteRule c = RouteRule.copyWithReplace(r, whenCondition, null);
            assertEquals(RouteRule.parse("when1 = w1a,w1b,w1c & when1 != w1-a & when9 = w9a,w9b " +
                " & when3 != valueWx,valueWy & when2 = valueW4,valueW2,valueW3 & when2 != valueWu,valueWv",
            "then2 = valueT2,valueT4,valueT3 & then1 = valueT1"), c);
        }
        {
            Map<String, RouteRule.MatchPair> thenCondition = new HashMap<String, RouteRule.MatchPair>();
            RouteRule.MatchPair p = new MatchPair();
            p.matches.add("t1a");
            p.matches.add("t1b");
            p.matches.add("t1c");
            p.unmatches.add("t1-a");
            thenCondition.put("then1", p);
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.