Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore non-dubbo nacos services #7602

Merged
merged 3 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.Collections;

import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
Expand All @@ -64,6 +65,7 @@
import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL;
import static org.apache.dubbo.registry.nacos.NacosServiceName.NAME_SEPARATOR;
import static org.apache.dubbo.registry.nacos.NacosServiceName.valueOf;

/**
Expand Down Expand Up @@ -286,19 +288,29 @@ private Set<String> getServiceNames0(URL url) {
private Set<String> filterServiceNames(NacosServiceName serviceName) {
Set<String> serviceNames = new LinkedHashSet<>();

execute(namingService -> {
execute(namingService -> serviceNames.addAll(namingService.getServicesOfServer(1, Integer.MAX_VALUE,
getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP)).getData()
.stream()
.filter(this::isConformRules)
.map(NacosServiceName::new)
.filter(serviceName::isCompatible)
.map(NacosServiceName::toString)
.collect(Collectors.toList())));

serviceNames.addAll(namingService.getServicesOfServer(1, Integer.MAX_VALUE,
getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP)).getData()
.stream()
.map(NacosServiceName::new)
.filter(serviceName::isCompatible)
.map(NacosServiceName::toString)
.collect(Collectors.toList()));
return serviceNames;
}

});
/**
* Verify whether it is a dubbo service
*
* @param serviceName
* @return
* @since 2.7.12
*/
private boolean isConformRules(String serviceName) {

return serviceName.split(NAME_SEPARATOR, -1).length == 4;
CrazyHZM marked this conversation as resolved.
Show resolved Hide resolved

return serviceNames;
}

/**
Expand Down Expand Up @@ -490,10 +502,9 @@ private void subscribeEventListener(String serviceName, final URL url, final Not


if (isServiceNamesWithCompatibleMode(url)) {
/**
* Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned
* in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
*/

// Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned
// in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
instances = NacosInstanceManageUtil.getAllCorrespondingServiceInstanceList(serviceName);
}
Expand Down Expand Up @@ -531,7 +542,7 @@ private void notifySubscriber(URL url, NotifyListener listener, Collection<Insta
*/
private List<String> getCategories(URL url) {
return ANY_VALUE.equals(url.getServiceInterface()) ?
ALL_SUPPORTED_CATEGORIES : Arrays.asList(DEFAULT_CATEGORY);
ALL_SUPPORTED_CATEGORIES : Collections.singletonList(DEFAULT_CATEGORY);
}

private URL buildURL(Instance instance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public boolean isConcrete() {

public boolean isCompatible(NacosServiceName concreteServiceName) {

if (!concreteServiceName.isConcrete()) { // The argument must be the concrete NacosServiceName
// The argument must be the concrete NacosServiceName
if (!concreteServiceName.isConcrete()) {
return false;
}

Expand Down Expand Up @@ -160,7 +161,7 @@ private boolean isWildcard(String value) {
}

private boolean isRange(String value) {
return value != null && value.indexOf(VALUE_SEPARATOR) > -1 && value.split(VALUE_SEPARATOR).length > 1;
return value != null && value.contains(VALUE_SEPARATOR) && value.split(VALUE_SEPARATOR).length > 1;
}

public String getCategory() {
Expand Down Expand Up @@ -203,11 +204,10 @@ public String getValue() {
}

private String toValue() {
return new StringBuilder(category)
.append(NAME_SEPARATOR).append(serviceInterface)
.append(NAME_SEPARATOR).append(version)
.append(NAME_SEPARATOR).append(group)
.toString();
return category +
NAME_SEPARATOR + serviceInterface +
NAME_SEPARATOR + version +
NAME_SEPARATOR + group;
}

@Override
Expand Down
Loading