Skip to content

Commit

Permalink
#269 Register instance with tenant info
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Dec 19, 2018
1 parent 53eb990 commit 947e043
Show file tree
Hide file tree
Showing 40 changed files with 402 additions and 621 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public class Entity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public class EntityEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public enum EntityEventType {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public class Label {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public enum PreservedEntityTypes {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Service to visit CMDB store
*
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public interface CmdbService {

Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ public class Constants {
public static final String NAMING_HTTP_HEADER_SPILIER = "\\|";

public static final String NAMING_DEFAULT_CLUSTER_NAME = "DEFAULT";

public static final String REQUEST_PARAM_TENANT_ID = "tid";
public static final String REQUEST_PARAM_SERVICE_NAME = "serviceName";
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public interface NamingService {
* @param selector selector to filter the resource
* @return list of service names
* @throws NacosException
* @since 0.7.0
*/
ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,45 +190,38 @@ public void setJsonFromServer(String jsonFromServer) {

@JSONField(serialize = false)
public String getKey() {
return getKey(name, clusters, env, isAllIPs());
return getKey(name, clusters, env);
}

@JSONField(serialize = false)
public String getKeyEncoded() {
try {
return getKey(URLEncoder.encode(name, "UTF-8"), clusters, env, isAllIPs());
return getKey(URLEncoder.encode(name, "UTF-8"), clusters, env);
} catch (UnsupportedEncodingException e) {
return getKey();
}
}

@JSONField(serialize = false)
public static String getKey(String name, String clusters, String unit) {
return getKey(name, clusters, unit, false);
}

@JSONField(serialize = false)
public static String getKey(String name, String clusters, String unit, boolean isAllIPs) {

if (isEmpty(unit)) {
unit = EMPTY;
}

if (!isEmpty(clusters) && !isEmpty(unit)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + unit + SPLITER + ALL_IPS
: name + SPLITER + clusters + SPLITER + unit;
return name + SPLITER + clusters + SPLITER + unit;
}

if (!isEmpty(clusters)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + ALL_IPS : name + SPLITER + clusters;
return name + SPLITER + clusters;
}

if (!isEmpty(unit)) {
return isAllIPs ? name + SPLITER + EMPTY + SPLITER + unit + SPLITER + ALL_IPS :
name + SPLITER + EMPTY + SPLITER + unit;
return name + SPLITER + EMPTY + SPLITER + unit;
}

return isAllIPs ? name + SPLITER + ALL_IPS : name;
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Abstract selector that only contains a type
*
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public abstract class AbstractSelector {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* The selector to filter resource with flexible expression.
*
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public class ExpressionSelector extends AbstractSelector {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* The types of selector accepted by Nacos
*
* @author <a href="mailto:[email protected]">nkorange</a>
* @since 0.7.0
*/
public enum SelectorType {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.pojo.Cluster;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
Expand Down Expand Up @@ -159,7 +158,7 @@ public void registerInstance(String serviceName, String ip, int port, String clu
public void registerInstance(String serviceName, Instance instance) throws NacosException {

BeatInfo beatInfo = new BeatInfo();
beatInfo.setDom(serviceName);
beatInfo.setServiceName(serviceName);
beatInfo.setIp(instance.getIp());
beatInfo.setPort(instance.getPort());
beatInfo.setCluster(instance.getClusterName());
Expand Down Expand Up @@ -191,7 +190,7 @@ public List<Instance> getAllInstances(String serviceName) throws NacosException
public List<Instance> getAllInstances(String serviceName, List<String> clusters) throws NacosException {

ServiceInfo serviceInfo = hostReactor.getServiceInfo(serviceName, StringUtils.join(clusters, ","),
StringUtils.EMPTY, false);
StringUtils.EMPTY);
List<Instance> list;
if (serviceInfo == null || CollectionUtils.isEmpty(list = serviceInfo.getHosts())) {
return new ArrayList<Instance>();
Expand All @@ -209,7 +208,7 @@ public List<Instance> selectInstances(String serviceName, List<String> clusters,
throws NacosException {

ServiceInfo serviceInfo = hostReactor.getServiceInfo(serviceName, StringUtils.join(clusters, ","),
StringUtils.EMPTY, false);
StringUtils.EMPTY);
List<Instance> list;
if (serviceInfo == null || CollectionUtils.isEmpty(list = serviceInfo.getHosts())) {
return new ArrayList<Instance>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BeatInfo {
private int port;
private String ip;
private double weight;
private String dom;
private String serviceName;
private String cluster;
private Map<String, String> metadata;

Expand All @@ -36,12 +36,12 @@ public String toString() {
return JSON.toJSONString(this);
}

public String getDom() {
return dom;
public String getServiceName() {
return serviceName;
}

public void setDom(String dom) {
this.dom = dom;
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public String getCluster() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.alibaba.nacos.client.naming.net.NamingProxy;
import com.alibaba.nacos.client.naming.utils.LogUtils;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import com.alibaba.nacos.common.util.HttpMethod;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -83,6 +84,7 @@ public void run() {
}

class BeatTask implements Runnable {

BeatInfo beatInfo;

public BeatTask(BeatInfo beatInfo) {
Expand All @@ -93,10 +95,10 @@ public BeatTask(BeatInfo beatInfo) {
public void run() {
Map<String, String> params = new HashMap<String, String>(2);
params.put("beat", JSON.toJSONString(beatInfo));
params.put("dom", beatInfo.getDom());
params.put("serviceName", beatInfo.getServiceName());

try {
String result = serverProxy.callAllServers(UtilAndComs.NACOS_URL_BASE + "/api/clientBeat", params);
String result = serverProxy.reqAPI(UtilAndComs.NACOS_URL_BASE + "/health", params, HttpMethod.POST);
JSONObject jsonObject = JSON.parseObject(result);

if (jsonObject != null) {
Expand Down
Loading

0 comments on commit 947e043

Please sign in to comment.