Search in sources :

Example 1 with Access

use of com.alibaba.dubbo.registry.common.domain.Access in project dubbo by alibaba.

the class Accesses method index.

public void index(Map<String, Object> context) throws Exception {
    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) {
        routes = routeService.findForceRouteByService(service);
    } else if (address != null && address.length() > 0) {
        routes = routeService.findForceRouteByAddress(address);
    } else {
        routes = routeService.findAllForceRoute();
    }
    List<Access> accesses = new ArrayList<Access>();
    if (routes == null) {
        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);
            }
        }
    }
    context.put("accesses", accesses);
}
Also used : MatchPair(com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair) ArrayList(java.util.ArrayList) Access(com.alibaba.dubbo.registry.common.domain.Access) Route(com.alibaba.dubbo.registry.common.domain.Route)

Aggregations

Access (com.alibaba.dubbo.registry.common.domain.Access)1 Route (com.alibaba.dubbo.registry.common.domain.Route)1 MatchPair (com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair)1 ArrayList (java.util.ArrayList)1