Apache Solr open-source search software
SOLR-15062: /api/cluster/zk/ls should give the stat of the current node (#2172)
Noble Paul3056296fa23b
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.javaindex 60a53b8f2f9..18bed3e9e01 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java@@ -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());}}diff --git a/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java b/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.javaindex d7ad7c6e59e..3376d34cb2f 100644--- a/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java+++ b/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java@@ -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",