Commit cf518256 by Nepxion

重构类结构

parent 01f5e28b
...@@ -12,5 +12,6 @@ package com.nepxion.discovery.common.apollo.constant; ...@@ -12,5 +12,6 @@ package com.nepxion.discovery.common.apollo.constant;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
public class ApolloConstant implements ConfigConsts { public class ApolloConstant implements ConfigConsts {
public static final String TYPE = "Apollo";
public static final String NAMESPACE = "apollo.discovery.namespace"; public static final String NAMESPACE = "apollo.discovery.namespace";
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ package com.nepxion.discovery.common.nacos.constant; ...@@ -12,6 +12,7 @@ package com.nepxion.discovery.common.nacos.constant;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
public class NacosConstant extends PropertyKeyConst { public class NacosConstant extends PropertyKeyConst {
public static final String TYPE = "Nacos";
public static final String URL = "nacos.url"; public static final String URL = "nacos.url";
public static final String NAMESPACE = "nacos.discovery.namespace"; public static final String NAMESPACE = "nacos.discovery.namespace";
public static final String TIMEOUT = "nacos.discovery.timout"; public static final String TIMEOUT = "nacos.discovery.timout";
......
package com.nepxion.discovery.common.redis.constant;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
public class RedisConstant {
public static final String TYPE = "Redis";
}
\ No newline at end of file
...@@ -47,4 +47,5 @@ public class DiscoveryConstant { ...@@ -47,4 +47,5 @@ public class DiscoveryConstant {
public static final String PARTIAL = "partial"; public static final String PARTIAL = "partial";
public static final String OK = "OK"; public static final String OK = "OK";
public static final String NO = "NO"; public static final String NO = "NO";
public static final String UNKNOWN = "UNKNOWN";
} }
\ No newline at end of file
package com.nepxion.discovery.common.nacos.thread; package com.nepxion.discovery.common.thread;
/** /**
* <p>Title: Nepxion Discovery</p> * <p>Title: Nepxion Discovery</p>
......
...@@ -13,6 +13,7 @@ import java.awt.Dimension; ...@@ -13,6 +13,7 @@ import java.awt.Dimension;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import com.nepxion.discovery.console.desktop.controller.ServiceController;
import com.nepxion.discovery.console.desktop.icon.ConsoleIconFactory; import com.nepxion.discovery.console.desktop.icon.ConsoleIconFactory;
import com.nepxion.discovery.console.desktop.locale.ConsoleLocale; import com.nepxion.discovery.console.desktop.locale.ConsoleLocale;
import com.nepxion.swing.frame.JBasicFrame; import com.nepxion.swing.frame.JBasicFrame;
...@@ -24,7 +25,7 @@ public class ConsoleFrame extends JBasicFrame { ...@@ -24,7 +25,7 @@ public class ConsoleFrame extends JBasicFrame {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public ConsoleFrame() { public ConsoleFrame() {
super(ConsoleLocale.getString("title"), ConsoleIconFactory.getSwingIcon("ribbon/navigator_nepxion.png"), new Dimension(1280, 900)); super(ConsoleLocale.getString("title") + " [" + ServiceController.getConfigType() + " " + ConsoleLocale.getString("config_center") + "]", ConsoleIconFactory.getSwingIcon("ribbon/navigator_nepxion.png"), new Dimension(1280, 900));
} }
public void launch() { public void launch() {
...@@ -42,7 +43,6 @@ public class ConsoleFrame extends JBasicFrame { ...@@ -42,7 +43,6 @@ public class ConsoleFrame extends JBasicFrame {
} }
}); });
setTitle(ConsoleLocale.getString("title"));
setExtendedState(ConsoleFrame.MAXIMIZED_BOTH); setExtendedState(ConsoleFrame.MAXIMIZED_BOTH);
setVisible(true); setVisible(true);
toFront(); toFront();
......
...@@ -36,6 +36,14 @@ public class ServiceController { ...@@ -36,6 +36,14 @@ public class ServiceController {
restTemplate.setErrorHandler(new RestErrorHandler()); restTemplate.setErrorHandler(new RestErrorHandler());
} }
public static String getConfigType() {
String url = getUrl() + "console/config-type";
String result = restTemplate.getForEntity(url, String.class).getBody();
return result;
}
public static Map<String, List<Instance>> getInstanceMap() { public static Map<String, List<Instance>> getInstanceMap() {
String url = getUrl() + "console/instance-map"; String url = getUrl() + "console/instance-map";
......
title=Discovery灰度发布控制台 title=Discovery 灰度发布控制台
navigator_bar=导航区 navigator_bar=导航区
content_bar=工作区 content_bar=工作区
...@@ -13,6 +13,7 @@ push_global_config=全链路灰度发布 ...@@ -13,6 +13,7 @@ push_global_config=全链路灰度发布
push_control_mode=推送模式设置 push_control_mode=推送模式设置
push_async_mode=异步推送 push_async_mode=异步推送
push_sync_mode=同步推送 push_sync_mode=同步推送
config_center=远程配置中心
rule_to_config_center=规则推送到远程配置中心 rule_to_config_center=规则推送到远程配置中心
rule_to_service=规则推送到服务或者服务集群 rule_to_service=规则推送到服务或者服务集群
......
title=Discovery\u7070\u5ea6\u53d1\u5e03\u63a7\u5236\u53f0 title=Discovery \u7070\u5ea6\u53d1\u5e03\u63a7\u5236\u53f0
navigator_bar=\u5bfc\u822a\u533a navigator_bar=\u5bfc\u822a\u533a
content_bar=\u5de5\u4f5c\u533a content_bar=\u5de5\u4f5c\u533a
...@@ -13,6 +13,7 @@ push_global_config=\u5168\u94fe\u8def\u7070\u5ea6\u53d1\u5e03 ...@@ -13,6 +13,7 @@ push_global_config=\u5168\u94fe\u8def\u7070\u5ea6\u53d1\u5e03
push_control_mode=\u63a8\u9001\u6a21\u5f0f\u8bbe\u7f6e push_control_mode=\u63a8\u9001\u6a21\u5f0f\u8bbe\u7f6e
push_async_mode=\u5f02\u6b65\u63a8\u9001 push_async_mode=\u5f02\u6b65\u63a8\u9001
push_sync_mode=\u540c\u6b65\u63a8\u9001 push_sync_mode=\u540c\u6b65\u63a8\u9001
config_center=\u8fdc\u7a0b\u914d\u7f6e\u4e2d\u5fc3
rule_to_config_center=\u89c4\u5219\u63a8\u9001\u5230\u8fdc\u7a0b\u914d\u7f6e\u4e2d\u5fc3 rule_to_config_center=\u89c4\u5219\u63a8\u9001\u5230\u8fdc\u7a0b\u914d\u7f6e\u4e2d\u5fc3
rule_to_service=\u89c4\u5219\u63a8\u9001\u5230\u670d\u52a1\u6216\u8005\u670d\u52a1\u96c6\u7fa4 rule_to_service=\u89c4\u5219\u63a8\u9001\u5230\u670d\u52a1\u6216\u8005\u670d\u52a1\u96c6\u7fa4
......
...@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.nacos.adapter; ...@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.nacos.adapter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.common.nacos.constant.NacosConstant;
import com.nepxion.discovery.common.nacos.operation.NacosOperation; import com.nepxion.discovery.common.nacos.operation.NacosOperation;
import com.nepxion.discovery.console.adapter.ConfigAdapter; import com.nepxion.discovery.console.adapter.ConfigAdapter;
...@@ -32,4 +33,9 @@ public class NacosConfigAdapter implements ConfigAdapter { ...@@ -32,4 +33,9 @@ public class NacosConfigAdapter implements ConfigAdapter {
public String getConfig(String group, String serviceId) throws Exception { public String getConfig(String group, String serviceId) throws Exception {
return nacosOperation.getConfig(group, serviceId); return nacosOperation.getConfig(group, serviceId);
} }
@Override
public String getConfigType() {
return NacosConstant.TYPE;
}
} }
\ No newline at end of file
...@@ -12,13 +12,25 @@ package com.nepxion.discovery.console.nacos.configuration; ...@@ -12,13 +12,25 @@ package com.nepxion.discovery.console.nacos.configuration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.nepxion.discovery.console.adapter.ConfigAdapter; import com.nepxion.discovery.common.nacos.constant.NacosConstant;
import com.nepxion.discovery.console.nacos.adapter.NacosConfigAdapter; import com.nepxion.discovery.console.nacos.adapter.NacosConfigAdapter;
@Configuration @Configuration
public class NacosConfigAutoConfiguration { public class NacosConfigAutoConfiguration {
static {
System.out.println("");
System.out.println("╔═╗ ╔╗");
System.out.println("║║╚╗║║");
System.out.println("║╔╗╚╝╠══╦══╦══╦══╗");
System.out.println("║║╚╗║║╔╗║╔═╣╔╗║══╣");
System.out.println("║║ ║║║╔╗║╚═╣╚╝╠══║");
System.out.println("╚╝ ╚═╩╝╚╩══╩══╩══╝");
System.out.println(NacosConstant.TYPE + " Config");
System.out.println("");
}
@Bean @Bean
public ConfigAdapter configAdapter() { public NacosConfigAdapter configAdapter() {
return new NacosConfigAdapter(); return new NacosConfigAdapter();
} }
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.redis.adapter; ...@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.redis.adapter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.common.redis.constant.RedisConstant;
import com.nepxion.discovery.common.redis.operation.RedisOperation; import com.nepxion.discovery.common.redis.operation.RedisOperation;
import com.nepxion.discovery.console.adapter.ConfigAdapter; import com.nepxion.discovery.console.adapter.ConfigAdapter;
...@@ -32,4 +33,9 @@ public class RedisConfigAdapter implements ConfigAdapter { ...@@ -32,4 +33,9 @@ public class RedisConfigAdapter implements ConfigAdapter {
public String getConfig(String group, String serviceId) throws Exception { public String getConfig(String group, String serviceId) throws Exception {
return redisOperation.getConfig(group, serviceId); return redisOperation.getConfig(group, serviceId);
} }
@Override
public String getConfigType() {
return RedisConstant.TYPE;
}
} }
\ No newline at end of file
...@@ -12,13 +12,25 @@ package com.nepxion.discovery.console.redis.configuration; ...@@ -12,13 +12,25 @@ package com.nepxion.discovery.console.redis.configuration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.nepxion.discovery.console.adapter.ConfigAdapter; import com.nepxion.discovery.common.redis.constant.RedisConstant;
import com.nepxion.discovery.console.redis.adapter.RedisConfigAdapter; import com.nepxion.discovery.console.redis.adapter.RedisConfigAdapter;
@Configuration @Configuration
public class RedisConfigAutoConfiguration { public class RedisConfigAutoConfiguration {
static {
System.out.println("");
System.out.println("╔═══╗ ╔╗");
System.out.println("║╔═╗║ ║║");
System.out.println("║╚═╝╠══╦═╝╠╦══╗");
System.out.println("║╔╗╔╣║═╣╔╗╠╣══╣");
System.out.println("║║║╚╣║═╣╚╝║╠══║");
System.out.println("╚╝╚═╩══╩══╩╩══╝");
System.out.println(RedisConstant.TYPE + " Config");
System.out.println("");
}
@Bean @Bean
public ConfigAdapter configAdapter() { public RedisConfigAdapter configAdapter() {
return new RedisConfigAdapter(); return new RedisConfigAdapter();
} }
} }
\ No newline at end of file
...@@ -15,4 +15,6 @@ public interface ConfigAdapter { ...@@ -15,4 +15,6 @@ public interface ConfigAdapter {
boolean clearConfig(String group, String serviceId) throws Exception; boolean clearConfig(String group, String serviceId) throws Exception;
String getConfig(String group, String serviceId) throws Exception; String getConfig(String group, String serviceId) throws Exception;
String getConfigType();
} }
\ No newline at end of file
...@@ -61,6 +61,14 @@ public class ConsoleEndpoint { ...@@ -61,6 +61,14 @@ public class ConsoleEndpoint {
@Autowired @Autowired
private RestTemplate consoleRestTemplate; private RestTemplate consoleRestTemplate;
@RequestMapping(path = "/config-type", method = RequestMethod.GET)
@ApiOperation(value = "获取配置中心类型", notes = "", response = String.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> configType() {
return getConfigType();
}
@RequestMapping(path = "/services", method = RequestMethod.GET) @RequestMapping(path = "/services", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的服务列表", notes = "", response = List.class, httpMethod = "GET") @ApiOperation(value = "获取服务注册中心的服务列表", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody @ResponseBody
...@@ -181,6 +189,18 @@ public class ConsoleEndpoint { ...@@ -181,6 +189,18 @@ public class ConsoleEndpoint {
return executeVersionClear(serviceId, version, false); return executeVersionClear(serviceId, version, false);
} }
private ResponseEntity<?> getConfigType() {
String configType = null;
if (configAdapter != null) {
configType = configAdapter.getConfigType();
} else {
configType = DiscoveryConstant.UNKNOWN;
}
return ResponseEntity.ok().body(configType);
}
public List<String> getServices() { public List<String> getServices() {
return discoveryClient.getServices(); return discoveryClient.getServices();
} }
......
...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; ...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.ctrip.framework.apollo.ConfigChangeListener; import com.ctrip.framework.apollo.ConfigChangeListener;
import com.nepxion.discovery.common.apollo.constant.ApolloConstant;
import com.nepxion.discovery.common.apollo.operation.ApolloOperation; import com.nepxion.discovery.common.apollo.operation.ApolloOperation;
import com.nepxion.discovery.common.apollo.operation.ApolloSubscribeCallback; import com.nepxion.discovery.common.apollo.operation.ApolloSubscribeCallback;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
...@@ -48,14 +49,14 @@ public class ApolloConfigAdapter extends ConfigAdapter { ...@@ -48,14 +49,14 @@ public class ApolloConfigAdapter extends ConfigAdapter {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
return config; return config;
} else { } else {
LOG.info("No partial config is retrieved from Apollo server"); LOG.info("No {} config is retrieved from {} server", getConfigScope(false), getConfigType());
} }
config = getConfig(true); config = getConfig(true);
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
return config; return config;
} else { } else {
LOG.info("No global config is retrieved from Apollo server"); LOG.info("No {} config is retrieved from {} server", getConfigScope(true), getConfigType());
} }
return null; return null;
...@@ -66,7 +67,7 @@ public class ApolloConfigAdapter extends ConfigAdapter { ...@@ -66,7 +67,7 @@ public class ApolloConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Get {} config from Apollo server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
return apolloOperation.getConfig(group, globalConfig ? group : serviceId); return apolloOperation.getConfig(group, globalConfig ? group : serviceId);
} }
...@@ -82,14 +83,14 @@ public class ApolloConfigAdapter extends ConfigAdapter { ...@@ -82,14 +83,14 @@ public class ApolloConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe {} config from Apollo server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Subscribe {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
try { try {
return apolloOperation.subscribeConfig(group, globalConfig ? group : serviceId, new ApolloSubscribeCallback() { return apolloOperation.subscribeConfig(group, globalConfig ? group : serviceId, new ApolloSubscribeCallback() {
@Override @Override
public void callback(String config) { public void callback(String config) {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
LOG.info("Get {} config updated event from Apollo server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config updated event from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule(); RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = null; String rule = null;
...@@ -99,17 +100,17 @@ public class ApolloConfigAdapter extends ConfigAdapter { ...@@ -99,17 +100,17 @@ public class ApolloConfigAdapter extends ConfigAdapter {
if (!StringUtils.equals(rule, config)) { if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true); fireRuleUpdated(new RuleUpdatedEvent(config), true);
} else { } else {
LOG.info("Retrieved {} config from Apollo server is same as current config, ignore to update, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Retrieved {} config from {} server is same as current config, ignore to update, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
} }
} else { } else {
LOG.info("Get {} config cleared event from Apollo server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config cleared event from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true); fireRuleCleared(new RuleClearedEvent(), true);
} }
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LOG.error("Subscribe " + getConfigType(globalConfig) + " config from Apollo server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId, e); LOG.error("Subscribe {} config from {} server failed, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId, e);
} }
return null; return null;
...@@ -130,12 +131,17 @@ public class ApolloConfigAdapter extends ConfigAdapter { ...@@ -130,12 +131,17 @@ public class ApolloConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Unsubscribe {} config from Apollo server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Unsubscribe {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
apolloOperation.unsubscribeConfig(group, globalConfig ? group : serviceId, configListener); apolloOperation.unsubscribeConfig(group, globalConfig ? group : serviceId, configListener);
} }
private String getConfigType(boolean globalConfig) { public String getConfigScope(boolean globalConfig) {
return globalConfig ? DiscoveryConstant.GLOBAL : DiscoveryConstant.PARTIAL; return globalConfig ? DiscoveryConstant.GLOBAL : DiscoveryConstant.PARTIAL;
} }
@Override
public String getConfigType() {
return ApolloConstant.TYPE;
}
} }
\ No newline at end of file
...@@ -12,13 +12,27 @@ package com.nepxion.discovery.plugin.configcenter.apollo.configuration; ...@@ -12,13 +12,27 @@ package com.nepxion.discovery.plugin.configcenter.apollo.configuration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter; import com.nepxion.discovery.common.apollo.constant.ApolloConstant;
import com.nepxion.discovery.plugin.configcenter.apollo.adapter.ApolloConfigAdapter; import com.nepxion.discovery.plugin.configcenter.apollo.adapter.ApolloConfigAdapter;
@Configuration @Configuration
public class ApolloConfigAutoConfiguration { public class ApolloConfigAutoConfiguration {
static {
System.out.println("");
System.out.println("╔═══╗ ╔╗╔╗");
System.out.println("║╔═╗║ ║║║║");
System.out.println("║║ ║╠══╦══╣║║║╔══╗");
System.out.println("║╚═╝║╔╗║╔╗║║║║║╔╗║");
System.out.println("║╔═╗║╚╝║╚╝║╚╣╚╣╚╝║");
System.out.println("╚╝ ╚╣╔═╩══╩═╩═╩══╝");
System.out.println(" ║║");
System.out.println(" ╚╝");
System.out.println(ApolloConstant.TYPE + " Config");
System.out.println("");
}
@Bean @Bean
public ConfigAdapter configAdapter() { public ApolloConfigAdapter configAdapter() {
return new ApolloConfigAdapter(); return new ApolloConfigAdapter();
} }
} }
\ No newline at end of file
...@@ -24,9 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,9 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.config.listener.Listener;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.entity.RuleEntity; import com.nepxion.discovery.common.entity.RuleEntity;
import com.nepxion.discovery.common.nacos.constant.NacosConstant;
import com.nepxion.discovery.common.nacos.operation.NacosOperation; import com.nepxion.discovery.common.nacos.operation.NacosOperation;
import com.nepxion.discovery.common.nacos.operation.NacosSubscribeCallback; import com.nepxion.discovery.common.nacos.operation.NacosSubscribeCallback;
import com.nepxion.discovery.common.nacos.thread.NamedThreadFactory; import com.nepxion.discovery.common.thread.NamedThreadFactory;
import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter; import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter; import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware; import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
...@@ -56,14 +57,14 @@ public class NacosConfigAdapter extends ConfigAdapter { ...@@ -56,14 +57,14 @@ public class NacosConfigAdapter extends ConfigAdapter {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
return config; return config;
} else { } else {
LOG.info("No partial config is retrieved from Nacos server"); LOG.info("No {} config is retrieved from {} server", getConfigScope(false), getConfigType());
} }
config = getConfig(true); config = getConfig(true);
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
return config; return config;
} else { } else {
LOG.info("No global config is retrieved from Nacos server"); LOG.info("No {} config is retrieved from {} server", getConfigScope(true), getConfigType());
} }
return null; return null;
...@@ -74,7 +75,7 @@ public class NacosConfigAdapter extends ConfigAdapter { ...@@ -74,7 +75,7 @@ public class NacosConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Get {} config from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
return nacosOperation.getConfig(group, globalConfig ? group : serviceId); return nacosOperation.getConfig(group, globalConfig ? group : serviceId);
} }
...@@ -90,14 +91,14 @@ public class NacosConfigAdapter extends ConfigAdapter { ...@@ -90,14 +91,14 @@ public class NacosConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe {} config from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Subscribe {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
try { try {
return nacosOperation.subscribeConfig(group, globalConfig ? group : serviceId, executorService, new NacosSubscribeCallback() { return nacosOperation.subscribeConfig(group, globalConfig ? group : serviceId, executorService, new NacosSubscribeCallback() {
@Override @Override
public void callback(String config) { public void callback(String config) {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
LOG.info("Get {} config updated event from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config updated event from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule(); RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = null; String rule = null;
...@@ -107,17 +108,17 @@ public class NacosConfigAdapter extends ConfigAdapter { ...@@ -107,17 +108,17 @@ public class NacosConfigAdapter extends ConfigAdapter {
if (!StringUtils.equals(rule, config)) { if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true); fireRuleUpdated(new RuleUpdatedEvent(config), true);
} else { } else {
LOG.info("Retrieved {} config from Nacos server is same as current config, ignore to update, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Retrieved {} config from {} server is same as current config, ignore to update, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
} }
} else { } else {
LOG.info("Get {} config cleared event from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config cleared event from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true); fireRuleCleared(new RuleClearedEvent(), true);
} }
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LOG.error("Subscribe " + getConfigType(globalConfig) + " config from Nacos server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId, e); LOG.error("Subscribe {} config from {} server failed, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId, e);
} }
return null; return null;
...@@ -140,12 +141,17 @@ public class NacosConfigAdapter extends ConfigAdapter { ...@@ -140,12 +141,17 @@ public class NacosConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Unsubscribe {} config from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Unsubscribe {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
nacosOperation.unsubscribeConfig(group, globalConfig ? group : serviceId, configListener); nacosOperation.unsubscribeConfig(group, globalConfig ? group : serviceId, configListener);
} }
private String getConfigType(boolean globalConfig) { public String getConfigScope(boolean globalConfig) {
return globalConfig ? DiscoveryConstant.GLOBAL : DiscoveryConstant.PARTIAL; return globalConfig ? DiscoveryConstant.GLOBAL : DiscoveryConstant.PARTIAL;
} }
@Override
public String getConfigType() {
return NacosConstant.TYPE;
}
} }
\ No newline at end of file
...@@ -12,13 +12,25 @@ package com.nepxion.discovery.plugin.configcenter.nacos.configuration; ...@@ -12,13 +12,25 @@ package com.nepxion.discovery.plugin.configcenter.nacos.configuration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter; import com.nepxion.discovery.common.nacos.constant.NacosConstant;
import com.nepxion.discovery.plugin.configcenter.nacos.adapter.NacosConfigAdapter; import com.nepxion.discovery.plugin.configcenter.nacos.adapter.NacosConfigAdapter;
@Configuration @Configuration
public class NacosConfigAutoConfiguration { public class NacosConfigAutoConfiguration {
static {
System.out.println("");
System.out.println("╔═╗ ╔╗");
System.out.println("║║╚╗║║");
System.out.println("║╔╗╚╝╠══╦══╦══╦══╗");
System.out.println("║║╚╗║║╔╗║╔═╣╔╗║══╣");
System.out.println("║║ ║║║╔╗║╚═╣╚╝╠══║");
System.out.println("╚╝ ╚═╩╝╚╩══╩══╩══╝");
System.out.println(NacosConstant.TYPE + " Config");
System.out.println("");
}
@Bean @Bean
public ConfigAdapter configAdapter() { public NacosConfigAdapter configAdapter() {
return new NacosConfigAdapter(); return new NacosConfigAdapter();
} }
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; ...@@ -19,6 +19,7 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.entity.RuleEntity; import com.nepxion.discovery.common.entity.RuleEntity;
import com.nepxion.discovery.common.redis.constant.RedisConstant;
import com.nepxion.discovery.common.redis.operation.RedisOperation; import com.nepxion.discovery.common.redis.operation.RedisOperation;
import com.nepxion.discovery.common.redis.operation.RedisSubscribeCallback; import com.nepxion.discovery.common.redis.operation.RedisSubscribeCallback;
import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter; import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter;
...@@ -54,14 +55,14 @@ public class RedisConfigAdapter extends ConfigAdapter { ...@@ -54,14 +55,14 @@ public class RedisConfigAdapter extends ConfigAdapter {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
return config; return config;
} else { } else {
LOG.info("No partial config is retrieved from Redis server"); LOG.info("No {} config is retrieved from {} server", getConfigScope(false), getConfigType());
} }
config = getConfig(true); config = getConfig(true);
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
return config; return config;
} else { } else {
LOG.info("No global config is retrieved from Redis server"); LOG.info("No {} config is retrieved from {} server", getConfigScope(true), getConfigType());
} }
return null; return null;
...@@ -72,7 +73,7 @@ public class RedisConfigAdapter extends ConfigAdapter { ...@@ -72,7 +73,7 @@ public class RedisConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Get {} config from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
return redisOperation.getConfig(group, globalConfig ? group : serviceId); return redisOperation.getConfig(group, globalConfig ? group : serviceId);
} }
...@@ -95,7 +96,7 @@ public class RedisConfigAdapter extends ConfigAdapter { ...@@ -95,7 +96,7 @@ public class RedisConfigAdapter extends ConfigAdapter {
@Override @Override
public void callback(String config) { public void callback(String config) {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
LOG.info("Get {} config updated event from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config updated event from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule(); RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = null; String rule = null;
...@@ -105,17 +106,17 @@ public class RedisConfigAdapter extends ConfigAdapter { ...@@ -105,17 +106,17 @@ public class RedisConfigAdapter extends ConfigAdapter {
if (!StringUtils.equals(rule, config)) { if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true); fireRuleUpdated(new RuleUpdatedEvent(config), true);
} else { } else {
LOG.info("Retrieved {} config from Redis server is same as current config, ignore to update, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Retrieved {} config from {} server is same as current config, ignore to update, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
} }
} else { } else {
LOG.info("Get {} config cleared event from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Get {} config cleared event from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true); fireRuleCleared(new RuleClearedEvent(), true);
} }
} }
}); });
} catch (Exception e) { } catch (Exception e) {
LOG.error("Subscribe " + getConfigType(globalConfig) + " config from Redis server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId, e); LOG.error("Subscribe {} config from {} server failed, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId, e);
} }
} }
...@@ -130,12 +131,17 @@ public class RedisConfigAdapter extends ConfigAdapter { ...@@ -130,12 +131,17 @@ public class RedisConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Unsubscribe {} config from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId); LOG.info("Unsubscribe {} config from {} server, {}={}, serviceId={}", getConfigScope(globalConfig), getConfigType(), groupKey, group, serviceId);
redisMessageListenerContainer.removeMessageListener(messageListenerAdapter, new PatternTopic(group + "-" + (globalConfig ? group : serviceId))); redisMessageListenerContainer.removeMessageListener(messageListenerAdapter, new PatternTopic(group + "-" + (globalConfig ? group : serviceId)));
} }
private String getConfigType(boolean globalConfig) { public String getConfigScope(boolean globalConfig) {
return globalConfig ? DiscoveryConstant.GLOBAL : DiscoveryConstant.PARTIAL; return globalConfig ? DiscoveryConstant.GLOBAL : DiscoveryConstant.PARTIAL;
} }
@Override
public String getConfigType() {
return RedisConstant.TYPE;
}
} }
\ No newline at end of file
...@@ -19,7 +19,7 @@ import org.springframework.data.redis.listener.PatternTopic; ...@@ -19,7 +19,7 @@ import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter; import com.nepxion.discovery.common.redis.constant.RedisConstant;
import com.nepxion.discovery.plugin.configcenter.redis.adapter.RedisConfigAdapter; import com.nepxion.discovery.plugin.configcenter.redis.adapter.RedisConfigAdapter;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter; import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware; import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
...@@ -28,6 +28,18 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware; ...@@ -28,6 +28,18 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
public class RedisConfigAutoConfiguration { public class RedisConfigAutoConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(RedisConfigAutoConfiguration.class); private static final Logger LOG = LoggerFactory.getLogger(RedisConfigAutoConfiguration.class);
static {
System.out.println("");
System.out.println("╔═══╗ ╔╗");
System.out.println("║╔═╗║ ║║");
System.out.println("║╚═╝╠══╦═╝╠╦══╗");
System.out.println("║╔╗╔╣║═╣╔╗╠╣══╣");
System.out.println("║║║╚╣║═╣╚╝║╠══║");
System.out.println("╚╝╚═╩══╩══╩╩══╝");
System.out.println(RedisConstant.TYPE + " Config");
System.out.println("");
}
@Autowired @Autowired
private RedisConnectionFactory redisConnectionFactory; private RedisConnectionFactory redisConnectionFactory;
...@@ -51,29 +63,29 @@ public class RedisConfigAutoConfiguration { ...@@ -51,29 +63,29 @@ public class RedisConfigAutoConfiguration {
} }
@Bean @Bean
public MessageListenerAdapter partialMessageListenerAdapter(ConfigAdapter configAdapter) { public MessageListenerAdapter partialMessageListenerAdapter(RedisConfigAdapter configAdapter) {
String groupKey = pluginContextAware.getGroupKey(); String groupKey = pluginContextAware.getGroupKey();
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe partial config from Redis server, {}={}, serviceId={}", groupKey, group, serviceId); LOG.info("Subscribe {} config from {} server, {}={}, serviceId={}", configAdapter.getConfigScope(false), configAdapter.getConfigType(), groupKey, group, serviceId);
return new MessageListenerAdapter(configAdapter, "subscribePartialConfig"); return new MessageListenerAdapter(configAdapter, "subscribePartialConfig");
} }
@Bean @Bean
public MessageListenerAdapter globalMessageListenerAdapter(ConfigAdapter configAdapter) { public MessageListenerAdapter globalMessageListenerAdapter(RedisConfigAdapter configAdapter) {
String groupKey = pluginContextAware.getGroupKey(); String groupKey = pluginContextAware.getGroupKey();
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe global config from Redis server, {}={}, serviceId={}", groupKey, group, serviceId); LOG.info("Subscribe {} config from {} server, {}={}, serviceId={}", configAdapter.getConfigScope(true), configAdapter.getConfigType(), groupKey, group, serviceId);
return new MessageListenerAdapter(configAdapter, "subscribeGlobalConfig"); return new MessageListenerAdapter(configAdapter, "subscribeGlobalConfig");
} }
@Bean @Bean
public ConfigAdapter configAdapter() { public RedisConfigAdapter configAdapter() {
return new RedisConfigAdapter(); return new RedisConfigAdapter();
} }
} }
\ No newline at end of file
...@@ -10,5 +10,7 @@ package com.nepxion.discovery.plugin.configcenter.loader; ...@@ -10,5 +10,7 @@ package com.nepxion.discovery.plugin.configcenter.loader;
*/ */
public abstract class RemoteConfigLoader implements ConfigLoader { public abstract class RemoteConfigLoader implements ConfigLoader {
public abstract String getConfigType();
public abstract void close(); public abstract void close();
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment