You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "liming0 (via GitHub)" <gi...@apache.org> on 2023/05/04 07:21:14 UTC

[GitHub] [shardingsphere] liming0 opened a new pull request, #25447: Liming0 patch 1

liming0 opened a new pull request, #25447:
URL: https://github.com/apache/shardingsphere/pull/25447

   Fixes #ISSUSE_ID.
   
   Changes proposed in this pull request:
     -
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] liming0 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "liming0 (via GitHub)" <gi...@apache.org>.
liming0 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1606519314

   > Will this issue be completed before June 15 which is the final date of version 5.4.0?
   
   I did not succeed in the CI phase, but there is a compilation issue with this project on my computer, which seems to be related to those. G4 files. I don't know how to solve it. Can you help me?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on a diff in pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on code in PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#discussion_r1185740040


##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/NacosDriverURLProvider.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.shardingsphere.driver.jdbc.core.driver.spi;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.common.Constants;
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.google.common.base.Preconditions;
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereDriverURLProvider;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public final class NacosDriverURLProvider implements ShardingSphereDriverURLProvider {
+
+    private static final String PARAM_PREFIX = "?";
+
+    private static final String NACOS_TYPE = "nacos:";
+
+    private static final String SHRDING_URL_PREFIX = "jdbc:shardingsphere:";
+
+    @Override
+    public boolean accept(final String url) {
+        return StringUtils.isNotBlank(url) && url.contains(NACOS_TYPE);
+    }
+
+    @Override
+    @SneakyThrows(NacosException.class)
+    public byte[] getContent(final String url) {
+        Properties props = getNacosConfigByUrl(url);
+        ConfigService configService = NacosFactory.createConfigService(props);
+        String dataId = props.getProperty(Constants.DATAID);
+        String config = configService.getConfig(dataId, props.getProperty(Constants.GROUP, Constants.DEFAULT_GROUP), 500);
+        Preconditions.checkArgument(config != null, "Nacos config [" + dataId + "] is Empty.");
+        return config.getBytes(StandardCharsets.UTF_8);
+    }
+
+    private Properties getNacosConfigByUrl(final String url) {
+        String nacosConfig = StringUtils.removeStart(url, SHRDING_URL_PREFIX + NACOS_TYPE);
+        Preconditions.checkArgument(nacosConfig.indexOf(PARAM_PREFIX) > 0, "Nacos param is required in ShardingSphere driver URL.");
+        String dataId = StringUtils.substringBefore(nacosConfig, PARAM_PREFIX);
+        //'withKeyValueSeparator(java.lang.String)' is marked unstable with @Beta
+        //Map<String, String> confMap = Splitter.on("&").withKeyValueSeparator("=").split(nacosConfig);
+        Map<String, String> confMap = getUrlParameters(StringUtils.substringAfter(nacosConfig, PARAM_PREFIX));
+        Properties properties = new Properties();
+        properties.putAll(confMap);
+        properties.put(Constants.DATAID, dataId);
+        return properties;
+    }
+
+    /**
+     * Parse url parameters.
+     *
+     * @param urlParam 'aaa=111&bbb=222'.

Review Comment:
   You can refer to other comment, remove `@author` and `@date`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] liming0 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "liming0 (via GitHub)" <gi...@apache.org>.
liming0 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1545389372

   > > > You can compile it at your local environment, The command is : `mvn clean install -Prelease -T1C -Djacoco.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -B`
   > > > @zhaojinchao95
   > > > Sorry, I encountered a problem while executing this command locally, but I haven't used this signed plugin before and don't know how to solve it
   > > 
   > > 
   > > ```
   > > Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-release-artifacts) on project shardingsphere: Execution sign-release-artifacts of goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign failed.
   > > ```
   > 
   > I haven't met this problem. You can run `JDBCMetaDataInfoExporterTest.class `
   There are several files that do not exist in my local environment, which has caused me to fail local compilation and cannot be tested. Can you tell me how they were generated? For example:
   `org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementLexer`
   `org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementLexer`
   ![image](https://github.com/apache/shardingsphere/assets/50445932/aa5daa56-5792-4057-b729-2ab4f9498489)
   ![image](https://github.com/apache/shardingsphere/assets/50445932/aa5daa56-5792-4057-b729-2ab4f9498489)
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] liming0 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "liming0 (via GitHub)" <gi...@apache.org>.
liming0 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1538078782

   > You can compile it at your local environment, The command is : `mvn clean install -Prelease -T1C -Djacoco.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -B`
   
   Sorry, I encountered a problem while executing this command locally, but I haven't used this signed plugin before and don't know how to solve it
   ```
   Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-release-artifacts) on project shardingsphere: Execution sign-release-artifacts of goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign failed.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] liming0 closed pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "liming0 (via GitHub)" <gi...@apache.org>.
liming0 closed pull request #25447: Sharding-jdbc supports nacos configuration
URL: https://github.com/apache/shardingsphere/pull/25447


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] vanniuner commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "vanniuner (via GitHub)" <gi...@apache.org>.
vanniuner commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1550626619

   what about this issue ? i'm waiting to use!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1545367246

   > > You can compile it at your local environment, The command is : `mvn clean install -Prelease -T1C -Djacoco.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -B`
   > > @zhaojinchao95
   > > Sorry, I encountered a problem while executing this command locally, but I haven't used this signed plugin before and don't know how to solve it
   > 
   > ```
   > Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-release-artifacts) on project shardingsphere: Execution sign-release-artifacts of goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign failed.
   > ```
   
   I haven't met this problem. You can run `JDBCMetaDataInfoExporterTest.class `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] liming0 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "liming0 (via GitHub)" <gi...@apache.org>.
liming0 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1535820797

   ![image](https://user-images.githubusercontent.com/50445932/236396638-9fbdebb0-942e-4d84-9d1c-a6eac85a731d.png)
   @zhaojinchao95 Hello, all the modifications have been completed, but there is an error that I don't know how to solve. This modification does not involve any modifications to the module. Can you help me specify it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on a diff in pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on code in PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#discussion_r1184739138


##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/NacosDriverURLProvider.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.shardingsphere.driver.jdbc.core.driver.spi;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.common.Constants;
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.google.common.base.Preconditions;
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereDriverURLProvider;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public class NacosDriverURLProvider implements ShardingSphereDriverURLProvider {

Review Comment:
   Add `final` decorate



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1535881656

   > ![image](https://user-images.githubusercontent.com/50445932/236396638-9fbdebb0-942e-4d84-9d1c-a6eac85a731d.png) @zhaojinchao95 Hello, all the modifications have been completed, but there is an error that I don't know how to solve. This modification does not involve any modifications to the module. Can you help me specify it
   
   You can look this: 
   
   <img width="1267" alt="image" src="https://user-images.githubusercontent.com/33742097/236405726-d9a33034-d7eb-4ad4-acbd-a60fc661a716.png">


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1535884312

   You can compile it at your local environment, The command is : `mvn clean install -Prelease -T1C -Djacoco.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -B`  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on a diff in pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on code in PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#discussion_r1185739470


##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/NacosDriverURLProvider.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.shardingsphere.driver.jdbc.core.driver.spi;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.common.Constants;
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.google.common.base.Preconditions;
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereDriverURLProvider;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public final class NacosDriverURLProvider implements ShardingSphereDriverURLProvider {
+
+    private static final String PARAM_PREFIX = "?";
+
+    private static final String NACOS_TYPE = "nacos:";
+
+    private static final String SHRDING_URL_PREFIX = "jdbc:shardingsphere:";
+
+    @Override
+    public boolean accept(final String url) {
+        return StringUtils.isNotBlank(url) && url.contains(NACOS_TYPE);
+    }
+
+    @Override
+    @SneakyThrows(NacosException.class)
+    public byte[] getContent(final String url) {
+        Properties props = getNacosConfigByUrl(url);
+        ConfigService configService = NacosFactory.createConfigService(props);
+        String dataId = props.getProperty(Constants.DATAID);
+        String config = configService.getConfig(dataId, props.getProperty(Constants.GROUP, Constants.DEFAULT_GROUP), 500);
+        Preconditions.checkArgument(config != null, "Nacos config [" + dataId + "] is Empty.");
+        return config.getBytes(StandardCharsets.UTF_8);
+    }
+
+    private Properties getNacosConfigByUrl(final String url) {
+        String nacosConfig = StringUtils.removeStart(url, SHRDING_URL_PREFIX + NACOS_TYPE);
+        Preconditions.checkArgument(nacosConfig.indexOf(PARAM_PREFIX) > 0, "Nacos param is required in ShardingSphere driver URL.");
+        String dataId = StringUtils.substringBefore(nacosConfig, PARAM_PREFIX);
+        //'withKeyValueSeparator(java.lang.String)' is marked unstable with @Beta

Review Comment:
   Please remove this comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1537835985

   @liming0 Hi, Can you fix it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1551477167

   > > > > You can compile it at your local environment, The command is : `mvn clean install -Prelease -T1C -Djacoco.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -B`
   > > > > @zhaojinchao95
   > > > > Sorry, I encountered a problem while executing this command locally, but I haven't used this signed plugin before and don't know how to solve it
   > > > 
   > > > 
   > > > ```
   > > > Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-release-artifacts) on project shardingsphere: Execution sign-release-artifacts of goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign failed.
   > > > ```
   > > 
   > > 
   > > I haven't met this problem. You can run `JDBCMetaDataInfoExporterTest.class `
   > > There are several files that do not exist in my local environment, which has caused me to fail local compilation and cannot be tested. Can you tell me how they were generated? For example:
   > > `org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementLexer`
   > > `org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementLexer`
   > > ![image](https://user-images.githubusercontent.com/50445932/237918107-aa5daa56-5792-4057-b729-2ab4f9498489.png)
   > > ![image](https://user-images.githubusercontent.com/50445932/237918107-aa5daa56-5792-4057-b729-2ab4f9498489.png)
   
   Excute `mvn clean install -B -T1C -Dmaven.javadoc.skip=true  -Drat.skip=true -Dcheckstyle.skip -Djacoco.skip=true` and run unit test again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on a diff in pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on code in PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#discussion_r1184737201


##########
docs/document/content/dev-manual/data-source.cn.md:
##########
@@ -118,7 +118,7 @@ ShardingSphere 驱动 URL 提供器
 | jdbc:shardingsphere:classpath:<path>    | 驱动的类路径加载器      | [`org.apache.shardingsphere.driver.jdbc.core.driver.spi.ClasspathDriverURLProvider`](https://github.com/apache/shardingsphere/blob/master/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/ClasspathDriverURLProvider.java)       |
 | jdbc:shardingsphere:absolutepath:<path> | 驱动的绝对路径加载器     | [`org.apache.shardingsphere.driver.jdbc.core.driver.spi.AbsolutePathDriverURLProvider`](https://github.com/apache/shardingsphere/blob/master/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/AbsolutePathDriverURLProvider.java) |
 | jdbc:shardingsphere:apollo:<namespace>  | 驱动的 Apollo 加载器 | [`org.apache.shardingsphere.driver.jdbc.core.driver.spi.ApolloDriverURLProvider`](https://github.com/apache/shardingsphere/blob/master/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/ApolloDriverURLProvider.java)             |
-
+| jdbc:shardingsphere:nacos:<param>      | 驱动的 Nacos 加载器 | [`org.apache.shardingsphere.driver.jdbc.core.driver.spi.ApolloDriverURLProvider`](https://github.com/apache/shardingsphere/blob/master/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/NacosDriverURLProvider.java)             |

Review Comment:
   Is it `NacosDriverURLProvider`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zhaojinchao95 commented on a diff in pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on code in PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#discussion_r1185740323


##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/NacosDriverURLProvider.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.shardingsphere.driver.jdbc.core.driver.spi;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.common.Constants;
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.google.common.base.Preconditions;
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereDriverURLProvider;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public final class NacosDriverURLProvider implements ShardingSphereDriverURLProvider {
+
+    private static final String PARAM_PREFIX = "?";
+
+    private static final String NACOS_TYPE = "nacos:";
+
+    private static final String SHRDING_URL_PREFIX = "jdbc:shardingsphere:";
+
+    @Override
+    public boolean accept(final String url) {
+        return StringUtils.isNotBlank(url) && url.contains(NACOS_TYPE);
+    }
+
+    @Override
+    @SneakyThrows(NacosException.class)
+    public byte[] getContent(final String url) {
+        Properties props = getNacosConfigByUrl(url);
+        ConfigService configService = NacosFactory.createConfigService(props);
+        String dataId = props.getProperty(Constants.DATAID);
+        String config = configService.getConfig(dataId, props.getProperty(Constants.GROUP, Constants.DEFAULT_GROUP), 500);
+        Preconditions.checkArgument(config != null, "Nacos config [" + dataId + "] is Empty.");
+        return config.getBytes(StandardCharsets.UTF_8);
+    }
+
+    private Properties getNacosConfigByUrl(final String url) {
+        String nacosConfig = StringUtils.removeStart(url, SHRDING_URL_PREFIX + NACOS_TYPE);
+        Preconditions.checkArgument(nacosConfig.indexOf(PARAM_PREFIX) > 0, "Nacos param is required in ShardingSphere driver URL.");
+        String dataId = StringUtils.substringBefore(nacosConfig, PARAM_PREFIX);
+        //'withKeyValueSeparator(java.lang.String)' is marked unstable with @Beta
+        //Map<String, String> confMap = Splitter.on("&").withKeyValueSeparator("=").split(nacosConfig);
+        Map<String, String> confMap = getUrlParameters(StringUtils.substringAfter(nacosConfig, PARAM_PREFIX));
+        Properties properties = new Properties();
+        properties.putAll(confMap);
+        properties.put(Constants.DATAID, dataId);
+        return properties;
+    }
+
+    /**
+     * Parse url parameters.
+     *
+     * @param urlParam 'aaa=111&bbb=222'.
+     * @return  return HashMap.
+     * @author: li.ming
+     * @date: 2023/5/4 17:34
+     */
+    public Map<String, String> getUrlParameters(final String urlParam) {
+        Map<String, String> mapRequest = new HashMap<>();
+        String[] arrSplit;
+        if (urlParam == null) {
+            return mapRequest;
+        }
+        arrSplit = urlParam.split("[&]");
+        for (String strSplit : arrSplit) {
+            String[] arrSplitEqual;
+            arrSplitEqual = strSplit.split("[=]");
+            if (arrSplitEqual.length > 1) {
+                mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);
+            } else {
+                if (!"".equals(arrSplitEqual[0])) {
+                    mapRequest.put(arrSplitEqual[0], "");
+                }
+            }
+        }
+        return mapRequest;

Review Comment:
   Change `mapRequest` to `result`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] liming0 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "liming0 (via GitHub)" <gi...@apache.org>.
liming0 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1606512524

   > Will this issue be completed before June 15 which is the final date of version 5.4.0?
   I'm afraid not. The code is already completed, but there are compilation issues. Looking forward to help😂


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] boyjoy1127 commented on pull request #25447: Sharding-jdbc supports nacos configuration

Posted by "boyjoy1127 (via GitHub)" <gi...@apache.org>.
boyjoy1127 commented on PR #25447:
URL: https://github.com/apache/shardingsphere/pull/25447#issuecomment-1585976336

   Will this issue be completed before June 15 which is the final date of version 5.4.0?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org