From 56f91e70f713b126abfd8275e1765b85a8cebb09 Mon Sep 17 00:00:00 2001 From: "kaitai.zj" Date: Mon, 25 Feb 2019 20:28:23 +0800 Subject: [PATCH] #821 Registering instance should update valid (health) --- .../java/com/alibaba/nacos/naming/core/Cluster.java | 10 +++++----- .../java/com/alibaba/nacos/naming/web/ApiCommands.java | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java index 9a64f14ae63..4a8dbd3a807 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java @@ -173,12 +173,12 @@ public void updateIPs(List ips) { if (responsible(ip)) { // do not update the ip validation status of updated ips // because the checker has the most precise result - - // Only when ip is not marked, don't we update the health status of IP: - if (!ip.isMarked()) { - ip.setValid(oldIP.isValid()); + if (((VirtualClusterDomain)dom).getEnableHealthCheck() || ((VirtualClusterDomain)dom).getEnableClientBeat()) { + // Only when ip is not marked, don't we update the health status of IP: + if (!ip.isMarked()) { + ip.setValid(oldIP.isValid()); + } } - } else { if (ip.isValid() != oldIP.isValid()) { // ip validation status updated diff --git a/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java b/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java index 52c5423e71f..9b3cd325ba5 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java @@ -526,6 +526,7 @@ private IpAddress getIPAddress(HttpServletRequest request) { cluster = WebUtils.optional(request, "clusterName", UtilsAndCommons.DEFAULT_CLUSTER_NAME); } boolean enabled = BooleanUtils.toBoolean(WebUtils.optional(request, "enable", "true")); + boolean valid = BooleanUtils.toBoolean(WebUtils.optional(request, "valid", "true")); IpAddress ipAddress = new IpAddress(); ipAddress.setPort(Integer.parseInt(port)); @@ -533,6 +534,7 @@ private IpAddress getIPAddress(HttpServletRequest request) { ipAddress.setWeight(Double.parseDouble(weight)); ipAddress.setClusterName(cluster); ipAddress.setEnabled(enabled); + ipAddress.setValid(valid); if (!ipAddress.validate()) { throw new IllegalArgumentException("malfomed ip config: " + ipAddress);