Skip to content

Commit

Permalink
Merge pull request alibaba#679 from alibaba/feature_compatible_for_ol…
Browse files Browse the repository at this point in the history
…d_dns_client

Close alibaba#678
  • Loading branch information
Fury Zhu authored Jan 22, 2019
2 parents 55178a6 + 54d4dce commit 742d1d7
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1900,24 +1900,52 @@ public JSONObject getAllChangeLog(HttpServletRequest request) throws Exception {
public JSONObject allDomNames(HttpServletRequest request) throws Exception {

boolean responsibleOnly = Boolean.parseBoolean(WebUtils.optional(request, "responsibleOnly", "false"));
Map<String, Set<String>> 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) {

Map<String, Set<String>> doms = new HashMap<>(16);
List<String> doms = new ArrayList<String>();
Set<String> domSet = null;

Map<String, Set<String>> domMap = domainsManager.getAllDomNames();
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<String, Set<String>> doms = new HashMap<>(16);
int count = 0;
for (String namespaceId : domMap.keySet()) {
doms.put(namespaceId, new HashSet<>());
for (String dom : domMap.get(namespaceId)) {
if (DistroMapper.responsible(dom) || !responsibleOnly) {
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;
}
Expand Down

0 comments on commit 742d1d7

Please sign in to comment.