#757 domain to service 90%
This commit is contained in:
parent
e24e836dab
commit
3735142788
@ -68,20 +68,20 @@ public class AuthChecker {
|
||||
|
||||
String namespaceId = WebUtils.optional(req, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String dom = WebUtils.optional(req, "name", "");
|
||||
if (StringUtils.isEmpty(dom)) {
|
||||
dom = WebUtils.optional(req, "dom", "");
|
||||
String serviceName = WebUtils.optional(req, "name", "");
|
||||
if (StringUtils.isEmpty(serviceName)) {
|
||||
serviceName = WebUtils.optional(req, "serviceName", "");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(dom)) {
|
||||
dom = WebUtils.optional(req, "tag", "");
|
||||
if (StringUtils.isEmpty(serviceName)) {
|
||||
serviceName = WebUtils.optional(req, "tag", "");
|
||||
}
|
||||
|
||||
Service domObj = serviceManager.getService(namespaceId, dom);
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (domObj == null) {
|
||||
if (service == null) {
|
||||
if (!req.getRequestURI().equals(UtilsAndCommons.NACOS_NAMING_CONTEXT + UtilsAndCommons.API_SET_ALL_WEIGHTS)) {
|
||||
throw new IllegalStateException("auth failed, dom does not exist: " + dom);
|
||||
throw new IllegalStateException("auth failed, service does not exist: " + serviceName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,11 +89,11 @@ public class AuthChecker {
|
||||
String auth = req.getParameter("auth");
|
||||
String userName = req.getParameter("userName");
|
||||
if (StringUtils.isEmpty(auth) && StringUtils.isEmpty(token)) {
|
||||
throw new IllegalArgumentException("provide 'authInfo' or 'token' to access this dom");
|
||||
throw new IllegalArgumentException("provide 'authInfo' or 'token' to access this service");
|
||||
}
|
||||
|
||||
// try valid token
|
||||
if ((domObj != null && StringUtils.equals(domObj.getToken(), token))) {
|
||||
if ((service != null && StringUtils.equals(service.getToken(), token))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ public class AuthChecker {
|
||||
throw new AccessControlException("un-registered SDK app");
|
||||
}
|
||||
|
||||
if (!domObj.getOwners().contains(authInfo.getOperator())
|
||||
if (!service.getOwners().contains(authInfo.getOperator())
|
||||
&& !switchDomain.masters.contains(authInfo.getOperator())) {
|
||||
throw new AccessControlException("dom already exists and you're not among the owners");
|
||||
}
|
||||
|
@ -59,25 +59,25 @@ public class CatalogController {
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pgSize"));
|
||||
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
|
||||
|
||||
List<Service> doms = new ArrayList<>();
|
||||
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, doms);
|
||||
List<Service> services = new ArrayList<>();
|
||||
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, services);
|
||||
|
||||
if (CollectionUtils.isEmpty(doms)) {
|
||||
if (CollectionUtils.isEmpty(services)) {
|
||||
result.put("serviceList", Collections.emptyList());
|
||||
result.put("count", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray domArray = new JSONArray();
|
||||
for (Service dom : doms) {
|
||||
JSONArray serviceJsonArray = new JSONArray();
|
||||
for (Service service : services) {
|
||||
ServiceView serviceView = new ServiceView();
|
||||
serviceView.setName(dom.getName());
|
||||
serviceView.setClusterCount(dom.getClusterMap().size());
|
||||
serviceView.setIpCount(dom.allIPs().size());
|
||||
serviceView.setName(service.getName());
|
||||
serviceView.setClusterCount(service.getClusterMap().size());
|
||||
serviceView.setIpCount(service.allIPs().size());
|
||||
|
||||
// FIXME should be optimized:
|
||||
int validCount = 0;
|
||||
for (Instance instance : dom.allIPs()) {
|
||||
for (Instance instance : service.allIPs()) {
|
||||
if (instance.isValid()) {
|
||||
validCount++;
|
||||
}
|
||||
@ -85,10 +85,10 @@ public class CatalogController {
|
||||
|
||||
serviceView.setHealthyInstanceCount(validCount);
|
||||
|
||||
domArray.add(serviceView);
|
||||
serviceJsonArray.add(serviceView);
|
||||
}
|
||||
|
||||
result.put("serviceList", domArray);
|
||||
result.put("serviceList", serviceJsonArray);
|
||||
result.put("count", total);
|
||||
|
||||
return result;
|
||||
@ -100,18 +100,18 @@ public class CatalogController {
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String serviceName = WebUtils.required(request, "serviceName");
|
||||
Service domain = serviceManager.getService(namespaceId, serviceName);
|
||||
if (domain == null) {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!");
|
||||
}
|
||||
|
||||
ServiceDetailView detailView = new ServiceDetailView();
|
||||
|
||||
detailView.setService(domain);
|
||||
detailView.setService(service);
|
||||
|
||||
List<Cluster> clusters = new ArrayList<>();
|
||||
|
||||
for (com.alibaba.nacos.naming.core.Cluster cluster : domain.getClusterMap().values()) {
|
||||
for (com.alibaba.nacos.naming.core.Cluster cluster : service.getClusterMap().values()) {
|
||||
Cluster clusterView = new Cluster();
|
||||
clusterView.setName(cluster.getName());
|
||||
clusterView.setHealthChecker(cluster.getHealthChecker());
|
||||
@ -138,16 +138,16 @@ public class CatalogController {
|
||||
int page = Integer.parseInt(WebUtils.required(request, "startPg"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pgSize"));
|
||||
|
||||
Service domain = serviceManager.getService(namespaceId, serviceName);
|
||||
if (domain == null) {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!");
|
||||
}
|
||||
|
||||
if (!domain.getClusterMap().containsKey(clusterName)) {
|
||||
if (!service.getClusterMap().containsKey(clusterName)) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!");
|
||||
}
|
||||
|
||||
List<Instance> instances = domain.getClusterMap().get(clusterName).allIPs();
|
||||
List<Instance> instances = service.getClusterMap().get(clusterName).allIPs();
|
||||
|
||||
int start = (page - 1) * pageSize;
|
||||
int end = page * pageSize;
|
||||
@ -197,22 +197,22 @@ public class CatalogController {
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/rt4Dom")
|
||||
public JSONObject rt4Dom(HttpServletRequest request) {
|
||||
@RequestMapping("/rt4Service")
|
||||
public JSONObject rt4Service(HttpServletRequest request) {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String dom = WebUtils.required(request, "dom");
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
|
||||
Service domObj = serviceManager.getService(namespaceId, dom);
|
||||
if (domObj == null) {
|
||||
throw new IllegalArgumentException("request dom doesn't exist");
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("request service doesn't exist");
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
JSONArray clusters = new JSONArray();
|
||||
for (Map.Entry<String, com.alibaba.nacos.naming.core.Cluster> entry : domObj.getClusterMap().entrySet()) {
|
||||
for (Map.Entry<String, com.alibaba.nacos.naming.core.Cluster> entry : service.getClusterMap().entrySet()) {
|
||||
JSONObject packet = new JSONObject();
|
||||
HealthCheckTask task = entry.getValue().getHealthCheckTask();
|
||||
|
||||
@ -228,11 +228,11 @@ public class CatalogController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/getDomsByIP")
|
||||
public JSONObject getDomsByIP(HttpServletRequest request) {
|
||||
@RequestMapping("/getServicesByIP")
|
||||
public JSONObject getServicesByIP(HttpServletRequest request) {
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
|
||||
Set<String> doms = new HashSet<String>();
|
||||
Set<String> serviceNames = new HashSet<>();
|
||||
Map<String, Set<String>> serviceNameMap = serviceManager.getAllServiceNames();
|
||||
|
||||
for (String namespaceId : serviceNameMap.keySet()) {
|
||||
@ -242,11 +242,11 @@ public class CatalogController {
|
||||
for (Instance instance : instances) {
|
||||
if (ip.contains(":")) {
|
||||
if (StringUtils.equals(instance.getIp() + ":" + instance.getPort(), ip)) {
|
||||
doms.add(namespaceId + UtilsAndCommons.SERVICE_GROUP_CONNECTOR + service.getName());
|
||||
serviceNames.add(namespaceId + UtilsAndCommons.SERVICE_GROUP_CONNECTOR + service.getName());
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.equals(instance.getIp(), ip)) {
|
||||
doms.add(namespaceId + UtilsAndCommons.SERVICE_GROUP_CONNECTOR + service.getName());
|
||||
serviceNames.add(namespaceId + UtilsAndCommons.SERVICE_GROUP_CONNECTOR + service.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,7 +255,7 @@ public class CatalogController {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put("doms", doms);
|
||||
result.put("doms", serviceNames);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
public class ClusterController {
|
||||
|
||||
@Autowired
|
||||
protected ServiceManager domainsManager;
|
||||
protected ServiceManager serviceManager;
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.PUT)
|
||||
public String update(HttpServletRequest request) throws Exception {
|
||||
@ -58,12 +58,12 @@ public class ClusterController {
|
||||
String checkPort = WebUtils.required(request, "checkPort");
|
||||
String useInstancePort4Check = WebUtils.required(request, "useInstancePort4Check");
|
||||
|
||||
Service domain = domainsManager.getService(namespaceId, serviceName);
|
||||
if (domain == null) {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "service not found:" + serviceName);
|
||||
}
|
||||
|
||||
Cluster cluster = domain.getClusterMap().get(clusterName);
|
||||
Cluster cluster = service.getClusterMap().get(clusterName);
|
||||
if (cluster == null) {
|
||||
Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName);
|
||||
cluster = new Cluster();
|
||||
@ -93,13 +93,13 @@ public class ClusterController {
|
||||
cluster.setHealthChecker(abstractHealthChecker);
|
||||
cluster.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
||||
|
||||
domain.getClusterMap().put(clusterName, cluster);
|
||||
service.getClusterMap().put(clusterName, cluster);
|
||||
|
||||
domain.setLastModifiedMillis(System.currentTimeMillis());
|
||||
domain.recalculateChecksum();
|
||||
domain.valid();
|
||||
service.setLastModifiedMillis(System.currentTimeMillis());
|
||||
service.recalculateChecksum();
|
||||
service.valid();
|
||||
|
||||
domainsManager.addOrReplaceService(domain);
|
||||
serviceManager.addOrReplaceService(service);
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
@ -72,15 +72,15 @@ public class HealthController {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String dom = WebUtils.required(request, "serviceName");
|
||||
String serviceName = WebUtils.required(request, "serviceName");
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
int port = Integer.parseInt(WebUtils.required(request, "port"));
|
||||
boolean valid = Boolean.valueOf(WebUtils.required(request, "valid"));
|
||||
String clusterName = WebUtils.optional(request, "clusterName", UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
|
||||
if (!distroMapper.responsible(dom)) {
|
||||
String server = distroMapper.mapSrv(dom);
|
||||
Loggers.EVT_LOG.info("I'm not responsible for " + dom + ", proxy it to " + server);
|
||||
if (!distroMapper.responsible(serviceName)) {
|
||||
String server = distroMapper.mapSrv(serviceName);
|
||||
Loggers.EVT_LOG.info("I'm not responsible for " + serviceName + ", proxy it to " + server);
|
||||
Map<String, String> proxyParams = new HashMap<>(16);
|
||||
for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
@ -97,10 +97,10 @@ public class HealthController {
|
||||
HttpClient.HttpResult httpResult = HttpClient.httpPost(url, null, proxyParams);
|
||||
|
||||
if (httpResult.code != HttpURLConnection.HTTP_OK) {
|
||||
throw new IllegalArgumentException("failed to proxy health update to " + server + ", dom: " + dom);
|
||||
throw new IllegalArgumentException("failed to proxy health update to " + server + ", service: " + serviceName);
|
||||
}
|
||||
} else {
|
||||
Service service = serviceManager.getService(namespaceId, dom);
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
// Only health check "none" need update health status with api
|
||||
if (HealthCheckType.NONE.name().equals(service.getClusterMap().get(clusterName).getHealthChecker().getType())) {
|
||||
for (Instance instance : service.allIPs(Lists.newArrayList(clusterName))) {
|
||||
@ -108,13 +108,13 @@ public class HealthController {
|
||||
instance.setValid(valid);
|
||||
Loggers.EVT_LOG.info((valid ? "[IP-ENABLED]" : "[IP-DISABLED]") + " ips: "
|
||||
+ instance.getIp() + ":" + instance.getPort() + "@" + instance.getClusterName()
|
||||
+ ", dom: " + dom + ", msg: update thought HealthController api");
|
||||
+ ", service: " + serviceName + ", msg: update thought HealthController api");
|
||||
pushService.serviceChanged(namespaceId, service.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("health check mode 'client' and 'server' are not supported , dom: " + dom);
|
||||
throw new IllegalArgumentException("health check mode 'client' and 'server' are not supported, service: " + serviceName);
|
||||
}
|
||||
}
|
||||
return "ok";
|
||||
|
@ -79,7 +79,7 @@ public class InstanceController {
|
||||
client.getClusters(), client.getSocketAddr().getAddress().getHostAddress(), 0, StringUtils.EMPTY,
|
||||
false, StringUtils.EMPTY, StringUtils.EMPTY, false);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("PUSH-SERVICE: dom is not modified", e);
|
||||
Loggers.SRV_LOG.warn("PUSH-SERVICE: service is not modified", e);
|
||||
}
|
||||
|
||||
// overdrive the cache millis to push mode
|
||||
@ -122,7 +122,7 @@ public class InstanceController {
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
|
||||
String dom = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
String agent = request.getHeader("Client-Version");
|
||||
if (StringUtils.isBlank(agent)) {
|
||||
agent = request.getHeader("User-Agent");
|
||||
@ -139,7 +139,7 @@ public class InstanceController {
|
||||
|
||||
boolean healthyOnly = Boolean.parseBoolean(WebUtils.optional(request, "healthyOnly", "false"));
|
||||
|
||||
return doSrvIPXT(namespaceId, dom, agent, clusters, clientIP, udpPort, env, isCheck, app, tenant, healthyOnly);
|
||||
return doSrvIPXT(namespaceId, serviceName, agent, clusters, clientIP, udpPort, env, isCheck, app, tenant, healthyOnly);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/instance", method = RequestMethod.GET)
|
||||
@ -152,17 +152,17 @@ public class InstanceController {
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
int port = Integer.parseInt(WebUtils.required(request, "port"));
|
||||
|
||||
Service domain = serviceManager.getService(namespaceId, serviceName);
|
||||
if (domain == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "no dom " + serviceName + " found!");
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "no service " + serviceName + " found!");
|
||||
}
|
||||
|
||||
List<String> clusters = new ArrayList<>();
|
||||
clusters.add(cluster);
|
||||
|
||||
List<Instance> ips = domain.allIPs(clusters);
|
||||
List<Instance> ips = service.allIPs(clusters);
|
||||
if (ips == null || ips.isEmpty()) {
|
||||
throw new IllegalStateException("no ips found for cluster " + cluster + " in dom " + serviceName);
|
||||
throw new IllegalStateException("no ips found for cluster " + cluster + " in service " + serviceName);
|
||||
}
|
||||
|
||||
for (Instance instance : ips) {
|
||||
@ -202,10 +202,7 @@ public class InstanceController {
|
||||
if (StringUtils.isBlank(clientBeat.getCluster())) {
|
||||
clientBeat.setCluster(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
String serviceName = WebUtils.optional(request, "serviceName", StringUtils.EMPTY);
|
||||
if (StringUtils.isBlank(serviceName)) {
|
||||
serviceName = WebUtils.required(request, "dom");
|
||||
}
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
|
||||
String clusterName = clientBeat.getCluster();
|
||||
|
||||
@ -274,24 +271,24 @@ public class InstanceController {
|
||||
|
||||
String key = WebUtils.required(request, "key");
|
||||
|
||||
String domName;
|
||||
String serviceName;
|
||||
String namespaceId;
|
||||
|
||||
if (key.contains(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)) {
|
||||
namespaceId = key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0];
|
||||
domName = key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
|
||||
serviceName = key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
|
||||
} else {
|
||||
namespaceId = UtilsAndCommons.DEFAULT_NAMESPACE_ID;
|
||||
domName = key;
|
||||
serviceName = key;
|
||||
}
|
||||
|
||||
Service dom = serviceManager.getService(namespaceId, domName);
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (dom == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "dom: " + domName + " not found.");
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "service: " + serviceName + " not found.");
|
||||
}
|
||||
|
||||
List<Instance> ips = dom.allIPs();
|
||||
List<Instance> ips = service.allIPs();
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
JSONArray ipArray = new JSONArray();
|
||||
@ -359,37 +356,37 @@ public class InstanceController {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void checkIfDisabled(Service domObj) throws Exception {
|
||||
if (!domObj.getEnabled()) {
|
||||
throw new Exception("domain is disabled now.");
|
||||
public void checkIfDisabled(Service service) throws Exception {
|
||||
if (!service.getEnabled()) {
|
||||
throw new Exception("service is disabled now.");
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject doSrvIPXT(String namespaceId, String dom, String agent, String clusters, String clientIP, int udpPort,
|
||||
public JSONObject doSrvIPXT(String namespaceId, String serviceName, String agent, String clusters, String clientIP, int udpPort,
|
||||
String env, boolean isCheck, String app, String tid, boolean healthyOnly) throws Exception {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
Service domObj = serviceManager.getService(namespaceId, dom);
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (domObj == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "dom not found: " + dom);
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "service not found: " + serviceName);
|
||||
}
|
||||
|
||||
checkIfDisabled(domObj);
|
||||
checkIfDisabled(service);
|
||||
|
||||
long cacheMillis = switchDomain.getDefaultCacheMillis();
|
||||
|
||||
// now try to enable the push
|
||||
try {
|
||||
if (udpPort > 0 && pushService.canEnablePush(agent)) {
|
||||
pushService.addClient(namespaceId, dom,
|
||||
pushService.addClient(namespaceId, serviceName,
|
||||
clusters,
|
||||
agent,
|
||||
new InetSocketAddress(clientIP, udpPort),
|
||||
pushDataSource,
|
||||
tid,
|
||||
app);
|
||||
cacheMillis = switchDomain.getPushCacheMillis(dom);
|
||||
cacheMillis = switchDomain.getPushCacheMillis(serviceName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.error("[NACOS-API] failed to added push client", e);
|
||||
@ -398,28 +395,29 @@ public class InstanceController {
|
||||
|
||||
List<Instance> srvedIPs;
|
||||
|
||||
srvedIPs = domObj.srvIPs(Arrays.asList(StringUtils.split(clusters, ",")));
|
||||
srvedIPs = service.srvIPs(Arrays.asList(StringUtils.split(clusters, ",")));
|
||||
|
||||
// filter ips using selector:
|
||||
if (domObj.getSelector() != null && StringUtils.isNotBlank(clientIP)) {
|
||||
srvedIPs = domObj.getSelector().select(clientIP, srvedIPs);
|
||||
if (service.getSelector() != null && StringUtils.isNotBlank(clientIP)) {
|
||||
srvedIPs = service.getSelector().select(clientIP, srvedIPs);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(srvedIPs)) {
|
||||
|
||||
if (Loggers.DEBUG_LOG.isDebugEnabled()) {
|
||||
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + dom);
|
||||
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName);
|
||||
}
|
||||
|
||||
result.put("hosts", new JSONArray());
|
||||
result.put("dom", dom);
|
||||
result.put("dom", serviceName);
|
||||
result.put("name", serviceName);
|
||||
result.put("cacheMillis", cacheMillis);
|
||||
result.put("lastRefTime", System.currentTimeMillis());
|
||||
result.put("checksum", domObj.getChecksum() + System.currentTimeMillis());
|
||||
result.put("checksum", service.getChecksum() + System.currentTimeMillis());
|
||||
result.put("useSpecifiedURL", false);
|
||||
result.put("clusters", clusters);
|
||||
result.put("env", env);
|
||||
result.put("metadata", domObj.getMetadata());
|
||||
result.put("metadata", service.getMetadata());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -435,11 +433,11 @@ public class InstanceController {
|
||||
result.put("reachProtectThreshold", false);
|
||||
}
|
||||
|
||||
double threshold = domObj.getProtectThreshold();
|
||||
double threshold = service.getProtectThreshold();
|
||||
|
||||
if ((float) ipMap.get(Boolean.TRUE).size() / srvedIPs.size() <= threshold) {
|
||||
|
||||
Loggers.SRV_LOG.warn("protect threshold reached, return all ips, dom: {}", dom);
|
||||
Loggers.SRV_LOG.warn("protect threshold reached, return all ips, service: {}", serviceName);
|
||||
if (isCheck) {
|
||||
result.put("reachProtectThreshold", true);
|
||||
}
|
||||
@ -449,7 +447,7 @@ public class InstanceController {
|
||||
}
|
||||
|
||||
if (isCheck) {
|
||||
result.put("protectThreshold", domObj.getProtectThreshold());
|
||||
result.put("protectThreshold", service.getProtectThreshold());
|
||||
result.put("reachLocalSiteCallThreshold", false);
|
||||
|
||||
return new JSONObject();
|
||||
@ -485,14 +483,15 @@ public class InstanceController {
|
||||
|
||||
result.put("hosts", hosts);
|
||||
|
||||
result.put("dom", dom);
|
||||
result.put("dom", serviceName);
|
||||
result.put("name", serviceName);
|
||||
result.put("cacheMillis", cacheMillis);
|
||||
result.put("lastRefTime", System.currentTimeMillis());
|
||||
result.put("checksum", domObj.getChecksum() + System.currentTimeMillis());
|
||||
result.put("checksum", service.getChecksum() + System.currentTimeMillis());
|
||||
result.put("useSpecifiedURL", false);
|
||||
result.put("clusters", clusters);
|
||||
result.put("env", env);
|
||||
result.put("metadata", domObj.getMetadata());
|
||||
result.put("metadata", service.getMetadata());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -134,14 +134,14 @@ public class OperatorController {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
int domCount = serviceManager.getServiceCount();
|
||||
int serviceCount = serviceManager.getServiceCount();
|
||||
int ipCount = serviceManager.getInstanceCount();
|
||||
|
||||
int responsibleDomCount = serviceManager.getResponsibleServiceCount();
|
||||
int responsibleIPCount = serviceManager.getResponsibleInstanceCount();
|
||||
|
||||
result.put("status", serverStatusManager.getServerStatus().name());
|
||||
result.put("serviceCount", domCount);
|
||||
result.put("serviceCount", serviceCount);
|
||||
result.put("instanceCount", ipCount);
|
||||
result.put("responsibleServiceCount", responsibleDomCount);
|
||||
result.put("responsibleInstanceCount", responsibleIPCount);
|
||||
@ -160,7 +160,7 @@ public class OperatorController {
|
||||
Service service = serviceManager.getService(namespaceId, dom);
|
||||
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("dom not found");
|
||||
throw new IllegalArgumentException("service not found");
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
@ -187,7 +187,7 @@ public class OperatorController {
|
||||
Service service = serviceManager.getService(namespaceId, dom);
|
||||
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("dom not found");
|
||||
throw new IllegalArgumentException("service not found");
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
@ -62,7 +62,7 @@ public class RaftController {
|
||||
private RaftConsistencyServiceImpl raftConsistencyService;
|
||||
|
||||
@Autowired
|
||||
private ServiceManager domainsManager;
|
||||
private ServiceManager serviceManager;
|
||||
|
||||
@Autowired
|
||||
private RaftCore raftCore;
|
||||
@ -192,7 +192,7 @@ public class RaftController {
|
||||
response.setHeader("Content-Encode", "gzip");
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("doms", domainsManager.getServiceCount());
|
||||
result.put("services", serviceManager.getServiceCount());
|
||||
result.put("peers", raftCore.getPeers());
|
||||
|
||||
return result;
|
||||
|
@ -29,7 +29,6 @@ import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.selector.LabelSelector;
|
||||
import com.alibaba.nacos.naming.selector.NoneSelector;
|
||||
import com.alibaba.nacos.naming.selector.Selector;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -85,7 +84,7 @@ public class ServiceController {
|
||||
service.setSelector(parseSelector(selector));
|
||||
service.setNamespaceId(namespaceId);
|
||||
|
||||
// now valid the dom. if failed, exception will be thrown
|
||||
// now valid the service. if failed, exception will be thrown
|
||||
service.setLastModifiedMillis(System.currentTimeMillis());
|
||||
service.recalculateChecksum();
|
||||
service.valid();
|
||||
@ -158,9 +157,9 @@ public class ServiceController {
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
|
||||
|
||||
List<String> doms = serviceManager.getAllDomNamesList(namespaceId);
|
||||
List<String> serviceNameList = serviceManager.getAllServiceNameList(namespaceId);
|
||||
|
||||
if (doms == null || doms.isEmpty()) {
|
||||
if (serviceNameList == null || serviceNameList.isEmpty()) {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "No service exist in " + namespaceId);
|
||||
}
|
||||
|
||||
@ -181,10 +180,10 @@ public class ServiceController {
|
||||
String[] factors = terms[0].split("\\.");
|
||||
switch (factors[0]) {
|
||||
case "INSTANCE":
|
||||
doms = filterInstanceMetadata(namespaceId, doms, factors[factors.length - 1], terms[1].replace("'", ""));
|
||||
serviceNameList = filterInstanceMetadata(namespaceId, serviceNameList, factors[factors.length - 1], terms[1].replace("'", ""));
|
||||
break;
|
||||
case "SERVICE":
|
||||
doms = filterServiceMetadata(namespaceId, doms, factors[factors.length - 1], terms[1].replace("'", ""));
|
||||
serviceNameList = filterServiceMetadata(namespaceId, serviceNameList, factors[factors.length - 1], terms[1].replace("'", ""));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -202,14 +201,14 @@ public class ServiceController {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (end > doms.size()) {
|
||||
end = doms.size();
|
||||
if (end > serviceNameList.size()) {
|
||||
end = serviceNameList.size();
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put("doms", doms.subList(start, end));
|
||||
result.put("count", doms.size());
|
||||
result.put("doms", serviceNameList.subList(start, end));
|
||||
result.put("count", serviceNameList.size());
|
||||
|
||||
return result;
|
||||
|
||||
@ -225,82 +224,64 @@ public class ServiceController {
|
||||
String metadata = WebUtils.optional(request, "metadata", StringUtils.EMPTY);
|
||||
String selector = WebUtils.optional(request, "selector", StringUtils.EMPTY);
|
||||
|
||||
Service domain = serviceManager.getService(namespaceId, serviceName);
|
||||
if (domain == null) {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "service " + serviceName + " not found!");
|
||||
}
|
||||
|
||||
domain.setProtectThreshold(protectThreshold);
|
||||
service.setProtectThreshold(protectThreshold);
|
||||
|
||||
Map<String, String> metadataMap = UtilsAndCommons.parseMetadata(metadata);
|
||||
domain.setMetadata(metadataMap);
|
||||
service.setMetadata(metadataMap);
|
||||
|
||||
domain.setSelector(parseSelector(selector));
|
||||
service.setSelector(parseSelector(selector));
|
||||
|
||||
domain.setLastModifiedMillis(System.currentTimeMillis());
|
||||
domain.recalculateChecksum();
|
||||
domain.valid();
|
||||
service.setLastModifiedMillis(System.currentTimeMillis());
|
||||
service.recalculateChecksum();
|
||||
service.valid();
|
||||
|
||||
serviceManager.addOrReplaceService(domain);
|
||||
serviceManager.addOrReplaceService(service);
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping("/allDomNames")
|
||||
public JSONObject allDomNames(HttpServletRequest request) throws Exception {
|
||||
@RequestMapping("/names")
|
||||
public JSONObject searchService(HttpServletRequest request) {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, StringUtils.EMPTY);
|
||||
String expr = WebUtils.optional(request, "expr", StringUtils.EMPTY);
|
||||
boolean responsibleOnly = Boolean.parseBoolean(WebUtils.optional(request, "responsibleOnly", "false"));
|
||||
|
||||
Map<String, Set<String>> doms = new HashMap<>(16);
|
||||
Map<String, List<Service>> services = new HashMap<>(16);
|
||||
if (StringUtils.isNotBlank(namespaceId)) {
|
||||
services.put(namespaceId, serviceManager.searchServices(namespaceId, ".*" + expr + ".*"));
|
||||
} else {
|
||||
for (String namespace : serviceManager.getAllNamespaces()) {
|
||||
services.put(namespace, serviceManager.searchServices(namespace, ".*" + expr + ".*"));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Set<String>> domMap = serviceManager.getAllServiceNames();
|
||||
|
||||
for (String namespaceId : domMap.keySet()) {
|
||||
doms.put(namespaceId, new HashSet<>());
|
||||
for (String dom : domMap.get(namespaceId)) {
|
||||
if (distroMapper.responsible(dom) || !responsibleOnly) {
|
||||
doms.get(namespaceId).add(dom);
|
||||
Map<String, Set<String>> serviceNameMap = new HashMap<>();
|
||||
for (String namespace : services.keySet()) {
|
||||
serviceNameMap.put(namespace, new HashSet<>());
|
||||
for (Service service : services.get(namespace)) {
|
||||
if (distroMapper.responsible(service.getName()) || !responsibleOnly) {
|
||||
serviceNameMap.get(namespace).add(service.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put("doms", doms);
|
||||
result.put("count", doms.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/names")
|
||||
public JSONObject searchService(HttpServletRequest request) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String expr = WebUtils.required(request, "expr");
|
||||
|
||||
List<Service> doms
|
||||
= serviceManager.searchServices(namespaceId, ".*" + expr + ".*");
|
||||
|
||||
if (CollectionUtils.isEmpty(doms)) {
|
||||
result.put("doms", Collections.emptyList());
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray domArray = new JSONArray();
|
||||
for (Service dom : doms) {
|
||||
domArray.add(dom.getName());
|
||||
}
|
||||
|
||||
result.put("doms", domArray);
|
||||
result.put("services", serviceNameMap);
|
||||
result.put("count", services.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/serviceStatus")
|
||||
public String serviceStatus(HttpServletRequest request) {
|
||||
//format: dom1@@checksum@@@dom2@@checksum
|
||||
//format: service1@@checksum@@@service2@@checksum
|
||||
String statuses = WebUtils.required(request, "statuses");
|
||||
String serverIP = WebUtils.optional(request, "clientIP", "");
|
||||
|
||||
@ -319,22 +300,22 @@ public class ServiceController {
|
||||
if (entry == null || StringUtils.isEmpty(entry.getKey()) || StringUtils.isEmpty(entry.getValue())) {
|
||||
continue;
|
||||
}
|
||||
String dom = entry.getKey();
|
||||
String serviceName = entry.getKey();
|
||||
String checksum = entry.getValue();
|
||||
Service domain = serviceManager.getService(checksums.namespaceId, dom);
|
||||
Service service = serviceManager.getService(checksums.namespaceId, serviceName);
|
||||
|
||||
if (domain == null) {
|
||||
if (service == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
domain.recalculateChecksum();
|
||||
service.recalculateChecksum();
|
||||
|
||||
if (!checksum.equals(domain.getChecksum())) {
|
||||
if (!checksum.equals(service.getChecksum())) {
|
||||
if (Loggers.SRV_LOG.isDebugEnabled()) {
|
||||
Loggers.SRV_LOG.debug("checksum of {} is not consistent, remote: {}, checksum: {}, local: {}",
|
||||
dom, serverIP, checksum, domain.getChecksum());
|
||||
serviceName, serverIP, checksum, service.getChecksum());
|
||||
}
|
||||
serviceManager.addUpdatedService2Queue(checksums.namespaceId, dom, serverIP, checksum);
|
||||
serviceManager.addUpdatedService2Queue(checksums.namespaceId, serviceName, serverIP, checksum);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -349,7 +330,7 @@ public class ServiceController {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
UtilsAndCommons.DEFAULT_NAMESPACE_ID);
|
||||
String serviceName = WebUtils.required(request, "serviceName");
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (service == null) {
|
||||
|
@ -83,13 +83,13 @@ public class DistroMapper implements ServerChangeListener {
|
||||
return target >= index && target <= lastIndex;
|
||||
}
|
||||
|
||||
public String mapSrv(String dom) {
|
||||
public String mapSrv(String serviceName) {
|
||||
if (CollectionUtils.isEmpty(healthyList) || !switchDomain.distroEnabled) {
|
||||
return NetUtils.localServer();
|
||||
}
|
||||
|
||||
try {
|
||||
return healthyList.get(distroHash(dom) % healthyList.size());
|
||||
return healthyList.get(distroHash(serviceName) % healthyList.size());
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("distro mapper failed, return localhost: " + NetUtils.localServer(), e);
|
||||
|
||||
@ -97,8 +97,8 @@ public class DistroMapper implements ServerChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
public int distroHash(String dom) {
|
||||
return Math.abs(dom.hashCode() % Integer.MAX_VALUE);
|
||||
public int distroHash(String serviceName) {
|
||||
return Math.abs(serviceName.hashCode() % Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,7 +242,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
stringBuilder.append(instance.toIPAddr()).append("_").append(instance.isValid()).append(",");
|
||||
}
|
||||
|
||||
Loggers.EVT_LOG.info("[IP-UPDATED] dom: {}, ips: {}", getName(), stringBuilder.toString());
|
||||
Loggers.EVT_LOG.info("[IP-UPDATED] service: {}, ips: {}", getName(), stringBuilder.toString());
|
||||
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
for (String cluster : clusters) {
|
||||
Cluster clusterObj = clusterMap.get(cluster);
|
||||
if (clusterObj == null) {
|
||||
throw new IllegalArgumentException("can not find cluster: " + cluster + ", dom:" + getName());
|
||||
throw new IllegalArgumentException("can not find cluster: " + cluster + ", service:" + getName());
|
||||
}
|
||||
|
||||
allIPs.addAll(clusterObj.allIPs());
|
||||
@ -308,13 +308,13 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public String getDomString() {
|
||||
Map<Object, Object> domain = new HashMap<Object, Object>(10);
|
||||
Service vDom = this;
|
||||
public String getServiceString() {
|
||||
Map<Object, Object> serviceObject = new HashMap<Object, Object>(10);
|
||||
Service service = this;
|
||||
|
||||
domain.put("name", vDom.getName());
|
||||
serviceObject.put("name", service.getName());
|
||||
|
||||
List<Instance> ips = vDom.allIPs();
|
||||
List<Instance> ips = service.allIPs();
|
||||
int invalidIPCount = 0;
|
||||
int ipCount = 0;
|
||||
for (Instance ip : ips) {
|
||||
@ -325,17 +325,17 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
ipCount++;
|
||||
}
|
||||
|
||||
domain.put("ipCount", ipCount);
|
||||
domain.put("invalidIPCount", invalidIPCount);
|
||||
serviceObject.put("ipCount", ipCount);
|
||||
serviceObject.put("invalidIPCount", invalidIPCount);
|
||||
|
||||
domain.put("owners", vDom.getOwners());
|
||||
domain.put("token", vDom.getToken());
|
||||
serviceObject.put("owners", service.getOwners());
|
||||
serviceObject.put("token", service.getToken());
|
||||
|
||||
domain.put("protectThreshold", vDom.getProtectThreshold());
|
||||
serviceObject.put("protectThreshold", service.getProtectThreshold());
|
||||
|
||||
List<Object> clustersList = new ArrayList<Object>();
|
||||
|
||||
for (Map.Entry<String, Cluster> entry : vDom.getClusterMap().entrySet()) {
|
||||
for (Map.Entry<String, Cluster> entry : service.getClusterMap().entrySet()) {
|
||||
Cluster cluster = entry.getValue();
|
||||
|
||||
Map<Object, Object> clusters = new HashMap<Object, Object>(10);
|
||||
@ -350,9 +350,9 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
clustersList.add(clusters);
|
||||
}
|
||||
|
||||
domain.put("clusters", clustersList);
|
||||
serviceObject.put("clusters", clustersList);
|
||||
|
||||
return JSON.toJSONString(domain);
|
||||
return JSON.toJSONString(serviceObject);
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
@ -390,27 +390,27 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
public void update(Service vDom) {
|
||||
|
||||
if (!StringUtils.equals(token, vDom.getToken())) {
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] dom: {}, token: {} -> {}", getName(), token, vDom.getToken());
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] service: {}, token: {} -> {}", getName(), token, vDom.getToken());
|
||||
token = vDom.getToken();
|
||||
}
|
||||
|
||||
if (!ListUtils.isEqualList(owners, vDom.getOwners())) {
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] dom: {}, owners: {} -> {}", getName(), owners, vDom.getOwners());
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] service: {}, owners: {} -> {}", getName(), owners, vDom.getOwners());
|
||||
owners = vDom.getOwners();
|
||||
}
|
||||
|
||||
if (getProtectThreshold() != vDom.getProtectThreshold()) {
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] dom: {}, protectThreshold: {} -> {}", getName(), getProtectThreshold(), vDom.getProtectThreshold());
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] service: {}, protectThreshold: {} -> {}", getName(), getProtectThreshold(), vDom.getProtectThreshold());
|
||||
setProtectThreshold(vDom.getProtectThreshold());
|
||||
}
|
||||
|
||||
if (resetWeight != vDom.getResetWeight().booleanValue()) {
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] dom: {}, resetWeight: {} -> {}", getName(), resetWeight, vDom.getResetWeight());
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] service: {}, resetWeight: {} -> {}", getName(), resetWeight, vDom.getResetWeight());
|
||||
resetWeight = vDom.getResetWeight();
|
||||
}
|
||||
|
||||
if (enabled != vDom.getEnabled().booleanValue()) {
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] dom: {}, enabled: {} -> {}", getName(), enabled, vDom.getEnabled());
|
||||
Loggers.SRV_LOG.info("[DOM-UPDATE] service: {}, enabled: {} -> {}", getName(), enabled, vDom.getEnabled());
|
||||
enabled = vDom.getEnabled();
|
||||
}
|
||||
|
||||
@ -435,9 +435,11 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
List<Instance> ips = allIPs();
|
||||
|
||||
StringBuilder ipsString = new StringBuilder();
|
||||
ipsString.append(getDomString());
|
||||
ipsString.append(getServiceString());
|
||||
|
||||
Loggers.SRV_LOG.debug("dom to json: " + getDomString());
|
||||
if (Loggers.SRV_LOG.isDebugEnabled()) {
|
||||
Loggers.SRV_LOG.debug("service to json: " + getServiceString());
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(ips)) {
|
||||
Collections.sort(ips);
|
||||
|
@ -269,7 +269,11 @@ public class ServiceManager implements DataListener<Service> {
|
||||
return namesMap;
|
||||
}
|
||||
|
||||
public List<String> getAllDomNamesList(String namespaceId) {
|
||||
public Set<String> getAllNamespaces() {
|
||||
return serviceMap.keySet();
|
||||
}
|
||||
|
||||
public List<String> getAllServiceNameList(String namespaceId) {
|
||||
if (chooseServiceMap(namespaceId) == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -652,7 +656,7 @@ public class ServiceManager implements DataListener<Service> {
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.error("[DOMAIN-STATUS] Exception while sending service status", e);
|
||||
} finally {
|
||||
UtilsAndCommons.DOMAIN_SYNCHRONIZATION_EXECUTOR.schedule(this, switchDomain.getDomStatusSynchronizationPeriodMillis(), TimeUnit.MILLISECONDS);
|
||||
UtilsAndCommons.DOMAIN_SYNCHRONIZATION_EXECUTOR.schedule(this, switchDomain.getServiceStatusSynchronizationPeriodMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class ClientBeatProcessor implements Runnable {
|
||||
if (!instance.isMarked()) {
|
||||
if (!instance.isValid()) {
|
||||
instance.setValid(true);
|
||||
Loggers.EVT_LOG.info("dom: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: client beat ok",
|
||||
Loggers.EVT_LOG.info("service: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: client beat ok",
|
||||
cluster.getService().getName(), ip, port, cluster.getName(), UtilsAndCommons.LOCALHOST_SITE);
|
||||
getPushService().serviceChanged(service.getNamespaceId(), this.service.getName());
|
||||
}
|
||||
|
@ -148,17 +148,17 @@ public class HealthCheckCommon {
|
||||
pushService.serviceChanged(vDom.getNamespaceId(), vDom.getName());
|
||||
addResult(new HealthCheckResult(vDom.getName(), ip));
|
||||
|
||||
Loggers.EVT_LOG.info("dom: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
|
||||
} else {
|
||||
if (!ip.isMockValid()) {
|
||||
ip.setMockValid(true);
|
||||
Loggers.EVT_LOG.info("dom: {} {PROBE} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {PROBE} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Loggers.EVT_LOG.info("dom: {} {OTHER} {IP-ENABLED} pre-valid: {}:{}@{} in {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-ENABLED} pre-valid: {}:{}@{} in {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), ip.getOKCount(), msg);
|
||||
}
|
||||
}
|
||||
@ -186,15 +186,15 @@ public class HealthCheckCommon {
|
||||
|
||||
pushService.serviceChanged(vDom.getNamespaceId(), vDom.getName());
|
||||
|
||||
Loggers.EVT_LOG.info("dom: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
|
||||
} else {
|
||||
Loggers.EVT_LOG.info("dom: {} {PROBE} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {PROBE} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
|
||||
}
|
||||
|
||||
} else {
|
||||
Loggers.EVT_LOG.info("dom: {} {OTHER} {IP-DISABLED} pre-invalid: {}:{}@{} in {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-DISABLED} pre-invalid: {}:{}@{} in {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), ip.getFailCount(), msg);
|
||||
}
|
||||
}
|
||||
@ -221,12 +221,12 @@ public class HealthCheckCommon {
|
||||
pushService.serviceChanged(vDom.getNamespaceId(), vDom.getName());
|
||||
addResult(new HealthCheckResult(vDom.getName(), ip));
|
||||
|
||||
Loggers.EVT_LOG.info("dom: {} {POS} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
|
||||
} else {
|
||||
if (ip.isMockValid()) {
|
||||
ip.setMockValid(false);
|
||||
Loggers.EVT_LOG.info("dom: {} {PROBE} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}",
|
||||
Loggers.EVT_LOG.info("serviceName: {} {PROBE} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}",
|
||||
cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ public class HealthCheckCommon {
|
||||
|
||||
private void addResult(HealthCheckResult result) {
|
||||
|
||||
if (!switchDomain.getIncrementalList().contains(result.getDom())) {
|
||||
if (!switchDomain.getIncrementalList().contains(result.getServiceName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -252,20 +252,20 @@ public class HealthCheckCommon {
|
||||
}
|
||||
|
||||
static class HealthCheckResult {
|
||||
private String dom;
|
||||
private String serviceName;
|
||||
private Instance instance;
|
||||
|
||||
public HealthCheckResult(String dom, Instance instance) {
|
||||
this.dom = dom;
|
||||
public HealthCheckResult(String serviceName, Instance instance) {
|
||||
this.serviceName = serviceName;
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
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 Instance getInstance() {
|
||||
|
@ -21,7 +21,7 @@ package com.alibaba.nacos.naming.healthcheck;
|
||||
public interface HealthCheckProcessor {
|
||||
|
||||
/**
|
||||
* Run check task for domain
|
||||
* Run check task for service
|
||||
*
|
||||
* @param task check task
|
||||
*/
|
||||
|
@ -58,9 +58,9 @@ public class HealthCheckStatus {
|
||||
try {
|
||||
|
||||
String clusterName = ip.getClusterName();
|
||||
String dom = ip.getServiceName();
|
||||
String serviceName = ip.getServiceName();
|
||||
String datumKey = ip.getDatumKey();
|
||||
return dom + ":"
|
||||
return serviceName + ":"
|
||||
+ clusterName + ":"
|
||||
+ datumKey;
|
||||
} catch (Throwable e) {
|
||||
|
@ -106,7 +106,7 @@ public class HttpHealthCheckProcessor implements HealthCheckProcessor {
|
||||
}
|
||||
|
||||
if (!ip.markChecking()) {
|
||||
SRV_LOG.warn("http check started before last one finished, dom: {}:{}:{}",
|
||||
SRV_LOG.warn("http check started before last one finished, service: {}:{}:{}",
|
||||
task.getCluster().getService().getName(), task.getCluster().getName(), ip.getIp());
|
||||
|
||||
healthCheckCommon.reEvaluateCheckRT(task.getCheckRTNormalized() * 2, task, switchDomain.getHttpHealthParams());
|
||||
|
@ -106,7 +106,7 @@ public class MysqlHealthCheckProcessor implements HealthCheckProcessor {
|
||||
}
|
||||
|
||||
if (!ip.markChecking()) {
|
||||
SRV_LOG.warn("mysql check started before last one finished, dom: {}:{}:{}",
|
||||
SRV_LOG.warn("mysql check started before last one finished, service: {}:{}:{}",
|
||||
task.getCluster().getService().getName(), task.getCluster().getName(), ip.getIp());
|
||||
|
||||
healthCheckCommon.reEvaluateCheckRT(task.getCheckRTNormalized() * 2, task, switchDomain.getMysqlHealthParams());
|
||||
|
@ -123,7 +123,7 @@ public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable {
|
||||
}
|
||||
|
||||
if (!ip.markChecking()) {
|
||||
SRV_LOG.warn("tcp check started before last one finished, dom: "
|
||||
SRV_LOG.warn("tcp check started before last one finished, service: "
|
||||
+ task.getCluster().getService().getName() + ":"
|
||||
+ task.getCluster().getName() + ":"
|
||||
+ ip.getIp() + ":"
|
||||
@ -194,7 +194,7 @@ public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable {
|
||||
SocketChannel channel = (SocketChannel) key.channel();
|
||||
try {
|
||||
if (!beat.isValid()) {
|
||||
//invalid beat means this server is no longer responsible for the current dom
|
||||
//invalid beat means this server is no longer responsible for the current service
|
||||
key.cancel();
|
||||
key.channel().close();
|
||||
|
||||
|
@ -78,11 +78,11 @@ public class ServiceStatusSynchronizer implements Synchronizer {
|
||||
|
||||
String result;
|
||||
try {
|
||||
Loggers.SRV_LOG.info("[STATUS-SYNCHRONIZE] sync dom status from: {}, dom: {}", serverIP, key);
|
||||
Loggers.SRV_LOG.info("[STATUS-SYNCHRONIZE] sync service status from: {}, service: {}", serverIP, key);
|
||||
result = NamingProxy.reqAPI(RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance/" + "listWithHealthStatus", params, serverIP);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("[STATUS-SYNCHRONIZE] Failed to get domain status from " + serverIP, e);
|
||||
Loggers.SRV_LOG.warn("[STATUS-SYNCHRONIZE] Failed to get service status from " + serverIP, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class SwitchDomain implements Cloneable {
|
||||
|
||||
public long serverStatusSynchronizationPeriodMillis = TimeUnit.SECONDS.toMillis(15);
|
||||
|
||||
public long domStatusSynchronizationPeriodMillis = TimeUnit.SECONDS.toMillis(5);
|
||||
public long serviceStatusSynchronizationPeriodMillis = TimeUnit.SECONDS.toMillis(5);
|
||||
|
||||
public boolean disableAddIP = false;
|
||||
|
||||
@ -196,7 +196,7 @@ public class SwitchDomain implements Cloneable {
|
||||
this.distroThreshold = distroThreshold;
|
||||
}
|
||||
|
||||
public long getPushCacheMillis(String dom) {
|
||||
public long getPushCacheMillis(String serviceName) {
|
||||
return defaultPushCacheMillis;
|
||||
}
|
||||
|
||||
@ -208,8 +208,8 @@ public class SwitchDomain implements Cloneable {
|
||||
this.healthCheckEnabled = healthCheckEnabled;
|
||||
}
|
||||
|
||||
public boolean isHealthCheckEnabled(String dom) {
|
||||
return healthCheckEnabled || getHealthCheckWhiteList().contains(dom);
|
||||
public boolean isHealthCheckEnabled(String serviceName) {
|
||||
return healthCheckEnabled || getHealthCheckWhiteList().contains(serviceName);
|
||||
}
|
||||
|
||||
public boolean isDistroEnabled() {
|
||||
@ -260,12 +260,12 @@ public class SwitchDomain implements Cloneable {
|
||||
this.serverStatusSynchronizationPeriodMillis = serverStatusSynchronizationPeriodMillis;
|
||||
}
|
||||
|
||||
public long getDomStatusSynchronizationPeriodMillis() {
|
||||
return domStatusSynchronizationPeriodMillis;
|
||||
public long getServiceStatusSynchronizationPeriodMillis() {
|
||||
return serviceStatusSynchronizationPeriodMillis;
|
||||
}
|
||||
|
||||
public void setDomStatusSynchronizationPeriodMillis(long domStatusSynchronizationPeriodMillis) {
|
||||
this.domStatusSynchronizationPeriodMillis = domStatusSynchronizationPeriodMillis;
|
||||
public void setServiceStatusSynchronizationPeriodMillis(long serviceStatusSynchronizationPeriodMillis) {
|
||||
this.serviceStatusSynchronizationPeriodMillis = serviceStatusSynchronizationPeriodMillis;
|
||||
}
|
||||
|
||||
public boolean isDisableAddIP() {
|
||||
|
@ -41,7 +41,7 @@ public class SwitchEntry {
|
||||
public static final String DISTRO = "distro";
|
||||
public static final String CHECK = "check";
|
||||
public static final String DEFAULT_HEALTH_CHECK_MODE = "defaultHealthCheckMode";
|
||||
public static final String DOM_STATUS_SYNC_PERIOD = "domStatusSynchronizationPeriodMillis";
|
||||
public static final String SERVICE_STATUS_SYNC_PERIOD = "serviceStatusSynchronizationPeriodMillis";
|
||||
public static final String SERVER_STATUS_SYNC_PERIOD = "serverStatusSynchronizationPeriodMillis";
|
||||
public static final String HEALTH_CHECK_TIMES = "healthCheckTimes";
|
||||
public static final String DISABLE_ADD_IP = "disableAddIP";
|
||||
|
@ -56,7 +56,7 @@ public class SwitchManager implements DataListener<SwitchDomain> {
|
||||
try {
|
||||
consistencyService.listen(UtilsAndCommons.getSwitchDomainKey(), this);
|
||||
} catch (NacosException e) {
|
||||
Loggers.SRV_LOG.error("listen switch domain failed.", e);
|
||||
Loggers.SRV_LOG.error("listen switch service failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,14 +218,14 @@ public class SwitchManager implements DataListener<SwitchDomain> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.equals(SwitchEntry.DOM_STATUS_SYNC_PERIOD)) {
|
||||
if (entry.equals(SwitchEntry.SERVICE_STATUS_SYNC_PERIOD)) {
|
||||
Long millis = Long.parseLong(value);
|
||||
|
||||
if (millis < SwitchEntry.MIN_DOM_SYNC_TIME_MIILIS) {
|
||||
throw new IllegalArgumentException("domStatusSynchronizationPeriodMillis is too small(<5000)");
|
||||
throw new IllegalArgumentException("serviceStatusSynchronizationPeriodMillis is too small(<5000)");
|
||||
}
|
||||
|
||||
switchDomain.setDomStatusSynchronizationPeriodMillis(millis);
|
||||
switchDomain.setServiceStatusSynchronizationPeriodMillis(millis);
|
||||
if (!debug) {
|
||||
consistencyService.put(UtilsAndCommons.getSwitchDomainKey(), switchDomain);
|
||||
}
|
||||
@ -369,7 +369,7 @@ public class SwitchManager implements DataListener<SwitchDomain> {
|
||||
switchDomain.setMysqlHealthParams(newSwitchDomain.getMysqlHealthParams());
|
||||
switchDomain.setIncrementalList(newSwitchDomain.getIncrementalList());
|
||||
switchDomain.setServerStatusSynchronizationPeriodMillis(newSwitchDomain.getServerStatusSynchronizationPeriodMillis());
|
||||
switchDomain.setDomStatusSynchronizationPeriodMillis(newSwitchDomain.getDomStatusSynchronizationPeriodMillis());
|
||||
switchDomain.setServiceStatusSynchronizationPeriodMillis(newSwitchDomain.getServiceStatusSynchronizationPeriodMillis());
|
||||
switchDomain.setDisableAddIP(newSwitchDomain.isDisableAddIP());
|
||||
switchDomain.setSendBeatOnly(newSwitchDomain.isSendBeatOnly());
|
||||
switchDomain.setLimitedUrlMap(newSwitchDomain.getLimitedUrlMap());
|
||||
|
@ -155,7 +155,7 @@ public class UtilsAndCommons {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setName("nacos.naming.domains.worker");
|
||||
t.setName("nacos.naming.service.worker");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
}
|
||||
@ -166,7 +166,7 @@ public class UtilsAndCommons {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setName("nacos.naming.domains.update.processor");
|
||||
t.setName("nacos.naming.service.update.processor");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class MetricsMonitor {
|
||||
private static AtomicInteger mysqlHealthCheck = new AtomicInteger();
|
||||
private static AtomicInteger httpHealthCheck = new AtomicInteger();
|
||||
private static AtomicInteger tcpHealthCheck = new AtomicInteger();
|
||||
private static AtomicInteger domCount = new AtomicInteger();
|
||||
private static AtomicInteger serviceCount = new AtomicInteger();
|
||||
private static AtomicInteger ipCount = new AtomicInteger();
|
||||
private static AtomicLong maxPushCost = new AtomicLong();
|
||||
private static AtomicLong avgPushCost = new AtomicLong();
|
||||
@ -60,8 +60,8 @@ public class MetricsMonitor {
|
||||
|
||||
tags = new ArrayList<Tag>();
|
||||
tags.add(new ImmutableTag("module", "naming"));
|
||||
tags.add(new ImmutableTag("name", "domCount"));
|
||||
Metrics.gauge("nacos_monitor", tags, domCount);
|
||||
tags.add(new ImmutableTag("name", "serviceCount"));
|
||||
Metrics.gauge("nacos_monitor", tags, serviceCount);
|
||||
|
||||
tags = new ArrayList<Tag>();
|
||||
tags.add(new ImmutableTag("module", "naming"));
|
||||
@ -107,7 +107,7 @@ public class MetricsMonitor {
|
||||
}
|
||||
|
||||
public static AtomicInteger getDomCountMonitor() {
|
||||
return domCount;
|
||||
return serviceCount;
|
||||
}
|
||||
|
||||
public static AtomicInteger getIpCountMonitor() {
|
||||
|
@ -103,8 +103,8 @@ public class PerformanceLoggerThread {
|
||||
|
||||
@Scheduled(cron = "0/15 * * * * ?")
|
||||
public void collectmetrics() {
|
||||
int domCount = serviceManager.getServiceCount();
|
||||
MetricsMonitor.getDomCountMonitor().set(domCount);
|
||||
int serviceCount = serviceManager.getServiceCount();
|
||||
MetricsMonitor.getDomCountMonitor().set(serviceCount);
|
||||
|
||||
int ipCount = serviceManager.getInstanceCount();
|
||||
MetricsMonitor.getIpCountMonitor().set(ipCount);
|
||||
@ -132,13 +132,13 @@ public class PerformanceLoggerThread {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int domCount = serviceManager.getServiceCount();
|
||||
int serviceCount = serviceManager.getServiceCount();
|
||||
int ipCount = serviceManager.getInstanceCount();
|
||||
long maxPushMaxCost = getMaxPushCost();
|
||||
long maxPushCost = getMaxPushCost();
|
||||
long avgPushCost = getAvgPushCost();
|
||||
|
||||
Loggers.PERFORMANCE_LOG.info("PERFORMANCE:" + "|" + domCount + "|" + ipCount + "|" + maxPushCost + "|" + avgPushCost);
|
||||
Loggers.PERFORMANCE_LOG.info("PERFORMANCE:" + "|" + serviceCount + "|" + ipCount + "|" + maxPushCost + "|" + avgPushCost);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("[PERFORMANCE] Exception while print performance log.", e);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class PushService {
|
||||
}
|
||||
|
||||
public void addClient(String namespaceId,
|
||||
String dom,
|
||||
String serviceName,
|
||||
String clusters,
|
||||
String agent,
|
||||
InetSocketAddress socketAddr,
|
||||
@ -138,7 +138,7 @@ public class PushService {
|
||||
String app) {
|
||||
|
||||
PushClient client = new PushService.PushClient(namespaceId,
|
||||
dom,
|
||||
serviceName,
|
||||
clusters,
|
||||
agent,
|
||||
socketAddr,
|
||||
@ -213,8 +213,8 @@ public class PushService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPushCacheKey(String dom, String clientIP, String agent) {
|
||||
return dom + UtilsAndCommons.CACHE_KEY_SPLITER + agent;
|
||||
public static String getPushCacheKey(String serviceName, String clientIP, String agent) {
|
||||
return serviceName + UtilsAndCommons.CACHE_KEY_SPLITER + agent;
|
||||
}
|
||||
|
||||
public void serviceChanged(final String namespaceId, final String serviceName) {
|
||||
|
@ -31,7 +31,7 @@ import org.mockito.MockitoAnnotations;
|
||||
public class BaseTest {
|
||||
|
||||
@Mock
|
||||
public ServiceManager domainsManager;
|
||||
public ServiceManager serviceManager;
|
||||
|
||||
@Mock
|
||||
public RaftPeerSet peerSet;
|
||||
|
@ -69,22 +69,22 @@ public class InstanceControllerTest extends BaseTest {
|
||||
@Test
|
||||
public void registerInstance() throws Exception {
|
||||
|
||||
Service domain = new Service();
|
||||
domain.setName("nacos.test.1");
|
||||
Service service = new Service();
|
||||
service.setName("nacos.test.1");
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
cluster.setService(domain);
|
||||
domain.addCluster(cluster);
|
||||
cluster.setService(service);
|
||||
service.addCluster(cluster);
|
||||
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("1.1.1.1");
|
||||
instance.setPort(9999);
|
||||
List<Instance> ipList = new ArrayList<Instance>();
|
||||
ipList.add(instance);
|
||||
domain.updateIPs(ipList, false);
|
||||
service.updateIPs(ipList, false);
|
||||
|
||||
Mockito.when(domainsManager.getService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(domain);
|
||||
Mockito.when(serviceManager.getService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(service);
|
||||
|
||||
MockHttpServletRequestBuilder builder =
|
||||
MockMvcRequestBuilders.put("/naming/instance")
|
||||
@ -113,13 +113,13 @@ public class InstanceControllerTest extends BaseTest {
|
||||
@Test
|
||||
public void getInstances() throws Exception {
|
||||
|
||||
Service domain = new Service();
|
||||
domain.setName("nacos.test.1");
|
||||
Service service = new Service();
|
||||
service.setName("nacos.test.1");
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
cluster.setService(domain);
|
||||
domain.addCluster(cluster);
|
||||
cluster.setService(service);
|
||||
service.addCluster(cluster);
|
||||
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("10.10.10.10");
|
||||
@ -127,9 +127,9 @@ public class InstanceControllerTest extends BaseTest {
|
||||
instance.setWeight(2.0);
|
||||
List<Instance> ipList = new ArrayList<Instance>();
|
||||
ipList.add(instance);
|
||||
domain.updateIPs(ipList, false);
|
||||
service.updateIPs(ipList, false);
|
||||
|
||||
Mockito.when(domainsManager.getService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(domain);
|
||||
Mockito.when(serviceManager.getService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1")).thenReturn(service);
|
||||
|
||||
MockHttpServletRequestBuilder builder =
|
||||
MockMvcRequestBuilders.get("/v1/ns/instances")
|
||||
@ -139,7 +139,7 @@ public class InstanceControllerTest extends BaseTest {
|
||||
String actualValue = response.getContentAsString();
|
||||
JSONObject result = JSON.parseObject(actualValue);
|
||||
|
||||
Assert.assertEquals("nacos.test.1", result.getString("dom"));
|
||||
Assert.assertEquals("nacos.test.1", result.getString("serviceName"));
|
||||
JSONArray hosts = result.getJSONArray("hosts");
|
||||
Assert.assertTrue(hosts != null);
|
||||
Assert.assertNotNull(hosts);
|
||||
|
@ -33,12 +33,12 @@ public class ClusterTest {
|
||||
@Before
|
||||
public void before() {
|
||||
|
||||
Service domain = new Service();
|
||||
domain.setName("nacos.domain.1");
|
||||
Service service = new Service();
|
||||
service.setName("nacos.service.1");
|
||||
|
||||
cluster = new Cluster();
|
||||
cluster.setName("nacos-cluster-1");
|
||||
cluster.setService(domain);
|
||||
cluster.setService(service);
|
||||
cluster.setDefCkport(80);
|
||||
cluster.setDefIPPort(8080);
|
||||
}
|
||||
@ -56,10 +56,10 @@ public class ClusterTest {
|
||||
healthCheckConfig.setHeaders("Client-Version:nacos-test-1");
|
||||
newCluster.setHealthChecker(healthCheckConfig);
|
||||
|
||||
Service domain = new Service();
|
||||
domain.setName("nacos.domain.2");
|
||||
Service service = new Service();
|
||||
service.setName("nacos.service.2");
|
||||
|
||||
newCluster.setService(domain);
|
||||
newCluster.setService(service);
|
||||
|
||||
cluster.update(newCluster);
|
||||
|
||||
|
@ -30,32 +30,32 @@ import java.util.Map;
|
||||
*/
|
||||
public class DomainTest {
|
||||
|
||||
private Service domain;
|
||||
private Service service;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
domain = new Service();
|
||||
domain.setName("nacos.domain.1");
|
||||
service = new Service();
|
||||
service.setName("nacos.service.1");
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
cluster.setService(domain);
|
||||
domain.addCluster(cluster);
|
||||
cluster.setService(service);
|
||||
service.addCluster(cluster);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDomain() {
|
||||
|
||||
Service newDomain = new Service();
|
||||
newDomain.setName("nacos.domain.1");
|
||||
newDomain.setName("nacos.service.1");
|
||||
newDomain.setProtectThreshold(0.7f);
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
cluster.setService(newDomain);
|
||||
newDomain.addCluster(cluster);
|
||||
|
||||
domain.update(newDomain);
|
||||
service.update(newDomain);
|
||||
|
||||
Assert.assertEquals(0.7f, domain.getProtectThreshold(), 0.0001f);
|
||||
Assert.assertEquals(0.7f, service.getProtectThreshold(), 0.0001f);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -63,9 +63,9 @@ public class DomainTest {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("nacos-cluster-1");
|
||||
|
||||
domain.addCluster(cluster);
|
||||
service.addCluster(cluster);
|
||||
|
||||
Map<String, Cluster> clusterMap = domain.getClusterMap();
|
||||
Map<String, Cluster> clusterMap = service.getClusterMap();
|
||||
Assert.assertNotNull(clusterMap);
|
||||
Assert.assertEquals(2, clusterMap.size());
|
||||
Assert.assertTrue(clusterMap.containsKey("nacos-cluster-1"));
|
||||
@ -90,9 +90,9 @@ public class DomainTest {
|
||||
|
||||
instances.setInstanceMap(instanceMap);
|
||||
|
||||
domain.onChange("iplist", instances);
|
||||
service.onChange("iplist", instances);
|
||||
|
||||
List<Instance> ips = domain.allIPs();
|
||||
List<Instance> ips = service.allIPs();
|
||||
|
||||
Assert.assertNotNull(ips);
|
||||
Assert.assertEquals(1, ips.size());
|
||||
|
@ -36,27 +36,25 @@ import java.util.List;
|
||||
@WebAppConfiguration
|
||||
public class DomainsManagerTest extends BaseTest {
|
||||
|
||||
private ServiceManager domainsManager;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
super.before();
|
||||
domainsManager = new ServiceManager();
|
||||
serviceManager = new ServiceManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easyRemoveDom() throws Exception {
|
||||
domainsManager.easyRemoveService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1");
|
||||
serviceManager.easyRemoveService(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchDom() throws Exception {
|
||||
Service domain = new Service();
|
||||
domain.setName("nacos.test.1");
|
||||
Service service = new Service();
|
||||
service.setName("nacos.test.1");
|
||||
|
||||
domainsManager.chooseServiceMap(UtilsAndCommons.DEFAULT_NAMESPACE_ID).put("nacos.test.1", domain);
|
||||
serviceManager.chooseServiceMap(UtilsAndCommons.DEFAULT_NAMESPACE_ID).put("nacos.test.1", service);
|
||||
|
||||
List<Service> list = domainsManager.searchServices(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.*");
|
||||
List<Service> list = serviceManager.searchServices(UtilsAndCommons.DEFAULT_NAMESPACE_ID, "nacos.test.*");
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertEquals(1, list.size());
|
||||
Assert.assertEquals("nacos.test.1", list.get(0).getName());
|
||||
|
Loading…
Reference in New Issue
Block a user