From 54d4dce869810e9cbea1b42898ad58cb7e1c68a5 Mon Sep 17 00:00:00 2001 From: nkorange Date: Tue, 22 Jan 2019 16:47:33 +0800 Subject: [PATCH] Close #678 --- .../alibaba/nacos/naming/web/ApiCommands.java | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) 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 88b7a5e33..0d9c8d7f4 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 @@ -1900,11 +1900,40 @@ public class ApiCommands { public JSONObject allDomNames(HttpServletRequest request) throws Exception { boolean responsibleOnly = Boolean.parseBoolean(WebUtils.optional(request, "responsibleOnly", "false")); + Map> domMap = domainsManager.getAllDomNames(); + JSONObject result = new JSONObject(); + // For old DNS-F client: + String dnsfVersion = "1.0.1"; + String agent = request.getHeader("Client-Version"); + ClientInfo clientInfo = new ClientInfo(agent); + if (clientInfo.type == ClientInfo.ClientType.DNS && clientInfo.version.compareTo(VersionUtil.parseVersion(dnsfVersion)) <= 0) { + + List doms = new ArrayList(); + Set domSet = null; + + if (domMap.containsKey(Constants.REQUEST_PARAM_DEFAULT_NAMESPACE_ID)) { + domSet = domMap.get(Constants.REQUEST_PARAM_DEFAULT_NAMESPACE_ID); + } + + if (CollectionUtils.isEmpty(domSet)) { + result.put("doms", new HashSet<>()); + result.put("count", 0); + return result; + } + + for (String dom : domSet) { + if (DistroMapper.responsible(dom) || !responsibleOnly) { + doms.add(dom); + } + } + + result.put("doms", doms); + result.put("count", doms.size()); + return result; + } Map> doms = new HashMap<>(16); - - Map> domMap = domainsManager.getAllDomNames(); - + int count = 0; for (String namespaceId : domMap.keySet()) { doms.put(namespaceId, new HashSet<>()); for (String dom : domMap.get(namespaceId)) { @@ -1912,12 +1941,11 @@ public class ApiCommands { doms.get(namespaceId).add(dom); } } + count += doms.get(namespaceId).size(); } - JSONObject result = new JSONObject(); - result.put("doms", doms); - result.put("count", doms.size()); + result.put("count", count); return result; }