Skip to content

Commit

Permalink
Merge pull request alibaba#627 from alibaba/feature_multi_tenant
Browse files Browse the repository at this point in the history
Feature multi tenant
  • Loading branch information
Fury Zhu authored Jan 15, 2019
2 parents 420141f + e9811c8 commit 663ed1a
Show file tree
Hide file tree
Showing 99 changed files with 2,304 additions and 2,167 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.7.0</version>
<version>0.8.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ public class PropertyKeyConst {
public final static String ENCODE = "encode";

public final static String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
public final static String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
public final static String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";

}
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
6 changes: 6 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 @@ -122,4 +122,10 @@ 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_NAMESPACE_ID = "namespaceId";
public static final String REQUEST_PARAM_DEFAULT_NAMESPACE_ID = "public";
public static final String REQUEST_PARAM_SERVICE_NAME = "serviceName";
public static final String REQUEST_PARAM_GROUP = "group";
public static final String REQUEST_PARAM_DEFAULT_GROUP = "DEFAULT_GROUP";
}
76 changes: 71 additions & 5 deletions api/src/main/java/com/alibaba/nacos/api/naming/NamingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ public interface NamingService {
List<Instance> getAllInstances(String serviceName) throws NacosException;

/**
* get all instances within specified clusters of a service
* Get all instances of a service
*
* @param serviceName name of service
* @param subscribe if subscribe the service
* @return A list of instance
* @throws NacosException
*/
List<Instance> getAllInstances(String serviceName, boolean subscribe) throws NacosException;

/**
* Get all instances within specified clusters of a service
*
* @param serviceName name of service
* @param clusters list of cluster
Expand All @@ -102,7 +112,18 @@ public interface NamingService {
List<Instance> getAllInstances(String serviceName, List<String> clusters) throws NacosException;

/**
* get qualified instances of service
* Get all instances within specified clusters of a service
*
* @param serviceName name of service
* @param clusters list of cluster
* @param subscribe if subscribe the service
* @return A list of qualified instance
* @throws NacosException
*/
List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe) throws NacosException;

/**
* Get qualified instances of service
*
* @param serviceName name of service
* @param healthy a flag to indicate returning healthy or unhealthy instances
Expand All @@ -112,7 +133,18 @@ public interface NamingService {
List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException;

/**
* get qualified instances within specified clusters of service
* Get qualified instances of service
*
* @param serviceName name of service
* @param healthy a flag to indicate returning healthy or unhealthy instances
* @param subscribe if subscribe the service
* @return A qualified list of instance
* @throws NacosException
*/
List<Instance> selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException;

/**
* Get qualified instances within specified clusters of service
*
* @param serviceName name of service
* @param clusters list of cluster
Expand All @@ -123,7 +155,19 @@ public interface NamingService {
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy) throws NacosException;

/**
* select one healthy instance of service using predefined load balance strategy
* Get qualified instances within specified clusters of service
*
* @param serviceName name of service
* @param clusters list of cluster
* @param healthy a flag to indicate returning healthy or unhealthy instances
* @param subscribe if subscribe the service
* @return A qualified list of instance
* @throws NacosException
*/
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy, boolean subscribe) throws NacosException;

/**
* Select one healthy instance of service using predefined load balance strategy
*
* @param serviceName name of service
* @return qualified instance
Expand All @@ -135,14 +179,35 @@ public interface NamingService {
* select one healthy instance of service using predefined load balance strategy
*
* @param serviceName name of service
* @param subscribe if subscribe the service
* @return qualified instance
* @throws NacosException
*/
Instance selectOneHealthyInstance(String serviceName, boolean subscribe) throws NacosException;

/**
* Select one healthy instance of service using predefined load balance strategy
*
* @param serviceName name of service
* @param clusters a list of clusters should the instance belongs to
* @return qualified instance
* @throws NacosException
*/
Instance selectOneHealthyInstance(String serviceName, List<String> clusters) throws NacosException;

/**
* subscribe service to receive events of instances alteration
* Select one healthy instance of service using predefined load balance strategy
*
* @param serviceName name of service
* @param clusters a list of clusters should the instance belongs to
* @param subscribe if subscribe the service
* @return qualified instance
* @throws NacosException
*/
Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe) throws NacosException;

/**
* Subscribe service to receive events of instances alteration
*
* @param serviceName name of service
* @param listener event listener
Expand Down Expand Up @@ -197,6 +262,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 @@ -48,8 +48,6 @@ public class ServiceInfo {

private String checksum = "";

private String env = "";

private volatile boolean allIPs = false;

public ServiceInfo() {
Expand All @@ -65,48 +63,22 @@ public void setAllIPs(boolean allIPs) {

public ServiceInfo(String key) {

int maxKeySectionCount = 4;
int allIpFlagIndex = 3;
int envIndex = 2;
int maxIndex = 2;
int clusterIndex = 1;
int serviceNameIndex = 0;

String[] keys = key.split(SPLITER);
if (keys.length >= maxKeySectionCount) {
if (keys.length >= maxIndex) {
this.name = keys[serviceNameIndex];
this.clusters = keys[clusterIndex];
this.env = keys[envIndex];
if (strEquals(keys[allIpFlagIndex], ALL_IPS)) {
this.setAllIPs(true);
}
} else if (keys.length >= allIpFlagIndex) {
this.name = keys[serviceNameIndex];
this.clusters = keys[clusterIndex];
if (strEquals(keys[envIndex], ALL_IPS)) {
this.setAllIPs(true);
} else {
this.env = keys[envIndex];
}
} else if (keys.length >= envIndex) {
this.name = keys[serviceNameIndex];
if (strEquals(keys[clusterIndex], ALL_IPS)) {
this.setAllIPs(true);
} else {
this.clusters = keys[clusterIndex];
}
}

this.name = keys[0];
}

public ServiceInfo(String name, String clusters) {
this(name, clusters, EMPTY);
}

public ServiceInfo(String name, String clusters, String env) {
this.name = name;
this.clusters = clusters;
this.env = env;
}

public int ipCount() {
Expand Down Expand Up @@ -158,7 +130,6 @@ public void setCacheMillis(long cacheMillis) {
}

public List<Instance> getHosts() {

return new ArrayList<Instance>(hosts);
}

Expand Down Expand Up @@ -192,45 +163,39 @@ public void setJsonFromServer(String jsonFromServer) {

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

@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);
} 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) {
public static ServiceInfo fromKey(String key) {
ServiceInfo serviceInfo = new ServiceInfo();

if (isEmpty(unit)) {
unit = EMPTY;
if (key.contains(SPLITER)) {
serviceInfo.setName(key.split(SPLITER)[0]);
serviceInfo.setClusters(key.split(SPLITER)[1]);
return serviceInfo;
}
serviceInfo.setName(key);
return serviceInfo;
}

if (!isEmpty(clusters) && !isEmpty(unit)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + unit + SPLITER + ALL_IPS
: name + SPLITER + clusters + SPLITER + unit;
}
@JSONField(serialize = false)
public static String getKey(String name, String clusters) {

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

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

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
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.7.0</version>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Loading

0 comments on commit 663ed1a

Please sign in to comment.