Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4498: Add list command to ZkCLI that prints out the contents of ZooKeeper.

Mark Robert Miller1115ba8aba15
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 52bde87711c..c4c78cc7095 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -81,6 +81,9 @@ New Features
* SOLR-4488: Return slave replication details for a master if the master has
also acted like a slave. (Mark Miller)
+* SOLR-4498: Add list command to ZkCLI that prints out the contents of
+ ZooKeeper. (Roman Shaposhnik via Mark Miller)
+
Bug Fixes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
index 9a0d69462f6..eb101217b2d 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
@@ -58,6 +58,7 @@ public class ZkCLI {
private static final String UPCONFIG = "upconfig";
private static final String COLLECTION = "collection";
private static final String CLEAR = "clear";
+ private static final String LIST = "list";
private static final String CMD = "cmd";
/**
@@ -85,7 +86,7 @@ public class ZkCLI {
.hasArg(true)
.withDescription(
"cmd to run: " + BOOTSTRAP + ", " + UPCONFIG + ", " + DOWNCONFIG
- + ", " + LINKCONFIG + ", " + MAKEPATH + ", "+ CLEAR).create(CMD));
+ + ", " + LINKCONFIG + ", " + MAKEPATH + ", "+ LIST + ", " +CLEAR).create(CMD));
Option zkHostOption = new Option("z", ZKHOST, true,
"ZooKeeper host address");
@@ -129,6 +130,7 @@ public class ZkCLI {
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + LINKCONFIG + " -" + COLLECTION + " collection1" + " -" + CONFNAME + " myconf");
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + MAKEPATH + " /apache/solr");
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + CLEAR + " /solr");
+ System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + LIST);
return;
}
@@ -216,6 +218,8 @@ public class ZkCLI {
String confName = line.getOptionValue(CONFNAME);
ZkController.linkConfSet(zkClient, collection, confName);
+ } else if (line.getOptionValue(CMD).equals(LIST)) {
+ zkClient.printLayoutToStdOut();
} else if (line.getOptionValue(CMD).equals(CLEAR)) {
List arglist = line.getArgList();
if (arglist.size() != 1) {
diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
index 03af80c77a1..e6ee995fdd2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
@@ -121,6 +121,14 @@ public class ZkCLITest extends SolrTestCaseJ4 {
assertTrue(zkClient.exists("/path/mynewpath", true));
}
+ @Test
+ public void testList() throws Exception {
+ zkClient.makePath("/test", true);
+ String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
+ "list"};
+ ZkCLI.main(args);
+ }
+
@Test
public void testUpConfigLinkConfigClearZk() throws Exception {
// test upconfig