You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/03/05 06:22:54 UTC
[shardingsphere-ui] branch master updated: Remove ConfigCenter (#79)
This is an automated email from the ASF dual-hosted git repository.
menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-ui.git
The following commit(s) were added to refs/heads/master by this push:
new 0b75ed3 Remove ConfigCenter (#79)
0b75ed3 is described below
commit 0b75ed333a8a7c8ec9c22748fedda0de0543ee00
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Fri Mar 5 14:22:48 2021 +0800
Remove ConfigCenter (#79)
---
.../ui/servcie/ConfigCenterService.java | 41 ---------------
.../ui/servcie/impl/ConfigCenterServiceImpl.java | 58 ----------------------
.../impl/ProxyAuthenticationServiceImpl.java | 10 ++--
.../impl/ShardingPropertiesServiceImpl.java | 8 +--
.../ui/servcie/impl/ShardingSchemaServiceImpl.java | 38 +++++++-------
.../ui/util/CenterRepositoryFactory.java | 31 ------------
6 files changed, 28 insertions(+), 158 deletions(-)
diff --git a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/ConfigCenterService.java b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/ConfigCenterService.java
deleted file mode 100644
index 54fa645..0000000
--- a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/ConfigCenterService.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.shardingsphere.ui.servcie;
-
-import org.apache.shardingsphere.governance.core.config.ConfigCenterNode;
-import org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
-
-/**
- * Config center service
- */
-public interface ConfigCenterService {
-
- /**
- * Get activated config center.
- *
- * @return config center
- */
- ConfigurationRepository getActivatedConfigCenter();
-
- /**
- * Get activated configuration node.
- *
- * @return configuration node
- */
- ConfigCenterNode getActivateConfigurationNode();
-}
diff --git a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ConfigCenterServiceImpl.java b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ConfigCenterServiceImpl.java
deleted file mode 100644
index 0dbc1ec..0000000
--- a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ConfigCenterServiceImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.shardingsphere.ui.servcie.impl;
-
-import org.apache.shardingsphere.governance.core.config.ConfigCenterNode;
-import org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
-import org.apache.shardingsphere.ui.common.domain.CenterConfig;
-import org.apache.shardingsphere.ui.common.exception.ShardingSphereUIException;
-import org.apache.shardingsphere.ui.servcie.CenterConfigService;
-import org.apache.shardingsphere.ui.servcie.ConfigCenterService;
-import org.apache.shardingsphere.ui.util.CenterRepositoryFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.Optional;
-
-/**
- * Implementation of Config center service.
- */
-@Service
-public final class ConfigCenterServiceImpl implements ConfigCenterService {
-
- @Autowired
- private CenterConfigService centerConfigService;
-
- @Override
- public ConfigurationRepository getActivatedConfigCenter() {
- Optional<CenterConfig> optional = centerConfigService.loadActivated();
- if (optional.isPresent()) {
- return CenterRepositoryFactory.createConfigurationRepository(optional.get());
- }
- throw new ShardingSphereUIException(ShardingSphereUIException.SERVER_ERROR, "No activated config center!");
- }
-
- @Override
- public ConfigCenterNode getActivateConfigurationNode() {
- Optional<CenterConfig> optional = centerConfigService.loadActivated();
- if (optional.isPresent()) {
- return new ConfigCenterNode();
- }
- throw new ShardingSphereUIException(ShardingSphereUIException.SERVER_ERROR, "No activated config center!");
- }
-}
diff --git a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ProxyAuthenticationServiceImpl.java b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ProxyAuthenticationServiceImpl.java
index 543303a..4543759 100644
--- a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ProxyAuthenticationServiceImpl.java
+++ b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ProxyAuthenticationServiceImpl.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.ui.servcie.impl;
import org.apache.shardingsphere.governance.core.yaml.config.YamlConfigurationConverter;
-import org.apache.shardingsphere.ui.servcie.ConfigCenterService;
import org.apache.shardingsphere.ui.servcie.ProxyAuthenticationService;
+import org.apache.shardingsphere.ui.servcie.RegistryCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,18 +30,18 @@ import org.springframework.stereotype.Service;
public final class ProxyAuthenticationServiceImpl implements ProxyAuthenticationService {
@Autowired
- private ConfigCenterService configCenterService;
+ private RegistryCenterService registryCenterService;
@Override
public String getAuthentication() {
- return configCenterService.getActivatedConfigCenter().get(configCenterService.getActivateConfigurationNode().getAuthenticationPath());
+ return registryCenterService.getActivatedRegistryCenter().get(registryCenterService.getActivatedStateNode().getAuthenticationPath());
}
@Override
public void updateAuthentication(final String authentication) {
checkAuthenticationConfiguration(authentication);
- configCenterService.getActivatedConfigCenter()
- .persist(configCenterService.getActivateConfigurationNode().getAuthenticationPath(), authentication);
+ registryCenterService.getActivatedRegistryCenter()
+ .persist(registryCenterService.getActivatedStateNode().getAuthenticationPath(), authentication);
}
private void checkAuthenticationConfiguration(final String data) {
diff --git a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingPropertiesServiceImpl.java b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingPropertiesServiceImpl.java
index bd2aee0..62edefe 100644
--- a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingPropertiesServiceImpl.java
+++ b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingPropertiesServiceImpl.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.ui.servcie.impl;
import org.apache.shardingsphere.governance.core.yaml.config.YamlConfigurationConverter;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.ui.servcie.ConfigCenterService;
+import org.apache.shardingsphere.ui.servcie.RegistryCenterService;
import org.apache.shardingsphere.ui.servcie.ShardingPropertiesService;
import org.springframework.stereotype.Service;
@@ -33,17 +33,17 @@ import java.util.Properties;
public final class ShardingPropertiesServiceImpl implements ShardingPropertiesService {
@Resource
- private ConfigCenterService configCenterService;
+ private RegistryCenterService registryCenterService;
@Override
public String loadShardingProperties() {
- return configCenterService.getActivatedConfigCenter().get(configCenterService.getActivateConfigurationNode().getPropsPath());
+ return registryCenterService.getActivatedRegistryCenter().get(registryCenterService.getActivatedStateNode().getPropsPath());
}
@Override
public void updateShardingProperties(final String configData) {
checkShardingProperties(configData);
- configCenterService.getActivatedConfigCenter().persist(configCenterService.getActivateConfigurationNode().getPropsPath(), configData);
+ registryCenterService.getActivatedRegistryCenter().persist(registryCenterService.getActivatedStateNode().getPropsPath(), configData);
}
private void checkShardingProperties(final String configData) {
diff --git a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingSchemaServiceImpl.java b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingSchemaServiceImpl.java
index 7a05e86..7ebba13 100644
--- a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingSchemaServiceImpl.java
+++ b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/servcie/impl/ShardingSchemaServiceImpl.java
@@ -22,9 +22,9 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import org.apache.shardingsphere.governance.core.yaml.config.YamlConfigurationConverter;
-import org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
+import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.ui.servcie.ConfigCenterService;
+import org.apache.shardingsphere.ui.servcie.RegistryCenterService;
import org.apache.shardingsphere.ui.servcie.ShardingSchemaService;
import org.springframework.stereotype.Service;
@@ -41,21 +41,21 @@ import java.util.Map;
public final class ShardingSchemaServiceImpl implements ShardingSchemaService {
@Resource
- private ConfigCenterService configCenterService;
+ private RegistryCenterService registryCenterService;
@Override
public Collection<String> getAllSchemaNames() {
- return configCenterService.getActivatedConfigCenter().getChildrenKeys(configCenterService.getActivateConfigurationNode().getMetadataNodePath());
+ return registryCenterService.getActivatedRegistryCenter().getChildrenKeys(registryCenterService.getActivatedStateNode().getMetadataNodePath());
}
@Override
public String getRuleConfiguration(final String schemaName) {
- return configCenterService.getActivatedConfigCenter().get(configCenterService.getActivateConfigurationNode().getRulePath(schemaName));
+ return registryCenterService.getActivatedRegistryCenter().get(registryCenterService.getActivatedStateNode().getRulePath(schemaName));
}
@Override
public String getDataSourceConfiguration(final String schemaName) {
- return configCenterService.getActivatedConfigCenter().get(configCenterService.getActivateConfigurationNode().getDataSourcePath(schemaName));
+ return registryCenterService.getActivatedRegistryCenter().get(registryCenterService.getActivatedStateNode().getMetadataDataSourcePath(schemaName));
}
@Override
@@ -82,19 +82,19 @@ public final class ShardingSchemaServiceImpl implements ShardingSchemaService {
@Override
public void deleteSchemaConfiguration(final String schemaName) {
- ConfigurationRepository configCenterRepository = configCenterService.getActivatedConfigCenter();
- String schemaNamePath = configCenterService.getActivateConfigurationNode().getSchemaNamePath(schemaName);
- configCenterRepository.delete(schemaNamePath);
- String schemaNames = configCenterRepository.get(configCenterService.getActivateConfigurationNode().getMetadataNodePath());
+ RegistryRepository registryRepository = registryCenterService.getActivatedRegistryCenter();
+ String schemaNamePath = registryCenterService.getActivatedStateNode().getSchemaNamePath(schemaName);
+ registryRepository.delete(schemaNamePath);
+ String schemaNames = registryCenterService.getActivatedRegistryCenter().get(registryCenterService.getActivatedStateNode().getMetadataNodePath());
List<String> schemaNameList = new ArrayList<>(Splitter.on(",").splitToList(schemaNames));
schemaNameList.remove(schemaName);
- configCenterRepository.persist(configCenterService.getActivateConfigurationNode().getMetadataNodePath(), Joiner.on(",").join(schemaNameList));
+ registryRepository.persist(registryCenterService.getActivatedStateNode().getMetadataNodePath(), Joiner.on(",").join(schemaNameList));
}
@Override
public String getMetadataConfiguration(final String schemaName) {
- return configCenterService.getActivatedConfigCenter().get(
- configCenterService.getActivateConfigurationNode().getSchemaPath(schemaName));
+ return registryCenterService.getActivatedRegistryCenter().get(
+ registryCenterService.getActivatedStateNode().getSchemaPath(schemaName));
}
private void checkRuleConfiguration(final String configData) {
@@ -108,7 +108,7 @@ public final class ShardingSchemaServiceImpl implements ShardingSchemaService {
}
private void persistRuleConfiguration(final String schemaName, final String ruleConfiguration) {
- configCenterService.getActivatedConfigCenter().persist(configCenterService.getActivateConfigurationNode().getRulePath(schemaName), ruleConfiguration);
+ registryCenterService.getActivatedRegistryCenter().persist(registryCenterService.getActivatedStateNode().getRulePath(schemaName), ruleConfiguration);
}
private void checkDataSourceConfiguration(final String configData) {
@@ -123,7 +123,7 @@ public final class ShardingSchemaServiceImpl implements ShardingSchemaService {
}
private void persistDataSourceConfiguration(final String schemaName, final String dataSourceConfiguration) {
- configCenterService.getActivatedConfigCenter().persist(configCenterService.getActivateConfigurationNode().getDataSourcePath(schemaName), dataSourceConfiguration);
+ registryCenterService.getActivatedRegistryCenter().persist(registryCenterService.getActivatedStateNode().getMetadataDataSourcePath(schemaName), dataSourceConfiguration);
}
private void checkSchemaName(final String schemaName, final Collection<String> existedSchemaNames) {
@@ -132,13 +132,13 @@ public final class ShardingSchemaServiceImpl implements ShardingSchemaService {
}
private void persistSchemaName(final String schemaName) {
- ConfigurationRepository configCenterRepository = configCenterService.getActivatedConfigCenter();
- String schemaPath = configCenterService.getActivateConfigurationNode().getMetadataNodePath();
- String schemaNames = configCenterRepository.get(schemaPath);
+ RegistryRepository registryRepository = registryCenterService.getActivatedRegistryCenter();
+ String schemaPath = registryCenterService.getActivatedStateNode().getMetadataNodePath();
+ String schemaNames = registryRepository.get(schemaPath);
List<String> schemaNameList = Strings.isNullOrEmpty(schemaNames) ? new ArrayList<>() : new ArrayList<>(Splitter.on(",").splitToList(schemaNames));
if (!schemaNameList.contains(schemaName)) {
schemaNameList.add(schemaName);
- configCenterRepository.persist(schemaPath, Joiner.on(",").join(schemaNameList));
+ registryRepository.persist(schemaPath, Joiner.on(",").join(schemaNameList));
}
}
}
diff --git a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java
index 374de71..2cb67d1 100644
--- a/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java
+++ b/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java
@@ -17,10 +17,8 @@
package org.apache.shardingsphere.ui.util;
-import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.governance.repository.api.GovernanceRepository;
import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceCenterConfiguration;
@@ -40,8 +38,6 @@ public final class CenterRepositoryFactory {
private static final ConcurrentHashMap<String, RegistryRepository> REGISTRY_REPOSITORY_MAP = new ConcurrentHashMap<>();
- private static final ConcurrentHashMap<String, ConfigurationRepository> CONFIG_REPOSITORY_MAP = new ConcurrentHashMap<>();
-
/**
* Create registry repository.
*
@@ -59,33 +55,6 @@ public final class CenterRepositoryFactory {
return result;
}
- /**
- * Create configuration repository.
- *
- * @param config center config
- * @return configuration repository
- */
- public static ConfigurationRepository createConfigurationRepository(final CenterConfig config) {
- ConfigurationRepository result = CONFIG_REPOSITORY_MAP.get(config.getName());
- if (null != result) {
- return result;
- }
- if (!Strings.isNullOrEmpty(config.getAdditionalConfigCenterServerList())
- && !Strings.isNullOrEmpty(config.getAdditionalConfigCenterType())) {
- result = (ConfigurationRepository) createGovernanceRepository(config.getAdditionalConfigCenterType());
- } else {
- RegistryRepository registryRepository = (RegistryRepository) createGovernanceRepository(config.getInstanceType());
- if (registryRepository instanceof ConfigurationRepository) {
- result = (ConfigurationRepository) registryRepository;
- } else {
- throw new IllegalArgumentException("Registry repository is not suitable for config center and no additional config center configuration provided.");
- }
- }
- result.init(config.getGovernanceName(), convert(config));
- CONFIG_REPOSITORY_MAP.put(config.getName(), result);
- return result;
- }
-
private static GovernanceCenterConfiguration convert(final CenterConfig config) {
GovernanceCenterConfiguration result = new GovernanceCenterConfiguration(config.getInstanceType(), config.getServerLists(), new Properties());
result.getProps().put("digest", config.getDigest());