use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Services method mock.
private boolean mock(Map<String, Object> context, String mock) throws Exception {
String services = (String) context.get("service");
String application = (String) context.get("application");
if (services == null || services.length() == 0 || application == null || application.length() == 0) {
context.put("message", getMessage("NoSuchOperationData"));
return false;
}
for (String service : SPACE_SPLIT_PATTERN.split(services)) {
if (!super.currentUser.hasServicePrivilege(service)) {
context.put("message", getMessage("HaveNoServicePrivilege", service));
return false;
}
}
for (String service : SPACE_SPLIT_PATTERN.split(services)) {
List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
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.setApplication(application);
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.Override in project dubbo by alibaba.
the class Tool method isProviderEnabled.
public static boolean isProviderEnabled(Provider provider, List<Override> oList) {
for (Override o : oList) {
if (o.isMatch(provider)) {
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
String disbaled = params.get(Constants.DISABLED_KEY);
if (disbaled != null && disbaled.length() > 0) {
return !"true".equals(disbaled);
}
}
}
return provider.isEnabled();
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Consumers method update.
public boolean update(Consumer newConsumer, Map<String, Object> context) {
Long id = newConsumer.getId();
String parameters = newConsumer.getParameters();
Consumer consumer = consumerService.findConsumer(id);
if (consumer == null) {
context.put("message", getMessage("NoSuchOperationData", id));
return false;
}
String service = consumer.getService();
if (!super.currentUser.hasServicePrivilege(service)) {
context.put("message", getMessage("HaveNoServicePrivilege", service));
return false;
}
Map<String, String> oldMap = StringUtils.parseQueryString(consumer.getParameters());
Map<String, String> newMap = StringUtils.parseQueryString(parameters);
for (Map.Entry<String, String> entry : oldMap.entrySet()) {
if (entry.getValue().equals(newMap.get(entry.getKey()))) {
newMap.remove(entry.getKey());
}
}
String address = consumer.getAddress();
List<Override> overrides = overrideService.findByServiceAndAddress(consumer.getService(), consumer.getAddress());
OverrideUtils.setConsumerOverrides(consumer, overrides);
Override override = consumer.getOverride();
if (override != null) {
if (newMap.size() > 0) {
override.setParams(StringUtils.toQueryString(newMap));
override.setEnabled(true);
override.setOperator(operator);
override.setOperatorAddress(operatorAddress);
overrideService.updateOverride(override);
} else {
overrideService.deleteOverride(override.getId());
}
} else {
override = new Override();
override.setService(service);
override.setAddress(address);
override.setParams(StringUtils.toQueryString(newMap));
override.setEnabled(true);
override.setOperator(operator);
override.setOperatorAddress(operatorAddress);
overrideService.saveOverride(override);
}
return true;
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Consumers method show.
public void show(Long id, Map<String, Object> context) {
Consumer consumer = consumerService.findConsumer(id);
List<Provider> providers = providerService.findByService(consumer.getService());
List<Route> routes = routeService.findByService(consumer.getService());
List<Override> overrides = overrideService.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("consumer", consumer);
context.put("providers", consumer.getProviders());
context.put("routes", consumer.getRoutes());
context.put("overrides", consumer.getOverrides());
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Providers method show.
public void show(Long id, Map<String, Object> context) {
Provider provider = providerService.findProvider(id);
if (provider != null && provider.isDynamic()) {
List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
OverrideUtils.setProviderOverrides(provider, overrides);
}
context.put("provider", provider);
}
Aggregations