Fix #190
This commit is contained in:
parent
077c4cdb6f
commit
dc7cb2bdee
@ -155,6 +155,8 @@ public class NacosNamingService implements NamingService {
|
||||
beatInfo.setIp(instance.getIp());
|
||||
beatInfo.setPort(instance.getPort());
|
||||
beatInfo.setCluster(instance.getCluster().getName());
|
||||
beatInfo.setWeight(instance.getWeight());
|
||||
beatInfo.setMetadata(instance.getMetadata());
|
||||
|
||||
beatReactor.addBeatInfo(serviceName, beatInfo);
|
||||
|
||||
|
@ -17,6 +17,8 @@ package com.alibaba.nacos.client.naming.beat;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dungu.zpf
|
||||
*/
|
||||
@ -24,8 +26,10 @@ public class BeatInfo {
|
||||
|
||||
private int port;
|
||||
private String ip;
|
||||
private double weight;
|
||||
private String dom;
|
||||
private String cluster;
|
||||
private Map<String, String> metadata;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -63,4 +67,20 @@ public class BeatInfo {
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,38 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dungu.zpf
|
||||
*/
|
||||
public class NamingTest {
|
||||
|
||||
@Test
|
||||
public void testServiceList() {
|
||||
@Ignore
|
||||
public void testServiceList() throws Exception {
|
||||
|
||||
NamingService namingService = NacosFactory.createNamingService("127.0.0.1:8848");
|
||||
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("1.1.1.1");
|
||||
instance.setPort(80);
|
||||
instance.setWeight(2);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("env", "prod");
|
||||
map.put("version", "2.0");
|
||||
instance.setMetadata(map);
|
||||
|
||||
namingService.registerInstance("dungu.test.1", instance);
|
||||
|
||||
Thread.sleep(1000000000L);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
* @author xxc
|
||||
*/
|
||||
@SpringBootApplication
|
||||
|
||||
public class NamingApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -17,6 +17,8 @@ package com.alibaba.nacos.naming.healthcheck;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Metrics info of server
|
||||
*
|
||||
@ -33,6 +35,8 @@ public class RsInfo {
|
||||
private String dom;
|
||||
private String ak;
|
||||
private String cluster;
|
||||
private double weight;
|
||||
private Map<String, String> metadata;
|
||||
|
||||
public String getDom() {
|
||||
return dom;
|
||||
@ -114,6 +118,22 @@ public class RsInfo {
|
||||
this.mem = mem;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
|
@ -308,7 +308,8 @@ public class ApiCommands {
|
||||
IpAddress ipAddress = new IpAddress();
|
||||
ipAddress.setPort(port);
|
||||
ipAddress.setIp(ip);
|
||||
ipAddress.setWeight(1);
|
||||
ipAddress.setWeight(clientBeat.getWeight());
|
||||
ipAddress.setMetadata(clientBeat.getMetadata());
|
||||
ipAddress.setClusterName(clusterName);
|
||||
|
||||
if (!virtualClusterDomain.allIPs().contains(ipAddress)) {
|
||||
|
@ -15,10 +15,15 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.naming.healthcheck.RsInfo;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dungu.zpf
|
||||
*/
|
||||
@ -50,4 +55,18 @@ public class IpAddressTest {
|
||||
Assert.assertEquals(2, ipAddress.getWeight(), 0.001);
|
||||
Assert.assertEquals("TEST1", ipAddress.getClusterName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rsInfo() {
|
||||
|
||||
RsInfo info = new RsInfo();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("version", "2222");
|
||||
info.setMetadata(metadata);
|
||||
System.out.println(JSON.toJSONString(info));
|
||||
|
||||
String json = JSON.toJSONString(info);
|
||||
RsInfo info1 = JSON.parseObject(json, RsInfo.class);
|
||||
System.out.println(info1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user