use of com.alibaba.dubbo.registry.common.domain.Consumer in project dubbo by alibaba.
the class Routes method routeselect.
/**
* 选择消费者
* @param context
*/
public void routeselect(Map<String, Object> context) {
long rid = Long.valueOf((String) context.get("id"));
context.put("id", rid);
Route route = routeService.findRoute(rid);
if (route == null) {
throw new IllegalStateException("Route(id=" + rid + ") is not existed!");
}
context.put("route", route);
// 获取数据
List<Consumer> consumers = consumerService.findByService(route.getService());
context.put("consumers", consumers);
Map<String, Boolean> matchRoute = new HashMap<String, Boolean>();
for (Consumer c : consumers) {
matchRoute.put(c.getAddress(), RouteUtils.matchRoute(c.getAddress(), null, route, null));
}
context.put("matchRoute", matchRoute);
}
use of com.alibaba.dubbo.registry.common.domain.Consumer 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);
}
}
use of com.alibaba.dubbo.registry.common.domain.Consumer 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());
}
use of com.alibaba.dubbo.registry.common.domain.Consumer 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;
}
use of com.alibaba.dubbo.registry.common.domain.Consumer 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);
}
Aggregations