Skip to content

Apache Lucene open-source search software

SOLR-4972: Add PUT command to ZkCli tool.

Mark Robert Miller280e96e81f24
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0ace027615c..2cf5d82b62d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -131,7 +131,9 @@ New Features
already are instances of the target class. Ordering the processors, e.g.
[Boolean, Long, Double, Date] will allow e.g. values ["2", "5", "8.6"] to
be left alone by the Boolean and Long processors, but then converted by the
- Double processor. (Steve Rowe, hossman)
+ Double processor. (Steve Rowe, hossman)
+
+* SOLR-4972: Add PUT command to ZkCli tool. (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 f8e171efab2..7dafae3a148 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
@@ -25,7 +25,10 @@ import org.apache.solr.core.ConfigSolr;
import org.apache.solr.core.ConfigSolrXml;
import org.apache.solr.core.ConfigSolrXmlOld;
import org.apache.solr.core.SolrResourceLoader;
+import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -49,6 +52,7 @@ import org.xml.sax.SAXException;
public class ZkCLI {
private static final String MAKEPATH = "makepath";
+ private static final String PUT = "put";
private static final String DOWNCONFIG = "downconfig";
private static final String ZK_CLI_NAME = "ZkCLI";
private static final String HELP = "help";
@@ -92,7 +96,7 @@ public class ZkCLI {
.hasArg(true)
.withDescription(
"cmd to run: " + BOOTSTRAP + ", " + UPCONFIG + ", " + DOWNCONFIG
- + ", " + LINKCONFIG + ", " + MAKEPATH + ", "+ LIST + ", " +CLEAR).create(CMD));
+ + ", " + LINKCONFIG + ", " + MAKEPATH + ", "+ PUT + ", "+ LIST + ", " + CLEAR).create(CMD));
Option zkHostOption = new Option("z", ZKHOST, true,
"ZooKeeper host address");
@@ -134,7 +138,8 @@ public class ZkCLI {
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + UPCONFIG + " -" + CONFDIR + " /opt/solr/collection1/conf" + " -" + CONFNAME + " myconf");
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + DOWNCONFIG + " -" + CONFDIR + " /opt/solr/collection1/conf" + " -" + CONFNAME + " myconf");
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 " + MAKEPATH + " /apache/solr/data.txt 'config data'");
+ System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + PUT + " /solr.conf 'conf data'");
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + CLEAR + " /solr");
System.out.println("zkcli.sh -zkhost localhost:9983 -cmd " + LIST);
return;
@@ -256,6 +261,15 @@ public class ZkCLI {
System.exit(1);
}
zkClient.makePath(arglist.get(0).toString(), true);
+ } else if (line.getOptionValue(CMD).equals(PUT)) {
+ List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
+ List arglist = line.getArgList();
+ if (arglist.size() != 2) {
+ System.out.println("-" + PUT + " requires two args - the path to create and the data string");
+ System.exit(1);
+ }
+ zkClient.create(arglist.get(0).toString(), arglist.get(1).toString().getBytes("UTF-8"),
+ acl, CreateMode.PERSISTENT, true);
}
} finally {
if (solrPort != null) {
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 22a201fb0b4..d51e6ac6e1a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
@@ -138,6 +138,19 @@ public class ZkCLITest extends SolrTestCaseJ4 {
assertTrue(zkClient.exists("/path/mynewpath", true));
}
+
+ @Test
+ public void testPut() throws Exception {
+ // test bootstrap_conf
+ String data = "my data";
+ String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
+ "put", "/data.txt", data};
+ ZkCLI.main(args);
+
+ zkClient.getData("/data.txt", null, null, true);
+
+ assertArrayEquals(zkClient.getData("/data.txt", null, null, true), data.getBytes("UTF-8"));
+ }
@Test
public void testList() throws Exception {