Skip to content

Commit

Permalink
Rename GovernanceCenter to RegistryCenter (apache#10336)
Browse files Browse the repository at this point in the history
* Update javadoc

* Rename YamlRegistryCenterConfiguration

* Rename RegistryCenterConfigurationYamlSwapper

* Rename YamlGovernanceConfigurationSwapperUtil

* Rename GovernanceCenter to RegistryCenter
  • Loading branch information
terrymanu authored May 14, 2021
1 parent a0e0f7e commit 8e2fd76
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,16 @@ public final class GovernanceRepositoryConfigurationUtil {
private static final String ZOOKEEPER_CONNECTION_STRING = "localhost:2181";

public static GovernanceConfiguration getZooKeeperConfiguration(final boolean overwrite, final ShardingType shardingType) {
RegistryCenterConfiguration governanceCenterConfig = new RegistryCenterConfiguration("ZooKeeper", ZOOKEEPER_CONNECTION_STRING, new Properties());
RegistryCenterConfiguration registryCenterConfig = new RegistryCenterConfiguration("ZooKeeper", ZOOKEEPER_CONNECTION_STRING, new Properties());
switch (shardingType) {
case SHARDING_DATABASES_AND_TABLES:
return new GovernanceConfiguration("governance-sharding-data-source", governanceCenterConfig, overwrite);
return new GovernanceConfiguration("governance-sharding-data-source", registryCenterConfig, overwrite);
case READWRITE_SPLITTING:
return new GovernanceConfiguration("governance-readwrite-splitting-data-source", governanceCenterConfig, overwrite);
return new GovernanceConfiguration("governance-readwrite-splitting-data-source", registryCenterConfig, overwrite);
case ENCRYPT:
return new GovernanceConfiguration("governance-encrypt-data-source", governanceCenterConfig, overwrite);
return new GovernanceConfiguration("governance-encrypt-data-source", registryCenterConfig, overwrite);
case SHADOW:
return new GovernanceConfiguration("governance-shadow-data-source", governanceCenterConfig, overwrite);
default:
throw new UnsupportedOperationException(shardingType.toString());
}
}

public static GovernanceConfiguration getNacosConfiguration(final boolean overwrite, final ShardingType shardingType) {
Properties zookeeperProperties = new Properties();
RegistryCenterConfiguration zookeeperConfig = new RegistryCenterConfiguration("ZooKeeper", ZOOKEEPER_CONNECTION_STRING, zookeeperProperties);
switch (shardingType) {
case SHARDING_DATABASES_AND_TABLES:
return new GovernanceConfiguration("governance-zookeeper-sharding-data-source", zookeeperConfig, overwrite);
case READWRITE_SPLITTING:
return new GovernanceConfiguration("governance-zookeeper-readwrite-splitting-data-source", zookeeperConfig, overwrite);
case ENCRYPT:
return new GovernanceConfiguration("governance-zookeeper-encrypt-data-source", zookeeperConfig, overwrite);
case SHADOW:
return new GovernanceConfiguration("governance-zookeeper-shadow-data-source", zookeeperConfig, overwrite);
return new GovernanceConfiguration("governance-shadow-data-source", registryCenterConfig, overwrite);
default:
throw new UnsupportedOperationException(shardingType.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public RegistryCenterRepositoryFacade(final GovernanceConfiguration config) {
}

private RegistryCenterRepository createGovernanceRepository(final GovernanceConfiguration config) {
RegistryCenterConfiguration governanceCenterConfig = config.getRegistryCenterConfiguration();
Preconditions.checkNotNull(governanceCenterConfig, "Governance center configuration cannot be null.");
RegistryCenterRepository result = TypedSPIRegistry.getRegisteredService(RegistryCenterRepository.class, governanceCenterConfig.getType(), governanceCenterConfig.getProps());
result.init(config.getName(), governanceCenterConfig);
RegistryCenterConfiguration registryCenterConfig = config.getRegistryCenterConfiguration();
Preconditions.checkNotNull(registryCenterConfig, "Registry center configuration cannot be null.");
RegistryCenterRepository result = TypedSPIRegistry.getRegisteredService(RegistryCenterRepository.class, registryCenterConfig.getType(), registryCenterConfig.getProps());
result.init(config.getName(), registryCenterConfig);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class YamlGovernanceConfiguration implements YamlConfiguration {

private String name;

private YamlGovernanceCenterConfiguration registryCenter;
private YamlRegistryCenterConfiguration registryCenter;

private boolean overwrite;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.Properties;

/**
* Governance center configuration for YAML.
* Registry center configuration for YAML.
*/
@Getter
@Setter
public final class YamlGovernanceCenterConfiguration implements YamlConfiguration {
public final class YamlRegistryCenterConfiguration implements YamlConfiguration {

private String type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
*/
public final class GovernanceConfigurationYamlSwapper implements YamlConfigurationSwapper<YamlGovernanceConfiguration, GovernanceConfiguration> {

private final GovernanceCenterConfigurationYamlSwapper governanceCenterConfigurationSwapper = new GovernanceCenterConfigurationYamlSwapper();
private final RegistryCenterConfigurationYamlSwapper registryCenterConfigurationYamlSwapper = new RegistryCenterConfigurationYamlSwapper();

@Override
public YamlGovernanceConfiguration swapToYamlConfiguration(final GovernanceConfiguration data) {
YamlGovernanceConfiguration result = new YamlGovernanceConfiguration();
result.setName(data.getName());
result.setRegistryCenter(governanceCenterConfigurationSwapper.swapToYamlConfiguration(data.getRegistryCenterConfiguration()));
result.setRegistryCenter(registryCenterConfigurationYamlSwapper.swapToYamlConfiguration(data.getRegistryCenterConfiguration()));
return result;
}

@Override
public GovernanceConfiguration swapToObject(final YamlGovernanceConfiguration yamlConfig) {
RegistryCenterConfiguration registryCenterConfiguration = governanceCenterConfigurationSwapper.swapToObject(yamlConfig.getRegistryCenter());
RegistryCenterConfiguration registryCenterConfiguration = registryCenterConfigurationYamlSwapper.swapToObject(yamlConfig.getRegistryCenter());
return new GovernanceConfiguration(yamlConfig.getName(), registryCenterConfiguration, yamlConfig.isOverwrite());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@

package org.apache.shardingsphere.governance.core.yaml.swapper;

import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlRegistryCenterConfiguration;
import org.apache.shardingsphere.governance.repository.api.config.RegistryCenterConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlConfigurationSwapper;

/**
* Governance center configuration YAML swapper.
* Registry center configuration YAML swapper.
*/
public final class GovernanceCenterConfigurationYamlSwapper implements YamlConfigurationSwapper<YamlGovernanceCenterConfiguration, RegistryCenterConfiguration> {
public final class RegistryCenterConfigurationYamlSwapper implements YamlConfigurationSwapper<YamlRegistryCenterConfiguration, RegistryCenterConfiguration> {

@Override
public YamlGovernanceCenterConfiguration swapToYamlConfiguration(final RegistryCenterConfiguration config) {
YamlGovernanceCenterConfiguration result = new YamlGovernanceCenterConfiguration();
public YamlRegistryCenterConfiguration swapToYamlConfiguration(final RegistryCenterConfiguration config) {
YamlRegistryCenterConfiguration result = new YamlRegistryCenterConfiguration();
result.setType(config.getType());
result.setServerLists(config.getServerLists());
result.setProps(config.getProps());
return result;
}

@Override
public RegistryCenterConfiguration swapToObject(final YamlGovernanceCenterConfiguration yamlConfig) {
public RegistryCenterConfiguration swapToObject(final YamlRegistryCenterConfiguration yamlConfig) {
return new RegistryCenterConfiguration(yamlConfig.getType(), yamlConfig.getServerLists(), yamlConfig.getProps());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.shardingsphere.governance.core.yaml.swapper;

import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlRegistryCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
import org.apache.shardingsphere.governance.repository.api.config.RegistryCenterConfiguration;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
Expand Down Expand Up @@ -97,8 +97,8 @@ private YamlGovernanceConfiguration createYamlGovernanceConfigurationWithAdditio
return result;
}

private YamlGovernanceCenterConfiguration createYamlRegistryCenterConfiguration() {
YamlGovernanceCenterConfiguration result = new YamlGovernanceCenterConfiguration();
private YamlRegistryCenterConfiguration createYamlRegistryCenterConfiguration() {
YamlRegistryCenterConfiguration result = new YamlRegistryCenterConfiguration();
result.setType("TEST");
result.setProps(new Properties());
result.setServerLists("127.0.0.1:2181");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.shardingsphere.governance.core.yaml.swapper;

import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlRegistryCenterConfiguration;
import org.apache.shardingsphere.governance.repository.api.config.RegistryCenterConfiguration;
import org.junit.Test;

Expand All @@ -31,23 +31,23 @@ public final class RegistryCenterConfigurationYamlSwapperTest {
@Test
public void assertToYamlConfiguration() {
RegistryCenterConfiguration expected = new RegistryCenterConfiguration("TEST", "127.0.0.1:2181", new Properties());
YamlGovernanceCenterConfiguration actual = new GovernanceCenterConfigurationYamlSwapper().swapToYamlConfiguration(expected);
YamlRegistryCenterConfiguration actual = new RegistryCenterConfigurationYamlSwapper().swapToYamlConfiguration(expected);
assertThat(actual.getType(), is(expected.getType()));
assertThat(actual.getServerLists(), is(expected.getServerLists()));
assertThat(actual.getProps(), is(expected.getProps()));
}

@Test
public void assertSwapToObject() {
YamlGovernanceCenterConfiguration yamlConfig = getYamlGovernanceCenterConfiguration();
RegistryCenterConfiguration governanceCenterConfig = new GovernanceCenterConfigurationYamlSwapper().swapToObject(yamlConfig);
assertThat(governanceCenterConfig.getType(), is(yamlConfig.getType()));
assertThat(governanceCenterConfig.getServerLists(), is(yamlConfig.getServerLists()));
assertThat(governanceCenterConfig.getProps(), is(yamlConfig.getProps()));
YamlRegistryCenterConfiguration yamlConfig = getYamlRegistryCenterConfiguration();
RegistryCenterConfiguration config = new RegistryCenterConfigurationYamlSwapper().swapToObject(yamlConfig);
assertThat(config.getType(), is(yamlConfig.getType()));
assertThat(config.getServerLists(), is(yamlConfig.getServerLists()));
assertThat(config.getProps(), is(yamlConfig.getProps()));
}

private YamlGovernanceCenterConfiguration getYamlGovernanceCenterConfiguration() {
YamlGovernanceCenterConfiguration result = new YamlGovernanceCenterConfiguration();
private YamlRegistryCenterConfiguration getYamlRegistryCenterConfiguration() {
YamlRegistryCenterConfiguration result = new YamlRegistryCenterConfiguration();
result.setType("TEST");
result.setProps(new Properties());
result.setServerLists("127.0.0.1:2181");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public interface RegistryCenterRepository extends TypedSPI {
String PATH_SEPARATOR = "/";

/**
* Initialize governance center.
* Initialize registry center.
*
* @param name governance center name
* @param config governance center configuration
* @param name registry center name
* @param config registry center configuration
*/
void init(String name, RegistryCenterConfiguration config);

/**
* Get data from governance center.
* Get data from registry center.
*
* <p>Maybe use cache if existed.</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.driver.governance.internal.datasource.GovernanceShardingSphereDataSource;
import org.apache.shardingsphere.driver.governance.internal.util.YamlGovernanceRepositoryConfigurationSwapperUtil;
import org.apache.shardingsphere.driver.governance.internal.util.YamlGovernanceConfigurationSwapperUtil;
import org.apache.shardingsphere.driver.governance.internal.yaml.YamlGovernanceRootRuleConfigurations;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
Expand Down Expand Up @@ -109,13 +109,13 @@ private static DataSource createDataSource(final Map<String, DataSource> dataSou
}

private static DataSource createDataSourceWithoutRules(final YamlGovernanceConfiguration governance) throws SQLException {
return new GovernanceShardingSphereDataSource(YamlGovernanceRepositoryConfigurationSwapperUtil.marshal(governance));
return new GovernanceShardingSphereDataSource(YamlGovernanceConfigurationSwapperUtil.marshal(governance));
}

private static DataSource createDataSourceWithRules(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
final Properties props, final YamlGovernanceConfiguration governance) throws SQLException {
return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigurations, props,
YamlGovernanceRepositoryConfigurationSwapperUtil.marshal(governance));
YamlGovernanceConfigurationSwapperUtil.marshal(governance));
}

private static YamlGovernanceRootRuleConfigurations unmarshal(final File yamlFile) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
import org.apache.shardingsphere.governance.core.yaml.swapper.GovernanceCenterConfigurationYamlSwapper;
import org.apache.shardingsphere.governance.core.yaml.swapper.RegistryCenterConfigurationYamlSwapper;

/**
* YAML governance configuration swapper utility.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class YamlGovernanceRepositoryConfigurationSwapperUtil {
public final class YamlGovernanceConfigurationSwapperUtil {

private static final GovernanceCenterConfigurationYamlSwapper SWAPPER = new GovernanceCenterConfigurationYamlSwapper();
private static final RegistryCenterConfigurationYamlSwapper SWAPPER = new RegistryCenterConfigurationYamlSwapper();

/**
* Marshal YAML governance repository configuration map to instance configuration map.
* Marshal YAML governance configuration to governance configuration.
*
* @param governance YAML governance configuration
* @return governance repository configuration map
* @return governance configuration
*/
public static GovernanceConfiguration marshal(final YamlGovernanceConfiguration governance) {
return new GovernanceConfiguration(governance.getName(), SWAPPER.swapToObject(governance.getRegistryCenter()), governance.isOverwrite());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.driver.governance.internal.util;

import org.apache.shardingsphere.governance.repository.api.config.RegistryCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlRegistryCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
import org.junit.Test;

Expand All @@ -27,12 +27,12 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public final class YamlInstanceConfigurationSwapperUtilTest {
public final class YamlGovernanceConfigurationSwapperUtilTest {

@Test
public void marshal() {
YamlGovernanceConfiguration expected = createExpectedYamlGovernanceConfiguration();
RegistryCenterConfiguration actual = YamlGovernanceRepositoryConfigurationSwapperUtil.marshal(expected).getRegistryCenterConfiguration();
RegistryCenterConfiguration actual = YamlGovernanceConfigurationSwapperUtil.marshal(expected).getRegistryCenterConfiguration();
assertThat(actual.getType(), is(expected.getRegistryCenter().getType()));
assertThat(actual.getServerLists(), is(expected.getRegistryCenter().getServerLists()));
assertThat(actual.getProps(), is(expected.getRegistryCenter().getProps()));
Expand All @@ -41,12 +41,12 @@ public void marshal() {
private YamlGovernanceConfiguration createExpectedYamlGovernanceConfiguration() {
YamlGovernanceConfiguration result = new YamlGovernanceConfiguration();
result.setName("test");
result.setRegistryCenter(createYamlGovernanceRepositoryConfiguration());
result.setRegistryCenter(createYamlRegistryRepositoryConfiguration());
return result;
}

private YamlGovernanceCenterConfiguration createYamlGovernanceRepositoryConfiguration() {
YamlGovernanceCenterConfiguration result = new YamlGovernanceCenterConfiguration();
private YamlRegistryCenterConfiguration createYamlRegistryRepositoryConfiguration() {
YamlRegistryCenterConfiguration result = new YamlRegistryCenterConfiguration();
result.setType("ZooKeeper");
result.setServerLists("localhost:2181");
result.setProps(new Properties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.driver.governance.internal.datasource.GovernanceShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.governance.core.yaml.swapper.GovernanceCenterConfigurationYamlSwapper;
import org.apache.shardingsphere.governance.core.yaml.swapper.RegistryCenterConfigurationYamlSwapper;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
import org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter;
import org.apache.shardingsphere.spring.boot.governance.common.GovernanceSpringBootRootConfiguration;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class ShardingSphereGovernanceAutoConfiguration implements EnvironmentAwa

private final GovernanceSpringBootRootConfiguration root;

private final GovernanceCenterConfigurationYamlSwapper swapper = new GovernanceCenterConfigurationYamlSwapper();
private final RegistryCenterConfigurationYamlSwapper swapper = new RegistryCenterConfigurationYamlSwapper();

/**
* Get governance configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


{
"groups": [
{
Expand Down Expand Up @@ -78,7 +77,7 @@
},
{
"name": "spring.shardingsphere.governance",
"type": "java.util.Map<java.lang.String,org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceCenterConfiguration>",
"type": "java.util.Map<java.lang.String,org.apache.shardingsphere.governance.core.yaml.config.YamlRegistryCenterConfiguration>",
"sourceType": "org.apache.shardingsphere.spring.boot.governance.common.GovernanceSpringBootRootConfiguration",
"description": "Customize ShardingSphere governance instance."
},
Expand Down
Loading

0 comments on commit 8e2fd76

Please sign in to comment.