use of com.alibaba.dubbo.registry.common.domain.Override 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());
}
use of com.alibaba.dubbo.registry.common.domain.Override 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);
}
}
use of com.alibaba.dubbo.registry.common.domain.Override 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);
}
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class OverrideUtils method setProviderOverrides.
public static void setProviderOverrides(Provider provider, List<Override> overrides) {
if (provider == null || overrides == null) {
return;
}
List<Override> result = new ArrayList<Override>(overrides.size());
for (Override override : overrides) {
if (!override.isEnabled()) {
continue;
}
if (override.isMatch(provider)) {
result.add(override);
}
if (override.isUniqueMatch(provider)) {
provider.setOverride(override);
}
}
provider.setOverrides(overrides);
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Services method index.
public void index(Map<String, Object> context) {
String application = (String) context.get("application");
String address = (String) context.get("address");
if (context.get("service") == null && context.get("application") == null && context.get("address") == null) {
context.put("service", "*");
}
List<String> providerServices = null;
List<String> consumerServices = null;
List<Override> overrides = null;
if (application != null && application.length() > 0) {
providerServices = providerService.findServicesByApplication(application);
consumerServices = consumerService.findServicesByApplication(application);
overrides = overrideService.findByApplication(application);
} else if (address != null && address.length() > 0) {
providerServices = providerService.findServicesByAddress(address);
consumerServices = consumerService.findServicesByAddress(address);
overrides = overrideService.findByAddress(Tool.getIP(address));
} else {
providerServices = providerService.findServices();
consumerServices = consumerService.findServices();
overrides = overrideService.findAll();
}
Set<String> services = new TreeSet<String>();
if (providerServices != null) {
services.addAll(providerServices);
}
if (consumerServices != null) {
services.addAll(consumerServices);
}
Map<String, List<Override>> service2Overrides = new HashMap<String, List<Override>>();
if (overrides != null && overrides.size() > 0 && services != null && services.size() > 0) {
for (String s : services) {
if (overrides != null && overrides.size() > 0) {
for (Override override : overrides) {
List<Override> serOverrides = new ArrayList<Override>();
if (override.isMatch(s, address, application)) {
serOverrides.add(override);
}
Collections.sort(serOverrides, OverrideUtils.OVERRIDE_COMPARATOR);
service2Overrides.put(s, serOverrides);
}
}
}
}
context.put("providerServices", providerServices);
context.put("consumerServices", consumerServices);
context.put("services", services);
context.put("overrides", service2Overrides);
String keyword = (String) context.get("keyword");
if (StringUtils.isNotEmpty(keyword) && !"*".equals(keyword)) {
keyword = keyword.toLowerCase();
Set<String> newList = new HashSet<String>();
Set<String> newProviders = new HashSet<String>();
Set<String> newConsumers = new HashSet<String>();
for (String o : services) {
if (o.toLowerCase().toLowerCase().indexOf(keyword) != -1) {
newList.add(o);
}
}
for (String o : providerServices) {
if (o.toLowerCase().indexOf(keyword) != -1) {
newProviders.add(o);
}
}
for (String o : consumerServices) {
if (o.toLowerCase().indexOf(keyword) != -1) {
newConsumers.add(o);
}
}
context.put("services", newList);
context.put("providerServices", newProviders);
context.put("consumerServices", newConsumers);
}
}
Aggregations