diff --git a/address/pom.xml b/address/pom.xml index b822cb2bf..0acb2cebf 100644 --- a/address/pom.xml +++ b/address/pom.xml @@ -16,7 +16,7 @@ nacos-all com.alibaba.nacos - 1.1.3 + 1.1.4 4.0.0 diff --git a/api/pom.xml b/api/pom.xml index ee6d89d24..c439d997e 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -16,7 +16,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 4.0.0 diff --git a/client/pom.xml b/client/pom.xml index 975f2862f..8f828e9fc 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -16,7 +16,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml diff --git a/cmdb/pom.xml b/cmdb/pom.xml index b679a7160..12a8a3abb 100644 --- a/cmdb/pom.xml +++ b/cmdb/pom.xml @@ -18,7 +18,7 @@ nacos-all com.alibaba.nacos - 1.1.3 + 1.1.4 ../pom.xml 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index b8b2adc04..f307af052 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml 4.0.0 diff --git a/config/pom.xml b/config/pom.xml index fe7aa30a2..00780d736 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -17,7 +17,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 4.0.0 diff --git a/console/pom.xml b/console/pom.xml index 1081847f5..d9b43ec84 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 nacos-console diff --git a/core/pom.xml b/core/pom.xml index d8cca04b7..9cf990e4c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml diff --git a/distribution/bin/startup.sh b/distribution/bin/startup.sh index 1054beb49..b3489257f 100644 --- a/distribution/bin/startup.sh +++ b/distribution/bin/startup.sh @@ -104,6 +104,7 @@ else JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" fi +JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000" JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}" JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins/health -jar ${BASE_DIR}/target/${SERVER}.jar" JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}" diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index 4fad462ef..00d21a48e 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -44,3 +44,5 @@ nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/ # nacos.naming.distro.syncRetryDelay=5000 # nacos.naming.data.warmup=true # nacos.naming.expireInstance=true + +nacos.istio.mcp.server.enabled=false diff --git a/distribution/pom.xml b/distribution/pom.xml index 2f20c26a9..8ef686e0e 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml diff --git a/example/pom.xml b/example/pom.xml index 5e9f2c19f..13191c2cc 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml diff --git a/istio/pom.xml b/istio/pom.xml index cfbb1de81..55c4ab9c3 100644 --- a/istio/pom.xml +++ b/istio/pom.xml @@ -18,7 +18,7 @@ nacos-all com.alibaba.nacos - 1.1.3 + 1.1.4 4.0.0 diff --git a/istio/src/main/java/com/alibaba/nacos/istio/mcp/NacosMcpService.java b/istio/src/main/java/com/alibaba/nacos/istio/mcp/NacosMcpService.java index 6aa5ceec7..72a41a3ed 100644 --- a/istio/src/main/java/com/alibaba/nacos/istio/mcp/NacosMcpService.java +++ b/istio/src/main/java/com/alibaba/nacos/istio/mcp/NacosMcpService.java @@ -32,6 +32,7 @@ import io.grpc.stub.StreamObserver; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.PostConstruct; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -64,7 +65,8 @@ public class NacosMcpService extends ResourceSourceGrpc.ResourceSourceImplBase { @Autowired private IstioConfig istioConfig; - public NacosMcpService() { + @PostConstruct + public void init() { if (!istioConfig.isMcpServerEnabled()) { return; } diff --git a/naming/pom.xml b/naming/pom.xml index f5835f6c9..ad55d4a93 100644 --- a/naming/pom.xml +++ b/naming/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ApiController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ApiController.java index 6175fdc43..db2ebbca0 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ApiController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ApiController.java @@ -25,6 +25,7 @@ import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.push.ClientInfo; import com.alibaba.nacos.naming.web.CanDistro; +import com.alibaba.nacos.naming.web.OverrideParameterRequestWrapper; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.codehaus.jackson.util.VersionUtil; @@ -141,13 +142,10 @@ public class ApiController extends InstanceController { @CanDistro @RequestMapping("/clientBeat") - public JSONObject clientBeat(HttpServletRequest request, - @RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, - @RequestParam String beat, - @RequestParam String dom) throws Exception { - - String serviceName = Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + dom; - - return beat(namespaceId, beat, serviceName); + public JSONObject clientBeat(HttpServletRequest request) throws Exception { + OverrideParameterRequestWrapper requestWrapper = OverrideParameterRequestWrapper.buildRequest(request); + requestWrapper.addParameter(CommonParams.SERVICE_NAME, + Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + WebUtils.required(request, "dom")); + return beat(requestWrapper); } } 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 c89577112..1c1a393a8 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 @@ -18,11 +18,13 @@ package com.alibaba.nacos.naming.controllers; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.api.common.Constants; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker; +import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.naming.core.Cluster; import com.alibaba.nacos.naming.core.Service; import com.alibaba.nacos.naming.core.ServiceManager; -import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.naming.healthcheck.HealthCheckType; import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.UtilsAndCommons; @@ -32,9 +34,10 @@ import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; + /** * @author nkorange */ @@ -46,13 +49,16 @@ public class ClusterController { protected ServiceManager serviceManager; @PutMapping - public String update( @RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, - @RequestParam String clusterName, - @RequestParam String serviceName, - @RequestParam String healthChecker, - @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, - @RequestParam String checkPort, - @RequestParam String useInstancePort4Check) throws Exception { + public String update(HttpServletRequest request) throws Exception { + + String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, + Constants.DEFAULT_NAMESPACE_ID); + String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); + String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); + String healthChecker = WebUtils.required(request, "healthChecker"); + String metadata = WebUtils.optional(request, "metadata", StringUtils.EMPTY); + String checkPort = WebUtils.required(request, "checkPort"); + String useInstancePort4Check = WebUtils.required(request, "useInstancePort4Check"); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/HealthController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/HealthController.java index 1c090f9e6..8fef9b240 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/HealthController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/HealthController.java @@ -17,7 +17,9 @@ package com.alibaba.nacos.naming.controllers; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.api.common.Constants; +import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker; +import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.naming.boot.RunningConfig; import com.alibaba.nacos.naming.core.Instance; import com.alibaba.nacos.naming.core.Service; @@ -34,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,23 +69,29 @@ public class HealthController { @CanDistro @PutMapping(value = {"", "/instance"}) - public String update(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, - @RequestParam String serviceName, - @RequestParam(defaultValue = UtilsAndCommons.DEFAULT_CLUSTER_NAME) String clusterName, - @RequestParam String ip, - @RequestParam int port, - @RequestParam(name = "healthy", defaultValue = StringUtils.EMPTY) String healthyString, - @RequestParam(defaultValue = StringUtils.EMPTY) String validString) { + public String update(HttpServletRequest request) { + String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, + Constants.DEFAULT_NAMESPACE_ID); + String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); + String clusterName = WebUtils.optional(request, CommonParams.CLUSTER_NAME + , UtilsAndCommons.DEFAULT_CLUSTER_NAME); + + String ip = WebUtils.required(request, "ip"); + int port = Integer.parseInt(WebUtils.required(request, "port")); + + boolean valid = false; + + String healthyString = WebUtils.optional(request, "healthy", StringUtils.EMPTY); if (StringUtils.isBlank(healthyString)) { - healthyString = validString; + healthyString = WebUtils.optional(request, "valid", StringUtils.EMPTY); } if (StringUtils.isBlank(healthyString)) { throw new IllegalArgumentException("Param 'healthy' is required."); } - boolean valid = BooleanUtils.toBoolean(healthyString); + valid = BooleanUtils.toBoolean(healthyString); Service service = serviceManager.getService(namespaceId, serviceName); // Only health check "none" need update health status with api diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java index 9bf175a11..f46681643 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java @@ -207,14 +207,15 @@ public class InstanceController { @CanDistro @PutMapping("/beat") - public JSONObject beat(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, - @RequestParam String beat, - @RequestParam String serviceName) throws Exception { + public JSONObject beat(HttpServletRequest request) throws Exception { JSONObject result = new JSONObject(); result.put("clientBeatInterval", switchDomain.getClientBeatInterval()); - + String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); + String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, + Constants.DEFAULT_NAMESPACE_ID); + String beat = WebUtils.required(request, "beat"); RsInfo clientBeat = JSON.parseObject(beat, RsInfo.class); if (!switchDomain.isDefaultInstanceEphemeral() && !clientBeat.isEphemeral()) { @@ -445,7 +446,7 @@ public class InstanceController { 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, service: {}", serviceName); if (isCheck) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/RaftController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/RaftController.java index 78a416a1f..ce7740492 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/RaftController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/RaftController.java @@ -20,6 +20,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.common.util.IoUtils; +import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.naming.consistency.Datum; import com.alibaba.nacos.naming.consistency.KeyBuilder; import com.alibaba.nacos.naming.consistency.RecordListener; @@ -33,6 +35,7 @@ import com.alibaba.nacos.naming.misc.NetUtils; import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.web.NeedAuth; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -40,6 +43,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -66,19 +70,24 @@ public class RaftController { @NeedAuth @PostMapping("/vote") - public JSONObject vote(@RequestParam String vote) { + public JSONObject vote(HttpServletRequest request, HttpServletResponse response) throws Exception { RaftPeer peer = raftCore.receivedVote( - JSON.parseObject(vote, RaftPeer.class)); + JSON.parseObject(WebUtils.required(request, "vote"), RaftPeer.class)); return JSON.parseObject(JSON.toJSONString(peer)); } @NeedAuth @PostMapping("/beat") - public JSONObject beat(@RequestBody JSONObject json) throws Exception { + public JSONObject beat(HttpServletRequest request, HttpServletResponse response) throws Exception { - JSONObject beat = json.getJSONObject("beat"); + String entity = new String(IoUtils.tryDecompress(request.getInputStream()), StandardCharsets.UTF_8); + String value = URLDecoder.decode(entity, "UTF-8"); + value = URLDecoder.decode(value, "UTF-8"); + + JSONObject json = JSON.parseObject(value); + JSONObject beat = JSON.parseObject(json.getString("beat")); RaftPeer peer = raftCore.receivedBeat(beat); @@ -87,7 +96,7 @@ public class RaftController { @NeedAuth @GetMapping("/peer") - public JSONObject getPeer() { + public JSONObject getPeer(HttpServletRequest request, HttpServletResponse response) { List peers = raftCore.getPeers(); RaftPeer peer = null; @@ -107,19 +116,24 @@ public class RaftController { @NeedAuth @PutMapping("/datum/reload") - public String reloadDatum(@RequestParam String key) { + public String reloadDatum(HttpServletRequest request, HttpServletResponse response) throws Exception { + String key = WebUtils.required(request, "key"); raftCore.loadDatum(key); return "ok"; } @NeedAuth @PostMapping("/datum") - public String publish(@RequestBody JSONObject json, HttpServletRequest request, HttpServletResponse response) throws Exception { + public String publish(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Content-Encode", "gzip"); + String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); + String value = URLDecoder.decode(entity, "UTF-8"); + JSONObject json = JSON.parseObject(value); + String key = json.getString("key"); if (KeyBuilder.matchInstanceListKey(key)) { raftConsistencyService.put(key, JSON.parseObject(json.getString("value"), Instances.class)); @@ -141,24 +155,23 @@ public class RaftController { @NeedAuth @DeleteMapping("/datum") - public String delete(@RequestParam String key, HttpServletRequest request, HttpServletResponse response) throws Exception { + public String delete(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Content-Encode", "gzip"); - - raftConsistencyService.remove(key); + raftConsistencyService.remove(WebUtils.required(request, "key")); return "ok"; } @NeedAuth @GetMapping("/datum") - public String get(@RequestParam(name = "keys") String keysString, HttpServletRequest request, HttpServletResponse response) throws Exception { + public String get(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Content-Encode", "gzip"); - + String keysString = WebUtils.required(request, "keys"); keysString = URLDecoder.decode(keysString, "UTF-8"); String[] keys = keysString.split(","); List datums = new ArrayList(); @@ -172,7 +185,7 @@ public class RaftController { } @GetMapping("/state") - public JSONObject state(HttpServletRequest request, HttpServletResponse response) { + public JSONObject state(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Cache-Control", "no-cache"); @@ -187,15 +200,18 @@ public class RaftController { @NeedAuth @PostMapping("/datum/commit") - public String onPublish(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) throws Exception { + public String onPublish(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Content-Encode", "gzip"); + String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); + String value = URLDecoder.decode(entity, "UTF-8"); + JSONObject jsonObject = JSON.parseObject(value); String key = "key"; - RaftPeer source = jsonObject.getObject("source", RaftPeer.class); + RaftPeer source = JSON.parseObject(jsonObject.getString("source"), RaftPeer.class); JSONObject datumJson = jsonObject.getJSONObject("datum"); Datum datum = null; @@ -216,21 +232,26 @@ public class RaftController { @NeedAuth @DeleteMapping("/datum/commit") - public String onDelete(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) throws Exception { + public String onDelete(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Content-Encode", "gzip"); - Datum datum = jsonObject.getObject("datum", Datum.class); - RaftPeer source = jsonObject.getObject("source", RaftPeer.class); + String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); + String value = URLDecoder.decode(entity, "UTF-8"); + value = URLDecoder.decode(value, "UTF-8"); + JSONObject jsonObject = JSON.parseObject(value); + + Datum datum = JSON.parseObject(jsonObject.getString("datum"), Datum.class); + RaftPeer source = JSON.parseObject(jsonObject.getString("source"), RaftPeer.class); raftConsistencyService.onRemove(datum, source); return "ok"; } @GetMapping("/leader") - public JSONObject getLeader() { + public JSONObject getLeader(HttpServletRequest request, HttpServletResponse response) { JSONObject result = new JSONObject(); result.put("leader", JSONObject.toJSONString(raftCore.getLeader())); @@ -238,20 +259,21 @@ public class RaftController { } @GetMapping("/listeners") - public JSONObject getAllListeners() { + public JSONObject getAllListeners(HttpServletRequest request, HttpServletResponse response) { JSONObject result = new JSONObject(); Map> listeners = raftCore.getListeners(); JSONArray listenerArray = new JSONArray(); - listenerArray.addAll(listeners.keySet()); - + for (String key : listeners.keySet()) { + listenerArray.add(key); + } result.put("listeners", listenerArray); return result; } - private static String getAcceptEncoding(HttpServletRequest req) { + public static String getAcceptEncoding(HttpServletRequest req) { String encode = StringUtils.defaultIfEmpty(req.getHeader("Accept-Charset"), "UTF-8"); encode = encode.contains(",") ? encode.substring(0, encode.indexOf(",")) : encode; return encode.contains(";") ? encode.substring(0, encode.indexOf(";")) : encode; 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 8cc677032..d92810ad6 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 @@ -209,11 +209,14 @@ public class ServiceController { } @PutMapping - public String update(HttpServletRequest request,@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, - @RequestParam String serviceName, - @RequestParam(required = false) float protectThreshold, - @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, - @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception { + public String update(HttpServletRequest request) throws Exception { + + String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, + Constants.DEFAULT_NAMESPACE_ID); + String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); + float protectThreshold = NumberUtils.toFloat(WebUtils.required(request, "protectThreshold")); + String metadata = WebUtils.optional(request, "metadata", StringUtils.EMPTY); + String selector = WebUtils.optional(request, "selector", StringUtils.EMPTY); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { 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 01a9806b3..6b8ad1cdf 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 @@ -315,28 +315,16 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(getName()) - .append(service) - .toHashCode(); + return Objects.hash(getName()); } @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { + public boolean equals(Object obj) { + if (!(obj instanceof Cluster)) { return false; } - Cluster cluster = (Cluster) o; - - return new EqualsBuilder() - .append(getName(), cluster.getName()) - .append(service, cluster.service) - .isEquals(); + return getName().equals(((Cluster) obj).getName()); } public int getDefCkport() { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java index 779a9e1f5..9e23c9279 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java @@ -424,6 +424,9 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement updateOrAddCluster(vDom.getClusterMap().values()); remvDeadClusters(this, vDom); + + Loggers.SRV_LOG.info("cluster size, new: {}, old: {}", getClusterMap().size(), vDom.getClusterMap().size()); + recalculateChecksum(); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index 55ed59519..17ea6ae04 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -322,7 +322,7 @@ public class ServiceManager implements RecordListener { if (valid != instance.isHealthy()) { changed = true; instance.setHealthy(valid); - Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}@{}{}", + Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}:{}@{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } @@ -454,30 +454,6 @@ public class ServiceManager implements RecordListener { } } - public void putServiceIfAbsent(Service service, boolean local, Cluster cluster) throws NacosException { - final String namespaceId = service.getNamespaceId(); - final String serviceName = service.getName(); - - if (getService(namespaceId, serviceName) != null) { - return; - } - - Loggers.SRV_LOG.info("creating empty service {}:{}", namespaceId, serviceName); - // now validate the service. if failed, exception will be thrown - service.setLastModifiedMillis(System.currentTimeMillis()); - service.recalculateChecksum(); - if (cluster != null) { - cluster.setService(service); - service.getClusterMap().put(cluster.getName(), cluster); - } - service.validate(); - - putServiceAndInit(service); - if (!local) { - addOrReplaceService(service); - } - } - /** * Register an instance to a service in AP mode. *

diff --git a/pom.xml b/pom.xml index 1a9736119..6509e3a29 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 2018 com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 pom Alibaba NACOS ${project.version} @@ -785,17 +785,5 @@ - - - - - sona - https://oss.sonatype.org/content/repositories/snapshots/ - - - sona - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - diff --git a/test/pom.xml b/test/pom.xml index d36bc462a..0c53d87af 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -17,7 +17,7 @@ com.alibaba.nacos nacos-all - 1.1.3 + 1.1.4 ../pom.xml 4.0.0