Skip to content

Commit

Permalink
Fixes #20457, allows to start proxy without configuring authority rul…
Browse files Browse the repository at this point in the history
…e. (#21599)
  • Loading branch information
RaigorJiang authored Oct 17, 2022
1 parent 95adb91 commit d3a91a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ private static File getResourceFile(final String path) {

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,14 +34,26 @@
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/");
Expand Down
17 changes: 17 additions & 0 deletions proxy/backend/src/test/resources/conf/empty/server.yaml
Original file line number Diff line number Diff line change
@@ -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.
#

0 comments on commit d3a91a0

Please sign in to comment.