Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1359

Merged
merged 165 commits into from
Jun 12, 2019
Merged

Develop #1359

Changes from 14 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
ce0b863
fixes #827
SLKun Apr 4, 2019
1a41ab6
fix-1036 :获取真正的GroupName,并设置.替代默认值
paulzhangcc Apr 15, 2019
96e8e14
Merge pull request #1067 from paulzhangcc/feature-fix-1036
Apr 16, 2019
da2f4a1
Add unit tests for com.alibaba.nacos.client.utils.StringUtils
EricHetti Apr 18, 2019
f002675
add cmdb testcases
alios-studio Apr 18, 2019
808ddae
add ignore flag
alios-studio Apr 19, 2019
2cb3878
to support registering instance with host name
Albert-Hugo Apr 19, 2019
fc6581d
feature: add yaml validator #1084
jameslcj Apr 19, 2019
55242c8
Merge pull request #996 from Summerslyb/fix-log4j2
hxy1991 Apr 19, 2019
e6f82a9
remove useless validate code
Albert-Hugo Apr 20, 2019
c896e37
Merge remote-tracking branch 'upstream/develop' into feature_host_nam…
Albert-Hugo Apr 20, 2019
b67956f
add only digit and dot char for ip validation
Albert-Hugo Apr 23, 2019
2f766c5
Merge pull request #1095 from alibaba/feature_naming_group
Apr 23, 2019
1cfd8a5
Merge pull request #1079 from Albert-Hugo/feature_host_name_ip
Apr 23, 2019
8ac94b6
NamingEvent add getGroupName and getClusters method
Albert-Hugo Apr 24, 2019
3ebff06
Merge branch 'develop' into feature-naming-event
Albert-Hugo Apr 24, 2019
35f3842
format code
Albert-Hugo Apr 26, 2019
6615ae8
[#359] Use SPI to make health scalable
XCXCXCXCX Apr 27, 2019
38f6508
add license
XCXCXCXCX Apr 27, 2019
ea214e1
feat(client): add feature of service curd
chuntaojun Apr 27, 2019
39b3820
refactor(client): delete unused file
chuntaojun Apr 27, 2019
5fec109
fix about licence position
XCXCXCXCX Apr 28, 2019
79c3fc6
Merge branch 'develop' of https://github.com/chuntaojun/nacos into fe…
chuntaojun Apr 28, 2019
c9a5134
fix: group form validation
loadchange Apr 28, 2019
fdcd379
Merge pull request #1101 from Albert-Hugo/feature-naming-event
nkorange Apr 28, 2019
0d436de
fix something
XCXCXCXCX Apr 29, 2019
22a2969
1. 修正服务和集群之间的关系(Correct the relationship between the service and clus…
jifengnan Apr 29, 2019
312b75b
Add licence info
jifengnan Apr 29, 2019
0ebc68c
Merge pull request #1159 from alibaba/hotfix_server_list_inconsistent
nkorange Apr 30, 2019
71d9cb3
历史配置文件保留天数,可配置
rushsky518 Apr 30, 2019
f2c046a
refactor(client): Service operation function module split
chuntaojun Apr 30, 2019
1b76780
refactor(naming): Modify the inheritance of NoneSelector class
chuntaojun Apr 30, 2019
320aca4
style(api): The revised code is in compliance with the specification
chuntaojun Apr 30, 2019
4fd773b
Rollback to use NamingUtils to grab service name and group name
jifengnan May 4, 2019
f8ec782
refactor(client): Delete Chinese comments
chuntaojun May 5, 2019
ef7e250
do not allow to add same type
XCXCXCXCX May 5, 2019
eef6e73
fix typo
ddatsh May 6, 2019
4817b26
refactor(client): Fix the issues raised in the comments
chuntaojun May 7, 2019
7ae757a
refactor(config): correct the mistake to Constants.HEALTH_CONTROLLER_…
chuntaojun May 7, 2019
8c82f85
refactor:
chuntaojun May 7, 2019
effb66c
梳理nacos集测ignore用例
alios-studio May 7, 2019
e9d10d8
Merge pull request #1181 from mingyixu/master
nkorange May 7, 2019
73ebb86
Merge pull request #1170 from ddatsh/master
nkorange May 7, 2019
8e29a34
Deleted the chinese comments
jifengnan May 7, 2019
968a69c
Merge pull request #1151 from jifengnan/develop
nkorange May 8, 2019
7568620
Merge pull request #1122 from Diffblue-benchmarks/add-diffblue-tests
nkorange May 8, 2019
6695805
Let nacos-server.jar import external jar package
XCXCXCXCX May 8, 2019
141f8a1
refactor(client):
chuntaojun May 8, 2019
af8e095
expose endpoint for front
XCXCXCXCX May 9, 2019
ac36a41
refactor(api、client): modify MaintainService to NamingMaintainService
chuntaojun May 9, 2019
33de06a
Fix #1062
May 9, 2019
a6ef86d
Merge pull request #1198 from nkorange/feature_filter_disabled_instances
May 9, 2019
221ce12
fix(api): fix NamingMaintainFactory create NamingMaintainService cann…
chuntaojun May 9, 2019
df6f3a8
Merge pull request #1130 from chuntaojun/feature_service_curd
May 9, 2019
c137994
fix pmd
XCXCXCXCX May 9, 2019
54e2afb
修复服务分组为非DEFAULT_GROUP,服务详情集群列表获取为DEFAULT_GROUP
justlive1 May 9, 2019
6dc3882
fix something
XCXCXCXCX May 10, 2019
f1fd3bb
Update DumpService.java
rushsky518 May 10, 2019
a3da313
Merge pull request #1161 from rushsky518/master
May 11, 2019
23454ff
fix something
XCXCXCXCX May 12, 2019
1f1b047
Merge pull request #1126 from XCXCXCXCX/ISSUE_#359
May 12, 2019
01b74be
refactor(client): delete useless test case
chuntaojun May 13, 2019
11304ff
Merge branch 'develop' of https://github.com/alibaba/nacos
justlive1 May 13, 2019
fd32726
build
justlive1 May 13, 2019
80dd3bd
Merge pull request #1212 from chuntaojun/develop
May 14, 2019
8639759
Merge pull request #1201 from justlive1/master
loadchange May 14, 2019
7c1afc3
fix: closes #1007
loadchange May 14, 2019
822e975
Update README.md
xuechaos Feb 22, 2019
26f2759
syncing upstream develop code
May 14, 2019
9aea3ff
windows 脚本支持 -m -f 参数
rushsky518 May 15, 2019
6a7a991
Merge branch 'master' of https://github.com/rushsky518/nacos
rushsky518 May 15, 2019
229262f
Update pom.xml
May 15, 2019
4c5c2a6
fix(test): fix NamingMaintainService_ITCase mistake
chuntaojun May 16, 2019
51ded2c
fix(fix NamingMaintainService_ITCase mistake):
chuntaojun May 16, 2019
f21db94
fix(test):
chuntaojun May 16, 2019
9ca6560
Merge pull request #1232 from chuntaojun/develop
May 16, 2019
2bb3387
Quick fixing for the cluster deserialization issue
jifengnan May 16, 2019
9ee2d11
Merge pull request #1233 from jifengnan/develop
May 17, 2019
5cab208
Merge pull request #1228 from sheiy/master
May 17, 2019
22310d0
Correct some unit test cases
jifengnan May 18, 2019
35e452e
Merge pull request #1225 from rushsky518/master
May 20, 2019
3148ba0
Fix #1007
nkorange May 20, 2019
bceba36
Merge pull request #1238 from jifengnan/develop
nkorange May 20, 2019
dd029a9
Merge pull request #1240 from nkorange/feature_enable_to_enabled
nkorange May 20, 2019
45f0177
Merge pull request #1221 from loadchange/issues-1007
nkorange May 20, 2019
b548389
issue#169 服务列表中增加示例代码查看功能
yongchao9 May 20, 2019
c15276c
[ISSUE #876] feature(console):support console show cluster node state
universefeeler May 22, 2019
67741c6
fix: #1260
pnboot May 24, 2019
e680f10
fix #676
jameslcj May 24, 2019
d5b5dbb
Merge branch 'develop' into hotfix_jackson_vulnerability
nkorange May 24, 2019
c10165f
Merge branch 'master' into master
dupengcheng May 25, 2019
ed1da58
Merge pull request #1268 from nkorange/hotfix_jackson_vulnerability
May 27, 2019
2561135
issue#169 服务列表中增加示例代码查看功能 提交编译后文件
yongchao9 May 28, 2019
1f9cda4
Merge remote-tracking branch 'upstream/develop' into hotfix_169
yongchao9 May 28, 2019
97ff458
feat(client): @NacosConfigurationProperties support yaml style config
chuntaojun May 29, 2019
3129238
Merge branch 'develop' of https://github.com/alibaba/nacos into develop
pbting May 30, 2019
554cfe3
Merge pull request #1264 from jameslcj/hotfix/676
jameslcj May 30, 2019
67d2673
Merge pull request #1 from alibaba/master
IanCao May 31, 2019
4fdca26
close stream safety
IanCao May 31, 2019
4b4c1b1
fix
IanCao May 31, 2019
c4be24a
nacos client namespace support multi enviroment switch
pbting May 31, 2019
9963ca5
change the version
pbting May 31, 2019
8acce1c
format code
IanCao May 31, 2019
40188f5
fix bug
IanCao May 31, 2019
5569e44
fix
IanCao May 31, 2019
dd8ee44
fix
IanCao May 31, 2019
37b880b
remove the distributionManagement
pbting May 31, 2019
fbc72f0
Close #1319
nkorange Jun 4, 2019
c97e216
Merge pull request #1320 from nkorange/feature_search_with_keyword_an…
nkorange Jun 4, 2019
302ae79
1. 注释改成中文
pbting Jun 4, 2019
f2c0610
Merge pull request #1309 from IanCao/fixbug2
nkorange Jun 4, 2019
403e9b8
Merge pull request #1303 from IanCao/master
nkorange Jun 4, 2019
9d57976
change the comment from Chinese to English
pbting Jun 4, 2019
3174aae
Merge pull request #1290 from chuntaojun/develop
nkorange Jun 4, 2019
3b869fc
change the comment from Chinese to English
pbting Jun 4, 2019
67ec4a4
Merge pull request #1262 from dupengcheng/master
nkorange Jun 4, 2019
138a15d
Remove useless test
nkorange Jun 4, 2019
9319b76
Merge pull request #1307 from pbting/namespace_unified
nkorange Jun 4, 2019
ef8e1aa
Merge remote-tracking branch 'upstream/develop'
universefeeler Jun 4, 2019
7a593ff
Fix bug
nkorange Jun 5, 2019
3a1869b
Fix #1215
nkorange Jun 5, 2019
911985e
Merge remote-tracking branch 'upstream/develop'
universefeeler Jun 5, 2019
82961fe
feat:
chuntaojun Jun 5, 2019
d0afee0
Merge remote-tracking branch 'upstream/develop'
universefeeler Jun 5, 2019
c33b651
Merge branch 'master' of https://github.com/universefeeler/nacos
universefeeler Jun 5, 2019
4fe09db
fixed(naming): add licensed for ClusterStateView.java
universefeeler Jun 5, 2019
d6d5ddf
Merge pull request #1328 from nkorange/feature_heartbeat_log_level_debug
nkorange Jun 5, 2019
6521aa3
Fix #1334
nkorange Jun 5, 2019
78a4f0c
Merge pull request #1335 from nkorange/hotfix_update_health_status_fa…
nkorange Jun 5, 2019
3c971e9
issue#169 服务列表中增加java示例代码查看功能 提交编译后文件
yongchao9 Jun 5, 2019
c1ac93a
同步远程develop分支
yongchao9 Jun 5, 2019
0a58348
Merge remote-tracking branch 'upstream/develop' into hotfix_169
yongchao9 Jun 5, 2019
a9a809b
清楚log文件
yongchao9 Jun 5, 2019
72a3a9b
feat:
chuntaojun Jun 5, 2019
224bc9c
删除log文件
yongchao9 Jun 6, 2019
320a496
同步develop分支pom配置
yongchao9 Jun 6, 2019
1f102f5
feat:
chuntaojun Jun 6, 2019
5623577
refactor(nacos-client): 修改config的LongPoll轮询的机制
chuntaojun Jun 6, 2019
d08557a
chore(clusterNode): adjust some code
universefeeler Jun 6, 2019
748070c
#169 示例代码中的服务名与点击记录进行联动
yongchao9 Jun 7, 2019
be213f5
test(nacos-client): add ConfigLongPollTest
chuntaojun Jun 7, 2019
92ff0a0
fix(remove ConfigLongPollTest):
chuntaojun Jun 7, 2019
456e847
refactor(nacos-client:config): Rewrite the HTTP retry rule
chuntaojun Jun 7, 2019
ecc0154
refactor(nacos-client): 修改与本pr无关的注释信息
chuntaojun Jun 7, 2019
d43e079
test(nacos-test:config): add ConfigLongPoll_ITCase
chuntaojun Jun 7, 2019
0bb8589
Merge pull request #1245 from yongchao9/hotfix_169
nkorange Jun 8, 2019
b989e50
format code
IanCao Jun 10, 2019
8502235
format code
IanCao Jun 10, 2019
5d9ae15
chore(console): adjust console show details
universefeeler Jun 10, 2019
1566cdc
formant code
IanCao Jun 10, 2019
eee5b34
format code
IanCao Jun 10, 2019
574a47c
remove useless code
IanCao Jun 10, 2019
555e323
Merge pull request #1258 from universefeeler/master
nkorange Jun 10, 2019
4ad21f2
Merge branch 'develop' into master
nkorange Jun 10, 2019
cdcbf10
resolve conflict #1084
jameslcj Jun 10, 2019
696312a
Merge pull request #1086 from jameslcj/feature/yaml
nkorange Jun 10, 2019
ddfbf20
Merge pull request #1345 from IanCao/master
nkorange Jun 10, 2019
0e653a9
refactor(nacos-client:config): Modify the long poll timeout parameter…
chuntaojun Jun 11, 2019
dd9676c
fix(nacos-client): fix merge conflict
chuntaojun Jun 11, 2019
be3cb03
refactor(nacos-client:config): remove un use constructor
chuntaojun Jun 11, 2019
aa41a10
fix(nacos-client:config): Fix failed custom parameter setting error
chuntaojun Jun 11, 2019
edf3f66
Merge pull request #1341 from chuntaojun/fix_issue_1214
TsingLiang Jun 11, 2019
a7f3cab
Update version to 1.0.1-SNAPSHOT
nkorange Jun 11, 2019
0b0d0c4
Optimize code
nkorange Jun 12, 2019
a60bed8
Update version to 1.0.1
nkorange Jun 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
@@ -46,6 +46,12 @@ public class PropertyKeyConst {

public final static String ENCODE = "encode";

public final static String CONFIG_LONG_POLL_TIMEOUT = "config.long-poll.timeout";

public final static String CONFIG_RETRY_TIME = "config.retry.time";

public final static String MAX_RETRY = "maxRetry";

public final static String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";

public final static String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
20 changes: 20 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
@@ -88,6 +88,26 @@ public class Constants {
*/
public static final int SO_TIMEOUT = 60000;

/**
* millisecond
*/
public static final int CONFIG_LONG_POLL_TIMEOUT = 30000;

/**
* millisecond
*/
public static final int MIN_CONFIG_LONG_POLL_TIMEOUT = 10000;

/**
* millisecond
*/
public static final int CONFIG_RETRY_TIME = 2000;

/**
* Maximum number of retries
*/
public static final int MAX_RETRY = 3;

/**
* millisecond
*/
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ public NacosConfigService(Properties properties) throws NacosException {
initNamespace(properties);
agent = new MetricsHttpAgent(new ServerHttpAgent(properties));
agent.start();
worker = new ClientWorker(agent, configFilterChainManager);
worker = new ClientWorker(agent, configFilterChainManager, properties);
}

private void initNamespace(Properties properties) {
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import com.alibaba.nacos.client.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import java.io.IOException;
import java.net.ConnectException;
@@ -67,33 +68,47 @@ public HttpResult httpGet(String path, List<String> headers, List<String> paramV
final long endTime = System.currentTimeMillis() + readTimeoutMs;
final boolean isSSL = false;

String currentServerAddr = serverListMgr.getCurrentServerAddr();
int maxRetry = this.maxRetry;

do {
try {
List<String> newHeaders = getSpasHeaders(paramValues);
if (headers != null) {
newHeaders.addAll(headers);
}
HttpResult result = HttpSimpleClient.httpGet(
getUrl(serverListMgr.getCurrentServerAddr(), path, isSSL), newHeaders, paramValues, encoding,
getUrl(currentServerAddr, path, isSSL), newHeaders, paramValues, encoding,
readTimeoutMs, isSSL);
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY
|| result.code == HttpURLConnection.HTTP_UNAVAILABLE) {
LOGGER.error("[NACOS ConnectException] currentServerAddr: {}, httpCode: {}",
serverListMgr.getCurrentServerAddr(), result.code);
} else {
// Update the currently available server addr
serverListMgr.updateCurrentServerAddr(currentServerAddr);
return result;
}
} catch (ConnectException ce) {
LOGGER.error("[NACOS ConnectException] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
serverListMgr.refreshCurrentServerAddr();
LOGGER.error("[NACOS ConnectException httpGet] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
} catch (SocketTimeoutException stoe) {
LOGGER.error("[NACOS SocketTimeoutException] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
serverListMgr.refreshCurrentServerAddr();
LOGGER.error("[NACOS SocketTimeoutException httpGet] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
} catch (IOException ioe) {
LOGGER.error("[NACOS IOException] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
LOGGER.error("[NACOS IOException httpGet] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
throw ioe;
}

if (serverListMgr.getIterator().hasNext()) {
currentServerAddr = serverListMgr.getIterator().next();
} else {
maxRetry --;
if (maxRetry < 0) {
throw new ConnectException("[NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached");
}
serverListMgr.refreshCurrentServerAddr();
}

} while (System.currentTimeMillis() <= endTime);

LOGGER.error("no available server");
@@ -105,74 +120,104 @@ public HttpResult httpPost(String path, List<String> headers, List<String> param
long readTimeoutMs) throws IOException {
final long endTime = System.currentTimeMillis() + readTimeoutMs;
boolean isSSL = false;

String currentServerAddr = serverListMgr.getCurrentServerAddr();
int maxRetry = this.maxRetry;

do {

try {
List<String> newHeaders = getSpasHeaders(paramValues);
if (headers != null) {
newHeaders.addAll(headers);
}

HttpResult result = HttpSimpleClient.httpPost(
getUrl(serverListMgr.getCurrentServerAddr(), path, isSSL), newHeaders, paramValues, encoding,
getUrl(currentServerAddr, path, isSSL), newHeaders, paramValues, encoding,
readTimeoutMs, isSSL);
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY
|| result.code == HttpURLConnection.HTTP_UNAVAILABLE) {
LOGGER.error("[NACOS ConnectException] currentServerAddr: {}, httpCode: {}",
serverListMgr.getCurrentServerAddr(), result.code);
LOGGER.error("[NACOS ConnectException httpPost] currentServerAddr: {}, httpCode: {}",
currentServerAddr, result.code);
} else {
// Update the currently available server addr
serverListMgr.updateCurrentServerAddr(currentServerAddr);
return result;
}
} catch (ConnectException ce) {
LOGGER.error("[NACOS ConnectException] currentServerAddr: {}", serverListMgr.getCurrentServerAddr());
serverListMgr.refreshCurrentServerAddr();
LOGGER.error("[NACOS ConnectException httpPost] currentServerAddr: {}", currentServerAddr);
} catch (SocketTimeoutException stoe) {
LOGGER.error("[NACOS SocketTimeoutException]", "currentServerAddr: {}",
serverListMgr.getCurrentServerAddr());
serverListMgr.refreshCurrentServerAddr();
LOGGER.error("[NACOS SocketTimeoutException httpPost] currentServerAddr: {}, err : {}",
currentServerAddr, stoe.getMessage());
} catch (IOException ioe) {
LOGGER.error("[NACOS IOException] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
LOGGER.error("[NACOS IOException httpPost] currentServerAddr: " + currentServerAddr, ioe);
throw ioe;
}

if (serverListMgr.getIterator().hasNext()) {
currentServerAddr = serverListMgr.getIterator().next();
} else {
maxRetry --;
if (maxRetry < 0) {
throw new ConnectException("[NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reached");
}
serverListMgr.refreshCurrentServerAddr();
}

} while (System.currentTimeMillis() <= endTime);

LOGGER.error("no available server");
throw new ConnectException("no available server");
LOGGER.error("no available server, currentServerAddr : {}", currentServerAddr);
throw new ConnectException("no available server, currentServerAddr : " + currentServerAddr);
}

@Override
public HttpResult httpDelete(String path, List<String> headers, List<String> paramValues, String encoding,
long readTimeoutMs) throws IOException {
final long endTime = System.currentTimeMillis() + readTimeoutMs;
boolean isSSL = false;

String currentServerAddr = serverListMgr.getCurrentServerAddr();
int maxRetry = this.maxRetry;

do {
try {
List<String> newHeaders = getSpasHeaders(paramValues);
if (headers != null) {
newHeaders.addAll(headers);
}
HttpResult result = HttpSimpleClient.httpDelete(
getUrl(serverListMgr.getCurrentServerAddr(), path, isSSL), newHeaders, paramValues, encoding,
getUrl(currentServerAddr, path, isSSL), newHeaders, paramValues, encoding,
readTimeoutMs, isSSL);
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY
|| result.code == HttpURLConnection.HTTP_UNAVAILABLE) {
LOGGER.error("[NACOS ConnectException] currentServerAddr: {}, httpCode: {}",
serverListMgr.getCurrentServerAddr(), result.code);
} else {
// Update the currently available server addr
serverListMgr.updateCurrentServerAddr(currentServerAddr);
return result;
}
} catch (ConnectException ce) {
LOGGER.error("[NACOS ConnectException] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
serverListMgr.refreshCurrentServerAddr();
LOGGER.error("[NACOS ConnectException httpDelete] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
} catch (SocketTimeoutException stoe) {
LOGGER.error("[NACOS SocketTimeoutException] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
serverListMgr.refreshCurrentServerAddr();
LOGGER.error("[NACOS SocketTimeoutException httpDelete] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
} catch (IOException ioe) {
LOGGER.error("[NACOS IOException] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
LOGGER.error("[NACOS IOException httpDelete] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
throw ioe;
}

if (serverListMgr.getIterator().hasNext()) {
currentServerAddr = serverListMgr.getIterator().next();
} else {
maxRetry --;
if (maxRetry < 0) {
throw new ConnectException("[NACOS HTTP-DELETE] The maximum number of tolerable server reconnection errors has been reached");
}
serverListMgr.refreshCurrentServerAddr();
}

} while (System.currentTimeMillis() <= endTime);

LOGGER.error("no available server");
@@ -208,6 +253,7 @@ public ServerHttpAgent(Properties properties) throws NacosException {
private void init(Properties properties) {
initEncode(properties);
initAkSk(properties);
initMaxRetry(properties);
}

private void initEncode(Properties properties) {
@@ -240,6 +286,10 @@ private void initAkSk(Properties properties) {
}
}

private void initMaxRetry(Properties properties) {
maxRetry = NumberUtils.toInt(String.valueOf(properties.get(PropertyKeyConst.MAX_RETRY)), Constants.MAX_RETRY);
}

@Override
public synchronized void start() throws NacosException {
serverListMgr.start();
@@ -391,6 +441,7 @@ public String toString() {
private String accessKey;
private String secretKey;
private String encode;
private int maxRetry = 3;
private volatile STSCredential sTSCredential;
final ServerListManager serverListMgr;

Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.client.config.impl;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
@@ -28,15 +29,26 @@
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.client.utils.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import com.alibaba.nacos.client.utils.TenantUtil;
import org.slf4j.Logger;

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URLDecoder;
import java.util.*;
import java.util.concurrent.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static com.alibaba.nacos.api.common.Constants.LINE_SEPARATOR;
@@ -302,7 +314,7 @@ public void checkConfigInfo() {
/**
* 从Server获取值变化了的DataID列表。返回的对象里只有dataId和group是有效的。 保证不返回NULL。
*/
List<String> checkUpdateDataIds(List<CacheData> cacheDatas, List<String> inInitializingCacheList) {
List<String> checkUpdateDataIds(List<CacheData> cacheDatas, List<String> inInitializingCacheList) throws IOException {
StringBuilder sb = new StringBuilder();
for (CacheData cacheData : cacheDatas) {
if (!cacheData.isUseLocalConfigInfo()) {
@@ -328,10 +340,9 @@ List<String> checkUpdateDataIds(List<CacheData> cacheDatas, List<String> inIniti
/**
* 从Server获取值变化了的DataID列表。返回的对象里只有dataId和group是有效的。 保证不返回NULL。
*/
List<String> checkUpdateConfigStr(String probeUpdateString, boolean isInitializingCacheList) {
List<String> checkUpdateConfigStr(String probeUpdateString, boolean isInitializingCacheList) throws IOException {

List<String> params = Arrays.asList(Constants.PROBE_MODIFY_REQUEST, probeUpdateString);
long timeout = TimeUnit.SECONDS.toMillis(30L);

List<String> headers = new ArrayList<String>(2);
headers.add("Long-Pulling-Timeout");
@@ -361,6 +372,7 @@ List<String> checkUpdateConfigStr(String probeUpdateString, boolean isInitializi
} catch (IOException e) {
setHealthServer(false);
LOGGER.error("[" + agent.getName() + "] [check-update] get changed dataId exception", e);
throw e;
}
return Collections.emptyList();
}
@@ -403,10 +415,14 @@ private List<String> parseUpdateDataIdResponse(String response) {
}

@SuppressWarnings("PMD.ThreadPoolCreationRule")
public ClientWorker(final HttpAgent agent, final ConfigFilterChainManager configFilterChainManager) {
public ClientWorker(final HttpAgent agent, final ConfigFilterChainManager configFilterChainManager, final Properties properties) {
this.agent = agent;
this.configFilterChainManager = configFilterChainManager;

// Initialize the timeout parameter

init(properties);

executor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
@@ -417,17 +433,18 @@ public Thread newThread(Runnable r) {
}
});

executorService = Executors.newCachedThreadPool(new ThreadFactory() {
executorService = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("com.alibaba.nacos.client.Worker.longPolling" + agent.getName());
t.setName("com.alibaba.nacos.client.Worker.longPolling." + agent.getName());
t.setDaemon(true);
return t;
}
});

executor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
checkConfigInfo();
@@ -438,16 +455,27 @@ public void run() {
}, 1L, 10L, TimeUnit.MILLISECONDS);
}

private void init(Properties properties) {

timeout = Math.max(NumberUtils.toInt(String.valueOf(properties.get(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT)),
Constants.CONFIG_LONG_POLL_TIMEOUT), Constants.MIN_CONFIG_LONG_POLL_TIMEOUT);

taskPenaltyTime = NumberUtils.toInt(String.valueOf(properties.get(PropertyKeyConst.CONFIG_RETRY_TIME)), Constants.CONFIG_RETRY_TIME);
}

class LongPollingRunnable implements Runnable {
private int taskId;

public LongPollingRunnable(int taskId) {
this.taskId = taskId;
}

@Override
public void run() {

List<CacheData> cacheDatas = new ArrayList<CacheData>();
List<String> inInitializingCacheList = new ArrayList<String>();
try {
List<CacheData> cacheDatas = new ArrayList<CacheData>();
// check failover config
for (CacheData cacheData : cacheMap.get().values()) {
if (cacheData.getTaskId() == taskId) {
@@ -463,7 +491,6 @@ public void run() {
}
}

List<String> inInitializingCacheList = new ArrayList<String>();
// check server config
List<String> changedGroupKeys = checkUpdateDataIds(cacheDatas, inInitializingCacheList);

@@ -497,10 +524,14 @@ public void run() {
}
}
inInitializingCacheList.clear();
} catch (Throwable e) {
LOGGER.error("longPolling error", e);
} finally {

executorService.execute(this);

} catch (Throwable e) {

// If the rotation training task is abnormal, the next execution time of the task will be punished
LOGGER.error("longPolling error : ", e);
executorService.schedule(this, taskPenaltyTime, TimeUnit.MILLISECONDS);
}
}
}
@@ -513,8 +544,9 @@ private void setHealthServer(boolean isHealthServer) {
this.isHealthServer = isHealthServer;
}

private final ScheduledExecutorService executor;
private final ExecutorService executorService;
final ScheduledExecutorService executor;
final ScheduledExecutorService executorService;

/**
* groupKey -> cacheData
*/
@@ -524,5 +556,7 @@ private void setHealthServer(boolean isHealthServer) {
private final HttpAgent agent;
private final ConfigFilterChainManager configFilterChainManager;
private boolean isHealthServer = true;
private long timeout;
private double currentLongingTaskCount = 0;
private int taskPenaltyTime;
}
Original file line number Diff line number Diff line change
@@ -152,6 +152,7 @@ public ServerListManager(Properties properties) throws NacosException {
contentPath, serverListName, namespace);
}
}

}

private void initParam(Properties properties) {
@@ -265,7 +266,8 @@ private void updateIfChanged(List<String> newList) {
return;
}
serverUrls = new ArrayList<String>(newList);
currentServerAddr = iterator().next();
iterator = iterator();
currentServerAddr = iterator.next();

EventDispatcher.fireEvent(new ServerlistChangeEvent());
LOGGER.info("[{}] [update-serverlist] serverlist updated to {}", name, serverUrls);
@@ -332,16 +334,26 @@ public boolean contain(String ip) {
}

public void refreshCurrentServerAddr() {
currentServerAddr = iterator().next();
iterator = iterator();
currentServerAddr = iterator.next();
}

public String getCurrentServerAddr() {
if (StringUtils.isBlank(currentServerAddr)) {
currentServerAddr = iterator().next();
iterator = iterator();
currentServerAddr = iterator.next();
}
return currentServerAddr;
}

public void updateCurrentServerAddr(String currentServerAddr) {
this.currentServerAddr = currentServerAddr;
}

public Iterator<String> getIterator() {
return iterator;
}

public String getContentPath() {
return contentPath;
}
@@ -383,11 +395,13 @@ public String getTenant() {

private volatile String currentServerAddr;

private Iterator<String> iterator;
public String serverPort = ParamUtil.getDefaultServerPort();

public String addressServerUrl;

private String serverAddrsStr;

}

/**
@@ -433,14 +447,17 @@ public ServerAddressIterator(List<String> source) {
iter = sorted.iterator();
}

@Override
public boolean hasNext() {
return iter.hasNext();
}

@Override
public String next() {
return iter.next().serverIp;
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -406,6 +406,7 @@ public void run() {
}

}

}, timeoutTime, TimeUnit.MILLISECONDS);

allSubs.add(this);
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.test.config;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.config.server.Config;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;

/**
* @author liaochuntao
* @date 2019-06-07 22:24
**/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Config.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ConfigLongPoll_ITCase {

@LocalServerPort
private int port;

private ConfigService configService;

@Before
public void init() throws NacosException {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:" + port);
properties.put(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT, "20000");
properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, 3000);
configService = NacosFactory.createConfigService(properties);
}

@Test
public void test() throws InterruptedException, NacosException {

configService.addListener("test", "DEFAULT_GROUP", new Listener() {
@Override
public Executor getExecutor() {
return null;
}

@Override
public void receiveConfigInfo(String configInfo) {
System.out.println(configInfo);
}
});

configService.addListener("test-1", "DEFAULT_GROUP", new Listener() {
@Override
public Executor getExecutor() {
return null;
}

@Override
public void receiveConfigInfo(String configInfo) {
System.out.println(configInfo);
}
});

TimeUnit.SECONDS.sleep(30);

}

}
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Arrays;
@@ -112,7 +113,6 @@ public void dregDomTest() throws Exception {
public void dregDomClusterTest() throws Exception {

String serviceName = randomDomainName();

System.out.println(serviceName);

naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");