Search in sources :

Example 16 with Override

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

the class Applications method index.

public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    if (context.get("service") != null) {
        Set<String> applications = new TreeSet<String>();
        List<String> providerApplications = providerService.findApplicationsByServiceName(service);
        if (providerApplications != null && providerApplications.size() > 0) {
            applications.addAll(providerApplications);
        }
        List<String> consumerApplications = consumerService.findApplicationsByServiceName(service);
        if (consumerApplications != null && consumerApplications.size() > 0) {
            applications.addAll(consumerApplications);
        }
        context.put("applications", applications);
        context.put("providerApplications", providerApplications);
        context.put("consumerApplications", consumerApplications);
        if (service != null && service.length() > 0) {
            List<Override> overrides = overrideService.findByService(service);
            Map<String, List<Override>> application2Overrides = new HashMap<String, List<Override>>();
            if (overrides != null && overrides.size() > 0 && applications != null && applications.size() > 0) {
                for (String a : applications) {
                    if (overrides != null && overrides.size() > 0) {
                        List<Override> appOverrides = new ArrayList<Override>();
                        for (Override override : overrides) {
                            if (override.isMatch(service, null, a)) {
                                appOverrides.add(override);
                            }
                        }
                        Collections.sort(appOverrides, OverrideUtils.OVERRIDE_COMPARATOR);
                        application2Overrides.put(a, appOverrides);
                    }
                }
            }
            context.put("overrides", application2Overrides);
        }
        return;
    }
    if (context.get("service") == null && context.get("application") == null && context.get("address") == null) {
        context.put("application", "*");
    }
    Set<String> applications = new TreeSet<String>();
    List<String> providerApplications = providerService.findApplications();
    if (providerApplications != null && providerApplications.size() > 0) {
        applications.addAll(providerApplications);
    }
    List<String> consumerApplications = consumerService.findApplications();
    if (consumerApplications != null && consumerApplications.size() > 0) {
        applications.addAll(consumerApplications);
    }
    Set<String> newList = new HashSet<String>();
    Set<String> newProviders = new HashSet<String>();
    Set<String> newConsumers = new HashSet<String>();
    context.put("applications", applications);
    context.put("providerApplications", providerApplications);
    context.put("consumerApplications", consumerApplications);
    String keyword = (String) context.get("keyword");
    if (StringUtils.isNotEmpty(keyword) && !"*".equals(keyword)) {
        keyword = keyword.toLowerCase();
        for (String o : applications) {
            if (o.toLowerCase().indexOf(keyword) != -1) {
                newList.add(o);
            }
        }
        for (String o : providerApplications) {
            if (o.toLowerCase().indexOf(keyword) != -1) {
                newProviders.add(o);
            }
        }
        for (String o : consumerApplications) {
            if (o.toLowerCase().indexOf(keyword) != -1) {
                newConsumers.add(o);
            }
        }
        context.put("applications", newList);
        context.put("providerApplications", newProviders);
        context.put("consumerApplications", newConsumers);
    }
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Override(com.alibaba.dubbo.registry.common.domain.Override) HashSet(java.util.HashSet)

Example 17 with Override

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

the class Consumers method mock.

private boolean mock(Long[] ids, Map<String, Object> context, String mock) throws Exception {
    if (ids == null || ids.length == 0) {
        context.put("message", getMessage("NoSuchOperationData"));
        return false;
    }
    List<Consumer> consumers = new ArrayList<Consumer>();
    for (Long id : ids) {
        Consumer c = consumerService.findConsumer(id);
        if (c != null) {
            consumers.add(c);
            if (!super.currentUser.hasServicePrivilege(c.getService())) {
                context.put("message", getMessage("HaveNoServicePrivilege", c.getService()));
                return false;
            }
        }
    }
    for (Consumer consumer : consumers) {
        String service = consumer.getService();
        String address = Tool.getIP(consumer.getAddress());
        List<Override> overrides = overrideService.findByServiceAndAddress(service, address);
        if (overrides != null && overrides.size() > 0) {
            for (Override override : overrides) {
                Map<String, String> map = StringUtils.parseQueryString(override.getParams());
                if (mock == null || mock.length() == 0) {
                    map.remove("mock");
                } else {
                    map.put("mock", URL.encode(mock));
                }
                if (map.size() > 0) {
                    override.setParams(StringUtils.toQueryString(map));
                    override.setEnabled(true);
                    override.setOperator(operator);
                    override.setOperatorAddress(operatorAddress);
                    overrideService.updateOverride(override);
                } else {
                    overrideService.deleteOverride(override.getId());
                }
            }
        } else if (mock != null && mock.length() > 0) {
            Override override = new Override();
            override.setService(service);
            override.setAddress(address);
            override.setParams("mock=" + URL.encode(mock));
            override.setEnabled(true);
            override.setOperator(operator);
            override.setOperatorAddress(operatorAddress);
            overrideService.saveOverride(override);
        }
    }
    return true;
}
Also used : Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) ArrayList(java.util.ArrayList) Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 18 with Override

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

