Skip to content

Commit

Permalink
Merge pull request alibaba#582 from FrankBian/feature/read-config
Browse files Browse the repository at this point in the history
Clean the code in config module
  • Loading branch information
hxy1991 authored Jan 8, 2019
2 parents 27ca776 + 4100189 commit f2cb9ce
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public abstract class PropertiesListener extends AbstractListener {
final static public Logger log = LogUtils.logger(PropertiesListener.class);

@Override
public void receiveConfigInfo(String configInfo) {
if (StringUtils.isEmpty(configInfo)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void listener(HttpServletRequest request, HttpServletResponse response)
inner.doPollingConfig(request, response, clientMd5Map, probeModify.length());
}

/*
/**
* 订阅改配置的客户端信息
*/
@RequestMapping(value = "/listener", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ public String getHealth() {
} else if (dbStatus.contains(heathWarnStr) && ServerListService.isAddressServerHealth() && ServerListService
.isInIpList()) {
sb.append("WARN:");
sb.append("从数据库 ").append(dbStatus.split(":")[1]).append(" down. ");
sb.append("slave db (").append(dbStatus.split(":")[1]).append(") down. ");
} else {
sb.append("DOWN:");
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()) {
sb.append("地址服务器 down. ");
sb.append("address server down. ");
}
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. ");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ListenerController {
@Autowired
public ListenerController(ConfigSubService configSubService) {this.configSubService = configSubService;}

/*
/**
* 获取客户端订阅配置信息
*/
@RequestMapping(method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
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.service.PersistService;
import com.alibaba.nacos.config.server.service.dump.DumpService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,9 +30,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* 管理控制器。
*
Expand All @@ -50,7 +51,9 @@ public OpsController(PersistService persistService, DumpService dumpService) {
this.dumpService = dumpService;
}

// ops call
/**
* ops call
*/
@RequestMapping(value = "/localCache", method = RequestMethod.POST)
@ResponseBody
public String updateLocalCacheFromStore(HttpServletRequest request, HttpServletResponse respons) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public interface TaskManagerMBean {
*
* @return info
*/
public String getTaskInfos();
String getTaskInfos();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@
*/
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 org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
Expand All @@ -28,15 +39,6 @@
import org.springframework.stereotype.Service;
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.config.server.service.PersistService.CONFIG_INFO4BETA_ROW_MAPPER;
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
Expand All @@ -51,9 +53,6 @@
public class BasicDataSourceServiceImpl implements DataSourceService {
private static final String JDBC_DRIVER_NAME = "com.mysql.jdbc.Driver";

@Autowired
private PropertyUtil propertyUtil;

/**
* JDBC执行超时时间, 单位秒
*/
Expand Down Expand Up @@ -109,7 +108,7 @@ public void init() {
* 事务的超时时间需要与普通操作区分开
*/
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
if (!STANDALONE_MODE || propertyUtil.isStandaloneUseMysql()) {
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
try {
reload();
} catch (IOException e) {
Expand All @@ -124,6 +123,7 @@ public void init() {
}
}

@Override
public synchronized void reload() throws IOException {
List<BasicDataSource> dblist = new ArrayList<BasicDataSource>();
try {
Expand Down Expand Up @@ -201,6 +201,7 @@ public synchronized void reload() throws IOException {
}
}

@Override
public boolean checkMasterWritable() {

testMasterWritableJT.setDataSource(jt.getDataSource());
Expand All @@ -224,14 +225,17 @@ public boolean checkMasterWritable() {

}

@Override
public JdbcTemplate getJdbcTemplate() {
return this.jt;
}

@Override
public TransactionTemplate getTransactionTemplate() {
return this.tjt;
}

@Override
public String getCurrentDBUrl() {
DataSource ds = this.jt.getDataSource();
if (ds == null) {
Expand All @@ -241,6 +245,7 @@ public String getCurrentDBUrl() {
return bds.getUrl();
}

@Override
public String getHealth() {
for (int i = 0; i < isHealthList.size(); i++) {
if (!isHealthList.get(i)) {
Expand Down Expand Up @@ -276,6 +281,7 @@ static String defaultIfNull(String value, String defaultValue) {
}

class SelectMasterTask implements Runnable {
@Override
public void run() {
defaultLog.info("check master db.");
boolean isFound = false;
Expand Down Expand Up @@ -309,6 +315,7 @@ public void run() {

@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
class CheckDBHealthTask implements Runnable {
@Override
public void run() {
defaultLog.info("check db health.");
String sql = "SELECT * FROM config_info_beta WHERE id = 1";
Expand Down

0 comments on commit f2cb9ce

Please sign in to comment.