From 216007ff9781ee63b38d54fcd90c12aeef1944e1 Mon Sep 17 00:00:00 2001 From: nkorange Date: Mon, 15 Oct 2018 20:16:55 +0800 Subject: [PATCH] Fix update metadata failed bug, modify health status display words --- .../main/resources/static/public/i18ndoc.js | 4 ++-- .../naming/controllers/CatalogController.java | 20 ++++--------------- .../naming/controllers/ClusterController.java | 10 +++++++++- .../naming/controllers/ServiceController.java | 3 ++- .../nacos/naming/misc/UtilsAndCommons.java | 4 ++++ .../src/main/resources/application.properties | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/console/src/main/resources/static/public/i18ndoc.js b/console/src/main/resources/static/public/i18ndoc.js index 7a7c471d7..a2caa93a2 100644 --- a/console/src/main/resources/static/public/i18ndoc.js +++ b/console/src/main/resources/static/public/i18ndoc.js @@ -473,7 +473,7 @@ window.i18ndoc = { "com.alibaba.nacos.page.serviceManagement.table.column.service_name": "服务名", "com.alibaba.nacos.page.serviceManagement.table.column.cluster_count": "集群数目", "com.alibaba.nacos.page.serviceManagement.table.column.ip_count": "IP数目", - "com.alibaba.nacos.page.serviceManagement.table.column.health_status": "健康程度", + "com.alibaba.nacos.page.serviceManagement.table.column.health_status": "健康实例/所有实例", "com.alibaba.nacos.page.serviceManagement.table.column.operation": "操作", "com.alibaba.nacos.page.serviceManagement.query": "查询", "serviceManagement": "服务列表", @@ -980,7 +980,7 @@ window.i18ndoc = { "com.alibaba.nacos.page.serviceManagement.table.column.service_name": "Service Name", "com.alibaba.nacos.page.serviceManagement.table.column.cluster_count": "Cluster Count", "com.alibaba.nacos.page.serviceManagement.table.column.ip_count": "IP Count", - "com.alibaba.nacos.page.serviceManagement.table.column.health_status": "Health Status", + "com.alibaba.nacos.page.serviceManagement.table.column.health_status": "Healthy Instances/All Instances", "com.alibaba.nacos.page.serviceManagement.table.column.operation": "Operation", "com.alibaba.nacos.page.serviceManagement.query": "Search", "serviceManagement": "Service Management", diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java index 554d561d9..7fb27fd03 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java @@ -31,14 +31,15 @@ import com.alibaba.nacos.naming.view.ServiceDetailView; import com.alibaba.nacos.naming.view.ServiceView; import com.alibaba.nacos.naming.web.BaseServlet; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * @author dungu.zpf @@ -84,20 +85,7 @@ public class CatalogController { } } - double validRatio = validCount * 1.0 / vDomain.allIPs().size(); - - // FIXME: - validRatio = RandomUtils.nextDouble(0, 1.2); - - if (validRatio > 0.9) { - serviceView.setStatus("优"); - } else if (validRatio > 0.6) { - serviceView.setStatus("良"); - } else if (validRatio > 0.3) { - serviceView.setStatus("中"); - } else { - serviceView.setStatus("差"); - } + serviceView.setStatus(validCount + "/" + vDomain.allIPs().size()); domArray.add(serviceView); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java index 8869c03db..f73931707 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java @@ -24,6 +24,9 @@ import com.alibaba.nacos.naming.core.VirtualClusterDomain; import com.alibaba.nacos.naming.exception.NacosException; import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.web.BaseServlet; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -47,7 +50,9 @@ public class ClusterController { String clusterName = BaseServlet.required(request, "clusterName"); String serviceName = BaseServlet.required(request, "serviceName"); String healthChecker = BaseServlet.required(request, "healthChecker"); - String metadata = BaseServlet.required(request, "metadata"); + String metadata = BaseServlet.optional(request, "metadata", StringUtils.EMPTY); + String checkPort = BaseServlet.required(request, "checkPort"); + String useInstancePort4Check = BaseServlet.required(request, "useInstancePort4Check"); VirtualClusterDomain domain = (VirtualClusterDomain) domainsManager.getDomain(serviceName); if (domain == null) { @@ -59,6 +64,9 @@ public class ClusterController { throw new NacosException(NacosException.INVALID_PARAM, "cluster not found:"+ clusterName + ", " + serviceName); } + cluster.setDefCkport(NumberUtils.toInt(checkPort)); + cluster.setUseIPPort4Check(BooleanUtils.toBoolean(useInstancePort4Check)); + JSONObject healthCheckObj = JSON.parseObject(healthChecker); AbstractHealthChecker abstractHealthChecker; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java index 2ba38f0c9..3ef837f3f 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java @@ -22,6 +22,7 @@ import com.alibaba.nacos.naming.exception.NacosException; import com.alibaba.nacos.naming.healthcheck.HealthCheckMode; import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.web.BaseServlet; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; @@ -77,7 +78,7 @@ public class ServiceController { String serviceName = BaseServlet.required(request, "serviceName"); float protectThreshold = NumberUtils.toFloat(BaseServlet.required(request, "protectThreshold")); String healthCheckMode = BaseServlet.required(request, "healthCheckMode"); - String metadata = BaseServlet.required(request, "metadata"); + String metadata = BaseServlet.optional(request, "metadata", StringUtils.EMPTY); VirtualClusterDomain domain = (VirtualClusterDomain) domainsManager.getDomain(serviceName); if (domain == null) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java index 3379c53d1..b1232f5ee 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java @@ -212,6 +212,10 @@ public class UtilsAndCommons { Map metadataMap = new HashMap<>(16); + if (StringUtils.isBlank(metadata)) { + return metadataMap; + } + try { metadataMap = JSON.parseObject(metadata, new TypeReference>(){}); } catch (Exception e) { diff --git a/naming/src/main/resources/application.properties b/naming/src/main/resources/application.properties index 0342d6dde..524265d42 100644 --- a/naming/src/main/resources/application.properties +++ b/naming/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.port=8080 +server.port=8848 server.servlet.context-path=/nacos