This commit is contained in:
nkorange 2019-03-04 17:12:29 +08:00
parent af26af7e6e
commit 8c23f34806
37 changed files with 328 additions and 138 deletions

View File

@ -124,4 +124,6 @@ public class Constants {
public static final String DEFAULT_NAMESPACE_ID = "public";
public static final int WRITE_REDIRECT_CODE = 307;
public static final String SERVICE_INFO_SPLITER = "@@";
}

View File

@ -418,7 +418,7 @@ public interface NamingService {
void subscribe(String serviceName, String groupName, EventListener listener) throws NacosException;
/**
* subscribe service to receive events of instances alteration
* Subscribe service to receive events of instances alteration
*
* @param serviceName name of service
* @param clusters list of cluster
@ -428,7 +428,7 @@ public interface NamingService {
void subscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException;
/**
* subscribe service to receive events of instances alteration
* Subscribe service to receive events of instances alteration
*
* @param serviceName name of service
* @param groupName group of service
@ -439,7 +439,7 @@ public interface NamingService {
void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException;
/**
* unsubscribe event listener of service
* Unsubscribe event listener of service
*
* @param serviceName name of service
* @param listener event listener
@ -458,7 +458,7 @@ public interface NamingService {
void unsubscribe(String serviceName, String groupName, EventListener listener) throws NacosException;
/**
* unsubscribe event listener of service
* Unsubscribe event listener of service
*
* @param serviceName name of service
* @param clusters list of cluster
@ -468,7 +468,7 @@ public interface NamingService {
void unsubscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException;
/**
* unsubscribe event listener of service
* Unsubscribe event listener of service
*
* @param serviceName name of service
* @param groupName group of service
@ -479,7 +479,7 @@ public interface NamingService {
void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException;
/**
* get all service names from server
* Get all service names from server
*
* @param pageNo page index
* @param pageSize page size
@ -489,7 +489,18 @@ public interface NamingService {
ListView<String> getServicesOfServer(int pageNo, int pageSize) throws NacosException;
/**
* Get all subscribed services of current client
* Get all service names from server
*
* @param pageNo page index
* @param pageSize page size
* @param groupName group name
* @return list of service names
* @throws NacosException
*/
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException;
/**
* Get all service names from server with selector
*
* @param pageNo page index
* @param pageSize page size
@ -500,6 +511,18 @@ public interface NamingService {
*/
ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException;
/**
* Get all service names from server with selector
*
* @param pageNo page index
* @param pageSize page size
* @param groupName group name
* @param selector selector to filter the resource
* @return list of service names
* @throws NacosException
*/
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException;
/**
* Get all subscribed services of current client
*

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.api.naming.pojo;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.nacos.api.common.Constants;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@ -37,6 +38,8 @@ public class ServiceInfo {
@JSONField(name = "dom")
private String name;
private String groupName;
private String clusters;
private long cacheMillis = 1000L;
@ -67,7 +70,7 @@ public class ServiceInfo {
int clusterIndex = 1;
int serviceNameIndex = 0;
String[] keys = key.split(SPLITER);
String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);
if (keys.length >= maxIndex) {
this.name = keys[serviceNameIndex];
this.clusters = keys[clusterIndex];
@ -105,6 +108,14 @@ public class ServiceInfo {
this.name = name;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public void setLastRefTime(long lastRefTime) {
this.lastRefTime = lastRefTime;
}
@ -178,13 +189,16 @@ public class ServiceInfo {
@JSONField(serialize = false)
public static ServiceInfo fromKey(String key) {
ServiceInfo serviceInfo = new ServiceInfo();
if (key.contains(SPLITER)) {
serviceInfo.setName(key.split(SPLITER)[0]);
serviceInfo.setClusters(key.split(SPLITER)[1]);
return serviceInfo;
int maxSegCount = 3;
String[] segs = key.split(Constants.SERVICE_INFO_SPLITER);
if (segs.length == maxSegCount -1) {
serviceInfo.setGroupName(segs[0]);
serviceInfo.setName(segs[1]);
} else if (segs.length == maxSegCount) {
serviceInfo.setGroupName(segs[0]);
serviceInfo.setName(segs[1]);
serviceInfo.setClusters(segs[2]);
}
serviceInfo.setName(key);
return serviceInfo;
}
@ -192,7 +206,7 @@ public class ServiceInfo {
public static String getKey(String name, String clusters) {
if (!isEmpty(clusters)) {
return name + SPLITER + clusters;
return name + Constants.SERVICE_INFO_SPLITER + clusters;
}
return name;

View File

@ -241,12 +241,17 @@ public class NacosNamingService implements NamingService {
@Override
public List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe)
throws NacosException {
return getAllInstances(serviceName, Constants.DEFAULT_GROUP, clusters, subscribe);
}
@Override
public List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException {
ServiceInfo serviceInfo;
if (subscribe) {
serviceInfo = hostReactor.getServiceInfo(serviceName, StringUtils.join(clusters, ","));
serviceInfo = hostReactor.getServiceInfo(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ","));
} else {
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName, StringUtils.join(clusters, ","));
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ","));
}
List<Instance> list;
if (serviceInfo == null || CollectionUtils.isEmpty(list = serviceInfo.getHosts())) {
@ -255,11 +260,6 @@ public class NacosNamingService implements NamingService {
return list;
}
@Override
public List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException {
return null;
}
@Override
public List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException {
return selectInstances(serviceName, new ArrayList<String>(), healthy);
@ -267,7 +267,7 @@ public class NacosNamingService implements NamingService {
@Override
public List<Instance> selectInstances(String serviceName, String groupName, boolean healthy) throws NacosException {
return null;
return selectInstances(serviceName, groupName, healthy, true);
}
@Override
@ -278,7 +278,7 @@ public class NacosNamingService implements NamingService {
@Override
public List<Instance> selectInstances(String serviceName, String groupName, boolean healthy, boolean subscribe) throws NacosException {
return null;
return selectInstances(serviceName, groupName, new ArrayList<String>(), healthy, subscribe);
}
@Override
@ -289,24 +289,25 @@ public class NacosNamingService implements NamingService {
@Override
public List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy) throws NacosException {
return null;
return selectInstances(serviceName, groupName, clusters, healthy, true);
}
@Override
public List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy,
boolean subscribe) throws NacosException {
ServiceInfo serviceInfo;
if (subscribe) {
serviceInfo = hostReactor.getServiceInfo(serviceName, StringUtils.join(clusters, ","));
} else {
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName, StringUtils.join(clusters, ","));
}
return selectInstances(serviceInfo, healthy);
return selectInstances(serviceName, Constants.DEFAULT_GROUP, clusters, healthy, subscribe);
}
@Override
public List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy, boolean subscribe) throws NacosException {
return null;
ServiceInfo serviceInfo;
if (subscribe) {
serviceInfo = hostReactor.getServiceInfo(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ","));
} else {
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ","));
}
return selectInstances(serviceInfo, healthy);
}
@Override
@ -316,7 +317,7 @@ public class NacosNamingService implements NamingService {
@Override
public Instance selectOneHealthyInstance(String serviceName, String groupName) throws NacosException {
return null;
return selectOneHealthyInstance(serviceName, groupName, true);
}
@Override
@ -326,7 +327,7 @@ public class NacosNamingService implements NamingService {
@Override
public Instance selectOneHealthyInstance(String serviceName, String groupName, boolean subscribe) throws NacosException {
return null;
return selectOneHealthyInstance(serviceName, groupName, new ArrayList<String>(), subscribe);
}
@Override
@ -336,78 +337,87 @@ public class NacosNamingService implements NamingService {
@Override
public Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters) throws NacosException {
return null;
return selectOneHealthyInstance(serviceName, groupName, clusters, true);
}
@Override
public Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe)
throws NacosException {
if (subscribe) {
return Balancer.RandomByWeight.selectHost(
hostReactor.getServiceInfo(serviceName, StringUtils.join(clusters, ",")));
} else {
return Balancer.RandomByWeight.selectHost(
hostReactor.getServiceInfoDirectlyFromServer(serviceName, StringUtils.join(clusters, ",")));
}
return selectOneHealthyInstance(serviceName, Constants.DEFAULT_GROUP, clusters, subscribe);
}
@Override
public Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException {
return null;
if (subscribe) {
return Balancer.RandomByWeight.selectHost(
hostReactor.getServiceInfo(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ",")));
} else {
return Balancer.RandomByWeight.selectHost(
hostReactor.getServiceInfoDirectlyFromServer(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ",")));
}
}
@Override
public void subscribe(String service, EventListener listener) {
eventDispatcher.addListener(hostReactor.getServiceInfo(service, StringUtils.EMPTY), StringUtils.EMPTY,
listener);
public void subscribe(String serviceName, EventListener listener) throws NacosException {
subscribe(serviceName, new ArrayList<String>(), listener);
}
@Override
public void subscribe(String serviceName, String groupName, EventListener listener) throws NacosException {
subscribe(serviceName, groupName, new ArrayList<String>(), listener);
}
@Override
public void subscribe(String service, List<String> clusters, EventListener listener) {
eventDispatcher.addListener(hostReactor.getServiceInfo(service, StringUtils.join(clusters, ",")),
StringUtils.join(clusters, ","), listener);
public void subscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException {
subscribe(serviceName, Constants.DEFAULT_GROUP, clusters, listener);
}
@Override
public void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException {
eventDispatcher.addListener(hostReactor.getServiceInfo(groupName + Constants.SERVICE_INFO_SPLITER + serviceName,
StringUtils.join(clusters, ",")), StringUtils.join(clusters, ","), listener);
}
@Override
public void unsubscribe(String service, EventListener listener) {
eventDispatcher.removeListener(service, StringUtils.EMPTY, listener);
public void unsubscribe(String serviceName, EventListener listener) throws NacosException {
unsubscribe(serviceName, new ArrayList<String>(), listener);
}
@Override
public void unsubscribe(String serviceName, String groupName, EventListener listener) throws NacosException {
unsubscribe(serviceName, groupName, new ArrayList<String>(), listener);
}
@Override
public void unsubscribe(String service, List<String> clusters, EventListener listener) {
eventDispatcher.removeListener(service, StringUtils.join(clusters, ","), listener);
public void unsubscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException {
unsubscribe(serviceName, Constants.DEFAULT_GROUP, clusters, listener);
}
@Override
public void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException {
eventDispatcher.removeListener(groupName + Constants.SERVICE_INFO_SPLITER + serviceName, StringUtils.join(clusters, ","), listener);
}
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize) throws NacosException {
return serverProxy.getServiceList(pageNo, pageSize);
return serverProxy.getServiceList(pageNo, pageSize, Constants.DEFAULT_GROUP);
}
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException {
return getServicesOfServer(pageNo, pageSize, groupName, null);
}
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector)
throws NacosException {
return serverProxy.getServiceList(pageNo, pageSize, selector);
return getServicesOfServer(pageNo, pageSize, Constants.DEFAULT_GROUP, selector);
}
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
return serverProxy.getServiceList(pageNo, pageSize, groupName, selector);
}
@Override

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.client.naming.cache;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
@ -44,7 +45,6 @@ public class DiskCache {
makeSureCacheDirExists(dir);
File file = new File(dir, dom.getKeyEncoded());
if (!file.exists()) {
// add another !file.exists() to avoid conflicted creating-new-file from multi-instances
@ -93,8 +93,8 @@ public class DiskCache {
String fileName = URLDecoder.decode(file.getName(), "UTF-8");
if (!(fileName.endsWith(ServiceInfo.SPLITER + "meta") || fileName.endsWith(
ServiceInfo.SPLITER + "special-url"))) {
if (!(fileName.endsWith(Constants.SERVICE_INFO_SPLITER + "meta") || fileName.endsWith(
Constants.SERVICE_INFO_SPLITER + "special-url"))) {
ServiceInfo dom = new ServiceInfo(fileName);
List<Instance> ips = new ArrayList<Instance>();
dom.setHosts(ips);

View File

@ -251,16 +251,17 @@ public class NamingProxy {
}
}
public ListView<String> getServiceList(int pageNo, int pageSize) throws NacosException {
return getServiceList(pageNo, pageSize, null);
public ListView<String> getServiceList(int pageNo, int pageSize, String groupName) throws NacosException {
return getServiceList(pageNo, pageSize, groupName, null);
}
public ListView<String> getServiceList(int pageNo, int pageSize, AbstractSelector selector) throws NacosException {
public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
Map<String, String> params = new HashMap<String, String>(4);
params.put("pageNo", String.valueOf(pageNo));
params.put("pageSize", String.valueOf(pageSize));
params.put(CommonParams.NAMESPACE_ID, namespaceId);
params.put(CommonParams.GROUP_NAME, groupName);
if (selector != null) {
switch (SelectorType.valueOf(selector.getType())) {

View File

@ -204,9 +204,9 @@
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
</excludes>
<!--<excludes>-->
<!--<exclude>application.properties</exclude>-->
<!--</excludes>-->
</resource>
</resources>
</build>

View File

@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.naming.acl;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.core.Service;
@ -67,7 +68,7 @@ public class AuthChecker {
public void doAuth(Map<String, String[]> params, HttpServletRequest req) throws Exception {
String namespaceId = WebUtils.optional(req, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.optional(req, "name", "");
if (StringUtils.isEmpty(serviceName)) {
serviceName = WebUtils.optional(req, "serviceName", "");

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.consistency.persistent.raft;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.consistency.ApplyAction;
import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
@ -145,11 +146,11 @@ public class RaftStore {
}
if (StringUtils.isBlank(serviceDatum.value.getGroupName())) {
serviceDatum.value.setGroupName(UtilsAndCommons.DEFAULT_GROUP_NAME);
serviceDatum.value.setGroupName(Constants.DEFAULT_GROUP);
}
if (!serviceDatum.value.getName().contains(UtilsAndCommons.GROUP_SERVICE_CONNECTOR)) {
serviceDatum.value.setName(UtilsAndCommons.DEFAULT_GROUP_NAME
+ UtilsAndCommons.GROUP_SERVICE_CONNECTOR + serviceDatum.value.getName());
if (!serviceDatum.value.getName().contains(Constants.SERVICE_INFO_SPLITER)) {
serviceDatum.value.setName(Constants.DEFAULT_GROUP
+ Constants.SERVICE_INFO_SPLITER + serviceDatum.value.getName());
}
return serviceDatum;

View File

@ -17,6 +17,7 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.naming.pojo.Cluster;
import com.alibaba.nacos.core.utils.WebUtils;
@ -52,7 +53,7 @@ public class CatalogController {
public JSONObject serviceList(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
JSONObject result = new JSONObject();
int page = Integer.parseInt(WebUtils.required(request, "startPg"));
@ -99,7 +100,7 @@ public class CatalogController {
public ServiceDetailView serviceDetail(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);
if (service == null) {
@ -133,7 +134,7 @@ public class CatalogController {
public JSONObject instanceList(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME);
int page = Integer.parseInt(WebUtils.required(request, "startPg"));
@ -176,7 +177,7 @@ public class CatalogController {
public List<ServiceDetailInfo> listDetail(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
serviceManager
@ -203,7 +204,7 @@ public class CatalogController {
public JSONObject rt4Service(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);

View File

@ -17,6 +17,7 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.alibaba.nacos.core.utils.WebUtils;
@ -50,7 +51,7 @@ public class ClusterController {
public String update(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String healthChecker = WebUtils.required(request, "healthChecker");

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.boot.RunningConfig;
@ -71,7 +72,7 @@ public class HealthController {
public String update(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String ip = WebUtils.required(request, "ip");
int port = Integer.parseInt(WebUtils.required(request, "port"));

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.boot.RunningConfig;
@ -95,7 +96,7 @@ public class InstanceController {
public String register(HttpServletRequest request) throws Exception {
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, UtilsAndCommons.DEFAULT_NAMESPACE_ID);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
return "ok";
@ -106,7 +107,7 @@ public class InstanceController {
public String deregister(HttpServletRequest request) throws Exception {
Instance instance = getIPAddress(request);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);
@ -119,10 +120,10 @@ public class InstanceController {
return "ok";
}
@RequestMapping(value = {"/instance/update", "instance"}, method = RequestMethod.PUT)
@RequestMapping(value = "/instance", method = RequestMethod.PUT)
public String update(HttpServletRequest request) throws Exception {
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, UtilsAndCommons.DEFAULT_NAMESPACE_ID);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
serviceManager.updateInstance(namespaceId, serviceName, parseInstance(request));
return "ok";
@ -132,7 +133,7 @@ public class InstanceController {
public JSONObject list(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String agent = request.getHeader("Client-Version");
@ -158,7 +159,7 @@ public class InstanceController {
public JSONObject detail(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, UtilsAndCommons.DEFAULT_CLUSTER_NAME);
String ip = WebUtils.required(request, "ip");
@ -209,7 +210,7 @@ public class InstanceController {
}
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String beat = WebUtils.required(request, "beat");
RsInfo clientBeat = JSON.parseObject(beat, RsInfo.class);
if (StringUtils.isBlank(clientBeat.getCluster())) {
@ -291,7 +292,7 @@ public class InstanceController {
namespaceId = key.split(UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR)[0];
serviceName = key.split(UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR)[1];
} else {
namespaceId = UtilsAndCommons.DEFAULT_NAMESPACE_ID;
namespaceId = Constants.DEFAULT_NAMESPACE_ID;
serviceName = key;
}

View File

@ -17,6 +17,7 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.core.utils.SystemUtils;
import com.alibaba.nacos.core.utils.WebUtils;
@ -154,7 +155,7 @@ public class OperatorController {
@RequestMapping("/getResponsibleServer4Dom")
public JSONObject getResponsibleServer4Dom(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String dom = WebUtils.required(request, "dom");
Service service = serviceManager.getService(namespaceId, dom);
@ -181,7 +182,7 @@ public class OperatorController {
@RequestMapping("/responsible")
public JSONObject responsible(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String dom = WebUtils.required(request, "dom");
Service service = serviceManager.getService(namespaceId, dom);

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.selector.SelectorType;
import com.alibaba.nacos.core.utils.WebUtils;
@ -61,7 +62,7 @@ public class ServiceController {
public String create(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
@ -99,7 +100,7 @@ public class ServiceController {
public String remove(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);
@ -120,7 +121,7 @@ public class ServiceController {
public JSONObject detail(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);
@ -156,7 +157,8 @@ public class ServiceController {
int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String groupName = WebUtils.optional(request, CommonParams.GROUP_NAME, Constants.DEFAULT_GROUP);
String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
List<String> serviceNameList = serviceManager.getAllServiceNameList(namespaceId);
@ -169,6 +171,15 @@ public class ServiceController {
return result;
}
Iterator<String> iterator = serviceNameList.iterator();
while (iterator.hasNext()) {
String serviceName = iterator.next();
if (!serviceName.startsWith(groupName + Constants.SERVICE_INFO_SPLITER)) {
iterator.remove();
}
}
if (StringUtils.isNotBlank(selectorString)) {
JSONObject selectorJson = JSON.parseObject(selectorString);
@ -211,6 +222,10 @@ public class ServiceController {
end = serviceNameList.size();
}
for (int i = start; i < end; i++) {
serviceNameList.add(i, serviceNameList.get(i).replace(groupName + Constants.SERVICE_INFO_SPLITER, ""));
}
result.put("doms", serviceNameList.subList(start, end));
result.put("count", serviceNameList.size());
@ -222,7 +237,7 @@ public class ServiceController {
public String update(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
float protectThreshold = NumberUtils.toFloat(WebUtils.required(request, "protectThreshold"));
String metadata = WebUtils.optional(request, "metadata", StringUtils.EMPTY);
@ -331,7 +346,7 @@ public class ServiceController {
public JSONObject checksum(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.core;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.naming.cluster.ServerListManager;
import com.alibaba.nacos.naming.cluster.ServerMode;
@ -112,12 +113,12 @@ public class ServiceManager implements RecordListener<Service> {
@Override
public boolean interests(String key) {
return KeyBuilder.matchServiceMetaKey(key);
return KeyBuilder.matchServiceMetaKey(key) && !KeyBuilder.matchSwitchKey(key);
}
@Override
public boolean matchUnlistenKey(String key) {
return KeyBuilder.matchServiceMetaKey(key);
return KeyBuilder.matchServiceMetaKey(key) && !KeyBuilder.matchSwitchKey(key);
}
@Override
@ -129,7 +130,7 @@ public class ServiceManager implements RecordListener<Service> {
}
if (StringUtils.isBlank(service.getNamespaceId())) {
service.setNamespaceId(UtilsAndCommons.DEFAULT_NAMESPACE_ID);
service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID);
}
Loggers.RAFT.info("[RAFT-NOTIFIER] datum is changed, key: {}, value: {}", key, service);
@ -332,7 +333,7 @@ public class ServiceManager implements RecordListener<Service> {
service = new Service();
service.setName(serviceName);
service.setNamespaceId(namespaceId);
service.setGroupName(UtilsAndCommons.DEFAULT_GROUP_NAME);
service.setGroupName(Constants.DEFAULT_GROUP);
// now validate the service. if failed, exception will be thrown
service.setLastModifiedMillis(System.currentTimeMillis());
service.recalculateChecksum();
@ -600,7 +601,7 @@ public class ServiceManager implements RecordListener<Service> {
public Map<String, String> serviceName2Checksum = new HashMap<String, String>();
public ServiceChecksum() {
this.namespaceId = UtilsAndCommons.DEFAULT_NAMESPACE_ID;
this.namespaceId = Constants.DEFAULT_NAMESPACE_ID;
}
public ServiceChecksum(String namespaceId) {

View File

@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.consistency.ConsistencyService;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.consistency.RecordListener;
import com.alibaba.nacos.naming.consistency.Datum;
import org.apache.commons.lang3.StringUtils;
@ -400,12 +401,12 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
@Override
public boolean interests(String key) {
return key.contains(UtilsAndCommons.SWITCH_DOMAIN_NAME);
return KeyBuilder.matchSwitchKey(key);
}
@Override
public boolean matchUnlistenKey(String key) {
return key.contains(UtilsAndCommons.SWITCH_DOMAIN_NAME);
return KeyBuilder.matchSwitchKey(key);
}
@Override

View File

@ -20,6 +20,7 @@ import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.JsonAdapter;
@ -111,16 +112,10 @@ public class UtilsAndCommons {
public static final String NAMESPACE_SERVICE_CONNECTOR = "##";
public static final String GROUP_SERVICE_CONNECTOR = "@@";
public static final String UPDATE_INSTANCE_ACTION_ADD = "add";
public static final String UPDATE_INSTANCE_ACTION_REMOVE = "remove";
public static final String DEFAULT_NAMESPACE_ID = "public";
public static final String DEFAULT_GROUP_NAME = "DEFAULT_GROUP";
public static final String DATA_BASE_DIR = NACOS_HOME + File.separator + "data" + File.separator + "naming";
public static final ScheduledExecutorService DOMAIN_SYNCHRONIZATION_EXECUTOR;
@ -245,16 +240,16 @@ public class UtilsAndCommons {
}
public static String getServiceName(String serviceNameWithGroup) {
if (!serviceNameWithGroup.contains(GROUP_SERVICE_CONNECTOR)) {
if (!serviceNameWithGroup.contains(Constants.SERVICE_INFO_SPLITER)) {
return serviceNameWithGroup;
}
return serviceNameWithGroup.split(GROUP_SERVICE_CONNECTOR)[1];
return serviceNameWithGroup.split(Constants.SERVICE_INFO_SPLITER)[1];
}
public static String getGroupName(String serviceNameWithGroup) {
if (!serviceNameWithGroup.contains(GROUP_SERVICE_CONNECTOR)) {
return DEFAULT_GROUP_NAME;
if (!serviceNameWithGroup.contains(Constants.SERVICE_INFO_SPLITER)) {
return Constants.DEFAULT_GROUP;
}
return serviceNameWithGroup.split(GROUP_SERVICE_CONNECTOR)[0];
return serviceNameWithGroup.split(Constants.SERVICE_INFO_SPLITER)[0];
}
}

View File

@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.naming.web;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.naming.core.DistroMapper;
import com.alibaba.nacos.naming.misc.HttpClient;
@ -112,11 +113,13 @@ public class DistroFilter implements Filter {
// user groupName@@serviceName as new service name:
String groupName = req.getParameter(CommonParams.GROUP_NAME);
if (StringUtils.isBlank(groupName)) {
groupName = UtilsAndCommons.DEFAULT_GROUP_NAME;
groupName = Constants.DEFAULT_GROUP;
}
OverrideParameterRequestWrapper requestWrapper = OverrideParameterRequestWrapper.buildRequest(req);
requestWrapper.addParameter(CommonParams.SERVICE_NAME, groupName + UtilsAndCommons.GROUP_SERVICE_CONNECTOR + serviceName);
if (StringUtils.isNotBlank(serviceName) && !serviceName.contains(Constants.SERVICE_INFO_SPLITER)) {
requestWrapper.addParameter(CommonParams.SERVICE_NAME, groupName + Constants.SERVICE_INFO_SPLITER + serviceName);
}
filterChain.doFilter(requestWrapper, resp);
} catch (AccessControlException e) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "access denied: " + UtilsAndCommons.getAllExceptionMsg(e));

View File

@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.naming.web;
import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.controllers.*;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
@ -50,7 +51,7 @@ public class FilterBase {
}
public Method getMethod(String httpMethod, String path) {
String key = httpMethod + "-->" + path;
String key = httpMethod + "-->" + path.replace("/nacos", "");
return methodCache.get(key);
}

View File

@ -98,7 +98,7 @@ public class TrafficReviseFilter implements Filter {
return;
}
resp.getWriter().write("service is " + serverStatusManager.getServerStatus().name() + " now, please try again later!");
resp.getWriter().write("server is " + serverStatusManager.getServerStatus().name() + " now, please try again later!");
resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
}

View File

@ -25,3 +25,9 @@ server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
nacos.naming.partition.taskDispatchThreadCount=10
nacos.naming.partition.taskDispatchPeriod=200
nacos.naming.partition.batchSyncKeyCount=1000
nacos.naming.partition.initDataRatio=0.9
nacos.naming.partition.syncRetryDelay=5000

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.BaseTest;
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet;
import com.alibaba.nacos.naming.core.Cluster;
@ -84,7 +85,7 @@ public class InstanceControllerTest extends BaseTest {
ipList.add(instance);
service.updateIPs(ipList, false);
Mockito.when(serviceManager.getService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(service);
Mockito.when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(service);
MockHttpServletRequestBuilder builder =
MockMvcRequestBuilders.put("/naming/instance")
@ -129,7 +130,7 @@ public class InstanceControllerTest extends BaseTest {
ipList.add(instance);
service.updateIPs(ipList, false);
Mockito.when(serviceManager.getService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(service);
Mockito.when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(service);
MockHttpServletRequestBuilder builder =
MockMvcRequestBuilders.get("/v1/ns/instances")

View File

@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.naming.core;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.BaseTest;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import org.junit.Assert;
@ -44,7 +45,7 @@ public class DomainsManagerTest extends BaseTest {
@Test
public void easyRemoveDom() throws Exception {
serviceManager.easyRemoveService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1");
serviceManager.easyRemoveService(Constants.DEFAULT_NAMESPACE_ID, "nacos.test.1");
}
@Test
@ -52,9 +53,9 @@ public class DomainsManagerTest extends BaseTest {
Service service = new Service();
service.setName("nacos.test.1");
serviceManager.chooseServiceMap(UtilsAndCommons.DEFAULT_NAMESPACE_ID).put("nacos.test.1", service);
serviceManager.chooseServiceMap(Constants.DEFAULT_NAMESPACE_ID).put("nacos.test.1", service);
List<Service> list = serviceManager.searchServices(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.*");
List<Service> list = serviceManager.searchServices(Constants.DEFAULT_NAMESPACE_ID, "nacos.test.*");
Assert.assertNotNull(list);
Assert.assertEquals(1, list.size());
Assert.assertEquals("nacos.test.1", list.get(0).getName());

View File

@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.test.naming;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
@ -55,10 +56,19 @@ public class AutoDeregisterInstance_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
// naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
naming = NamingFactory.createNamingService("11.239.112.161:8848,11.239.113.204:8848,11.239.114.187:8848");
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
@ -84,7 +94,7 @@ public class AutoDeregisterInstance_ITCase {
NacosNamingService namingServiceImpl = (NacosNamingService) naming;
namingServiceImpl.getBeatReactor().removeBeatInfo(serviceName, "DEFAULT_GROUP", "127.0.0.1", TEST_PORT);
namingServiceImpl.getBeatReactor().removeBeatInfo(serviceName, Constants.DEFAULT_GROUP, "127.0.0.1", TEST_PORT);
verifyInstanceList(instances, 1, serviceName);
instances = naming.getAllInstances(serviceName);

View File

@ -18,7 +18,6 @@ package com.alibaba.nacos.test.naming;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.NacosNamingService;
import com.alibaba.nacos.naming.NamingApp;
import org.junit.Assert;
import org.junit.Before;
@ -53,12 +52,20 @@ public class DeregisterInstance_ITCase {
@Before
public void init() throws Exception {
NamingBase.setServerStatusUp(port);
NamingBase.prepareServer(port);
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
/**
@ -69,7 +76,7 @@ public class DeregisterInstance_ITCase {
@Test
public void dregDomTest() throws Exception {
String serviceName = randomDomainName();
System.out.println(serviceName);
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT);
naming.registerInstance(serviceName, "127.0.0.2", TEST_PORT);
@ -77,7 +84,7 @@ public class DeregisterInstance_ITCase {
verifyInstanceList(instances, 2, serviceName);
instances = naming.getAllInstances(serviceName);
Assert.assertEquals(instances.size(), 2);
Assert.assertEquals(2, instances.size());
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT);

View File

@ -44,7 +44,19 @@ public class MultiTenant_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
Properties properties = new Properties();
properties.put(PropertyKeyConst.NAMESPACE, "namespace-1");
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port);

View File

@ -61,11 +61,22 @@ public class MultiTenant_InstanceAPI_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
String url = String.format("http://localhost:%d/", port);
this.base = new URL(url);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
Properties properties = new Properties();
properties.put(PropertyKeyConst.NAMESPACE, "namespace-1");
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port);
@ -221,10 +232,10 @@ public class MultiTenant_InstanceAPI_ITCase {
.appendParam("serviceName", serviceName)
.appendParam("ip", "33.33.33.33")
.appendParam("port", "8888")
.appendParam("namespaceId", "namespace-1") //新增
.done(),
String.class,
HttpMethod.PUT);
System.out.println(response.getBody());
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
response = request("/nacos/v1/ns/instance/list",
@ -235,7 +246,7 @@ public class MultiTenant_InstanceAPI_ITCase {
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
Assert.assertEquals(2, json.getJSONArray("hosts").size());
Assert.assertEquals(1, json.getJSONArray("hosts").size());
//namespace-2个数
response = request("/nacos/v1/ns/instance/list",

View File

@ -156,7 +156,7 @@ public class NamingBase {
return true;
}
public static void setServerStatusUp(int localPort) {
public static void prepareServer(int localPort) {
String url = "http://127.0.0.1:" + localPort + "/nacos/v1/ns/operator/switches?entry=overriddenServerStatus&value=UP";
List<String> headers = new ArrayList<String>();
headers.add("User-Agent");
@ -165,5 +165,15 @@ public class NamingBase {
HttpClient.request(url, headers, new HashMap<String, String>(), "UTF-8", "PUT");
Assert.assertEquals(HttpStatus.SC_OK, result.code);
url = "http://127.0.0.1:" + localPort + "/nacos/v1/ns/operator/switches?entry=serverMode&value=AP";
headers = new ArrayList<String>();
headers.add("User-Agent");
headers.add("Nacos-Server");
result =
HttpClient.request(url, headers, new HashMap<String, String>(), "UTF-8", "PUT");
Assert.assertEquals(HttpStatus.SC_OK, result.code);
}
}

View File

@ -53,10 +53,21 @@ public class RegisterInstance_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
if (naming == null) {
TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
@Test

View File

@ -508,7 +508,7 @@ public class RestAPI_ITCase {
ResponseEntity<String> response = request("/nacos/v1/ns/api/reCalculateCheckSum4Dom",
Params.newParams()
.appendParam(CommonParams.NAMESPACE_ID, UtilsAndCommons.DEFAULT_NAMESPACE_ID)
.appendParam(CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID)
.appendParam("dom", NamingBase.TEST_DOM_1)
.done(),
String.class);

View File

@ -56,10 +56,18 @@ public class SelectInstances_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
/**

View File

@ -50,10 +50,18 @@ public class SelectOneHealthyInstance_ITCase {
private int port;
@Before
public void init() throws Exception{
NamingBase.prepareServer(port);
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1"+":"+port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}

View File

@ -57,9 +57,17 @@ public class ServiceListTest {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
if (naming == null) {
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
@Test

View File

@ -54,11 +54,19 @@ public class SubscribeCluster_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
instances.clear();
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
private volatile List<Instance> instances = Collections.emptyList();

View File

@ -53,11 +53,19 @@ public class Subscribe_ITCase {
@Before
public void init() throws Exception {
NamingBase.prepareServer(port);
instances.clear();
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
private volatile List<Instance> instances = Collections.emptyList();

View File

@ -51,14 +51,22 @@ public class Unsubscribe_ITCase {
private NamingService naming;
@LocalServerPort
private int port;
@Before
public void init() throws Exception{
NamingBase.prepareServer(port);
instances = Collections.emptyList();
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1"+":"+port);
}
while (true) {
if (!"UP".equals(naming.getServerStatus())) {
Thread.sleep(1000L);
continue;
}
break;
}
}
private volatile List<Instance> instances = Collections.emptyList();