You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/04/24 14:26:16 UTC

[shardingsphere] branch master updated: Support default proxy port configurable (#17003) (#17062)

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

zhangliang 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 d138adb15d8 Support default proxy port configurable (#17003) (#17062)
d138adb15d8 is described below

commit d138adb15d8fde683da16aea1ac512fdd877bfb7
Author: galaxy <ga...@tencent.com>
AuthorDate: Sun Apr 24 22:26:07 2022 +0800

    Support default proxy port configurable (#17003) (#17062)
    
    * Support default proxy port configurable (#17003)
    
    * add Line feed (#17003)
---
 .../config/props/ConfigurationPropertyKey.java     |  7 ++++++-
 .../proxy/arguments/BootstrapArguments.java        | 22 +++++++++++++++++++++-
 .../src/main/resources/conf/server.yaml            |  1 +
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertyKey.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertyKey.java
index b3e257b79de..5ef197f5c23 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertyKey.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertyKey.java
@@ -122,7 +122,12 @@ public enum ConfigurationPropertyKey implements TypedPropertyKey {
     /**
      * Proxy mysql default version, default 5.7.22.
      */
-    PROXY_MYSQL_DEFAULT_VERSION("proxy-mysql-default-version", "5.7.22", String.class, false);
+    PROXY_MYSQL_DEFAULT_VERSION("proxy-mysql-default-version", "5.7.22", String.class, false),
+    
+    /**
+     * Proxy default port, default 3307.
+     */
+    PROXY_DEFAULT_PORT("proxy-default-port", "3307", String.class, false);
     
     private final String key;
     
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java
index 239b5dc9533..368a8f9dcc3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java
@@ -18,6 +18,11 @@
 package org.apache.shardingsphere.proxy.arguments;
 
 import lombok.Getter;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader;
+import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration;
+
+import java.io.IOException;
 
 /**
  * Bootstrap arguments.
@@ -40,7 +45,7 @@ public final class BootstrapArguments {
     
     private int getPort(final String[] args) {
         if (0 == args.length) {
-            return DEFAULT_PORT;
+            return getProxyDefaultPort(DEFAULT_CONFIG_PATH);
         }
         try {
             return Integer.parseInt(args[0]);
@@ -63,4 +68,19 @@ public final class BootstrapArguments {
         }
         return result.toString();
     }
+    
+    private static int getProxyDefaultPort(final String configurationPath) {
+        YamlProxyConfiguration yamlConfig;
+        try {
+            yamlConfig = ProxyConfigurationLoader.load(configurationPath);
+            return yamlConfig.getServerConfiguration().getProps().get(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getKey()) == null
+                    ? Integer.parseInt(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getDefaultValue())
+                    : Integer.parseInt(
+                            yamlConfig.getServerConfiguration().getProps().get(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getKey()).toString());
+        } catch (IOException e) {
+            return DEFAULT_PORT;
+        } catch (NullPointerException e) {
+            return DEFAULT_PORT;
+        }
+    }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
index 7b06e5205d2..51e146c28d6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
@@ -82,3 +82,4 @@
 #    # Available proxy backend driver type: JDBC (default), ExperimentalVertx
 #  proxy-backend-driver-type: JDBC
 #  proxy-mysql-default-version: 5.7.22 # In the absence of schema name, the default version will be used.
+#  proxy-default-port: 3307 # Proxy default port.