Merge pull request #679 from alibaba/feature_compatible_for_old_dns_client

Close #678
This commit is contained in:
Fury Zhu 2019-01-22 17:05:49 +08:00 committed by GitHub
commit 742d1d757e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1900,11 +1900,40 @@ public class ApiCommands {
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) {
List<String> doms = new ArrayList<String>();
Set<String> 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<String, Set<String>> doms = new HashMap<>(16);
Map<String, Set<String>> 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;
}