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