mirror of https://github.com/apache/lucene.git
SOLR-4972: Add PUT command to ZkCli tool.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1497499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4567a2f6cc
commit
280e96e81f
|
@ -133,6 +133,8 @@ New Features
|
|||
be left alone by the Boolean and Long processors, but then converted by the
|
||||
Double processor. (Steve Rowe, hossman)
|
||||
|
||||
* SOLR-4972: Add PUT command to ZkCli tool. (Roman Shaposhnik via Mark Miller)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -139,6 +139,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 {
|
||||
zkClient.makePath("/test", true);
|
||||
|
|
Loading…
Reference in New Issue