You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/06/04 08:32:26 UTC
[servicecomb-java-chassis] 02/03: [SCB-2273]support kie latest
layered configuration. Part2: config center implementation
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 23e0feb9b882cc6c34b299f47b2aaea1d4b2b6dc
Author: liubao68 <bi...@qq.com>
AuthorDate: Wed Jun 2 18:07:48 2021 +0800
[SCB-2273]support kie latest layered configuration. Part2: config center implementation
---
dynamic-config/config-cc/pom.xml | 4 +
.../config/{client => }/ConfigCenterConfig.java | 45 +--
.../ConfigCenterConfigurationSourceImpl.java | 177 +++++++++
.../apache/servicecomb/config/TransportUtils.java | 118 ++++++
.../ConfigCenterConfigurationSourceImpl.java | 171 ---------
.../config/client/ConfigCenterClient.java | 427 ---------------------
.../client/ConfigCenterHttpClientOptionsSPI.java | 177 ---------
.../servicecomb/config/client/ConnFailEvent.java | 35 --
.../servicecomb/config/client/ConnSuccEvent.java | 22 --
.../servicecomb/config/client/MemberDiscovery.java | 90 -----
.../config/client/ParseConfigUtils.java | 183 ---------
.../apache/servicecomb/config/client/URIConst.java | 42 --
...comb.config.spi.ConfigCenterConfigurationSource | 2 +-
.../TestConfigCenterConfigurationSource.java | 124 ------
.../config/client/TestConfigCenterClient.java | 353 -----------------
.../config/client/TestConfigCenterConfig.java | 56 ---
.../config/client/TestMemberDiscovery.java | 84 ----
.../config/client/TestParseConfigUtils.java | 122 ------
.../servicecomb/config/client/TestURIConst.java | 60 ---
...TestConfigCenterDefaultDeploymentProvider.java} | 2 +-
20 files changed, 316 insertions(+), 1978 deletions(-)
diff --git a/dynamic-config/config-cc/pom.xml b/dynamic-config/config-cc/pom.xml
index 1ab6d3f..2ebea1e 100644
--- a/dynamic-config/config-cc/pom.xml
+++ b/dynamic-config/config-cc/pom.xml
@@ -59,6 +59,10 @@
<artifactId>foundation-test-scaffolding</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>config-center-client</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java
similarity index 85%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java
index 219329b..f65d12e 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java
@@ -15,18 +15,17 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.client;
+package org.apache.servicecomb.config;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
-import com.google.common.base.Joiner;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider;
import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.foundation.vertx.VertxConst;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import com.netflix.config.ConcurrentCompositeConfiguration;
public final class ConfigCenterConfig {
public static final ConfigCenterConfig INSTANCE = new ConfigCenterConfig();
@@ -146,35 +145,21 @@ public final class ConfigCenterConfig {
return finalConfig.getString(VertxConst.PROXY_PASSWD, null);
}
- @SuppressWarnings("unchecked")
public String getServiceName() {
- String service = BootStrapProperties.readServiceName(finalConfig);
- String appName = BootStrapProperties.readApplication(finalConfig);
- String tags;
- if (appName != null) {
- service = service + "@" + appName;
- }
+ return BootStrapProperties.readServiceName(finalConfig);
+ }
- String serviceVersion = BootStrapProperties.readServiceVersion(finalConfig);
- if (serviceVersion != null) {
- service = service + "#" + serviceVersion;
- }
+ public String getAppName() {
+ return BootStrapProperties.readApplication(finalConfig);
+ }
- Object o = BootStrapProperties.readServiceInstanceTags(finalConfig);
- if (o == null) {
- return service;
- }
- if (o instanceof List) {
- tags = Joiner.on(",").join((List<String>) o);
- } else {
- tags = o.toString();
- }
- service += "!" + tags;
- return service;
+ public String getServiceVersion() {
+ return BootStrapProperties.readServiceVersion(finalConfig);
}
public List<String> getServerUri() {
- return Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER).getAccessURL();
+ return Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER)
+ .getAccessURL();
}
public boolean getAutoDiscoveryEnabled() {
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/ConfigCenterConfigurationSourceImpl.java
new file mode 100644
index 0000000..d471e08
--- /dev/null
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java
@@ -0,0 +1,177 @@
+/*
+ * 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.servicecomb.config;
+
+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.client.config.RequestConfig;
+import org.apache.servicecomb.config.center.client.AddressManager;
+import org.apache.servicecomb.config.center.client.ConfigCenterClient;
+import org.apache.servicecomb.config.center.client.ConfigCenterManager;
+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.event.EventManager;
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.http.client.auth.RequestAuthHeaderProvider;
+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 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);
+
+ private List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
+
+ private ConfigCenterManager configCenterManager;
+
+ private ConfigConverter configConverter = new ConfigConverter(null);
+
+ @Override
+ public int getOrder() {
+ return ORDER_BASE * 2;
+ }
+
+ @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;
+ }
+
+ @Override
+ public void init(Configuration localConfiguration) {
+ AddressManager kieAddressManager = configKieAddressManager();
+
+ RequestConfig.Builder requestBuilder = HttpTransportFactory.defaultRequestConfig();
+
+ HttpTransport httpTransport = createHttpTransport(requestBuilder.build(), localConfiguration);
+ ConfigCenterClient configCenterClient = new ConfigCenterClient(kieAddressManager, httpTransport);
+ EventManager.register(this);
+
+ QueryConfigurationsRequest queryConfigurationsRequest = createQueryConfigurationsRequest();
+ QueryConfigurationsResponse response = configCenterClient
+ .queryConfigurations(queryConfigurationsRequest);
+ if (response.isChanged()) {
+ configConverter.updateData(response.getConfigurations());
+ updateConfiguration(WatchedUpdateResult.createIncremental(configConverter.getCurrentData(), null, null));
+ }
+ queryConfigurationsRequest.setRevision(response.getRevision());
+
+ configCenterManager = new ConfigCenterManager(configCenterClient, EventManager.getEventBus(),
+ configConverter);
+ configCenterManager.setQueryConfigurationsRequest(queryConfigurationsRequest);
+ configCenterManager.startConfigCenterManager();
+ }
+
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ updateConfiguration(
+ WatchedUpdateResult.createIncremental(event.getAdded(), event.getUpdated(), event.getDeleted()));
+ }
+
+ 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());
+ // 需要设置为 null, 并且 query 参数为 revision=null 才会返回 revision 信息。 revision = 是不行的。
+ request.setRevision(null);
+ return request;
+ }
+
+ private HttpTransport createHttpTransport(RequestConfig requestConfig, Configuration localConfiguration) {
+ List<AuthHeaderProvider> authHeaderProviders = SPIServiceUtils.getOrLoadSortedService(AuthHeaderProvider.class);
+
+ return HttpTransportFactory
+ .createHttpTransport(
+ TransportUtils.createSSLProperties(localConfiguration, "kie"),
+ getRequestAuthHeaderProvider(authHeaderProviders), requestConfig);
+ }
+
+ private static RequestAuthHeaderProvider getRequestAuthHeaderProvider(List<AuthHeaderProvider> authHeaderProviders) {
+ return signRequest -> {
+ Map<String, String> headers = new HashMap<>();
+ authHeaderProviders.forEach(provider -> headers.putAll(provider.authHeaders()));
+ return headers;
+ };
+ }
+
+ private AddressManager configKieAddressManager() {
+ AddressManager kieAddressManager = new AddressManager(ConfigCenterConfig.INSTANCE.getDomainName(),
+ Deployment
+ .getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER).getAccessURL());
+ return kieAddressManager;
+ }
+
+ private void updateConfiguration(WatchedUpdateResult result) {
+ 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();
+ }
+
+ @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 {
+ return configConverter.getCurrentData();
+ }
+}
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/TransportUtils.java
new file mode 100644
index 0000000..e6c8b48
--- /dev/null
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java
@@ -0,0 +1,118 @@
+/*
+ * 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.servicecomb.config;
+
+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;
+
+public class TransportUtils {
+ public static SSLProperties createSSLProperties(Configuration configuration, String tag) {
+ SSLProperties sslProperties = new SSLProperties();
+
+ SSLOption option = new SSLOption();
+ option.setEngine(getStringProperty(configuration,
+ DEFAULT_OPTION.getEngine(),
+ "ssl." + tag + ".engine",
+ "ssl.engine"));
+ option.setProtocols(
+ getStringProperty(configuration,
+ DEFAULT_OPTION.getProtocols(),
+ "ssl." + tag + ".protocols",
+ "ssl.protocols"));
+ option.setCiphers(
+ getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
+ option.setAuthPeer(
+ getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
+ option.setCheckCNHost(
+ getBooleanProperty(configuration,
+ DEFAULT_OPTION.isCheckCNHost(),
+ "ssl." + tag + ".checkCN.host",
+ "ssl.checkCN.host"));
+ option.setCheckCNWhite(
+ getBooleanProperty(configuration,
+ DEFAULT_OPTION.isCheckCNWhite(),
+ "ssl." + tag + ".checkCN.white",
+ "ssl.checkCN.white"));
+ option.setCheckCNWhiteFile(getStringProperty(configuration,
+ DEFAULT_OPTION.getCiphers(),
+ "ssl." + tag + ".checkCN.white.file",
+ "ssl.checkCN.white.file"));
+ option.setAllowRenegociate(getBooleanProperty(configuration,
+ DEFAULT_OPTION.isAllowRenegociate(),
+ "ssl." + tag + ".allowRenegociate",
+ "ssl.allowRenegociate"));
+ option.setStorePath(
+ getStringProperty(configuration,
+ DEFAULT_OPTION.getStorePath(),
+ "ssl." + tag + ".storePath",
+ "ssl.storePath"));
+ option.setTrustStore(
+ getStringProperty(configuration,
+ DEFAULT_OPTION.getTrustStore(),
+ "ssl." + tag + ".trustStore",
+ "ssl.trustStore"));
+ option.setTrustStoreType(getStringProperty(configuration,
+ DEFAULT_OPTION.getTrustStoreType(),
+ "ssl." + tag + ".trustStoreType",
+ "ssl.trustStoreType"));
+ option.setTrustStoreValue(getStringProperty(configuration,
+ DEFAULT_OPTION.getTrustStoreValue(),
+ "ssl." + tag + ".trustStoreValue",
+ "ssl.trustStoreValue"));
+ option.setKeyStore(
+ getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
+ option.setKeyStoreType(
+ getStringProperty(configuration,
+ DEFAULT_OPTION.getKeyStoreType(),
+ "ssl." + tag + ".keyStoreType",
+ "ssl.keyStoreType"));
+ option.setKeyStoreValue(getStringProperty(configuration,
+ DEFAULT_OPTION.getKeyStoreValue(),
+ "ssl." + tag + ".keyStoreValue",
+ "ssl.keyStoreValue"));
+ option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
+ option.setSslCustomClass(
+ getStringProperty(configuration, 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) {
+ for (String key : keys) {
+ if (configuration.containsKey(key)) {
+ return configuration.getString(key);
+ }
+ }
+ return defaultValue;
+ }
+
+ private static boolean getBooleanProperty(Configuration configuration, boolean defaultValue, String... keys) {
+ for (String key : keys) {
+ if (configuration.containsKey(key)) {
+ return configuration.getBoolean(key);
+ }
+ }
+ return defaultValue;
+ }
+}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java
deleted file mode 100644
index 04b53a7..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java
+++ /dev/null
@@ -1,171 +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.servicecomb.config.archaius.sources;
-
-import static com.netflix.config.WatchedUpdateResult.createIncremental;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.config.ConfigMapping;
-import org.apache.servicecomb.config.YAMLUtil;
-import org.apache.servicecomb.config.client.ConfigCenterClient;
-import org.apache.servicecomb.config.client.ConfigCenterConfig;
-import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
-import org.apache.servicecomb.deployment.Deployment;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
-/**
- * Created by on 2017/1/9.
- */
-public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigurationSource {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfigurationSourceImpl.class);
-
- private final Map<String, Object> valueCache = Maps.newConcurrentMap();
-
- private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
-
- private UpdateHandler updateHandler = new UpdateHandler();
-
- private ConfigCenterClient configCenterClient;
-
- public ConfigCenterConfigurationSourceImpl() {
- }
-
- @Override
- public int getOrder() {
- return ORDER_BASE * 1;
- }
-
- @Override
- public boolean isValidSource(Configuration localConfiguration) {
- return Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER) != null;
- }
-
- private void init() {
- configCenterClient = new ConfigCenterClient(updateHandler);
- configCenterClient.connectServer();
- }
-
- @Override
- public void init(Configuration localConfiguration) {
- ConfigCenterConfig.setConcurrentCompositeConfiguration((ConcurrentCompositeConfiguration) localConfiguration);
- init();
- }
-
- @Override
- public void destroy() {
- if (configCenterClient == null) {
- return;
- }
-
- configCenterClient.destroy();
- }
-
- public void addUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- if (watchedUpdateListener != null) {
- listeners.add(watchedUpdateListener);
- }
- }
-
- public void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- if (watchedUpdateListener != null) {
- listeners.remove(watchedUpdateListener);
- }
- }
-
- private void updateConfiguration(WatchedUpdateResult result) {
- for (WatchedUpdateListener l : listeners) {
- try {
- l.updateConfiguration(result);
- } catch (Throwable ex) {
- LOGGER.error("Error in invoking WatchedUpdateListener", ex);
- }
- }
- }
-
- public Map<String, Object> getCurrentData()
- throws Exception {
- return valueCache;
- }
-
- public List<WatchedUpdateListener> getCurrentListeners() {
- return listeners;
- }
-
- public class UpdateHandler {
-
- public void handle(String action, Map<String, Object> parseConfigs) {
- if (parseConfigs == null || parseConfigs.isEmpty()) {
- return;
- }
-
- Map<String, Object> configuration = ConfigMapping.getConvertedMap(parseConfigs);
- if (configCenterClient != null) {
- List<String> fileSourceList = configCenterClient.getFileSources();
- if (fileSourceList != null) {
- fileSourceList.forEach(fileName -> {
- if (configuration.containsKey(fileName)) {
- replaceConfig(configuration, fileName);
- }
- });
- }
- }
-
- if ("create".equals(action)) {
- valueCache.putAll(configuration);
- updateConfiguration(createIncremental(ImmutableMap.<String, Object>copyOf(configuration),
- null,
- null));
- } else if ("set".equals(action)) {
- valueCache.putAll(configuration);
- updateConfiguration(createIncremental(null, ImmutableMap.<String, Object>copyOf(configuration),
- null));
- } else if ("delete".equals(action)) {
- configuration.keySet().forEach(valueCache::remove);
- updateConfiguration(createIncremental(null,
- null,
- ImmutableMap.<String, Object>copyOf(configuration)));
- } else {
- LOGGER.error("action: {} is invalid.", action);
- return;
- }
- LOGGER.info("Config value cache changed: action:{}; item:{}", action, configuration.keySet());
- }
-
- private void replaceConfig(Map<String, Object> configuration, String fileName) {
- Object tempConfig = configuration.get(fileName);
- try {
- Map<String, Object> properties = YAMLUtil.yaml2Properties(tempConfig.toString());
- configuration.putAll(properties);
- } catch (Exception e) {
- LOGGER.warn("yaml file has incorrect format", e);
- }
- }
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
deleted file mode 100644
index 290a6d4..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
+++ /dev/null
@@ -1,427 +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.servicecomb.config.client;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import io.vertx.core.MultiMap;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.http.HttpClientRequest;
-import io.vertx.core.http.WebSocket;
-import io.vertx.core.http.WebSocketConnectOptions;
-import io.vertx.core.http.impl.FrameType;
-import io.vertx.core.http.impl.ws.WebSocketFrameImpl;
-import org.apache.commons.lang.StringUtils;
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl;
-import org.apache.servicecomb.foundation.auth.AuthHeaderLoader;
-import org.apache.servicecomb.foundation.auth.SignRequest;
-import org.apache.servicecomb.foundation.common.event.EventManager;
-import org.apache.servicecomb.foundation.common.net.IpPort;
-import org.apache.servicecomb.foundation.common.net.NetUtils;
-import org.apache.servicecomb.foundation.common.utils.JsonUtils;
-import org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext;
-import org.apache.servicecomb.foundation.vertx.client.http.HttpClients;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.net.UnknownHostException;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-public class ConfigCenterClient {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterClient.class);
-
- private static final ConfigCenterConfig CONFIG_CENTER_CONFIG = ConfigCenterConfig.INSTANCE;
-
- private static final long HEARTBEAT_INTERVAL = 30000;
-
- private static final long BOOTUP_WAIT_TIME = 10;
-
- private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
-
- private ScheduledExecutorService heartbeatTask = null;
-
- private int refreshMode = CONFIG_CENTER_CONFIG.getRefreshMode();
-
- private int refreshInterval = CONFIG_CENTER_CONFIG.getRefreshInterval();
-
- private int firstRefreshInterval = CONFIG_CENTER_CONFIG.getFirstRefreshInterval();
-
- private int refreshPort = CONFIG_CENTER_CONFIG.getRefreshPort();
-
- private String tenantName = CONFIG_CENTER_CONFIG.getTenantName();
-
- private String serviceName = CONFIG_CENTER_CONFIG.getServiceName();
-
- private String environment = CONFIG_CENTER_CONFIG.getEnvironment();
-
- private List<String> fileSources = CONFIG_CENTER_CONFIG.getFileSources();
-
- public List<String> getFileSources() {
- return fileSources;
- }
-
- private MemberDiscovery memberDiscovery = new MemberDiscovery(CONFIG_CENTER_CONFIG.getServerUri());
-
- private ConfigCenterConfigurationSourceImpl.UpdateHandler updateHandler;
-
- private boolean isWatching = false;
-
- private URIConst uriConst = new URIConst();
-
- public ConfigCenterClient(ConfigCenterConfigurationSourceImpl.UpdateHandler updateHandler) {
- HttpClients.addNewClientPoolManager(new ConfigCenterHttpClientOptionsSPI());
- this.updateHandler = updateHandler;
- }
-
- public void connectServer() {
- if (refreshMode != 0 && refreshMode != 1) {
- LOGGER.error("refreshMode must be 0 or 1.");
- return;
- }
- ParseConfigUtils.getInstance().initWithUpdateHandler(updateHandler);
- refreshMembers(memberDiscovery);
- ConfigRefresh refreshTask = new ConfigRefresh(ParseConfigUtils.getInstance(), memberDiscovery);
- refreshTask.run(true);
- executor.scheduleWithFixedDelay(refreshTask,
- firstRefreshInterval,
- refreshInterval,
- TimeUnit.MILLISECONDS);
- }
-
- public void destroy() {
- if (executor != null) {
- executor.shutdown();
- executor = null;
- }
-
- if (heartbeatTask != null) {
- heartbeatTask.shutdown();
- heartbeatTask = null;
- }
- }
-
- private void refreshMembers(MemberDiscovery memberDiscovery) {
- if (CONFIG_CENTER_CONFIG.getAutoDiscoveryEnabled()) {
- String configCenter = memberDiscovery.getConfigServer();
- IpPort ipPort = NetUtils.parseIpPortFromURI(configCenter);
- HttpClients.getClient(ConfigCenterHttpClientOptionsSPI.CLIENT_NAME).runOnContext(client -> {
- @SuppressWarnings("deprecation")
- HttpClientRequest request =
- client.get(ipPort.getPort(), ipPort.getHostOrIp(), uriConst.MEMBERS, rsp -> {
- if (rsp.statusCode() == HttpResponseStatus.OK.code()) {
- rsp.bodyHandler(buf -> {
- memberDiscovery.refreshMembers(buf.toJsonObject());
- });
- }
- });
- SignRequest signReq = createSignRequest(request.method().toString(),
- configCenter + uriConst.MEMBERS,
- new HashMap<>(),
- null);
- if (ConfigCenterConfig.INSTANCE.getToken() != null) {
- request.headers().add("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
- }
- request.headers()
- .addAll(AuthHeaderLoader.getInstance().loadAuthHeaders(signReq));
- request.exceptionHandler(e -> {
- LOGGER.error("Fetch member from {} failed. Error message is [{}].", configCenter, e.getMessage());
- logIfDnsFailed(e);
- });
- request.end();
- });
- }
- }
-
- class ConfigRefresh implements Runnable {
- private ParseConfigUtils parseConfigUtils;
-
- private MemberDiscovery memberdis;
-
- ConfigRefresh(ParseConfigUtils parseConfigUtils, MemberDiscovery memberdis) {
- this.parseConfigUtils = parseConfigUtils;
- this.memberdis = memberdis;
- }
-
- public void run(boolean wait) {
- try {
- String configCenter = memberdis.getConfigServer();
- if (refreshMode == 1) {
- //make sure that revision is updated timely,wait sub thread to finish it's pull task
- refreshConfig(configCenter, true);
- } else if (!isWatching) {
- // 重新监听时需要先加载,避免在断开期间丢失变更
- //we do not need worry about that the revision may not be updated timely, because we do not need
- //revision info in the push mode. the config-center will push the changing to us
- refreshConfig(configCenter, wait);
- doWatch(configCenter);
- }
- } catch (Throwable e) {
- LOGGER.error("client refresh thread exception", e);
- }
- }
-
- // 具体动作
- @Override
- public void run() {
- run(false);
- }
-
- // create watch and wait for done
- public void doWatch(String configCenter)
- throws UnsupportedEncodingException, InterruptedException {
- CountDownLatch waiter = new CountDownLatch(1);
- IpPort ipPort = NetUtils.parseIpPortFromURI(configCenter);
- String url = uriConst.REFRESH_ITEMS + "?dimensionsInfo="
- + StringUtils.deleteWhitespace(URLEncoder.encode(serviceName, "UTF-8"));
- Map<String, String> headers = new HashMap<>();
- headers.put("x-domain-name", tenantName);
- if (ConfigCenterConfig.INSTANCE.getToken() != null) {
- headers.put("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
- }
- headers.put("x-environment", environment);
-
- HttpClientWithContext vertxHttpClient = HttpClients.getClient(ConfigCenterHttpClientOptionsSPI.CLIENT_NAME);
-
- vertxHttpClient.runOnContext(client -> {
- Map<String, String> authHeaders = new HashMap<>();
- authHeaders.putAll(AuthHeaderLoader.getInstance().loadAuthHeaders((
- createSignRequest(null, configCenter + url, headers, null))));
- WebSocketConnectOptions options = new WebSocketConnectOptions();
- options.setHost(ipPort.getHostOrIp()).setPort(refreshPort).setURI(url)
- .setHeaders(MultiMap.caseInsensitiveMultiMap().addAll(headers)
- .addAll(authHeaders));
- client.webSocket(options, asyncResult -> {
- if (asyncResult.failed()) {
- LOGGER.error(
- "watcher connect to config center {} refresh port {} failed. Error message is [{}]",
- configCenter,
- refreshPort,
- asyncResult.cause().getMessage());
- waiter.countDown();
- } else {
- {
- asyncResult.result().exceptionHandler(e -> {
- LOGGER.error("watch config read fail", e);
- stopHeartBeatThread();
- isWatching = false;
- });
- asyncResult.result().closeHandler(v -> {
- LOGGER.warn("watching config connection is closed accidentally");
- stopHeartBeatThread();
- isWatching = false;
- });
-
- asyncResult.result().pongHandler(pong -> {
- // ignore, just prevent NPE.
- });
- asyncResult.result().frameHandler(frame -> {
- if (frame.isText() || frame.isBinary()) {
- Buffer action = frame.binaryData();
- LOGGER.debug("watching config received {}", action);
- Map<String, Object> mAction = null;
-
- try {
- mAction = action.toJsonObject().getMap();
- } catch (Exception e) {
- LOGGER.error("parse config item failed.", e);
- return;
- }
-
- if ("CREATE".equals(mAction.get("action"))) {
- //event loop can not be blocked,we just keep nothing changed in push mode
- refreshConfig(configCenter, false);
- } else if ("MEMBER_CHANGE".equals(mAction.get("action"))) {
- refreshMembers(memberdis);
- } else {
- parseConfigUtils.refreshConfigItemsIncremental(mAction);
- }
- }
- });
- startHeartBeatThread(asyncResult.result());
- isWatching = true;
- waiter.countDown();
- }
- }
- });
- });
- waiter.await();
- }
-
- private void startHeartBeatThread(WebSocket ws) {
- heartbeatTask = Executors.newScheduledThreadPool(1);
- heartbeatTask.scheduleWithFixedDelay(() -> sendHeartbeat(ws),
- HEARTBEAT_INTERVAL,
- HEARTBEAT_INTERVAL,
- TimeUnit.MILLISECONDS);
- }
-
- private void stopHeartBeatThread() {
- if (heartbeatTask != null) {
- heartbeatTask.shutdownNow();
- }
- }
-
- private void sendHeartbeat(WebSocket ws) {
- try {
- ws.writeFrame(new WebSocketFrameImpl(FrameType.PING));
- EventManager.post(new ConnSuccEvent());
- } catch (IllegalStateException e) {
- EventManager.post(new ConnFailEvent("heartbeat fail, " + e.getMessage()));
- LOGGER.error("heartbeat fail", e);
- }
- }
-
- public void refreshConfig(String configcenter, boolean wait) {
- CountDownLatch latch = new CountDownLatch(1);
- String encodeServiceName = "";
- try {
- encodeServiceName =
- URLEncoder.encode(StringUtils.deleteWhitespace(serviceName), StandardCharsets.UTF_8.name());
- } catch (UnsupportedEncodingException e) {
- LOGGER.error("encode failed. Error message: {}", e.getMessage());
- encodeServiceName = StringUtils.deleteWhitespace(serviceName);
- }
- //just log in the debug level
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Updating remote config...");
- }
- String path = uriConst.ITEMS + "?dimensionsInfo=" + encodeServiceName + "&revision="
- + ParseConfigUtils.getInstance().getCurrentVersionInfo();
- HttpClients.getClient(ConfigCenterHttpClientOptionsSPI.CLIENT_NAME).runOnContext(client -> {
- IpPort ipPort = NetUtils.parseIpPortFromURI(configcenter);
- @SuppressWarnings("deprecation")
- HttpClientRequest request = client.get(ipPort.getPort(), ipPort.getHostOrIp(), path, rsp -> {
- if (rsp.statusCode() == HttpResponseStatus.OK.code()) {
- rsp.bodyHandler(buf -> {
- try {
- parseConfigUtils
- .refreshConfigItems(JsonUtils.OBJ_MAPPER.readValue(buf.toString(),
- new TypeReference<LinkedHashMap<String, Map<String, Object>>>() {
- }));
- EventManager.post(new ConnSuccEvent());
- } catch (IOException e) {
- EventManager.post(new ConnFailEvent(
- "config update result parse fail " + e.getMessage()));
- LOGGER.error("Config update from {} failed. Error message is [{}].",
- configcenter,
- e.getMessage());
- }
- latch.countDown();
- });
- } else if (rsp.statusCode() == HttpResponseStatus.NOT_MODIFIED.code()) {
- //nothing changed
- EventManager.post(new ConnSuccEvent());
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Updating remote config is done. the revision {} has no change",
- ParseConfigUtils.getInstance().getCurrentVersionInfo());
- }
- latch.countDown();
- } else {
- rsp.bodyHandler(buf -> {
- LOGGER.error("Server error message is [{}].", buf);
- latch.countDown();
- });
- EventManager.post(new ConnFailEvent("fetch config fail"));
- LOGGER.error("Config update from {} failed.", configcenter);
- }
- }).setTimeout((BOOTUP_WAIT_TIME - 1) * 1000);
- Map<String, String> headers = new HashMap<>();
- headers.put("x-domain-name", tenantName);
- if (ConfigCenterConfig.INSTANCE.getToken() != null) {
- headers.put("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
- }
- headers.put("x-environment", environment);
- request.headers().addAll(headers);
- request.headers()
- .addAll(AuthHeaderLoader.getInstance().loadAuthHeaders(createSignRequest(request.method().toString(),
- configcenter + path,
- headers,
- null)));
- request.exceptionHandler(e -> {
- EventManager.post(new ConnFailEvent("fetch config fail"));
- LOGGER.error("Config update from {} failed. Error message is [{}].",
- configcenter,
- e.getMessage());
- logIfDnsFailed(e);
- latch.countDown();
- });
- request.end();
- });
- if (wait) {
- try {
- latch.await(BOOTUP_WAIT_TIME, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- LOGGER.warn(e.getMessage());
- }
- }
- }
- }
-
- public static SignRequest createSignRequest(String method, String endpoint, Map<String, String> headers,
- InputStream content) {
- SignRequest signReq = new SignRequest();
- try {
- signReq.setEndpoint(new URI(endpoint));
- } catch (URISyntaxException e) {
- LOGGER.warn("set uri failed, uri is {}, message: {}", endpoint, e.getMessage());
- }
-
- Map<String, String[]> queryParams = new HashMap<>();
- if (endpoint.contains("?")) {
- String parameters = endpoint.substring(endpoint.indexOf("?") + 1);
- if (null != parameters && !"".equals(parameters)) {
- String[] parameterarray = parameters.split("&");
- for (String p : parameterarray) {
- String key = p.split("=")[0];
- String value = p.split("=")[1];
- if (!queryParams.containsKey(key)) {
- queryParams.put(key, new String[] {value});
- } else {
- List<String> vals = new ArrayList<>(Arrays.asList(queryParams.get(key)));
- vals.add(value);
- queryParams.put(key, vals.toArray(new String[vals.size()]));
- }
- }
- }
- }
- signReq.setQueryParams(queryParams);
-
- signReq.setHeaders(headers);
- signReq.setHttpMethod(method);
- signReq.setContent(content);
- return signReq;
- }
-
- private void logIfDnsFailed(Throwable e) {
- if (e instanceof UnknownHostException) {
- LOGGER.error("DNS resolve failed!", e);
- }
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterHttpClientOptionsSPI.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterHttpClientOptionsSPI.java
deleted file mode 100644
index e9980f2..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterHttpClientOptionsSPI.java
+++ /dev/null
@@ -1,177 +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.servicecomb.config.client;
-
-import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.foundation.vertx.client.http.HttpClientOptionsSPI;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
-
-import io.vertx.core.VertxOptions;
-import io.vertx.core.http.HttpClientOptions;
-import io.vertx.core.http.HttpVersion;
-
-public class ConfigCenterHttpClientOptionsSPI implements HttpClientOptionsSPI {
- public static final String CLIENT_NAME = "config-center";
-
- @Override
- public String clientName() {
- return CLIENT_NAME;
- }
-
- @Override
- public int getOrder() {
- return -100;
- }
-
- @Override
- public boolean enabled() {
- return Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER) != null;
- }
-
- @Override
- public String getConfigTag() {
- return "cc.consumer";
- }
-
- @Override
- public ConcurrentCompositeConfiguration getConfigReader() {
- return ConfigCenterConfig.getConcurrentCompositeConfiguration();
- }
-
- @Override
- public int getEventLoopPoolSize() {
- return ConfigCenterConfig.INSTANCE.getEventLoopSize();
- }
-
- @Override
- public boolean useSharedVertx() {
- return false;
- }
-
- @Override
- public int getInstanceCount() {
- return ConfigCenterConfig.INSTANCE.getVerticalInstanceCount();
- }
-
- @Override
- public boolean isWorker() {
- return false;
- }
-
- @Override
- public String getWorkerPoolName() {
- return "pool-worker-config-center-client";
- }
-
- @Override
- public int getWorkerPoolSize() {
- return VertxOptions.DEFAULT_WORKER_POOL_SIZE;
- }
-
- @Override
- public HttpVersion getHttpVersion() {
- return HttpVersion.HTTP_1_1;
- }
-
- @Override
- public int getConnectTimeoutInMillis() {
- return ConfigCenterConfig.INSTANCE.getConnectionTimeout();
- }
-
- @Override
- public int getIdleTimeoutInSeconds() {
- return ConfigCenterConfig.INSTANCE.getIdleTimeoutInSeconds();
- }
-
- @Override
- public boolean isTryUseCompression() {
- return HttpClientOptions.DEFAULT_TRY_USE_COMPRESSION;
- }
-
- @Override
- public int getMaxWaitQueueSize() {
- return HttpClientOptions.DEFAULT_MAX_WAIT_QUEUE_SIZE;
- }
-
- @Override
- public int getMaxPoolSize() {
- return HttpClientOptions.DEFAULT_MAX_POOL_SIZE;
- }
-
- @Override
- public boolean isKeepAlive() {
- return HttpClientOptions.DEFAULT_KEEP_ALIVE;
- }
-
- @Override
- public int getMaxHeaderSize() {
- return HttpClientOptions.DEFAULT_MAX_HEADER_SIZE;
- }
-
- @Override
- public int getKeepAliveTimeout() {
- return HttpClientOptions.DEFAULT_KEEP_ALIVE_TIMEOUT;
- }
-
- @Override
- public int getHttp2MultiplexingLimit() {
- return HttpClientOptions.DEFAULT_HTTP2_MULTIPLEXING_LIMIT;
- }
-
- @Override
- public int getHttp2MaxPoolSize() {
- return HttpClientOptions.DEFAULT_HTTP2_MAX_POOL_SIZE;
- }
-
- @Override
- public boolean isUseAlpn() {
- return HttpClientOptions.DEFAULT_USE_ALPN;
- }
-
- @Override
- public boolean isProxyEnable() {
- return ConfigCenterConfig.INSTANCE.isProxyEnable();
- }
-
- @Override
- public String getProxyHost() {
- return ConfigCenterConfig.INSTANCE.getProxyHost();
- }
-
- @Override
- public int getProxyPort() {
- return ConfigCenterConfig.INSTANCE.getProxyPort();
- }
-
- @Override
- public String getProxyUsername() {
- return ConfigCenterConfig.INSTANCE.getProxyUsername();
- }
-
- @Override
- public String getProxyPassword() {
- return ConfigCenterConfig.INSTANCE.getProxyPasswd();
- }
-
- @Override
- public boolean isSsl() {
- return ConfigCenterConfig.INSTANCE.getServerUri().get(0).startsWith("https");
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConnFailEvent.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConnFailEvent.java
deleted file mode 100644
index b608fae..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConnFailEvent.java
+++ /dev/null
@@ -1,35 +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.servicecomb.config.client;
-
-public class ConnFailEvent {
-
- private String msg;
-
- public ConnFailEvent(String msg) {
- this.msg = msg;
- }
-
- public String getMsg() {
- return msg;
- }
-
- public void setMsg(String msg) {
- this.msg = msg;
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConnSuccEvent.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConnSuccEvent.java
deleted file mode 100644
index 54239ab..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConnSuccEvent.java
+++ /dev/null
@@ -1,22 +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.servicecomb.config.client;
-
-public class ConnSuccEvent {
-
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/MemberDiscovery.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/MemberDiscovery.java
deleted file mode 100644
index cee4c04..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/MemberDiscovery.java
+++ /dev/null
@@ -1,90 +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.servicecomb.config.client;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.servicecomb.foundation.common.event.EventManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.eventbus.Subscribe;
-
-import io.vertx.core.json.JsonObject;
-
-/**
- * Created by on 2016/11/19.
- */
-public class MemberDiscovery {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MemberDiscovery.class);
-
- private static final String SCHEMA_SEPRATOR = "://";
-
- private List<String> configServerAddresses = new ArrayList<>();
-
- private Object lock = new Object();
-
- private AtomicInteger counter = new AtomicInteger(0);
-
- public MemberDiscovery(List<String> configCenterUri) {
- if (configCenterUri != null && !configCenterUri.isEmpty()) {
- configServerAddresses.addAll(configCenterUri);
- }
- Collections.shuffle(configServerAddresses);
- EventManager.register(this);
- }
-
- public String getConfigServer() {
- synchronized (lock) {
- if (configServerAddresses.isEmpty()) {
- throw new IllegalStateException("Config center address is not available.");
- }
- int index = Math.abs(counter.get() % configServerAddresses.size());
- return configServerAddresses.get(index);
- }
- }
-
- @Subscribe
- public void onConnFailEvent(ConnFailEvent e) {
- counter.incrementAndGet();
- }
-
- public void refreshMembers(JsonObject members) {
- List<String> newServerAddresses = new ArrayList<>();
- members.getJsonArray("instances").forEach(m -> {
- JsonObject instance = (JsonObject) m;
- if ("UP".equals(instance.getString("status", "UP"))) {
- String endpoint = instance.getJsonArray("endpoints").getString(0);
- String scheme = instance.getBoolean("isHttps", false) ? "https" : "http";
- newServerAddresses.add(scheme + SCHEMA_SEPRATOR
- + endpoint.substring(endpoint.indexOf(SCHEMA_SEPRATOR) + SCHEMA_SEPRATOR.length()));
- }
- });
-
- synchronized (lock) {
- this.configServerAddresses.clear();
- this.configServerAddresses.addAll(newServerAddresses);
- Collections.shuffle(this.configServerAddresses);
- }
- LOGGER.info("New config center members: {}", this.configServerAddresses);
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ParseConfigUtils.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ParseConfigUtils.java
deleted file mode 100644
index b20262a..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ParseConfigUtils.java
+++ /dev/null
@@ -1,183 +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.servicecomb.config.client;
-
-import java.io.IOException;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler;
-import org.apache.servicecomb.foundation.common.utils.JsonUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-
-/**
- * Created by on 2017/1/5.
- */
-public class ParseConfigUtils {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ParseConfigUtils.class);
-
- private static final ParseConfigUtils INSTANCE = new ParseConfigUtils();
-
- private LinkedHashMap<String, Map<String, Object>> multiDimensionItems = new LinkedHashMap<>();
-
- //it's dangerous to make flatItems public
- private final Map<String, Object> flatItems = new HashMap<>();
-
- private String currentVersionInfo = "default";
-
- private UpdateHandler updateHandler;
-
- private Lock configLock = new ReentrantLock();
-
- //for compatibility with other modules and JunitTest
- public ParseConfigUtils(UpdateHandler updateHandler) {
- this.updateHandler = updateHandler;
- }
-
- private ParseConfigUtils() {
- }
-
- public void initWithUpdateHandler(UpdateHandler updateHandler) {
- if (updateHandler == null) {
- LOGGER.error("when init ParseConfigUtils, updateHandler can not be null");
- }
- this.updateHandler = updateHandler;
- }
-
- /*
- as the data is returned, we can block the thread at a short time. consider that if the multiple verticles were deployed
- and if we use pull mode and push mode at the same time , we must share a common lock with all methods which would
- change the config setting
- */
- public void refreshConfigItems(Map<String, Map<String, Object>> remoteItems) {
- try {
- configLock.lock();
- String oldRevision = currentVersionInfo;
- currentVersionInfo =
- remoteItems.getOrDefault("revision", new HashMap<>()).getOrDefault("version", "default").toString();
- //make sure the currentVersionInfo != ""
- currentVersionInfo = currentVersionInfo.equals("") ? "default" : currentVersionInfo;
- //the key revision is not the config setting
- boolean newVersion = (remoteItems.remove("revision") != null);
- multiDimensionItems.clear();
- multiDimensionItems.putAll(remoteItems);
- doRefreshItems();
- if (newVersion) {
- LOGGER.info("Updating remote config is done. revision has changed from {} to {}", oldRevision,
- currentVersionInfo);
- }
- } finally {
- configLock.unlock();
- }
- }
-
- public static ParseConfigUtils getInstance() {
- return INSTANCE;
- }
-
- public String getCurrentVersionInfo() {
- return this.currentVersionInfo;
- }
-
- public void refreshConfigItemsIncremental(Map<String, Object> action) {
- try {
- configLock.lock();
- if ("UPDATE".equals(action.get("action"))) {
- try {
- multiDimensionItems.put((String) action.get("key"), JsonUtils.OBJ_MAPPER
- .readValue(action.get("value").toString(), new TypeReference<Map<String, Object>>() {
- }));
- } catch (IOException e) {
- LOGGER.error("parse config change action fail");
- }
- doRefreshItems();
- } else if ("DELETE".equals(action.get("action"))) {
- multiDimensionItems.remove(action.get("key"));
- doRefreshItems();
- }
- } finally {
- configLock.unlock();
- }
- }
-
- private void doRefreshItems() {
- Map<String, Object> freshFlatItems = mergeDimensionItems(multiDimensionItems);
- notifyItemsChangedNeedRefresh(flatItems, freshFlatItems);
- flatItems.clear();
- flatItems.putAll(freshFlatItems);
- }
-
- private Map<String, Object> mergeDimensionItems(Map<String, Map<String, Object>> items) {
- Map<String, Object> flatMap = new HashMap<>();
- Set<String> keySet = items.keySet();
- if (keySet.contains("application")) {
- flatMap.putAll(items.get("application"));
- keySet.remove("application");
- }
- if (!keySet.isEmpty()) {
- TreeSet<String> sortedKeys = new TreeSet<String>(new Comparator<String>() {
- @Override
- public int compare(String o1, String o2) {
- return o1.length() - o2.length();
- }
- });
- sortedKeys.addAll(keySet);
- sortedKeys.forEach(key -> flatMap.putAll(items.get(key)));
- }
- return flatMap;
- }
-
- private void notifyItemsChangedNeedRefresh(Map<String, Object> before, Map<String, Object> after) {
- Map<String, Object> itemsCreated = new HashMap<>();
- Map<String, Object> itemsDeleted = new HashMap<>();
- Map<String, Object> itemsModified = new HashMap<>();
- if (before == null || before.isEmpty()) {
- updateHandler.handle("create", after);
- return;
- }
- if (after == null || after.isEmpty()) {
- updateHandler.handle("delete", before);
- return;
- }
- for (String itemKey : after.keySet()) {
- if (!before.containsKey(itemKey)) {
- itemsCreated.put(itemKey, after.get(itemKey));
- } else if (!after.get(itemKey).equals(before.get(itemKey))) {
- itemsModified.put(itemKey, after.get(itemKey));
- }
- }
- for (String itemKey : before.keySet()) {
- if (!after.containsKey(itemKey)) {
- itemsDeleted.put(itemKey, "");
- }
- }
- updateHandler.handle("create", itemsCreated);
- updateHandler.handle("set", itemsModified);
- updateHandler.handle("delete", itemsDeleted);
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/URIConst.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/URIConst.java
deleted file mode 100644
index 14be671..0000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/URIConst.java
+++ /dev/null
@@ -1,42 +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.servicecomb.config.client;
-
-public class URIConst {
- private final String DOMAIN_NAME = ConfigCenterConfig.INSTANCE.getDomainName();
-
- private final String CURRENT_VERSION = ConfigCenterConfig.INSTANCE.getApiVersion();
-
- private final String VERSION_V2 = "v2";
-
- private final String PREFIX_V2 = "/configuration/v2";
-
- private final String PREFIX_V3 = String.format("/v3/%s/configuration", DOMAIN_NAME);
-
- private final boolean isV2 = VERSION_V2.equals(CURRENT_VERSION);
-
- private final String CURRENT_PREFIX = isV2 ? PREFIX_V2 : PREFIX_V3;
-
- // v2 no prefix
- public final String MEMBERS = isV2 ? "/members" : PREFIX_V3 + "/members";
-
- // v2 has prefix
- public final String REFRESH_ITEMS = CURRENT_PREFIX + "/refresh/items";
-
- public final String ITEMS = CURRENT_PREFIX + "/items";
-}
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
index 10d2b83..d38ec07 100644
--- 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
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl
\ No newline at end of file
+org.apache.servicecomb.config.ConfigCenterConfigurationSourceImpl
\ No newline at end of file
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/archaius/sources/TestConfigCenterConfigurationSource.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/archaius/sources/TestConfigCenterConfigurationSource.java
deleted file mode 100644
index ec45127..0000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/archaius/sources/TestConfigCenterConfigurationSource.java
+++ /dev/null
@@ -1,124 +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.servicecomb.config.archaius.sources;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.commons.lang.reflect.FieldUtils;
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler;
-import org.apache.servicecomb.config.client.ConfigCenterClient;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
-import mockit.Deencapsulation;
-import mockit.Mock;
-import mockit.MockUp;
-
-/**
- * Created by on 2017/1/12.
- */
-public class TestConfigCenterConfigurationSource {
- @Test
- public void testCreate() throws Exception {
-
- ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
- configCenterSource.addUpdateListener(new WatchedUpdateListener() {
- @Override
- public void updateConfiguration(WatchedUpdateResult result) {
- Assert.assertTrue(!result.getAdded().isEmpty());
- }
- });
- UpdateHandler udateHandler = Deencapsulation.getField(configCenterSource, UpdateHandler.class);
- Map<String, Object> addedItems = new HashMap<>();
- addedItems.put("testKey", "testValue");
- udateHandler.handle("create", addedItems);
- }
-
- @Test
- public void testUpdate() throws Exception {
-
- ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
- configCenterSource.addUpdateListener(new WatchedUpdateListener() {
- @Override
- public void updateConfiguration(WatchedUpdateResult result) {
- Assert.assertTrue(!result.getChanged().isEmpty());
- }
- });
- UpdateHandler udateHandler = Deencapsulation.getField(configCenterSource, UpdateHandler.class);
- Map<String, Object> addedItems = new HashMap<>();
- addedItems.put("testKey", "testValue");
- udateHandler.handle("set", addedItems);
- }
-
- @Test
- public void testDelete() throws Exception {
- ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
- configCenterSource.addUpdateListener(new WatchedUpdateListener() {
- @Override
- public void updateConfiguration(WatchedUpdateResult result) {
- Assert.assertTrue(!result.getDeleted().isEmpty());
- }
- });
- UpdateHandler udateHandler = Deencapsulation.getField(configCenterSource, UpdateHandler.class);
- Map<String, Object> addedItems = new HashMap<>();
- addedItems.put("testKey", "testValue");
-
- configCenterSource.getCurrentData().put("testKey", "testValue");
- udateHandler.handle("delete", addedItems);
- Assert.assertTrue(configCenterSource.getCurrentData().isEmpty());
- }
-
- @Test
- public void testRemoveUpdateListener() {
- ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
- WatchedUpdateListener watchedUpdateListener = Mockito.mock(WatchedUpdateListener.class);
- configCenterSource.addUpdateListener(watchedUpdateListener);
- configCenterSource.removeUpdateListener(watchedUpdateListener);
- Assert.assertTrue(configCenterSource.getCurrentListeners().isEmpty());
- }
-
- @Test
- public void destroy_notInit() {
- ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
-
- // need not throw exception
- configCenterSource.destroy();
- }
-
- @Test
- public void destroy_inited() throws IllegalAccessException {
- AtomicInteger count = new AtomicInteger();
- ConfigCenterClient configCenterClient = new MockUp<ConfigCenterClient>() {
- @Mock
- void destroy() {
- count.incrementAndGet();
- }
- }.getMockInstance();
- ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
- FieldUtils.writeDeclaredField(configCenterSource, "configCenterClient", configCenterClient, true);
-
- configCenterSource.destroy();
-
- Assert.assertEquals(1, count.get());
- }
-}
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterClient.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterClient.java
deleted file mode 100644
index efbd2d3..0000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterClient.java
+++ /dev/null
@@ -1,353 +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.servicecomb.config.client;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl;
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler;
-import org.apache.servicecomb.config.client.ConfigCenterClient.ConfigRefresh;
-import org.apache.servicecomb.foundation.common.event.EventManager;
-import org.apache.servicecomb.foundation.vertx.client.ClientPoolManager;
-import org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext;
-import org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext.RunHandler;
-import org.apache.servicecomb.foundation.vertx.client.http.HttpClients;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import com.google.common.eventbus.Subscribe;
-
-import io.vertx.core.Handler;
-import io.vertx.core.MultiMap;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.http.HttpClient;
-import io.vertx.core.http.HttpClientRequest;
-import io.vertx.core.http.HttpClientResponse;
-import io.vertx.core.http.HttpMethod;
-import io.vertx.core.http.WebSocket;
-import io.vertx.core.json.JsonObject;
-import mockit.Deencapsulation;
-import mockit.Expectations;
-import mockit.Mock;
-import mockit.MockUp;
-import mockit.Mocked;
-
-@SuppressWarnings("deprecation")
-public class TestConfigCenterClient {
- @BeforeClass
- public static void setUpClass() {
- ConfigCenterConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testConnectServer(@Mocked ClientPoolManager<HttpClientWithContext> clientMgr) {
- HttpClients.mockClientPoolManager("config-center", clientMgr);
-
- HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
- Mockito.when(request.method()).thenReturn(HttpMethod.GET);
- Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
- Buffer rsp = Mockito.mock(Buffer.class);
- Mockito.when(rsp.toJsonObject()).thenReturn(new JsonObject(
- "{\"instances\":[{\"status\":\"UP\",\"endpoints\":[\"rest:0.0.0.0:30103\"],\"hostName\":\"125292-0.0.0.0\",\"serviceName\":\"configServer\",\"https\":false}]}"));
- HttpClientResponse event = Mockito.mock(HttpClientResponse.class);
- Mockito.when(event.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
- Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
- handler.handle(rsp);
- return null;
- });
- Mockito.when(event.statusCode()).thenReturn(200);
- HttpClient httpClient = Mockito.mock(HttpClient.class);
- Mockito.when(
- httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class)))
- .then(invocation -> {
- Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
- handler.handle(event);
- return request;
- });
- new MockUp<HttpClientWithContext>() {
- @Mock
- public void runOnContext(RunHandler handler) {
- handler.run(httpClient);
- }
- };
- new MockUp<MemberDiscovery>() {
- @Mock
- public void refreshMembers(JsonObject members) {
- Assert.assertTrue(members.size() == 1);
- }
- };
- UpdateHandler updateHandler = new ConfigCenterConfigurationSourceImpl().new UpdateHandler();
- ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
- cc.connectServer();
- }
-
- @Test
- public void testConnectRefreshModeTwo() {
- ConfigCenterClient cc2 = new ConfigCenterClient(null);
- boolean status = false;
- try {
- Deencapsulation.setField(cc2, "refreshMode", 2);
- cc2.connectServer();
- } catch (Exception e) {
- status = true;
- }
- Assert.assertFalse(status);
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- @Test
- public void testConfigRefreshModeOne(@Mocked ClientPoolManager clientMgr) {
- String version1 = refreshAndGetCurrentRevision(clientMgr, 200, "huawei");
- //test the sdk get and change the latestRevision
- Assert.assertEquals("huawei", version1);
- String version2 = refreshAndGetCurrentRevision(clientMgr, 304, "rkd");
- //test that when return code is 304, the sdk do not change the latestRevision
- Assert.assertNotEquals("rkd", version2);
- String version3 = refreshAndGetCurrentRevision(clientMgr, 200, "");
- //make sure the current version is not ""
- Assert.assertNotEquals("", version3);
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private String refreshAndGetCurrentRevision(ClientPoolManager clientMgr, int statusCode, String version) {
-
- ConfigCenterConfigurationSourceImpl impl = new ConfigCenterConfigurationSourceImpl();
- UpdateHandler updateHandler = impl.new UpdateHandler();
- HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
- Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
- Buffer rsp = Mockito.mock(Buffer.class);
- Mockito.when(rsp.toString())
- .thenReturn(String.format(
- "{\"application\":{\"3\":\"2\",\"aa\":\"1\"},\"vmalledge\":{\"aa\":\"3\"},\"revision\": { \"version\": \"%s\"} }",
- version));
-
- HttpClientResponse httpClientResponse = Mockito.mock(HttpClientResponse.class);
- Mockito.when(httpClientResponse.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
- Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
- handler.handle(rsp);
- return null;
- });
- Mockito.when(httpClientResponse.statusCode()).thenReturn(statusCode);
-
- HttpClient httpClient = Mockito.mock(HttpClient.class);
- Mockito.when(
- httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class)))
- .then(invocation -> {
- Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
- handler.handle(httpClientResponse);
- return request;
- });
-
- HttpClientWithContext httpClientWithContext = new MockUp<HttpClientWithContext>() {
- @Mock
- public void runOnContext(RunHandler handler) {
- handler.run(httpClient);
- }
- }.getMockInstance();
-
- HttpClients.mockClientPoolManager("config-center", clientMgr);
-
- new Expectations() {
- {
- clientMgr.findThreadBindClientPool();
- result = httpClientWithContext;
- }
- };
-
- ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
- ParseConfigUtils parseConfigUtils = new ParseConfigUtils(updateHandler);
- MemberDiscovery memberdis = new MemberDiscovery(Arrays.asList("http://configcentertest:30103"));
- ConfigRefresh refresh = cc.new ConfigRefresh(parseConfigUtils, memberdis);
- Deencapsulation.setField(cc, "refreshMode", 1);
- refresh.run();
- String currentVersionInfo = Deencapsulation.getField(parseConfigUtils, "currentVersionInfo").toString();
- return currentVersionInfo;
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- @Test
- public void testConfigRefreshModeZero(@Mocked ClientPoolManager clientMgr) {
- ConfigCenterConfigurationSourceImpl impl = new ConfigCenterConfigurationSourceImpl();
- UpdateHandler updateHandler = impl.new UpdateHandler();
- HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
- Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
- Buffer rsp = Mockito.mock(Buffer.class);
- Mockito.when(rsp.toString())
- .thenReturn("{\"application\":{\"2\":\"2\",\"aa\":\"1\"},\"vmalledge\":{\"aa\":\"3\"}}");
-
- HttpClientResponse httpClientResponse = Mockito.mock(HttpClientResponse.class);
- Mockito.when(httpClientResponse.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
- Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
- handler.handle(rsp);
- return null;
- });
- Mockito.when(httpClientResponse.statusCode()).thenReturn(200);
-
- Buffer buf = Mockito.mock(Buffer.class);
- Mockito.when(buf.toJsonObject()).thenReturn(new JsonObject(
- "{\"action\":\"UPDATE\",\"key\":\"vmalledge\",\"value\":\"{\\\"aa\\\":\\\"3\\\"}\"}"));
- WebSocket websocket = Mockito.mock(WebSocket.class);
- Mockito.when(websocket.handler(Mockito.any(Handler.class))).then(invocation -> {
- Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
- handler.handle(buf);
- return websocket;
- });
- HttpClient httpClient = Mockito.mock(HttpClient.class);
- Mockito.when(
- httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class)))
- .then(invocation -> {
- Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
- handler.handle(httpClientResponse);
- return request;
- });
- Mockito.when(httpClient.websocket(Mockito.anyInt(),
- Mockito.anyString(),
- Mockito.anyString(),
- Mockito.any(MultiMap.class),
- Mockito.any(Handler.class),
- Mockito.any(Handler.class)))
- .then(invocation -> {
- Handler<WebSocket> handler = invocation.getArgumentAt(4, Handler.class);
- handler.handle(websocket);
- return null;
- });
-
- HttpClientWithContext httpClientWithContext = new MockUp<HttpClientWithContext>() {
- @Mock
- public void runOnContext(RunHandler handler) {
- handler.run(httpClient);
- }
- }.getMockInstance();
-
- HttpClients.mockClientPoolManager("config-center", clientMgr);
-
- new Expectations() {
- {
- clientMgr.findThreadBindClientPool();
- result = httpClientWithContext;
- }
- };
-
- ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
- ParseConfigUtils parseConfigUtils = new ParseConfigUtils(updateHandler);
- MemberDiscovery memberdis = new MemberDiscovery(Arrays.asList("http://configcentertest:30103"));
- ConfigRefresh refresh = cc.new ConfigRefresh(parseConfigUtils, memberdis);
- refresh.run();
- Map<String, Object> flatItems = Deencapsulation.getField(parseConfigUtils, "flatItems");
- Assert.assertEquals(2, flatItems.size());
- Deencapsulation.setField(cc, "refreshMode", 0);
- refresh.run();
- }
-
- public static class ConfigRefreshExceptionEvent {
- Map<String, String> map;
-
- public ConfigRefreshExceptionEvent(Map<String, String> map) {
- this.map = map;
- }
-
- @Subscribe
- public void testMsg(Object event) {
- if (event instanceof ConnFailEvent) {
- map.put("result", "Fail event trigger");
- }
- if (event instanceof ConnSuccEvent) {
- map.put("result", "Succ event trigger");
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testConfigRefreshException(@Mocked ClientPoolManager<HttpClientWithContext> clientMgr,
- @Mocked HttpClientWithContext httpClientWithContext) {
- ConfigCenterConfigurationSourceImpl impl = new ConfigCenterConfigurationSourceImpl();
- Map<String, String> map = new HashMap<>();
- EventManager.register(new ConfigRefreshExceptionEvent(map));
- UpdateHandler updateHandler = impl.new UpdateHandler();
- HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
- Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
- Buffer rsp = Mockito.mock(Buffer.class);
- Mockito.when(rsp.toString())
- .thenReturn("{\"application\":{\"2\":\"2\",\"aa\":\"1\"},\"vmalledge\":{\"aa\":\"3\"}}");
-
- HttpClientResponse event = Mockito.mock(HttpClientResponse.class);
- Mockito.when(event.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
- Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
- handler.handle(rsp);
- return null;
- });
- Mockito.when(event.statusCode()).thenReturn(400);
- Buffer buf = Mockito.mock(Buffer.class);
- Mockito.when(buf.toJsonObject()).thenReturn(new JsonObject(
- "{\"action\":\"UPDATE\",\"key\":\"vmalledge\",\"value\":\"{\\\"aa\\\":\\\"3\\\"}\"}"));
- HttpClient httpClient = Mockito.mock(HttpClient.class);
- Mockito.when(
- httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class)))
- .then(invocation -> {
- Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
- handler.handle(event);
- return request;
- });
- new MockUp<HttpClientWithContext>() {
- @Mock
- public void runOnContext(RunHandler handler) {
- handler.run(httpClient);
- }
- };
- new Expectations() {
- {
- clientMgr.findThreadBindClientPool();
- result = httpClientWithContext;
- }
- };
- ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
- HttpClients.mockClientPoolManager("config-center", clientMgr);
- ParseConfigUtils parseConfigUtils = new ParseConfigUtils(updateHandler);
- MemberDiscovery memberdis = new MemberDiscovery(Arrays.asList("http://configcentertest:30103"));
- ConfigRefresh refresh = cc.new ConfigRefresh(parseConfigUtils, memberdis);
- refresh.run();
- Assert.assertEquals("Fail event trigger", map.get("result"));
- Mockito.when(event.statusCode()).thenReturn(200);
- refresh.run();
- Assert.assertEquals("Succ event trigger", map.get("result"));
- }
-
- @Test
- public void destroy() {
- ConfigCenterClient configCenterClient = new ConfigCenterClient(null);
- ScheduledExecutorService executor = Deencapsulation.getField(configCenterClient, "executor");
- ScheduledExecutorService heartbeatTask = Executors.newScheduledThreadPool(1);
- Deencapsulation.setField(configCenterClient, "heartbeatTask", heartbeatTask);
-
- Assert.assertFalse(executor.isShutdown());
-
- configCenterClient.destroy();
-
- Assert.assertTrue(executor.isShutdown());
- Assert.assertTrue(heartbeatTask.isShutdown());
- }
-}
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java
deleted file mode 100644
index dda2a21..0000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java
+++ /dev/null
@@ -1,56 +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.servicecomb.config.client;
-
-import java.util.List;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestConfigCenterConfig {
- @BeforeClass
- public static void setUpClass() {
- ConfigCenterConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
- }
-
- @Test
- public void getServerUri() {
- List<String> servers = ConfigCenterConfig.INSTANCE.getServerUri();
- Assert.assertEquals("https://172.16.8.7:30103", servers.get(0));
- Assert.assertEquals("https://172.16.8.7:30103", servers.get(1));
- }
-
- @Test
- public void getEnvironment() {
- Assert.assertEquals("testing", ConfigCenterConfig.INSTANCE.getEnvironment());
- System.setProperty("SERVICECOMB_ENV", "development");
- ConfigCenterConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
- Assert.assertEquals("development", ConfigCenterConfig.INSTANCE.getEnvironment());
- }
-
- @Test
- public void getProxyConfig() {
- Assert.assertFalse(ConfigCenterConfig.INSTANCE.isProxyEnable());
- Assert.assertEquals("127.0.0.1", ConfigCenterConfig.INSTANCE.getProxyHost());
- Assert.assertEquals(8080, ConfigCenterConfig.INSTANCE.getProxyPort());
- Assert.assertNull(ConfigCenterConfig.INSTANCE.getProxyUsername());
- Assert.assertNull(ConfigCenterConfig.INSTANCE.getProxyPasswd());
- }
-}
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestMemberDiscovery.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestMemberDiscovery.java
deleted file mode 100644
index 2362902..0000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestMemberDiscovery.java
+++ /dev/null
@@ -1,84 +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.servicecomb.config.client;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Arrays;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.foundation.common.event.EventManager;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import io.vertx.core.json.JsonObject;
-
-public class TestMemberDiscovery {
- @BeforeClass
- public static void setUpClass() {
- ConfigCenterConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
- }
-
- @Test
- public void testGetConfigServerURIs() {
- MemberDiscovery dc = new MemberDiscovery(ConfigCenterConfig.INSTANCE.getServerUri());
- assertNotNull(dc.getConfigServer());
- }
-
- @Test
- public void testServerChange() {
- MemberDiscovery dc = new MemberDiscovery(Arrays.asList("http://127.0.0.1:30103", "http://127.0.0.1:30104"));
- String server1 = dc.getConfigServer();
- EventManager.post(new ConnFailEvent("connect failed."));
- String server2 = dc.getConfigServer();
- Assert.assertNotEquals(server1, server2);
- EventManager.post(new ConnFailEvent("connect failed."));
- server2 = dc.getConfigServer();
- Assert.assertEquals(server1, server2);
-
- dc.refreshMembers(new JsonObject(
- "{\"instances\":"
- + "[{\"status\":\"UP\",\"endpoints\":[\"rest://0.0.0.0:30109\"],\"hostName\":\"125292-0.0.0.0\",\"serviceName\":\"configServer\",\"isHttps\":false}"
- + ",{\"status\":\"UP\",\"endpoints\":[\"rest://0.0.0.0:30108\"],\"hostName\":\"125293-0.0.0.0\",\"serviceName\":\"configServer\",\"isHttps\":false}"
- + "]}"));
- server1 = dc.getConfigServer();
- EventManager.post(new ConnFailEvent("connect failed."));
- server2 = dc.getConfigServer();
- Assert.assertNotEquals(server1, server2);
- EventManager.post(new ConnFailEvent("connect failed."));
- server2 = dc.getConfigServer();
- Assert.assertEquals(server1, server2);
- }
-
- @Test
- public void testDiscoverywithHttp() {
- MemberDiscovery discoveryClient1 = new MemberDiscovery(null);
- discoveryClient1.refreshMembers(new JsonObject(
- "{\"instances\":[{\"status\":\"UP\",\"endpoints\":[\"rest://0.0.0.0:30103\"],\"hostName\":\"125292-0.0.0.0\",\"serviceName\":\"configServer\",\"isHttps\":false}]}"));
- Assert.assertEquals("http://0.0.0.0:30103", discoveryClient1.getConfigServer());
- }
-
- @Test
- public void testDiscoverywithHttps() {
- MemberDiscovery discoveryClient1 = new MemberDiscovery(null);
- discoveryClient1.refreshMembers(new JsonObject(
- "{\"instances\":[{\"status\":\"UP\",\"endpoints\":[\"rest://0.0.0.0:30103\"],\"hostName\":\"125292-0.0.0.0\",\"serviceName\":\"configServer\",\"isHttps\":true}]}"));
- Assert.assertEquals("https://0.0.0.0:30103", discoveryClient1.getConfigServer());
- }
-}
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestParseConfigUtils.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestParseConfigUtils.java
deleted file mode 100644
index 9c12cb1..0000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestParseConfigUtils.java
+++ /dev/null
@@ -1,122 +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.servicecomb.config.client;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl;
-import org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler;
-import org.junit.Assert;
-import org.junit.Test;
-
-import mockit.Deencapsulation;
-
-/**
- * @author
- */
-public class TestParseConfigUtils {
-
- private ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
-
- private UpdateHandler uh = configCenterSource.new UpdateHandler();
-
- private ParseConfigUtils pc = new ParseConfigUtils(uh);
-
- @Test
- public void testNotifyItemsChangedNeedRefresh() {
-
- boolean status = true;
- Map<String, Object> before = new HashMap<>();
- Map<String, Object> after = new HashMap<>();
- try {
- Deencapsulation.invoke(pc, "notifyItemsChangedNeedRefresh", before, after);
- } catch (Exception e) {
- status = false;
- }
- Assert.assertTrue(status);
-
- // Check with valid before object
- status = true;
- before.put("test", "testValue");
- try {
- Deencapsulation.invoke(pc, "notifyItemsChangedNeedRefresh", before, after);
- } catch (Exception e) {
- status = false;
- }
- Assert.assertTrue(status);
-
- // Check with valid after object
- status = true;
- after.put("test", "testValue2");
- try {
- Deencapsulation.invoke(pc, "notifyItemsChangedNeedRefresh", before, after);
- } catch (Exception e) {
- status = false;
- }
- Assert.assertTrue(status);
-
- // Check with valid localItems object
- status = true;
- try {
- Deencapsulation.invoke(pc, "notifyItemsChangedNeedRefresh", before, after);
- } catch (Exception e) {
- status = false;
- }
- Assert.assertTrue(status);
- }
-
- @Test
- public void testMergeDimensionItems() {
-
- boolean status = true;
- Map<String, Object> application = new HashMap<>();
- application.put("key1", "application1");
- application.put("key2", "application2");
- application.put("key3", "application3");
- application.put("key4", "application4");
- Map<String, Object> service = new HashMap<>();
- service.put("key1", "service1");
- service.put("key2", "service2");
- service.put("key3", "service3");
- Map<String, Object> version = new HashMap<>();
- version.put("key1", "version1");
- version.put("key2", "version1");
- Map<String, Object> tag = new HashMap<>();
- tag.put("key1", "tag1");
-
- Map<String, Map<String, Object>> items = new LinkedHashMap<String, Map<String, Object>>();
- items.put("application", application);
- items.put("service@app", service);
- items.put("service@app#version", version);
- items.put("service@app#version!tag", tag);
-
- Map<String, Object> result = null;
- try {
- result = Deencapsulation.invoke(pc, "mergeDimensionItems", items);
- } catch (Exception e) {
- status = false;
- }
- Assert.assertTrue(status);
- Assert.assertEquals(application.get("key4"), result.get("key4"));
- Assert.assertEquals(service.get("key3"), result.get("key3"));
- Assert.assertEquals(version.get("key2"), result.get("key2"));
- Assert.assertEquals(tag.get("key1"), result.get("key1"));
- }
-}
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestURIConst.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestURIConst.java
deleted file mode 100644
index 8877624..0000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestURIConst.java
+++ /dev/null
@@ -1,60 +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.servicecomb.config.client;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import mockit.Expectations;
-import mockit.Mocked;
-
-public class TestURIConst {
- @Test
- public void testURI_v2(final @Mocked ConfigCenterConfig config) {
- new Expectations() {
- {
- config.getDomainName();
- result = "mytenant";
- config.getApiVersion();
- result = "v2";
- }
- };
-
- URIConst uriConst = new URIConst();
- Assert.assertEquals("/members", uriConst.MEMBERS);
- Assert.assertEquals("/configuration/v2/refresh/items", uriConst.REFRESH_ITEMS);
- Assert.assertEquals("/configuration/v2/items", uriConst.ITEMS);
- }
-
- @Test
- public void testURI_v3(final @Mocked ConfigCenterConfig config) {
- new Expectations() {
- {
- config.getDomainName();
- result = "mytenant";
- config.getApiVersion();
- result = "v3";
- }
- };
-
- URIConst uriConst = new URIConst();
- Assert.assertEquals("/v3/mytenant/configuration/members", uriConst.MEMBERS);
- Assert.assertEquals("/v3/mytenant/configuration/refresh/items", uriConst.REFRESH_ITEMS);
- Assert.assertEquals("/v3/mytenant/configuration/items", uriConst.ITEMS);
- }
-}
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvder.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java
similarity index 98%
rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvder.java
rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java
index 486cade..597c31f 100644
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvder.java
+++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java
@@ -26,7 +26,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-public class TestConfigCenterDefaultDeploymentProvder {
+public class TestConfigCenterDefaultDeploymentProvider {
@Before
public void start() {
ArchaiusUtils.resetConfig();