Search in sources :

Example 11 with Provider

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

the class Versions method index.

public void index(Map<String, Object> context) {
    List<Provider> providers = providerService.findAll();
    List<Consumer> consumers = consumerService.findAll();
    Set<String> parametersSet = new HashSet<String>();
    for (Provider provider : providers) {
        parametersSet.add(provider.getParameters());
    }
    for (Consumer consumer : consumers) {
        parametersSet.add(consumer.getParameters());
    }
    Map<String, Set<String>> versions = new HashMap<String, Set<String>>();
    Iterator<String> temp = parametersSet.iterator();
    while (temp.hasNext()) {
        Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
        if (parameter != null) {
            String dubbo = parameter.get("dubbo");
            if (dubbo == null)
                dubbo = "0.0.0";
            String application = parameter.get("application");
            if (versions.get(dubbo) == null) {
                Set<String> apps = new HashSet<String>();
                versions.put(dubbo, apps);
            }
            versions.get(dubbo).add(application);
        }
    }
    context.put("versions", versions);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) HashMap(java.util.HashMap) Provider(com.alibaba.dubbo.registry.common.domain.Provider) HashSet(java.util.HashSet)

Example 12 with Provider

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

the class Providers method add.

/**
     * 装载新增服务页面,获取所有的服务名称
     * @param context
     */
public void add(Long id, Map<String, Object> context) {
    if (context.get("service") == null) {
        List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
        context.put("serviceList", serviceList);
    }
    if (id != null) {
        Provider p = providerService.findProvider(id);
        if (p != null) {
            context.put("provider", p);
            String parameters = p.getParameters();
            if (parameters != null && parameters.length() > 0) {
                Map<String, String> map = StringUtils.parseQueryString(parameters);
                map.put("timestamp", String.valueOf(System.currentTimeMillis()));
                map.remove("pid");
                p.setParameters(StringUtils.toQueryString(map));
            }
        }
    }
}
Also used : Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 13 with Provider

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

the class Providers method enable.

public boolean enable(Long[] ids, Map<String, Object> context) {
    Map<Long, Provider> id2Provider = new HashMap<Long, Provider>();
    for (Long id : ids) {
        Provider provider = providerService.findProvider(id);
        if (provider == null) {
            context.put("message", getMessage("NoSuchOperationData", id));
            return false;
        } else if (!super.currentUser.hasServicePrivilege(provider.getService())) {
            context.put("message", getMessage("HaveNoServicePrivilege", provider.getService()));
            return false;
        }
        id2Provider.put(id, provider);
    }
    for (Long id : ids) {
        providerService.enableProvider(id);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 14 with Provider

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

the class Routes method preview.

public void preview(Map<String, Object> context) throws Exception {
    String rid = (String) context.get("id");
    String consumerid = (String) context.get("cid");
    if (StringUtils.isEmpty(rid)) {
        context.put("message", getMessage("MissRequestParameters", "id"));
    }
    Map<String, String> serviceUrls = new HashMap<String, String>();
    Route route = routeService.findRoute(Long.valueOf(rid));
    if (null == route) {
        context.put("message", getMessage("NoSuchRecord"));
    }
    List<Provider> providers = providerService.findByService(route.getService());
    if (providers != null) {
        for (Provider p : providers) {
            serviceUrls.put(p.getUrl(), p.getParameters());
        }
    }
    if (StringUtils.isNotEmpty(consumerid)) {
        Consumer consumer = consumerService.findConsumer(Long.valueOf(consumerid));
        if (null == consumer) {
            context.put("message", getMessage("NoSuchRecord"));
        }
        Map<String, String> result = RouteUtils.previewRoute(consumer.getService(), consumer.getAddress(), consumer.getParameters(), serviceUrls, route, null, null);
        context.put("route", route);
        context.put("consumer", consumer);
        context.put("result", result);
    } else {
        String address = (String) context.get("address");
        String service = (String) context.get("service");
        Map<String, String> result = RouteUtils.previewRoute(service, address, null, serviceUrls, route, null, null);
        context.put("route", route);
        Consumer consumer = new Consumer();
        consumer.setService(service);
        consumer.setAddress(address);
        context.put("consumer", consumer);
        context.put("result", result);
    }
}
Also used : Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) HashMap(java.util.HashMap) Route(com.alibaba.dubbo.registry.common.domain.Route) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 15 with Provider

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

the class Index method execute.

public void execute(Context context) {
    Set<String> applications = new HashSet<String>();
    Set<String> services = new HashSet<String>();
    List<Provider> pList = new ArrayList<Provider>();
    try {
        pList = providerService.findAll();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    for (Provider p : pList) {
        applications.add(p.getApplication());
        services.add(p.getService());
    }
    List<Consumer> cList = new ArrayList<Consumer>();
    try {
        cList = consumerService.findAll();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    for (Consumer c : cList) {
        applications.add(c.getApplication());
        services.add(c.getService());
    }
    context.put("rootContextPath", new RootContextPath(request.getContextPath()));
    context.put("services", services.size());
    context.put("providers", pList.size());
    context.put("consumers", cList.size());
    context.put("applications", applications.size());
}
Also used : Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) RootContextPath(com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) 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