This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 42d07fd84b0e383df924d41c2a0de752d68636ce Author: liubao <[email protected]> AuthorDate: Mon Sep 25 18:22:24 2023 +0800 [SCB-2008]remove archaius dependency: cc adapter --- .../config/{ => cc}/ConfigCenterConfig.java | 66 +++------- .../config/{ => cc}/ConfigCenterConfiguration.java | 14 +- .../ConfigCenterDefaultDeploymentProvider.java | 2 +- .../ConfigCenterDynamicPropertiesSource.java} | 141 ++++++++------------- .../ConfigCenterInformationCollector.java | 2 +- .../config/{ => cc}/TransportUtils.java | 54 ++++---- ...comb.config.spi.ConfigCenterConfigurationSource | 18 --- ...vicecomb.core.bootup.BootUpInformationCollector | 2 +- ...pache.servicecomb.deployment.DeploymentProvider | 2 +- ...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +- .../ConfigCenterAddressManagerTest.java | 3 +- .../ConfigCenterConfigurationSourceImplTest.java | 2 +- .../TestConfigCenterDefaultDeploymentProvider.java | 3 +- 13 files changed, 121 insertions(+), 190 deletions(-) diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java similarity index 57% rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java index 837f6e0c7..0522f5b43 100644 --- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java +++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java @@ -15,22 +15,18 @@ * limitations under the License. */ -package org.apache.servicecomb.config; +package org.apache.servicecomb.config.cc; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider; import org.apache.servicecomb.deployment.Deployment; import org.apache.servicecomb.foundation.vertx.VertxConst; +import org.springframework.core.env.Environment; import com.netflix.config.ConcurrentCompositeConfiguration; public final class ConfigCenterConfig { - public static final ConfigCenterConfig INSTANCE = new ConfigCenterConfig(); - public static final String SSL_TAG = "cc.consumer"; private static ConcurrentCompositeConfiguration finalConfig; @@ -51,76 +47,52 @@ public final class ConfigCenterConfig { private static final int DEFAULT_FIRST_REFRESH_INTERVAL = 0; - private ConfigCenterConfig() { - } - - public static void setConcurrentCompositeConfiguration(ConcurrentCompositeConfiguration config) { - finalConfig = config; - } + private final Environment environment; - public static ConcurrentCompositeConfiguration getConcurrentCompositeConfiguration() { - return finalConfig; + public ConfigCenterConfig(Environment environment) { + this.environment = environment; } - public String getDomainName() { - return finalConfig.getString(DOMAIN_NAME, "default"); + return environment.getProperty(DOMAIN_NAME, "default"); } public boolean firstPullRequired() { - return finalConfig.getBoolean(FIRST_PULL_REQUIRED, false); + return environment.getProperty(FIRST_PULL_REQUIRED, boolean.class, false); } @SuppressWarnings("unchecked") public List<String> getFileSources() { - Object property = finalConfig.getProperty(FILE_SOURCE); - if (property instanceof String) { - return new ArrayList<>(Arrays.asList(((String) property).split(","))); - } - if (property instanceof List) { - return (List<String>) property; - } - return Collections.EMPTY_LIST; + return environment.getProperty(FILE_SOURCE, List.class, Collections.emptyList()); } public long getRefreshInterval() { - return finalConfig.getLong(REFRESH_INTERVAL, DEFAULT_REFRESH_INTERVAL); + return environment.getProperty( + REFRESH_INTERVAL, long.class, (long) DEFAULT_REFRESH_INTERVAL); } public int getFirstRefreshInterval() { - return finalConfig.getInt(FIRST_REFRESH_INTERVAL, DEFAULT_FIRST_REFRESH_INTERVAL); + return environment.getProperty(FIRST_REFRESH_INTERVAL, int.class, DEFAULT_FIRST_REFRESH_INTERVAL); } public Boolean isProxyEnable() { - return finalConfig.getBoolean(VertxConst.PROXY_ENABLE, false); + return environment.getProperty(VertxConst.PROXY_ENABLE, boolean.class, false); } public String getProxyHost() { - return finalConfig.getString(VertxConst.PROXY_HOST, "127.0.0.1"); + return environment.getProperty(VertxConst.PROXY_HOST, "127.0.0.1"); } public int getProxyPort() { - return finalConfig.getInt(VertxConst.PROXY_PORT, 8080); + return environment.getProperty(VertxConst.PROXY_PORT, int.class, 8080); } public String getProxyUsername() { - return finalConfig.getString(VertxConst.PROXY_USERNAME, null); + return environment.getProperty(VertxConst.PROXY_USERNAME); } public String getProxyPasswd() { - return finalConfig.getString(VertxConst.PROXY_PASSWD, null); - } - - public String getServiceName() { - return BootStrapProperties.readServiceName(finalConfig); - } - - public String getAppName() { - return BootStrapProperties.readApplication(finalConfig); - } - - public String getServiceVersion() { - return BootStrapProperties.readServiceVersion(finalConfig); + return environment.getProperty(VertxConst.PROXY_PASSWD); } public List<String> getServerUri() { @@ -129,10 +101,6 @@ public final class ConfigCenterConfig { } public boolean getAutoDiscoveryEnabled() { - return finalConfig.getBoolean(AUTO_DISCOVERY_ENABLED, false); - } - - public String getEnvironment() { - return BootStrapProperties.readServiceEnvironment(finalConfig); + return environment.getProperty(AUTO_DISCOVERY_ENABLED, boolean.class, false); } } diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfiguration.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfiguration.java similarity index 73% rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfiguration.java rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfiguration.java index bb95c43a2..97578fb2d 100644 --- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfiguration.java +++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfiguration.java @@ -14,14 +14,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.servicecomb.config; +package org.apache.servicecomb.config.cc; -import org.apache.servicecomb.config.collect.ConfigCenterInformationCollector; import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; public class ConfigCenterConfiguration { @Bean public ConfigCenterInformationCollector configCenterInformationCollector() { return new ConfigCenterInformationCollector(); } + + @Bean + public ConfigCenterDynamicPropertiesSource configCenterDynamicPropertiesSource() { + return new ConfigCenterDynamicPropertiesSource(); + } + + @Bean + public ConfigCenterConfig configCenterConfig(Environment environment) { + return new ConfigCenterConfig(environment); + } } diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java similarity index 97% rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java index 34cfa7332..e6e836c47 100644 --- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java +++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.servicecomb.config.collect; +package org.apache.servicecomb.config.cc; import java.util.List; diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java similarity index 59% rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java index 74834aaef..089741159 100644 --- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java +++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java @@ -14,16 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.apache.servicecomb.config.cc; -package org.apache.servicecomb.config; - -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; -import org.apache.commons.configuration.Configuration; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -31,19 +27,19 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.servicecomb.config.DynamicPropertiesSource; +import org.apache.servicecomb.config.MicroserviceProperties; import org.apache.servicecomb.config.center.client.ConfigCenterAddressManager; import org.apache.servicecomb.config.center.client.ConfigCenterClient; -import org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration; import org.apache.servicecomb.config.center.client.ConfigCenterManager; +import org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration; import org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest; import org.apache.servicecomb.config.center.client.model.QueryConfigurationsResponse; -import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider; import org.apache.servicecomb.config.common.ConfigConverter; import org.apache.servicecomb.config.common.ConfigurationChangedEvent; -import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource; import org.apache.servicecomb.deployment.Deployment; -import org.apache.servicecomb.deployment.SystemBootstrapInfo; import org.apache.servicecomb.foundation.auth.AuthHeaderProvider; +import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx; import org.apache.servicecomb.foundation.common.event.EventManager; import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils; import org.apache.servicecomb.http.client.auth.RequestAuthHeaderProvider; @@ -51,52 +47,50 @@ import org.apache.servicecomb.http.client.common.HttpTransport; import org.apache.servicecomb.http.client.common.HttpTransportFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MapPropertySource; import com.google.common.eventbus.Subscribe; -import com.netflix.config.ConcurrentCompositeConfiguration; -import com.netflix.config.WatchedUpdateListener; -import com.netflix.config.WatchedUpdateResult; -public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigurationSource { - private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfigurationSourceImpl.class); +public class ConfigCenterDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> { + public static final String SOURCE_NAME = "config-center"; - private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>(); + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterDynamicPropertiesSource.class); + + private final Map<String, Object> data = new ConcurrentHashMapEx<>(); private ConfigCenterManager configCenterManager; private ConfigConverter configConverter; - @Override - public int getOrder() { - return ORDER_BASE * 2; + private ConfigCenterConfig configCenterConfig; + + private MicroserviceProperties microserviceProperties; + + @Autowired + public void setConfigCenterConfig(ConfigCenterConfig configCenterConfig) { + this.configCenterConfig = configCenterConfig; } - @Override - public boolean isValidSource(Configuration localConfiguration) { - ConfigCenterConfig.setConcurrentCompositeConfiguration((ConcurrentCompositeConfiguration) localConfiguration); - SystemBootstrapInfo address = Deployment - .getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER); - - if (address == null) { - LOGGER.info("config center server is not configured."); - return false; - } - return true; + @Autowired + public void setMicroserviceProperties(MicroserviceProperties microserviceProperties) { + this.microserviceProperties = microserviceProperties; } - @Override - public void init(Configuration localConfiguration) { - configConverter = new ConfigConverter(ConfigCenterConfig.INSTANCE.getFileSources()); + private void init(Environment environment) { + configConverter = new ConfigConverter(configCenterConfig.getFileSources()); ConfigCenterAddressManager kieAddressManager = configKieAddressManager(); HttpTransport httpTransport = createHttpTransport(kieAddressManager, HttpTransportFactory.defaultRequestConfig().build(), - localConfiguration); + environment); ConfigCenterClient configCenterClient = new ConfigCenterClient(kieAddressManager, httpTransport); EventManager.register(this); - ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration(); + org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration(); QueryConfigurationsRequest queryConfigurationsRequest = firstPull(configCenterClient); @@ -104,6 +98,7 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur configConverter, configCenterConfiguration); configCenterManager.setQueryConfigurationsRequest(queryConfigurationsRequest); configCenterManager.startConfigCenterManager(); + data.putAll(configConverter.getCurrentData()); } private QueryConfigurationsRequest firstPull(ConfigCenterClient configCenterClient) { @@ -113,11 +108,10 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur .queryConfigurations(queryConfigurationsRequest); if (response.isChanged()) { configConverter.updateData(response.getConfigurations()); - updateConfiguration(WatchedUpdateResult.createIncremental(configConverter.getCurrentData(), null, null)); queryConfigurationsRequest.setRevision(response.getRevision()); } } catch (Exception e) { - if (ConfigCenterConfig.INSTANCE.firstPullRequired()) { + if (configCenterConfig.firstPullRequired()) { throw e; } LOGGER.warn("first pull failed, and ignore {}", e.getMessage()); @@ -127,52 +121,54 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur @Subscribe public void onConfigurationChangedEvent(ConfigurationChangedEvent event) { - updateConfiguration( - WatchedUpdateResult.createIncremental(event.getAdded(), event.getUpdated(), event.getDeleted())); + data.putAll(event.getAdded()); + data.putAll(event.getUpdated()); + event.getDeleted().forEach((k, v) -> data.remove(k)); } private QueryConfigurationsRequest createQueryConfigurationsRequest() { QueryConfigurationsRequest request = new QueryConfigurationsRequest(); - request.setApplication(ConfigCenterConfig.INSTANCE.getAppName()); - request.setServiceName(ConfigCenterConfig.INSTANCE.getServiceName()); - request.setVersion(ConfigCenterConfig.INSTANCE.getServiceVersion()); - request.setEnvironment(ConfigCenterConfig.INSTANCE.getEnvironment()); + request.setApplication(microserviceProperties.getApplication()); + request.setServiceName(microserviceProperties.getName()); + request.setVersion(microserviceProperties.getVersion()); + request.setEnvironment(microserviceProperties.getEnvironment()); // 需要设置为 null, 并且 query 参数为 revision=null 才会返回 revision 信息。 revision = 是不行的。 request.setRevision(null); return request; } - private ConfigCenterConfiguration createConfigCenterConfiguration(){ - return new ConfigCenterConfiguration().setRefreshIntervalInMillis(ConfigCenterConfig.INSTANCE.getRefreshInterval()); + private org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration createConfigCenterConfiguration() { + return new ConfigCenterConfiguration().setRefreshIntervalInMillis(configCenterConfig.getRefreshInterval()); } - private HttpTransport createHttpTransport(ConfigCenterAddressManager kieAddressManager, RequestConfig requestConfig, - Configuration localConfiguration) { + private HttpTransport createHttpTransport(ConfigCenterAddressManager kieAddressManager, + RequestConfig requestConfig, + Environment environment) { List<AuthHeaderProvider> authHeaderProviders = SPIServiceUtils.getOrLoadSortedService(AuthHeaderProvider.class); - if (ConfigCenterConfig.INSTANCE.isProxyEnable()) { + if (configCenterConfig.isProxyEnable()) { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(). setDefaultRequestConfig(requestConfig); - HttpHost proxy = new HttpHost(ConfigCenterConfig.INSTANCE.getProxyHost(), - ConfigCenterConfig.INSTANCE.getProxyPort(), "http"); // now only support http proxy + HttpHost proxy = new HttpHost(configCenterConfig.getProxyHost(), + configCenterConfig.getProxyPort(), "http"); // now only support http proxy httpClientBuilder.setProxy(proxy); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(proxy), - new UsernamePasswordCredentials(ConfigCenterConfig.INSTANCE.getProxyUsername(), - ConfigCenterConfig.INSTANCE.getProxyPasswd())); + new UsernamePasswordCredentials(configCenterConfig.getProxyUsername(), + configCenterConfig.getProxyPasswd())); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); return HttpTransportFactory .createHttpTransport( TransportUtils - .createSSLProperties(kieAddressManager.sslEnabled(), localConfiguration, ConfigCenterConfig.SSL_TAG), + .createSSLProperties(kieAddressManager.sslEnabled(), environment, ConfigCenterConfig.SSL_TAG), getRequestAuthHeaderProvider(authHeaderProviders), httpClientBuilder); } return HttpTransportFactory .createHttpTransport( TransportUtils - .createSSLProperties(kieAddressManager.sslEnabled(), localConfiguration, ConfigCenterConfig.SSL_TAG), + .createSSLProperties(kieAddressManager.sslEnabled(), environment, ConfigCenterConfig.SSL_TAG), getRequestAuthHeaderProvider(authHeaderProviders), requestConfig); } @@ -185,47 +181,20 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur } private ConfigCenterAddressManager configKieAddressManager() { - return new ConfigCenterAddressManager(ConfigCenterConfig.INSTANCE.getDomainName(), + return new ConfigCenterAddressManager(configCenterConfig.getDomainName(), Deployment .getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER).getAccessURL(), EventManager.getEventBus()); } - private void updateConfiguration(WatchedUpdateResult result) { - LOGGER.info("configuration changed keys, added=[{}], updated=[{}], deleted=[{}]", - result.getAdded() == null ? "" : result.getAdded().keySet(), - result.getChanged() == null ? "" : result.getChanged().keySet(), - result.getDeleted() == null ? "" : result.getDeleted().keySet()); - for (WatchedUpdateListener l : listeners) { - try { - l.updateConfiguration(result); - } catch (Throwable ex) { - LOGGER.error("Error in invoking WatchedUpdateListener", ex); - } - } - } - @Override - public void destroy() { - if (configCenterManager == null) { - return; - } - configCenterManager.stop(); + public EnumerablePropertySource<Map<String, Object>> create(Environment environment) { + init(environment); + return new MapPropertySource(SOURCE_NAME, data); } @Override - public void addUpdateListener(WatchedUpdateListener watchedUpdateListener) { - listeners.add(watchedUpdateListener); - } - - @Override - public void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) { - listeners.remove(watchedUpdateListener); - } - - @Override - public Map<String, Object> getCurrentData() throws Exception { - // data will updated by first pull, set empty to DynamicWatchedConfiguration first. - return Collections.emptyMap(); + public int getOrder() { + return 200; } } diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterInformationCollector.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java similarity index 96% rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterInformationCollector.java rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java index 89568debc..76cc6fa19 100644 --- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterInformationCollector.java +++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.servicecomb.config.collect; +package org.apache.servicecomb.config.cc; import org.apache.servicecomb.core.bootup.BootUpInformationCollector; import org.apache.servicecomb.deployment.Deployment; diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/TransportUtils.java similarity index 66% rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/TransportUtils.java index 21a510ac4..6a91ea6a2 100644 --- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java +++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/TransportUtils.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.servicecomb.config; +package org.apache.servicecomb.config.cc; import static org.apache.servicecomb.foundation.ssl.SSLOption.DEFAULT_OPTION; -import org.apache.commons.configuration.Configuration; import org.apache.servicecomb.foundation.ssl.SSLCustom; import org.apache.servicecomb.foundation.ssl.SSLOption; import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties; +import org.springframework.core.env.Environment; public class TransportUtils { - public static SSLProperties createSSLProperties(boolean sslEnabled, Configuration configuration, String tag) { + public static SSLProperties createSSLProperties(boolean sslEnabled, Environment environment, String tag) { SSLProperties sslProperties = new SSLProperties(); sslProperties.setEnabled(sslEnabled); @@ -34,93 +34,93 @@ public class TransportUtils { } SSLOption option = new SSLOption(); - option.setEngine(getStringProperty(configuration, + option.setEngine(getStringProperty(environment, DEFAULT_OPTION.getEngine(), "ssl." + tag + ".engine", "ssl.engine")); option.setProtocols( - getStringProperty(configuration, + getStringProperty(environment, DEFAULT_OPTION.getProtocols(), "ssl." + tag + ".protocols", "ssl.protocols")); option.setCiphers( - getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers")); + getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers")); option.setAuthPeer( - getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer")); + getBooleanProperty(environment, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer")); option.setCheckCNHost( - getBooleanProperty(configuration, + getBooleanProperty(environment, DEFAULT_OPTION.isCheckCNHost(), "ssl." + tag + ".checkCN.host", "ssl.checkCN.host")); option.setCheckCNWhite( - getBooleanProperty(configuration, + getBooleanProperty(environment, DEFAULT_OPTION.isCheckCNWhite(), "ssl." + tag + ".checkCN.white", "ssl.checkCN.white")); - option.setCheckCNWhiteFile(getStringProperty(configuration, + option.setCheckCNWhiteFile(getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".checkCN.white.file", "ssl.checkCN.white.file")); - option.setAllowRenegociate(getBooleanProperty(configuration, + option.setAllowRenegociate(getBooleanProperty(environment, DEFAULT_OPTION.isAllowRenegociate(), "ssl." + tag + ".allowRenegociate", "ssl.allowRenegociate")); option.setStorePath( - getStringProperty(configuration, + getStringProperty(environment, DEFAULT_OPTION.getStorePath(), "ssl." + tag + ".storePath", "ssl.storePath")); option.setClientAuth( - getStringProperty(configuration, + getStringProperty(environment, DEFAULT_OPTION.getClientAuth(), "ssl." + tag + ".clientAuth", "ssl.clientAuth")); option.setTrustStore( - getStringProperty(configuration, + getStringProperty(environment, DEFAULT_OPTION.getTrustStore(), "ssl." + tag + ".trustStore", "ssl.trustStore")); - option.setTrustStoreType(getStringProperty(configuration, + option.setTrustStoreType(getStringProperty(environment, DEFAULT_OPTION.getTrustStoreType(), "ssl." + tag + ".trustStoreType", "ssl.trustStoreType")); - option.setTrustStoreValue(getStringProperty(configuration, + option.setTrustStoreValue(getStringProperty(environment, DEFAULT_OPTION.getTrustStoreValue(), "ssl." + tag + ".trustStoreValue", "ssl.trustStoreValue")); option.setKeyStore( - getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore")); + getStringProperty(environment, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore")); option.setKeyStoreType( - getStringProperty(configuration, + getStringProperty(environment, DEFAULT_OPTION.getKeyStoreType(), "ssl." + tag + ".keyStoreType", "ssl.keyStoreType")); - option.setKeyStoreValue(getStringProperty(configuration, + option.setKeyStoreValue(getStringProperty(environment, DEFAULT_OPTION.getKeyStoreValue(), "ssl." + tag + ".keyStoreValue", "ssl.keyStoreValue")); - option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl")); + option.setCrl(getStringProperty(environment, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl")); option.setSslCustomClass( - getStringProperty(configuration, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass")); + getStringProperty(environment, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass")); sslProperties.setSslOption(option); sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass())); return sslProperties; } - private static String getStringProperty(Configuration configuration, String defaultValue, String... keys) { + private static String getStringProperty(Environment environment, String defaultValue, String... keys) { for (String key : keys) { - if (configuration.containsKey(key)) { - return configuration.getString(key); + if (environment.getProperty(key) != null) { + return environment.getProperty(key); } } return defaultValue; } - private static boolean getBooleanProperty(Configuration configuration, boolean defaultValue, String... keys) { + private static boolean getBooleanProperty(Environment environment, boolean defaultValue, String... keys) { for (String key : keys) { - if (configuration.containsKey(key)) { - return configuration.getBoolean(key); + if (environment.getProperty(key) != null) { + return environment.getProperty(key, boolean.class, false); } } return defaultValue; diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource deleted file mode 100644 index d38ec076a..000000000 --- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource +++ /dev/null @@ -1,18 +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. -# - -org.apache.servicecomb.config.ConfigCenterConfigurationSourceImpl \ No newline at end of file diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector index 58062576e..f49c5aacf 100644 --- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector +++ b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -org.apache.servicecomb.config.collect.ConfigCenterInformationCollector \ No newline at end of file +org.apache.servicecomb.config.cc.ConfigCenterInformationCollector \ No newline at end of file diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider index 39efa46f7..bd9118aff 100644 --- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider +++ b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider \ No newline at end of file +org.apache.servicecomb.config.cc.ConfigCenterDefaultDeploymentProvider \ No newline at end of file diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index d917e1e79..febb89438 100644 --- a/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -15,4 +15,4 @@ ## limitations under the License. ## --------------------------------------------------------------------------- -org.apache.servicecomb.config.ConfigCenterConfiguration +org.apache.servicecomb.config.cc.ConfigCenterConfiguration diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManagerTest.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterAddressManagerTest.java similarity index 96% rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManagerTest.java rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterAddressManagerTest.java index f47cc35be..1642d11ff 100644 --- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManagerTest.java +++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterAddressManagerTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.servicecomb.config.center.client; +package org.apache.servicecomb.config.cc; import java.lang.reflect.Field; import java.util.ArrayList; @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.servicecomb.config.center.client.ConfigCenterAddressManager; import org.apache.servicecomb.http.client.event.RefreshEndpointEvent; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImplTest.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterConfigurationSourceImplTest.java similarity index 98% rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImplTest.java rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterConfigurationSourceImplTest.java index 4a9b64a88..f9424c9a2 100644 --- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImplTest.java +++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterConfigurationSourceImplTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.servicecomb.config; +package org.apache.servicecomb.config.cc; import java.lang.reflect.Field; diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java similarity index 96% rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java index 540ac2c52..be3c4b207 100644 --- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java +++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java @@ -15,9 +15,10 @@ * limitations under the License. */ -package org.apache.servicecomb.config.collect; +package org.apache.servicecomb.config.cc; import org.apache.servicecomb.config.ConfigUtil; +import org.apache.servicecomb.config.cc.ConfigCenterDefaultDeploymentProvider; import org.apache.servicecomb.deployment.Deployment; import org.apache.servicecomb.deployment.SystemBootstrapInfo; import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
