Search in sources :

Example 1 with Provider

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

the class OwnerServiceImpl method toOverrideLiset.

private List<Owner> toOverrideLiset(List<Provider> pList, List<Override> cList) {
    Map<String, Owner> oList = new HashMap<String, Owner>();
    for (Provider p : pList) {
        if (p.getUsername() != null) {
            for (String username : Constants.COMMA_SPLIT_PATTERN.split(p.getUsername())) {
                Owner o = new Owner();
                o.setService(p.getService());
                o.setUsername(username);
                oList.put(o.getService() + "/" + o.getUsername(), o);
            }
        }
    }
    for (Override c : cList) {
        Map<String, String> params = StringUtils.parseQueryString(c.getParams());
        String usernames = params.get("owner");
        if (usernames != null && usernames.length() > 0) {
            for (String username : Constants.COMMA_SPLIT_PATTERN.split(usernames)) {
                Owner o = new Owner();
                o.setService(c.getService());
                o.setUsername(username);
                oList.put(o.getService() + "/" + o.getUsername(), o);
            }
        }
    }
    return new ArrayList<Owner>(oList.values());
}
Also used : Owner(com.alibaba.dubbo.registry.common.domain.Owner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Override(com.alibaba.dubbo.registry.common.domain.Override) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 2 with Provider

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

the class ProviderServiceImpl method disableProvider.

public void disableProvider(Long id) {
    if (id == null) {
        throw new IllegalStateException("no provider id");
    }
    Provider oldProvider = findProvider(id);
    if (oldProvider == null) {
        throw new IllegalStateException("Provider was changed!");
    }
    if (oldProvider.isDynamic()) {
        //保证disable的override唯一
        if (oldProvider.isEnabled()) {
            Override override = new Override();
            override.setAddress(oldProvider.getAddress());
            override.setService(oldProvider.getService());
            override.setEnabled(true);
            override.setParams(Constants.DISABLED_KEY + "=true");
            overrideService.saveOverride(override);
            return;
        }
        List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
        for (Override o : oList) {
            Map<String, String> params = StringUtils.parseQueryString(o.getParams());
            if (params.containsKey(Constants.DISABLED_KEY)) {
                if (params.get(Constants.DISABLED_KEY).equals("false")) {
                    overrideService.deleteOverride(o.getId());
                }
            }
        }
    } else {
        oldProvider.setEnabled(false);
        updateProvider(oldProvider);
    }
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 3 with Provider

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

the class ProviderServiceImpl method enableProvider.

public void enableProvider(Long id) {
    if (id == null) {
        throw new IllegalStateException("no provider id");
    }
    Provider oldProvider = findProvider(id);
    if (oldProvider == null) {
        throw new IllegalStateException("Provider was changed!");
    }
    if (oldProvider.isDynamic()) {
        //保证disable的override唯一
        if (!oldProvider.isEnabled()) {
            Override override = new Override();
            override.setAddress(oldProvider.getAddress());
            override.setService(oldProvider.getService());
            override.setEnabled(true);
            override.setParams(Constants.DISABLED_KEY + "=false");
            overrideService.saveOverride(override);
            return;
        }
        List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
        for (Override o : oList) {
            Map<String, String> params = StringUtils.parseQueryString(o.getParams());
            if (params.containsKey(Constants.DISABLED_KEY)) {
                if (params.get(Constants.DISABLED_KEY).equals("true")) {
                    overrideService.deleteOverride(o.getId());
                }
            }
        }
    } else {
        oldProvider.setEnabled(true);
        updateProvider(oldProvider);
    }
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 4 with Provider

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

the class RouteUtils method route.

public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) {
    if (providers == null) {
        return null;
    }
    Map<String, String> urls = new HashMap<String, String>();
    // not empty dummy data
    urls.put("consumer://" + consumerAddress + "/" + serviceName, consumerQueryUrl);
    for (Provider provider : providers) {
        if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) {
            urls.put(provider.getUrl(), provider.getParameters());
        }
    }
    urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed);
    List<Provider> result = new ArrayList<Provider>();
    for (Provider provider : providers) {
        if (urls.containsKey(provider.getUrl())) {
            result.add(provider);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 5 with Provider

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

the class Weights method add.

/**
     * load页面供新增操作
     * @param context
     */
public void add(Map<String, Object> context) {
    String service = (String) context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for (Provider provider : providerList) {
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if (context.get("input") != null)
        context.put("input", context.get("input"));
}
Also used : ArrayList(java.util.ArrayList) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Aggregations

Provider (com.alibaba.dubbo.registry.common.domain.Provider)22 Override (com.alibaba.dubbo.registry.common.domain.Override)8 ArrayList (java.util.ArrayList)8 Consumer (com.alibaba.dubbo.registry.common.domain.Consumer)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)4 Route (com.alibaba.dubbo.registry.common.domain.Route)3 PrintWriter (java.io.PrintWriter)2 Set (java.util.Set)2 URL (com.alibaba.dubbo.common.URL)1 RootContextPath (com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath)1 Owner (com.alibaba.dubbo.registry.common.domain.Owner)1 Map (java.util.Map)1