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

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


The following commit(s) were added to refs/heads/master by this push:
     new 21c96bb9a02 Make ProxyConfigurationLoader compatible with classless 
runtime environments (#38721)
21c96bb9a02 is described below

commit 21c96bb9a02f8ad2a6e65475ff4886a6aa22e676
Author: Hengqian Ling <[email protected]>
AuthorDate: Sat Jun 6 15:42:42 2026 +0800

    Make ProxyConfigurationLoader compatible with classless runtime 
environments (#38721)
    
    * Make ProxyConfigurationLoader compatible with classless runtime 
environments
    
    * Adapt the instructions in the PR review
    
    * Made the second adjustment based on the review in the PR
    
    * Refactor existing changes
---
 .../backend/config/ProxyConfigurationLoader.java   | 21 +++++++++++--
 .../config/ProxyConfigurationLoaderTest.java       | 36 ++++++++++++++++++++++
 .../conf/compatible_server_yaml/server.yaml        | 28 +++++++++++++++++
 3 files changed, 82 insertions(+), 3 deletions(-)

diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
index 2b01f673736..a7d1a7164ad 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
@@ -90,14 +90,29 @@ public final class ProxyConfigurationLoader {
     }
     
     private static File getGlobalConfigFile(final String path) {
-        File result = getResourceFile(String.join("/", path, 
GLOBAL_CONFIG_FILE));
-        return result.exists() ? result : getResourceFile(String.join("/", 
path, COMPATIBLE_GLOBAL_CONFIG_FILE));
+        File globalFile = new File(path, GLOBAL_CONFIG_FILE);
+        if (globalFile.exists()) {
+            return globalFile;
+        }
+        File compatibleFile = new File(path, COMPATIBLE_GLOBAL_CONFIG_FILE);
+        if (compatibleFile.exists()) {
+            return compatibleFile;
+        }
+        File classpathGlobal = getResourceFile(String.join("/", path, 
GLOBAL_CONFIG_FILE));
+        if (classpathGlobal.exists()) {
+            return classpathGlobal;
+        }
+        return getResourceFile(String.join("/", path, 
COMPATIBLE_GLOBAL_CONFIG_FILE));
     }
     
     @SneakyThrows(URISyntaxException.class)
     private static File getResourceFile(final String path) {
+        File result = new File(path);
+        if (result.exists()) {
+            return result;
+        }
         URL url = ProxyConfigurationLoader.class.getResource(path);
-        return null == url ? new File(path) : new File(url.toURI().getPath());
+        return null == url ? result : new File(url.toURI());
     }
     
     private static YamlProxyServerConfiguration loadServerConfiguration(final 
File yamlFile) throws IOException {
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
index cc3370fd911..899153a998f 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
@@ -152,6 +152,42 @@ class ProxyConfigurationLoaderTest {
         }
     }
     
+    @Test
+    void assertLoadWithFilesystemPath(@TempDir final Path tempDir) throws 
IOException {
+        writeConfigurationFile(tempDir, "global.yaml", "");
+        YamlProxyConfiguration actual = 
ProxyConfigurationLoader.load(tempDir.toString());
+        assertNotNull(actual.getServerConfiguration());
+        assertTrue(actual.getServerConfiguration().getRules().isEmpty());
+        assertTrue(actual.getDatabaseConfigurations().isEmpty());
+    }
+    
+    @Test
+    void assertLoadWithCompatibleServerYamlOnly(@TempDir final Path tempDir) 
throws IOException {
+        writeConfigurationFile(tempDir, "server.yaml", "authority:\n"
+                + "  users:\n"
+                + "    - user: root\n"
+                + "      password: root\n");
+        YamlProxyConfiguration actual = 
ProxyConfigurationLoader.load(tempDir.toString());
+        assertNotNull(actual.getServerConfiguration());
+        assertFalse(actual.getServerConfiguration().getRules().isEmpty());
+        assertTrue(actual.getDatabaseConfigurations().isEmpty());
+    }
+    
+    @Test
+    void assertLoadFromClasspathWhenPathDoesNotExistOnFilesystem() throws 
IOException {
+        YamlProxyConfiguration actual = 
ProxyConfigurationLoader.load("/conf/config_loader/");
+        assertNotNull(actual.getServerConfiguration());
+        assertThat(actual.getDatabaseConfigurations().size(), is(3));
+    }
+    
+    @Test
+    void assertLoadFromClasspathWithCompatibleServerYaml() throws IOException {
+        YamlProxyConfiguration actual = 
ProxyConfigurationLoader.load("/conf/compatible_server_yaml/");
+        assertNotNull(actual.getServerConfiguration());
+        assertFalse(actual.getServerConfiguration().getRules().isEmpty());
+        assertTrue(actual.getDatabaseConfigurations().isEmpty());
+    }
+    
     private void assertShardingRuleConfiguration(final 
YamlProxyDatabaseConfiguration actual) {
         assertThat(actual.getDatabaseName(), is("sharding_db"));
         assertThat(actual.getDataSources().size(), is(2));
diff --git 
a/proxy/backend/core/src/test/resources/conf/compatible_server_yaml/server.yaml 
b/proxy/backend/core/src/test/resources/conf/compatible_server_yaml/server.yaml
new file mode 100644
index 00000000000..3a5005f7724
--- /dev/null
+++ 
b/proxy/backend/core/src/test/resources/conf/compatible_server_yaml/server.yaml
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+authority:
+  users:
+    - user: root
+      password: root
+      admin: true
+  privilege:
+    type: ALL_PERMITTED
+
+props:
+  max-connections-size-per-query: 1
+  sql-show: false

Reply via email to