Merge pull request #582 from FrankBian/feature/read-config
Clean the code in config module
This commit is contained in:
commit
f2cb9ce698
@ -33,6 +33,7 @@ import java.util.Properties;
|
|||||||
public abstract class PropertiesListener extends AbstractListener {
|
public abstract class PropertiesListener extends AbstractListener {
|
||||||
final static public Logger log = LogUtils.logger(PropertiesListener.class);
|
final static public Logger log = LogUtils.logger(PropertiesListener.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
public void receiveConfigInfo(String configInfo) {
|
public void receiveConfigInfo(String configInfo) {
|
||||||
if (StringUtils.isEmpty(configInfo)) {
|
if (StringUtils.isEmpty(configInfo)) {
|
||||||
return;
|
return;
|
||||||
|
@ -252,7 +252,7 @@ public class ConfigController {
|
|||||||
inner.doPollingConfig(request, response, clientMd5Map, probeModify.length());
|
inner.doPollingConfig(request, response, clientMd5Map, probeModify.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* 订阅改配置的客户端信息
|
* 订阅改配置的客户端信息
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/listener", method = RequestMethod.GET)
|
@RequestMapping(value = "/listener", method = RequestMethod.GET)
|
||||||
|
@ -64,17 +64,17 @@ public class HealthController {
|
|||||||
} else if (dbStatus.contains(heathWarnStr) && ServerListService.isAddressServerHealth() && ServerListService
|
} else if (dbStatus.contains(heathWarnStr) && ServerListService.isAddressServerHealth() && ServerListService
|
||||||
.isInIpList()) {
|
.isInIpList()) {
|
||||||
sb.append("WARN:");
|
sb.append("WARN:");
|
||||||
sb.append("从数据库 ").append(dbStatus.split(":")[1]).append(" down. ");
|
sb.append("slave db (").append(dbStatus.split(":")[1]).append(") down. ");
|
||||||
} else {
|
} else {
|
||||||
sb.append("DOWN:");
|
sb.append("DOWN:");
|
||||||
if (dbStatus.contains(heathDownStr)) {
|
if (dbStatus.contains(heathDownStr)) {
|
||||||
sb.append("主数据库 ").append(dbStatus.split(":")[1]).append(" down. ");
|
sb.append("master db (").append(dbStatus.split(":")[1]).append(") down. ");
|
||||||
}
|
}
|
||||||
if (!ServerListService.isAddressServerHealth()) {
|
if (!ServerListService.isAddressServerHealth()) {
|
||||||
sb.append("地址服务器 down. ");
|
sb.append("address server down. ");
|
||||||
}
|
}
|
||||||
if (!ServerListService.isInIpList()) {
|
if (!ServerListService.isInIpList()) {
|
||||||
sb.append("server ").append(LOCAL_IP).append(" 不在地址服务器的IP列表中. ");
|
sb.append("server ip ").append(LOCAL_IP).append(" is not in the serverList of address server. ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class ListenerController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
public ListenerController(ConfigSubService configSubService) {this.configSubService = configSubService;}
|
public ListenerController(ConfigSubService configSubService) {this.configSubService = configSubService;}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* 获取客户端订阅配置信息
|
* 获取客户端订阅配置信息
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.GET)
|
@RequestMapping(method = RequestMethod.GET)
|
||||||
|
@ -15,9 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.nacos.config.server.controller;
|
package com.alibaba.nacos.config.server.controller;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.alibaba.nacos.config.server.constant.Constants;
|
import com.alibaba.nacos.config.server.constant.Constants;
|
||||||
import com.alibaba.nacos.config.server.service.PersistService;
|
import com.alibaba.nacos.config.server.service.PersistService;
|
||||||
import com.alibaba.nacos.config.server.service.dump.DumpService;
|
import com.alibaba.nacos.config.server.service.dump.DumpService;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -26,9 +30,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理控制器。
|
* 管理控制器。
|
||||||
*
|
*
|
||||||
@ -50,7 +51,9 @@ public class OpsController {
|
|||||||
this.dumpService = dumpService;
|
this.dumpService = dumpService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ops call
|
/**
|
||||||
|
* ops call
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/localCache", method = RequestMethod.POST)
|
@RequestMapping(value = "/localCache", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String updateLocalCacheFromStore(HttpServletRequest request, HttpServletResponse respons) {
|
public String updateLocalCacheFromStore(HttpServletRequest request, HttpServletResponse respons) {
|
||||||
|
@ -28,6 +28,6 @@ public interface TaskManagerMBean {
|
|||||||
*
|
*
|
||||||
* @return info
|
* @return info
|
||||||
*/
|
*/
|
||||||
public String getTaskInfos();
|
String getTaskInfos();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.nacos.config.server.service;
|
package com.alibaba.nacos.config.server.service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
@ -28,15 +39,6 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||||
import static com.alibaba.nacos.config.server.service.PersistService.CONFIG_INFO4BETA_ROW_MAPPER;
|
import static com.alibaba.nacos.config.server.service.PersistService.CONFIG_INFO4BETA_ROW_MAPPER;
|
||||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||||
@ -51,9 +53,6 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
|||||||
public class BasicDataSourceServiceImpl implements DataSourceService {
|
public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||||
private static final String JDBC_DRIVER_NAME = "com.mysql.jdbc.Driver";
|
private static final String JDBC_DRIVER_NAME = "com.mysql.jdbc.Driver";
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PropertyUtil propertyUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDBC执行超时时间, 单位秒
|
* JDBC执行超时时间, 单位秒
|
||||||
*/
|
*/
|
||||||
@ -109,7 +108,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
* 事务的超时时间需要与普通操作区分开
|
* 事务的超时时间需要与普通操作区分开
|
||||||
*/
|
*/
|
||||||
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
|
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
|
||||||
if (!STANDALONE_MODE || propertyUtil.isStandaloneUseMysql()) {
|
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||||
try {
|
try {
|
||||||
reload();
|
reload();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -124,6 +123,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public synchronized void reload() throws IOException {
|
public synchronized void reload() throws IOException {
|
||||||
List<BasicDataSource> dblist = new ArrayList<BasicDataSource>();
|
List<BasicDataSource> dblist = new ArrayList<BasicDataSource>();
|
||||||
try {
|
try {
|
||||||
@ -201,6 +201,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean checkMasterWritable() {
|
public boolean checkMasterWritable() {
|
||||||
|
|
||||||
testMasterWritableJT.setDataSource(jt.getDataSource());
|
testMasterWritableJT.setDataSource(jt.getDataSource());
|
||||||
@ -224,14 +225,17 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public JdbcTemplate getJdbcTemplate() {
|
public JdbcTemplate getJdbcTemplate() {
|
||||||
return this.jt;
|
return this.jt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public TransactionTemplate getTransactionTemplate() {
|
public TransactionTemplate getTransactionTemplate() {
|
||||||
return this.tjt;
|
return this.tjt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getCurrentDBUrl() {
|
public String getCurrentDBUrl() {
|
||||||
DataSource ds = this.jt.getDataSource();
|
DataSource ds = this.jt.getDataSource();
|
||||||
if (ds == null) {
|
if (ds == null) {
|
||||||
@ -241,6 +245,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
return bds.getUrl();
|
return bds.getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getHealth() {
|
public String getHealth() {
|
||||||
for (int i = 0; i < isHealthList.size(); i++) {
|
for (int i = 0; i < isHealthList.size(); i++) {
|
||||||
if (!isHealthList.get(i)) {
|
if (!isHealthList.get(i)) {
|
||||||
@ -276,6 +281,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SelectMasterTask implements Runnable {
|
class SelectMasterTask implements Runnable {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
defaultLog.info("check master db.");
|
defaultLog.info("check master db.");
|
||||||
boolean isFound = false;
|
boolean isFound = false;
|
||||||
@ -309,6 +315,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
|||||||
|
|
||||||
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
|
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
|
||||||
class CheckDBHealthTask implements Runnable {
|
class CheckDBHealthTask implements Runnable {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
defaultLog.info("check db health.");
|
defaultLog.info("check db health.");
|
||||||
String sql = "SELECT * FROM config_info_beta WHERE id = 1";
|
String sql = "SELECT * FROM config_info_beta WHERE id = 1";
|
||||||
|
Loading…
Reference in New Issue
Block a user