use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class SyncUtils method url2Override.
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
if (pair == null) {
return null;
}
Long id = pair.getKey();
URL url = pair.getValue();
if (null == url)
return null;
com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
o.setId(id);
Map<String, String> parameters = new HashMap<String, String>(url.getParameters());
o.setService(url.getServiceKey());
parameters.remove(Constants.INTERFACE_KEY);
parameters.remove(Constants.GROUP_KEY);
parameters.remove(Constants.VERSION_KEY);
parameters.remove(Constants.APPLICATION_KEY);
parameters.remove(Constants.CATEGORY_KEY);
parameters.remove(Constants.DYNAMIC_KEY);
parameters.remove(Constants.ENABLED_KEY);
o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
String host = url.getHost();
boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
if (!anyhost || !"0.0.0.0".equals(host)) {
o.setAddress(url.getAddress());
}
o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
parameters.remove(Constants.VERSION_KEY);
o.setParams(StringUtils.toQueryString(parameters));
return o;
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class SyncUtils method filterFromUrls.
// Map<Long, URL>
static void filterFromUrls(Map<Long, URL> from, Map<Long, URL> to, Map<String, String> filter) {
if (from == null || from.isEmpty())
return;
for (Map.Entry<Long, URL> entry : from.entrySet()) {
URL url = entry.getValue();
boolean match = true;
for (Map.Entry<String, String> e : filter.entrySet()) {
String key = e.getKey();
String value = e.getValue();
if (ADDRESS_FILTER_KEY.equals(key)) {
if (!value.equals(url.getAddress())) {
match = false;
break;
}
} else {
if (!value.equals(url.getParameter(key))) {
match = false;
break;
}
}
}
if (match) {
to.put(entry.getKey(), url);
}
}
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class SyncUtils method url2Route.
public static Route url2Route(Pair<Long, URL> pair) {
if (pair == null) {
return null;
}
Long id = pair.getKey();
URL url = pair.getValue();
if (null == url)
return null;
Route r = new Route();
r.setId(id);
r.setName(url.getParameter("name"));
r.setService(url.getServiceKey());
r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
r.setForce(url.getParameter(Constants.FORCE_KEY, false));
r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
return r;
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class OverrideServiceImpl method updateOverride.
public void updateOverride(Override override) {
Long id = override.getId();
if (id == null) {
throw new IllegalStateException("no override id");
}
URL oldOverride = findOverrideUrl(id);
if (oldOverride == null) {
throw new IllegalStateException("Route was changed!");
}
URL newOverride = getUrlFromOverride(override);
registryService.unregister(oldOverride);
registryService.register(newOverride);
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class OverrideServiceImpl method enableOverride.
public void enableOverride(Long id) {
if (id == null) {
throw new IllegalStateException("no override id");
}
URL oldOverride = findOverrideUrl(id);
if (oldOverride == null) {
throw new IllegalStateException("Override was changed!");
}
if (oldOverride.getParameter("enabled", true)) {
return;
}
URL newOverride = oldOverride.removeParameter("enabled");
registryService.unregister(oldOverride);
registryService.register(newOverride);
}
Aggregations