SOLR-15062: /api/cluster/zk/ls should give the stat of the current node (#2172)

This commit is contained in:
Noble Paul 2021-01-04 14:08:14 +11:00 committed by GitHub
parent 23e206d085
commit 3056296fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -101,6 +101,11 @@ public class ZookeeperReadAPI {
String path = req.getPathTemplateValues().get("*");
if (path == null || path.isEmpty()) path = "/";
try {
Stat stat = coreContainer.getZkController().getZkClient().exists(path, null, true);
rsp.add("stat", (MapWriter) ew -> printStat(ew, stat));
if(!req.getParams().getBool("c", true)) {
return;
}
List<String> l = coreContainer.getZkController().getZkClient().getChildren(path, null, false);
String prefix = path.endsWith("/") ? path : path + "/";
@ -114,7 +119,7 @@ public class ZookeeperReadAPI {
}
rsp.add(path, (MapWriter) ew -> {
for (Map.Entry<String, Stat> e : stats.entrySet()) {
printStat(ew, e.getKey(), e.getValue());
ew.put(e.getKey(), (MapWriter) ew1 -> printStat(ew1, e.getValue()));
}
});
} catch (KeeperException.NoNodeException e) {
@ -126,20 +131,18 @@ public class ZookeeperReadAPI {
}
}
private void printStat(MapWriter.EntryWriter ew, String s, Stat stat) throws IOException {
ew.put(s, (MapWriter) ew1 -> {
ew1.put("version", stat.getVersion());
ew1.put("aversion", stat.getAversion());
ew1.put("children", stat.getNumChildren());
ew1.put("ctime", stat.getCtime());
ew1.put("cversion", stat.getCversion());
ew1.put("czxid", stat.getCzxid());
ew1.put("ephemeralOwner", stat.getEphemeralOwner());
ew1.put("mtime", stat.getMtime());
ew1.put("mzxid", stat.getMzxid());
ew1.put("pzxid", stat.getPzxid());
ew1.put("dataLength", stat.getDataLength());
});
private void printStat(MapWriter.EntryWriter ew, Stat stat) throws IOException {
ew.put("version", stat.getVersion());
ew.put("aversion", stat.getAversion());
ew.put("children", stat.getNumChildren());
ew.put("ctime", stat.getCtime());
ew.put("cversion", stat.getCversion());
ew.put("czxid", stat.getCzxid());
ew.put("ephemeralOwner", stat.getEphemeralOwner());
ew.put("mtime", stat.getMtime());
ew.put("mzxid", stat.getMzxid());
ew.put("pzxid", stat.getPzxid());
ew.put("dataLength", stat.getDataLength());
}
}

View File

@ -73,6 +73,7 @@ public class ZookeeperReadAPITest extends SolrCloudTestCase {
Utils.JSONCONSUMER);
assertEquals("0", String.valueOf(getObjectByPath(o, true, split(":/configs:_default:dataLength", ':'))));
assertEquals("0", String.valueOf(getObjectByPath(o, true, split(":/configs:conf:dataLength", ':'))));
assertEquals("0", String.valueOf(getObjectByPath(o, true, split("/stat/version", '/'))));
o = Utils.executeGET(client.getHttpClient(),
basezk + "/configs",