You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/10/17 00:02:53 UTC

[shardingsphere] branch master updated: Fixes #20457, allows to start proxy without configuring authority rule. (#21599)

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

sunnianjun 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 d3a91a03971 Fixes #20457, allows to start proxy without configuring authority rule. (#21599)
d3a91a03971 is described below

commit d3a91a03971edfc288c66aae265f86ed64f25bdf
Author: Raigor <ra...@gmail.com>
AuthorDate: Mon Oct 17 08:02:36 2022 +0800

    Fixes #20457, allows to start proxy without configuring authority rule. (#21599)
---
 .../proxy/backend/config/ProxyConfigurationLoader.java  |  9 ++++-----
 .../backend/config/ProxyConfigurationLoaderTest.java    | 17 +++++++++++++++--
 proxy/backend/src/test/resources/conf/empty/server.yaml | 17 +++++++++++++++++
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
index e81e3ea3c06..b89658c7d2f 100644
--- a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
+++ b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoader.java
@@ -77,15 +77,14 @@ public final class ProxyConfigurationLoader {
     
     private static YamlProxyServerConfiguration loadServerConfiguration(final File yamlFile) throws IOException {
         YamlProxyServerConfiguration result = YamlEngine.unmarshal(yamlFile, YamlProxyServerConfiguration.class);
-        Preconditions.checkNotNull(result, "Server configuration file `%s` is invalid.", yamlFile.getName());
-        // TODO use SPI with pluggable
-        boolean containsGovernance = null != result.getMode() && "Cluster".equals(result.getMode().getType());
+        if (null == result) {
+            return new YamlProxyServerConfiguration();
+        }
+        // TODO make authority configuration more clear
         if (null != result.getAuthority()) {
             result.getRules().removeIf(each -> each instanceof YamlAuthorityRuleConfiguration);
             result.getRules().add(result.getAuthority().convertToYamlAuthorityRuleConfiguration());
         }
-        YamlRuleConfiguration authorityRuleConfig = result.getRules().stream().filter(each -> each instanceof YamlAuthorityRuleConfiguration).findAny().orElse(null);
-        Preconditions.checkState(containsGovernance || null != authorityRuleConfig, "Authority configuration is invalid.");
         return result;
     }
     
diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
index 500916af7ea..b90ca73fd0e 100644
--- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
+++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
@@ -18,10 +18,11 @@
 package org.apache.shardingsphere.proxy.backend.config;
 
 import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
 import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
 import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration;
 import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDatabaseConfiguration;
+import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyServerConfiguration;
 import org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration;
 import org.apache.shardingsphere.readwritesplitting.yaml.config.rule.YamlReadwriteSplittingDataSourceRuleConfiguration;
 import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
@@ -33,14 +34,26 @@ import java.util.Iterator;
 import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public final class ProxyConfigurationLoaderTest {
     
+    @Test
+    public void assertLoadEmptyConfiguration() throws IOException {
+        YamlProxyConfiguration actual = ProxyConfigurationLoader.load("/conf/empty/");
+        YamlProxyServerConfiguration serverConfiguration = actual.getServerConfiguration();
+        assertNull(serverConfiguration.getMode());
+        assertNull(serverConfiguration.getAuthority());
+        assertNull(serverConfiguration.getLabels());
+        assertTrue(serverConfiguration.getProps().isEmpty());
+        assertTrue(serverConfiguration.getRules().isEmpty());
+        assertTrue(actual.getDatabaseConfigurations().isEmpty());
+    }
+    
     @Test
     public void assertLoad() throws IOException {
         YamlProxyConfiguration actual = ProxyConfigurationLoader.load("/conf/config_loader/");
diff --git a/proxy/backend/src/test/resources/conf/empty/server.yaml b/proxy/backend/src/test/resources/conf/empty/server.yaml
new file mode 100644
index 00000000000..6222972176a
--- /dev/null
+++ b/proxy/backend/src/test/resources/conf/empty/server.yaml
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+