This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f8181e  [ISSUE-#7129] 
NacosRegistry,NacosMetadataReport,NacosDynamicConfiguration compatible with 
innerclass symbol  '$' (#7346)
8f8181e is described below

commit 8f8181e717b026300dc5e09d645883c8962e454f
Author: 赵延 <[email protected]>
AuthorDate: Thu Mar 25 23:01:51 2021 +0800

    [ISSUE-#7129] NacosRegistry,NacosMetadataReport,NacosDynamicConfiguration 
compatible with innerclass symbol  '$' (#7346)
    
    * use '___' to replace '$' when some operation about serviceName.
    
    * nacosMetadata and nacosDynamicConfig support compatible with inner symbol 
'$'.
    
    * group also compatible with inner symbol '$'.
    
    * modify the final variable name.
    
    * remove unnecessary import.
    
    * some code format
    
    * Revert "some code format"
    
    This reverts commit d60d3984
---
 .../support/nacos/NacosConfigServiceWrapper.java   | 65 ++++++++++++++++
 .../support/nacos/NacosDynamicConfiguration.java   |  8 +-
 .../store/nacos/NacosConfigServiceWrapper.java     | 55 ++++++++++++++
 .../metadata/store/nacos/NacosMetadataReport.java  |  7 +-
 .../registry/nacos/NacosNamingServiceWrapper.java  | 87 ++++++++++++++++++++++
 .../apache/dubbo/registry/nacos/NacosRegistry.java |  7 +-
 .../registry/nacos/NacosServiceDiscovery.java      |  3 +-
 .../nacos/util/NacosNamingServiceUtils.java        |  5 +-
 8 files changed, 222 insertions(+), 15 deletions(-)

diff --git 
a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosConfigServiceWrapper.java
 
b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosConfigServiceWrapper.java
new file mode 100644
index 0000000..b085597
--- /dev/null
+++ 
b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosConfigServiceWrapper.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.configcenter.support.nacos;
+
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.config.listener.Listener;
+import com.alibaba.nacos.api.exception.NacosException;
+
+public class NacosConfigServiceWrapper {
+
+    private static final String INNERCLASS_SYMBOL = "$";
+
+    private static final String INNERCLASS_COMPATIBLE_SYMBOL = "___";
+
+    private ConfigService configService;
+
+
+    public NacosConfigServiceWrapper(ConfigService configService) {
+        this.configService = configService;
+    }
+
+    public ConfigService getConfigService() {
+        return configService;
+    }
+
+    public void addListener(String dataId, String group, Listener listener) 
throws NacosException {
+        configService.addListener(handleInnerSymbol(dataId), 
handleInnerSymbol(group), listener);
+    }
+
+    public String getConfig(String dataId, String group, long timeout) throws 
NacosException {
+        return configService.getConfig(handleInnerSymbol(dataId), 
handleInnerSymbol(group), timeout);
+    }
+
+    public boolean publishConfig(String dataId, String group, String content) 
throws NacosException {
+        return configService.publishConfig(handleInnerSymbol(dataId), 
handleInnerSymbol(group), content);
+    }
+
+    public boolean removeConfig(String dataId, String group) throws 
NacosException {
+        return configService.removeConfig(handleInnerSymbol(dataId), 
handleInnerSymbol(group));
+    }
+
+    /**
+     * see {@link 
com.alibaba.nacos.client.config.utils.ParamUtils#isValid(java.lang.String)}
+     */
+    private String handleInnerSymbol(String dataId) {
+        if (dataId == null) {
+            return null;
+        }
+        return dataId.replace(INNERCLASS_SYMBOL, INNERCLASS_COMPATIBLE_SYMBOL);
+    }
+}
diff --git 
a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
 
b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
index cc7f0e0..310310f 100644
--- 
a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
+++ 
b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
@@ -82,7 +82,7 @@ public class NacosDynamicConfiguration implements 
DynamicConfiguration {
     /**
      * The nacos configService
      */
-    private final ConfigService configService;
+    private final NacosConfigServiceWrapper configService;
 
     private HttpAgent httpAgent;
 
@@ -94,11 +94,11 @@ public class NacosDynamicConfiguration implements 
DynamicConfiguration {
     NacosDynamicConfiguration(URL url) {
         this.nacosProperties = buildNacosProperties(url);
         this.configService = buildConfigService(url);
-        this.httpAgent = getHttpAgent(configService);
+        this.httpAgent = getHttpAgent(configService.getConfigService());
         watchListenerMap = new ConcurrentHashMap<>();
     }
 
-    private ConfigService buildConfigService(URL url) {
+    private NacosConfigServiceWrapper buildConfigService(URL url) {
         ConfigService configService = null;
         try {
             configService = NacosFactory.createConfigService(nacosProperties);
@@ -108,7 +108,7 @@ public class NacosDynamicConfiguration implements 
DynamicConfiguration {
             }
             throw new IllegalStateException(e);
         }
-        return configService;
+        return new NacosConfigServiceWrapper(configService);
     }
 
     private HttpAgent getHttpAgent(ConfigService configService) {
diff --git 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosConfigServiceWrapper.java
 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosConfigServiceWrapper.java
new file mode 100644
index 0000000..e5f4074
--- /dev/null
+++ 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosConfigServiceWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.metadata.store.nacos;
+
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.exception.NacosException;
+
+public class NacosConfigServiceWrapper {
+
+    private static final String INNERCLASS_SYMBOL = "$";
+
+    private static final String INNERCLASS_COMPATIBLE_SYMBOL = "___";
+
+    private ConfigService configService;
+
+    public NacosConfigServiceWrapper(ConfigService configService) {
+        this.configService = configService;
+    }
+
+    public boolean publishConfig(String dataId, String group, String content) 
throws NacosException {
+        return configService.publishConfig(handleInnerSymbol(dataId), 
handleInnerSymbol(group), content);
+    }
+
+    public boolean removeConfig(String dataId, String group) throws 
NacosException {
+        return configService.removeConfig(handleInnerSymbol(dataId), 
handleInnerSymbol(group));
+    }
+
+    public String getConfig(String dataId, String group, long timeout) throws 
NacosException {
+        return configService.getConfig(handleInnerSymbol(dataId), 
handleInnerSymbol(group), timeout);
+    }
+
+    /**
+     * see {@link 
com.alibaba.nacos.client.config.utils.ParamUtils#isValid(java.lang.String)}
+     */
+    private String handleInnerSymbol(String dataId) {
+        if (dataId == null) {
+            return null;
+        }
+        return dataId.replace(INNERCLASS_SYMBOL, INNERCLASS_COMPATIBLE_SYMBOL);
+    }
+}
diff --git 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
index 69024e1..c59f3ba 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
@@ -28,7 +28,6 @@ import 
org.apache.dubbo.metadata.report.support.AbstractMetadataReport;
 import org.apache.dubbo.rpc.RpcException;
 
 import com.alibaba.nacos.api.NacosFactory;
-import com.alibaba.nacos.api.config.ConfigService;
 import com.alibaba.nacos.api.exception.NacosException;
 
 import java.util.ArrayList;
@@ -65,7 +64,7 @@ import static 
org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
  */
 public class NacosMetadataReport extends AbstractMetadataReport {
 
-    private ConfigService configService;
+    private NacosConfigServiceWrapper configService;
 
     /**
      * The group used to store metadata in Nacos
@@ -79,10 +78,10 @@ public class NacosMetadataReport extends 
AbstractMetadataReport {
         group = url.getParameter(GROUP_KEY, DEFAULT_ROOT);
     }
 
-    public ConfigService buildConfigService(URL url) {
+    public NacosConfigServiceWrapper buildConfigService(URL url) {
         Properties nacosProperties = buildNacosProperties(url);
         try {
-            configService = NacosFactory.createConfigService(nacosProperties);
+            configService = new 
NacosConfigServiceWrapper(NacosFactory.createConfigService(nacosProperties));
         } catch (NacosException e) {
             if (logger.isErrorEnabled()) {
                 logger.error(e.getErrMsg(), e);
diff --git 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosNamingServiceWrapper.java
 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosNamingServiceWrapper.java
new file mode 100644
index 0000000..6aa2bdf
--- /dev/null
+++ 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosNamingServiceWrapper.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.registry.nacos;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingService;
+import com.alibaba.nacos.api.naming.listener.EventListener;
+import com.alibaba.nacos.api.naming.pojo.Instance;
+import com.alibaba.nacos.api.naming.pojo.ListView;
+
+import java.util.List;
+
+public class NacosNamingServiceWrapper {
+
+    private static final String INNERCLASS_SYMBOL = "$";
+
+    private static final String INNERCLASS_COMPATIBLE_SYMBOL = "___";
+
+    private NamingService namingService;
+
+    public NacosNamingServiceWrapper(NamingService namingService) {
+        this.namingService = namingService;
+    }
+
+
+    public String getServerStatus() {
+        return namingService.getServerStatus();
+    }
+
+    public void subscribe(String serviceName, EventListener eventListener) 
throws NacosException {
+        namingService.subscribe(handleInnerSymbol(serviceName), eventListener);
+    }
+
+    public void subscribe(String serviceName, String group, EventListener 
eventListener) throws NacosException {
+        namingService.subscribe(handleInnerSymbol(serviceName), group, 
eventListener);
+    }
+
+    public List<Instance> getAllInstances(String serviceName, String group) 
throws NacosException {
+        return namingService.getAllInstances(handleInnerSymbol(serviceName), 
group);
+    }
+
+    public void registerInstance(String serviceName, String group, Instance 
instance) throws NacosException {
+        namingService.registerInstance(handleInnerSymbol(serviceName), group, 
instance);
+    }
+
+    public void deregisterInstance(String serviceName, String group, String 
ip, int port) throws NacosException {
+        namingService.deregisterInstance(handleInnerSymbol(serviceName), 
group, ip, port);
+    }
+
+
+    public void deregisterInstance(String serviceName, String group, Instance 
instance) throws NacosException {
+        namingService.deregisterInstance(handleInnerSymbol(serviceName), 
group, instance);
+    }
+
+    public ListView<String> getServicesOfServer(int pageNo, int pageSize, 
String parameter) throws NacosException {
+        return namingService.getServicesOfServer(pageNo, pageSize, parameter);
+    }
+
+    public List<Instance> selectInstances(String serviceName, boolean healthy) 
throws NacosException {
+        return namingService.selectInstances(handleInnerSymbol(serviceName), 
healthy);
+    }
+
+    /**
+     * see https://github.com/apache/dubbo/issues/7129
+     * nacos service name just support `0-9a-zA-Z-._:`, grpc interface is 
inner interface, need compatible.
+     */
+    private String handleInnerSymbol(String serviceName) {
+        if (serviceName == null) {
+            return null;
+        }
+        return serviceName.replace(INNERCLASS_SYMBOL, 
INNERCLASS_COMPATIBLE_SYMBOL);
+    }
+}
diff --git 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
index b397077..d93d8c3 100644
--- 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
+++ 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
@@ -118,9 +118,9 @@ public class NacosRegistry extends FailbackRegistry {
      */
     private volatile ScheduledExecutorService scheduledExecutorService;
 
-    private final NamingService namingService;
+    private final NacosNamingServiceWrapper namingService;
 
-    public NacosRegistry(URL url, NamingService namingService) {
+    public NacosRegistry(URL url, NacosNamingServiceWrapper namingService) {
         super(url);
         this.namingService = namingService;
     }
@@ -147,6 +147,7 @@ public class NacosRegistry extends FailbackRegistry {
     @Override
     public void doRegister(URL url) {
         final String serviceName = getServiceName(url);
+
         final Instance instance = createInstance(url);
         /**
          *  namingService.registerInstance with {@link 
org.apache.dubbo.registry.support.AbstractRegistry#registryUrl}
@@ -617,7 +618,7 @@ public class NacosRegistry extends FailbackRegistry {
          * @param namingService {@link NamingService}
          * @throws NacosException
          */
-        void callback(NamingService namingService) throws NacosException;
+        void callback(NacosNamingServiceWrapper namingService) throws 
NacosException;
 
     }
 }
diff --git 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
index 6297868..28e4cea 100644
--- 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
+++ 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
@@ -27,7 +27,6 @@ import 
org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedLi
 import org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils;
 
 import com.alibaba.nacos.api.exception.NacosException;
-import com.alibaba.nacos.api.naming.NamingService;
 import com.alibaba.nacos.api.naming.listener.NamingEvent;
 import com.alibaba.nacos.api.naming.pojo.Instance;
 import com.alibaba.nacos.api.naming.pojo.ListView;
@@ -55,7 +54,7 @@ public class NacosServiceDiscovery extends 
AbstractServiceDiscovery {
 
     private String group;
 
-    private NamingService namingService;
+    private NacosNamingServiceWrapper namingService;
 
     private URL registryURL;
 
diff --git 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java
 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java
index 893cccb..3889280 100644
--- 
a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java
+++ 
b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java
@@ -22,6 +22,7 @@ import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.registry.client.DefaultServiceInstance;
 import org.apache.dubbo.registry.client.ServiceInstance;
+import org.apache.dubbo.registry.nacos.NacosNamingServiceWrapper;
 
 import com.alibaba.nacos.api.NacosFactory;
 import com.alibaba.nacos.api.PropertyKeyConst;
@@ -103,7 +104,7 @@ public class NacosNamingServiceUtils {
      * @return {@link NamingService}
      * @since 2.7.5
      */
-    public static NamingService createNamingService(URL connectionURL) {
+    public static NacosNamingServiceWrapper createNamingService(URL 
connectionURL) {
         Properties nacosProperties = buildNacosProperties(connectionURL);
         NamingService namingService;
         try {
@@ -114,7 +115,7 @@ public class NacosNamingServiceUtils {
             }
             throw new IllegalStateException(e);
         }
-        return namingService;
+        return new NacosNamingServiceWrapper(namingService);
     }
 
     private static Properties buildNacosProperties(URL url) {

Reply via email to