Hotfix double register null service and beat info invalid problem (#3260)
* Hotfix, double register null service and beat info invalid problem * Revert nacos-client JDK back to 6 * Revert nacos-client JDK back to 6
This commit is contained in:
parent
9966ec38d9
commit
220b6c4f8d
@ -137,8 +137,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -192,11 +192,12 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException {
|
||||
String groupedServiceName = NamingUtils.getGroupedName(serviceName, groupName);
|
||||
if (instance.isEphemeral()) {
|
||||
BeatInfo beatInfo = beatReactor.buildBeatInfo(instance);
|
||||
beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo);
|
||||
BeatInfo beatInfo = beatReactor.buildBeatInfo(groupedServiceName, instance);
|
||||
beatReactor.addBeatInfo(groupedServiceName, beatInfo);
|
||||
}
|
||||
serverProxy.registerService(NamingUtils.getGroupedName(serviceName, groupName), groupName, instance);
|
||||
serverProxy.registerService(groupedServiceName, groupName, instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -356,7 +357,7 @@ public class NacosNamingService implements NamingService {
|
||||
private List<Instance> selectInstances(ServiceInfo serviceInfo, boolean healthy) {
|
||||
List<Instance> list;
|
||||
if (serviceInfo == null || CollectionUtils.isEmpty(list = serviceInfo.getHosts())) {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<Instance>();
|
||||
}
|
||||
|
||||
Iterator<Instance> iterator = list.iterator();
|
||||
|
@ -52,7 +52,7 @@ public class BeatReactor implements Closeable {
|
||||
|
||||
private boolean lightBeatEnabled = false;
|
||||
|
||||
public final Map<String, BeatInfo> dom2Beat = new ConcurrentHashMap<>();
|
||||
public final Map<String, BeatInfo> dom2Beat = new ConcurrentHashMap<String, BeatInfo>();
|
||||
|
||||
public BeatReactor(NamingProxy serverProxy) {
|
||||
this(serverProxy, UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT);
|
||||
@ -114,8 +114,19 @@ public class BeatReactor implements Closeable {
|
||||
* @return new beat information
|
||||
*/
|
||||
public BeatInfo buildBeatInfo(Instance instance) {
|
||||
return buildBeatInfo(instance.getServiceName(), instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build new beat information.
|
||||
*
|
||||
* @param groupedServiceName service name with group name, format: ${groupName}@@${serviceName}
|
||||
* @param instance instance
|
||||
* @return new beat information
|
||||
*/
|
||||
public BeatInfo buildBeatInfo(String groupedServiceName, Instance instance) {
|
||||
BeatInfo beatInfo = new BeatInfo();
|
||||
beatInfo.setServiceName(instance.getServiceName());
|
||||
beatInfo.setServiceName(groupedServiceName);
|
||||
beatInfo.setIp(instance.getIp());
|
||||
beatInfo.setPort(instance.getPort());
|
||||
beatInfo.setCluster(instance.getClusterName());
|
||||
|
@ -480,7 +480,7 @@ public class NamingProxy implements Closeable {
|
||||
String result = reqApi(UtilAndComs.nacosUrlBase + "/service/list", params, HttpMethod.GET);
|
||||
|
||||
JsonNode json = JacksonUtils.toObj(result);
|
||||
ListView<String> listView = new ListView<>();
|
||||
ListView<String> listView = new ListView<String>();
|
||||
listView.setCount(json.get("count").asInt());
|
||||
listView.setData(JacksonUtils.toObj(json.get("doms").toString(), new TypeReference<List<String>>() {
|
||||
}));
|
||||
|
@ -128,7 +128,7 @@ public class SecurityProxy {
|
||||
|
||||
if (StringUtils.isNotBlank(username)) {
|
||||
Map<String, String> params = new HashMap<String, String>(2);
|
||||
Map<String, String> bodyMap = new HashMap<>(2);
|
||||
Map<String, String> bodyMap = new HashMap<String, String>(2);
|
||||
params.put("username", username);
|
||||
bodyMap.put("password", password);
|
||||
String url = "http://" + server + contextPath + LOGIN_URL;
|
||||
|
@ -56,7 +56,7 @@ public class ConfigTest {
|
||||
boolean result = configService.publishConfig(dataId, group, content);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
ThreadUtils.sleep(10_000);
|
||||
ThreadUtils.sleep(10000L);
|
||||
|
||||
String response = configService.getConfigAndSignListener(dataId, group, 5000, new AbstractListener() {
|
||||
@Override
|
||||
@ -70,7 +70,7 @@ public class ConfigTest {
|
||||
System.out.println("input content");
|
||||
while (scanner.hasNextLine()) {
|
||||
String s = scanner.next();
|
||||
if (Objects.equals("exit", s)) {
|
||||
if ("exit".equals(s)) {
|
||||
scanner.close();
|
||||
return;
|
||||
}
|
||||
|
@ -52,13 +52,13 @@ public class NamingTest {
|
||||
NamingService namingService = NacosFactory.createNamingService(properties);
|
||||
namingService.registerInstance("nacos.test.1", instance);
|
||||
|
||||
ThreadUtils.sleep(5_000L);
|
||||
ThreadUtils.sleep(5000L);
|
||||
|
||||
List<Instance> list = namingService.getAllInstances("nacos.test.1");
|
||||
|
||||
System.out.println(list);
|
||||
|
||||
ThreadUtils.sleep(30_000L);
|
||||
ThreadUtils.sleep(30000L);
|
||||
// ExpressionSelector expressionSelector = new ExpressionSelector();
|
||||
// expressionSelector.setExpression("INSTANCE.metadata.registerSource = 'dubbo'");
|
||||
// ListView<String> serviceList = namingService.getServicesOfServer(1, 10, expressionSelector);
|
||||
|
Loading…
Reference in New Issue
Block a user