the class Consumers method allmock.

private boolean allmock(Map<String, Object> context, String mock) throws Exception {
    String service = (String) context.get("service");
    if (service == null || service.length() == 0) {
        context.put("message", getMessage("NoSuchOperationData"));
        return false;
    }
    if (!super.currentUser.hasServicePrivilege(service)) {
        context.put("message", getMessage("HaveNoServicePrivilege", service));
        return false;
    }
    List<Override> overrides = overrideService.findByService(service);
    Override allOverride = null;
    if (overrides != null && overrides.size() > 0) {
        for (Override override : overrides) {
            if (override.isDefault()) {
                allOverride = override;
                break;
            }
        }
    }
    if (allOverride != null) {
        Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
        if (mock == null || mock.length() == 0) {
            map.remove("mock");
        } else {
            map.put("mock", URL.encode(mock));
        }
        if (map.size() > 0) {
            allOverride.setParams(StringUtils.toQueryString(map));
            allOverride.setEnabled(true);
            allOverride.setOperator(operator);
            allOverride.setOperatorAddress(operatorAddress);
            overrideService.updateOverride(allOverride);
        } else {
            overrideService.deleteOverride(allOverride.getId());
        }
    } else if (mock != null && mock.length() > 0) {
        Override override = new Override();
        override.setService(service);
        override.setParams("mock=" + URL.encode(mock));
        override.setEnabled(true);
        override.setOperator(operator);
        override.setOperatorAddress(operatorAddress);
        overrideService.saveOverride(override);
    }
    return true;
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 19 with Override

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

the class Consumers method index.

public void index(Map<String, Object> context) throws Exception {
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    String address = (String) context.get("address");
    List<Consumer> consumers;
    List<Override> overrides;
    List<Provider> providers = null;
    List<Route> routes = null;
    // service
    if (service != null && service.length() > 0) {
        consumers = consumerService.findByService(service);
        overrides = overrideService.findByService(service);
        providers = providerService.findByService(service);
        routes = routeService.findByService(service);
    } else // address
    if (address != null && address.length() > 0) {
        consumers = consumerService.findByAddress(address);
        overrides = overrideService.findByAddress(Tool.getIP(address));
    } else // application
    if (application != null && application.length() > 0) {
        consumers = consumerService.findByApplication(application);
        overrides = overrideService.findByApplication(application);
    } else // all
    {
        consumers = consumerService.findAll();
        overrides = overrideService.findAll();
    }
    if (consumers != null && consumers.size() > 0) {
        for (Consumer consumer : consumers) {
            if (service == null || service.length() == 0) {
                providers = providerService.findByService(consumer.getService());
                routes = routeService.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("consumers", consumers);
}
Also used : Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) ArrayList(java.util.ArrayList) Override(com.alibaba.dubbo.registry.common.domain.Override) Route(com.alibaba.dubbo.registry.common.domain.Route) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 20 with Override

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

the class Overrides method update.

public boolean update(Override override, Map<String, Object> context) {
    Override o = overrideService.findById(override.getId());
    override.setService(o.getService());
    override.setAddress(o.getAddress());
    override.setApplication(o.getApplication());
    if (!catchParams(override, context))
        return false;
    overrideService.updateOverride(override);
    return true;
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Aggregations

Override (com.alibaba.dubbo.registry.common.domain.Override)30 ArrayList (java.util.ArrayList)10 Provider (com.alibaba.dubbo.registry.common.domain.Provider)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Consumer (com.alibaba.dubbo.registry.common.domain.Consumer)4 Route (com.alibaba.dubbo.registry.common.domain.Route)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 LoadBalance (com.alibaba.dubbo.registry.common.domain.LoadBalance)1 Owner (com.alibaba.dubbo.registry.common.domain.Owner)1 Weight (com.alibaba.dubbo.registry.common.domain.Weight)1