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 45bbdf9d7..e15ec0bcb 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 @@ -21,7 +21,6 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.core.utils.WebUtils; -import com.alibaba.nacos.naming.boot.RunningConfig; import com.alibaba.nacos.naming.cluster.ServerMode; import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.Instance; @@ -29,7 +28,6 @@ import com.alibaba.nacos.naming.core.Service; import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.exception.NacosException; import com.alibaba.nacos.naming.healthcheck.RsInfo; -import com.alibaba.nacos.naming.misc.HttpClient; import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.misc.UtilsAndCommons; @@ -45,7 +43,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; -import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.util.*; @@ -251,30 +248,7 @@ public class InstanceController { throw new NacosException(NacosException.SERVER_ERROR, "service not found: " + serviceName + "@" + namespaceId); } - if (!distroMapper.responsible(serviceName)) { - String server = distroMapper.mapSrv(serviceName); - Loggers.EVT_LOG.info("I'm not responsible for {}, proxy it to {}", serviceName, server); - Map proxyParams = new HashMap<>(16); - for (Map.Entry entry : request.getParameterMap().entrySet()) { - String key = entry.getKey(); - String value = entry.getValue()[0]; - proxyParams.put(key, value); - } - - if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) { - server = server + UtilsAndCommons.IP_PORT_SPLITER + RunningConfig.getServerPort(); - } - - String url = "http://" + server + RunningConfig.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance/clientBeat"; - HttpClient.HttpResult httpResult = HttpClient.httpGet(url, null, proxyParams); - - if (httpResult.code != HttpURLConnection.HTTP_OK) { - throw new IllegalArgumentException("failed to proxy client beat to" + server + ", beat: " + beat); - } - } else { - service.processClientBeat(clientBeat); - } + service.processClientBeat(clientBeat); return result; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/PartitionController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/PartitionController.java index 45d7904d0..b9e91dc62 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/PartitionController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/PartitionController.java @@ -32,6 +32,7 @@ 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.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; @@ -61,8 +62,8 @@ public class PartitionController { @Autowired private SwitchDomain switchDomain; - @RequestMapping("/onSync") - public String onSync(HttpServletRequest request, HttpServletResponse response) throws Exception { + @RequestMapping(value = "/datum", method = RequestMethod.PUT) + public String onSyncDatum(HttpServletRequest request, HttpServletResponse response) throws Exception { String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); @@ -88,7 +89,7 @@ public class PartitionController { return "ok"; } - @RequestMapping("/syncTimestamps") + @RequestMapping(value = "/timestamps", method = RequestMethod.PUT) public String syncTimestamps(HttpServletRequest request, HttpServletResponse response) throws Exception { String source = WebUtils.required(request, "source"); String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); @@ -109,7 +110,7 @@ public class PartitionController { return "ok"; } - @RequestMapping("/get") + @RequestMapping(value = "/datum", method = RequestMethod.GET) public void get(HttpServletRequest request, HttpServletResponse response) throws Exception { String keys = WebUtils.required(request, "keys"); String keySplitter = ","; 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 668c8dd54..d73c4336e 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 @@ -296,7 +296,7 @@ public class ServiceController { return result; } - @RequestMapping("/serviceStatus") + @RequestMapping(value = "/status", method = RequestMethod.POST) public String serviceStatus(HttpServletRequest request) { //format: service1@@checksum@@@service2@@checksum String statuses = WebUtils.required(request, "statuses"); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java index b596064eb..5f9e6d0dd 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java @@ -31,11 +31,11 @@ import java.util.*; */ public class NamingProxy { - private static final String DATA_ON_SYNC_URL = "/partition/onSync"; + private static final String DATA_ON_SYNC_URL = "/partition/datum"; - private static final String DATA_GET_URL = "/partition/get"; + private static final String DATA_GET_URL = "/partition/datum"; - private static final String TIMESTAMP_SYNC_URL = "/partition/syncTimestamps"; + private static final String TIMESTAMP_SYNC_URL = "/partition/timestamps"; public static void syncTimestamps(Map timestamps, String server) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java index ab4af2564..41b7d7e73 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java @@ -41,11 +41,11 @@ public class ServiceStatusSynchronizer implements Synchronizer { String url = "http://" + serverIP + ":" + RunningConfig.getServerPort() + RunningConfig.getContextPath() + - UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/serviceStatus"; + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/status"; if (serverIP.contains(UtilsAndCommons.IP_PORT_SPLITER)) { url = "http://" + serverIP + RunningConfig.getContextPath() + - UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/serviceStatus"; + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/status"; } try { diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java index a141c85dc..c7a78f251 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java @@ -60,7 +60,7 @@ public class AutoDeregisterInstance_ITCase { NamingBase.prepareServer(port); if (naming == null) { - naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port); + naming = NamingFactory.createNamingService("127.0.0.1:" + port); } while (true) { @@ -174,7 +174,7 @@ public class AutoDeregisterInstance_ITCase { Assert.assertEquals(instances.size(), 1); BeatInfo beatInfo = new BeatInfo(); - beatInfo.setServiceName(serviceName); + beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName); beatInfo.setIp("127.0.0.1"); beatInfo.setPort(TEST_PORT); @@ -220,12 +220,11 @@ public class AutoDeregisterInstance_ITCase { Assert.assertEquals(1, instances.size()); BeatInfo beatInfo = new BeatInfo(); - beatInfo.setServiceName(serviceName); + beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName); beatInfo.setIp("127.0.0.1"); beatInfo.setPort(TEST_PORT); beatInfo.setCluster("c1"); - namingServiceImpl.getBeatReactor(). addBeatInfo(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName, beatInfo); //TimeUnit.SECONDS.sleep(15); @@ -238,10 +237,10 @@ public class AutoDeregisterInstance_ITCase { instances = naming.getAllInstances(serviceName, Arrays.asList("c2")); Assert.assertEquals(1, instances.size()); + TimeUnit.SECONDS.sleep(5); + instances = naming.getAllInstances(serviceName, Arrays.asList("c1")); Assert.assertEquals(1, instances.size()); - - } public void verifyInstanceList(List instances, int size, String serviceName) throws Exception {