From 7f3a17c6209aa56f5dcf80079c25104f3050210c Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Thu, 31 Dec 2020 14:24:41 +0800 Subject: [PATCH] Solve conflict with develop branch. --- .../client/naming/NacosNamingService.java | 2 ++ .../remote/http/NamingHttpClientProxy.java | 9 ++++++--- .../service/notify/AsyncNotifyService.java | 4 ++-- .../controller/ServerLoaderController.java | 6 +++--- .../cluster/remote/ClusterRpcClientProxy.java | 6 +++--- .../naming/core/CatalogServiceV1Impl.java | 18 +----------------- .../nacos/naming/utils/ServiceUtil.java | 3 +++ 7 files changed, 20 insertions(+), 28 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java index b35cb02fc..83f7ccfc5 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java @@ -24,6 +24,7 @@ import com.alibaba.nacos.api.naming.listener.EventListener; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.api.naming.pojo.ServiceInfo; +import com.alibaba.nacos.api.naming.utils.NamingUtils; import com.alibaba.nacos.api.selector.AbstractSelector; import com.alibaba.nacos.client.naming.cache.ServiceInfoHolder; import com.alibaba.nacos.client.naming.core.Balancer; @@ -134,6 +135,7 @@ public class NacosNamingService implements NamingService { @Override public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException { + NamingUtils.checkInstanceIsLegal(instance); clientProxy.registerService(serviceName, groupName, instance); } diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/remote/http/NamingHttpClientProxy.java b/client/src/main/java/com/alibaba/nacos/client/naming/remote/http/NamingHttpClientProxy.java index 69b87b762..f99972afd 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/remote/http/NamingHttpClientProxy.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/remote/http/NamingHttpClientProxy.java @@ -49,7 +49,6 @@ import com.alibaba.nacos.common.http.HttpRestResult; import com.alibaba.nacos.common.http.client.NacosRestTemplate; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.http.param.Query; -import com.alibaba.nacos.common.lifecycle.Closeable; import com.alibaba.nacos.common.utils.ConvertUtils; import com.alibaba.nacos.common.utils.HttpMethod; import com.alibaba.nacos.common.utils.IPUtil; @@ -100,6 +99,8 @@ public class NamingHttpClientProxy implements NamingClientProxy { private final PushReceiver pushReceiver; + private final int maxRetry; + private int serverPort = DEFAULT_SERVER_PORT; private ScheduledExecutorService executorService; @@ -117,6 +118,8 @@ public class NamingHttpClientProxy implements NamingClientProxy { this.initRefreshTask(); this.pushReceiver = new PushReceiver(serviceInfoHolder); this.serviceInfoHolder = serviceInfoHolder; + this.maxRetry = ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_REQUEST_DOMAIN_RETRY_COUNT, + String.valueOf(UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT))); } private void initRefreshTask() { @@ -412,7 +415,7 @@ public class NamingHttpClientProxy implements NamingClientProxy { if (serverListManager.isDomain()) { String nacosDomain = serverListManager.getNacosDomain(); - for (int i = 0; i < UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT; i++) { + for (int i = 0; i < maxRetry; i++) { try { return callServer(api, params, body, nacosDomain, method); } catch (NacosException e) { @@ -423,7 +426,7 @@ public class NamingHttpClientProxy implements NamingClientProxy { } } } - + if (servers != null && !servers.isEmpty()) { Random random = new Random(System.currentTimeMillis()); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java index a9679f8bd..3f6db7ee0 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java @@ -37,7 +37,7 @@ import com.alibaba.nacos.config.server.service.trace.ConfigTraceService; import com.alibaba.nacos.config.server.utils.ConfigExecutor; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.core.cluster.Member; -import com.alibaba.nacos.core.cluster.MemberUtils; +import com.alibaba.nacos.core.cluster.MemberUtil; import com.alibaba.nacos.core.cluster.ServerMemberManager; import com.alibaba.nacos.sys.env.EnvUtil; import com.alibaba.nacos.sys.utils.InetUtils; @@ -94,7 +94,7 @@ public class AsyncNotifyService { Queue rpcQueue = new LinkedList(); for (Member member : ipList) { - if (MemberUtils.getSupportedConnectionType(member) == null) { + if (MemberUtil.getSupportedConnectionType(member) == null) { httpQueue.add(new NotifySingleTask(dataId, group, tenant, tag, dumpTs, member.getAddress(), evt.isBeta)); } else { diff --git a/console/src/main/java/com/alibaba/nacos/console/controller/ServerLoaderController.java b/console/src/main/java/com/alibaba/nacos/console/controller/ServerLoaderController.java index d24cf32a1..2872b3028 100644 --- a/console/src/main/java/com/alibaba/nacos/console/controller/ServerLoaderController.java +++ b/console/src/main/java/com/alibaba/nacos/console/controller/ServerLoaderController.java @@ -29,7 +29,7 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.console.security.nacos.NacosAuthConfig; import com.alibaba.nacos.core.cluster.Member; -import com.alibaba.nacos.core.cluster.MemberUtils; +import com.alibaba.nacos.core.cluster.MemberUtil; import com.alibaba.nacos.core.cluster.ServerMemberManager; import com.alibaba.nacos.core.cluster.remote.ClusterRpcClientProxy; import com.alibaba.nacos.core.remote.Connection; @@ -182,7 +182,7 @@ public class ServerLoaderController { serverLoaderInfoRequest.setReloadCount(reloadcount); int count = 0; for (Member member : serverMemberManager.allMembersWithoutSelf()) { - if (MemberUtils.isSupportedLongCon(member)) { + if (MemberUtil.isSupportedLongCon(member)) { count++; completionService.submit(new ServerReLoaderRpcTask(serverLoaderInfoRequest, member)); } @@ -217,7 +217,7 @@ public class ServerLoaderController { int count = 0; for (Member member : serverMemberManager.allMembersWithoutSelf()) { - if (MemberUtils.isSupportedLongCon(member)) { + if (MemberUtil.isSupportedLongCon(member)) { count++; ServerLoaderInfoRequest serverLoaderInfoRequest = new ServerLoaderInfoRequest(); completionService.submit(new ServerLoaderInfoRpcTask(serverLoaderInfoRequest, member)); diff --git a/core/src/main/java/com/alibaba/nacos/core/cluster/remote/ClusterRpcClientProxy.java b/core/src/main/java/com/alibaba/nacos/core/cluster/remote/ClusterRpcClientProxy.java index 473ae6925..7298b3264 100644 --- a/core/src/main/java/com/alibaba/nacos/core/cluster/remote/ClusterRpcClientProxy.java +++ b/core/src/main/java/com/alibaba/nacos/core/cluster/remote/ClusterRpcClientProxy.java @@ -28,7 +28,7 @@ import com.alibaba.nacos.common.remote.client.RpcClientFactory; import com.alibaba.nacos.common.remote.client.ServerListFactory; import com.alibaba.nacos.core.cluster.Member; import com.alibaba.nacos.core.cluster.MemberChangeListener; -import com.alibaba.nacos.core.cluster.MemberUtils; +import com.alibaba.nacos.core.cluster.MemberUtil; import com.alibaba.nacos.core.cluster.MembersChangeEvent; import com.alibaba.nacos.core.cluster.ServerMemberManager; import com.alibaba.nacos.core.utils.Loggers; @@ -85,7 +85,7 @@ public class ClusterRpcClientProxy extends MemberChangeListener { //ensure to create client of new members for (Member member : members) { - ConnectionType supportedConnectionType = MemberUtils.getSupportedConnectionType(member); + ConnectionType supportedConnectionType = MemberUtil.getSupportedConnectionType(member); if (supportedConnectionType != null) { createRpcClientAndStart(member, supportedConnectionType); } @@ -94,7 +94,7 @@ public class ClusterRpcClientProxy extends MemberChangeListener { //shutdown and remove old members. Set> allClientEntrys = RpcClientFactory.getAllClientEntrys(); Iterator> iterator = allClientEntrys.iterator(); - List newMemberKeys = members.stream().filter(a -> MemberUtils.isSupportedLongCon(a)) + List newMemberKeys = members.stream().filter(a -> MemberUtil.isSupportedLongCon(a)) .map(a -> memberClientKey(a)).collect(Collectors.toList()); while (iterator.hasNext()) { Map.Entry next1 = iterator.next(); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV1Impl.java b/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV1Impl.java index 8d208621b..66672b194 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV1Impl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV1Impl.java @@ -67,23 +67,7 @@ public class CatalogServiceV1Impl implements CatalogService { ObjectNode detailView = JacksonUtils.createEmptyJsonNode(); detailView.replace("service", serviceObject); - - List clusters = new ArrayList<>(); - - for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) { - com.alibaba.nacos.api.naming.pojo.Cluster clusterView = new com.alibaba.nacos.api.naming.pojo.Cluster(); - clusterView.setName(cluster.getName()); - clusterView.setHealthChecker(cluster.getHealthChecker()); - clusterView.setMetadata(cluster.getMetadata()); - clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check()); - clusterView.setDefaultPort(cluster.getDefaultPort()); - clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort()); - clusterView.setServiceName(cluster.getService().getName()); - clusters.add(clusterView); - } - - detailView.replace("clusters", JacksonUtils.transferToJsonNode(clusters)); - + detailView.replace("clusters", JacksonUtils.transferToJsonNode(detailedService.getClusterMap().values())); return detailView; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/utils/ServiceUtil.java b/naming/src/main/java/com/alibaba/nacos/naming/utils/ServiceUtil.java index 7c3f7bcce..f2d649670 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/utils/ServiceUtil.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/utils/ServiceUtil.java @@ -154,6 +154,9 @@ public class ServiceUtil { if (start < 0) { start = 0; } + if (start >= result.size()) { + return result; + } int end = start + pageSize; if (end > result.size()) { end = result.size();