You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2016/12/30 01:41:11 UTC
lucene-solr:master: SOLR-9891: Add mkroot command to bin/solr and
bin/solr.cmd
Repository: lucene-solr
Updated Branches:
refs/heads/master b584f9c56 -> cb266d5fc
SOLR-9891: Add mkroot command to bin/solr and bin/solr.cmd
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/cb266d5f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/cb266d5f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/cb266d5f
Branch: refs/heads/master
Commit: cb266d5fc775bd9d26ed7f0e68e9d0d12793f9b5
Parents: b584f9c
Author: Erick Erickson <er...@apache.org>
Authored: Thu Dec 29 17:39:48 2016 -0800
Committer: Erick Erickson <er...@apache.org>
Committed: Thu Dec 29 17:39:48 2016 -0800
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
solr/bin/solr | 26 +++++++-
solr/bin/solr.cmd | 21 ++++++-
.../src/java/org/apache/solr/util/SolrCLI.java | 65 +++++++++++++++++++-
4 files changed, 108 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cb266d5f/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7f83de0..59dde90 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -204,6 +204,8 @@ New Features
* SOLR-9905: Add NullStream to isolate the performance of the ExportWriter (Joel Bernstein)
+* SOLR-9891: Add mkroot command to bin/solr and bin/solr.cmd (Erick Erickson)
+
Optimizations
----------------------
* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cb266d5f/solr/bin/solr
----------------------------------------------------------------------
diff --git a/solr/bin/solr b/solr/bin/solr
index c1add26..fcf864b 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -493,6 +493,12 @@ function print_usage() {
echo ""
echo " Only the node names are listed, not data"
echo ""
+ echo " mkroot makes a znode on Zookeeper with no data. Can be used to make a path of arbitrary"
+ echo " depth but primarily intended to create a 'chroot'."
+ echo ""
+ echo " <path>: The Zookeeper path to create. Leading slash is assumed if not present."
+ echo " Intermediate nodes are created as needed if not present."
+ echo ""
fi
} # end print_usage
@@ -507,6 +513,7 @@ function print_short_zk_usage() {
echo " solr zk rm [-r] <path> [-z zkHost]"
echo " solr zk mv <src> <dest> [-z zkHost]"
echo " solr zk ls [-r] <path> [-z zkHost]"
+ echo " solr zk mkroot <path> [-z zkHost]"
echo ""
if [ "$1" == "" ]; then
@@ -1001,7 +1008,7 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then
if [ $# -gt 0 ]; then
while true; do
case "$1" in
- -upconfig|upconfig|-downconfig|downconfig|cp|rm|mv|ls)
+ -upconfig|upconfig|-downconfig|downconfig|cp|rm|mv|ls|mkroot)
if [ "${1:0:1}" == "-" ]; then
ZK_OP=${1:1}
else
@@ -1042,7 +1049,7 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then
shift
break
;;
- *) # Pick up <src> <dst> or <path> params for rm, ls, cp, mv.
+ *) # Pick up <src> <dst> or <path> params for rm, ls, cp, mv, mkroot.
if [ "$1" == "" ]; then
break # out-of-args, stop looping
fi
@@ -1062,7 +1069,7 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then
fi
if [ -z "$ZK_OP" ]; then
- print_short_zk_usage "Zookeeper operation (one of 'upconfig', 'downconfig', 'rm', 'mv', 'cp', 'ls') is required!"
+ print_short_zk_usage "Zookeeper operation (one of 'upconfig', 'downconfig', 'rm', 'mv', 'cp', 'ls', 'mkroot') is required!"
fi
if [ -z "$ZK_HOST" ]; then
@@ -1088,6 +1095,13 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then
fi
fi
+ if [[ "$ZK_OP" == "mkroot" ]]; then
+ if [[ -z "$ZK_SRC" ]]; then
+ print_short_zk_usage "<path> must be specified when using the 'mkroot' command."
+ fi
+ fi
+
+
case "$ZK_OP" in
upconfig)
run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" -configsetsDir "$SOLR_TIP/server/solr/configsets"
@@ -1113,6 +1127,12 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then
fi
run_tool "$ZK_OP" -path "$ZK_SRC" -recurse "$ZK_RECURSE" -zkHost "$ZK_HOST"
;;
+ mkroot)
+ if [ -z "$ZK_SRC" ]; then
+ print_short_zk_usage "Zookeeper path to list must be specified when using the 'mkroot' command"
+ fi
+ run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST"
+ ;;
*)
print_short_zk_usage "Unrecognized Zookeeper operation $ZK_OP"
;;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cb266d5f/solr/bin/solr.cmd
----------------------------------------------------------------------
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 4b6081f..04398bc 100644
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -480,6 +480,13 @@ echo ^<path^>: The Zookeeper path to use as the root.
echo.
echo Only the node names are listed, not data
echo.
+echo mkroot makes a znode in Zookeeper with no data. Can be used to make a path of arbitrary
+echo depth but primarily intended to create a 'chroot'."
+echo.
+echo ^<path^>: The Zookeeper path to create. Leading slash is assumed if not present.
+echo Intermediate nodes are created as needed if not present.
+echo.
+
goto done
:zk_short_usage
@@ -492,6 +499,7 @@ echo solr zk cp [-r] ^<src^> ^<dest^> [-z zkHost]
echo solr zk rm [-r] ^<path^> [-z zkHost]
echo solr zk mv ^<src^> ^<dest^> [-z zkHost]
echo solr zk ls [-r] ^<path^> [-z zkHost]
+echo solr zk mkroot ^<path^> [-z zkHost]
echo.
IF "%ZK_FULL%"=="true" (
goto zk_full_usage
@@ -1399,6 +1407,8 @@ IF "%1"=="-upconfig" (
goto set_zk_op
) ELSE IF "%1"=="ls" (
goto set_zk_op
+) ELSE IF "%1"=="mkroot" (
+ goto set_zk_op
) ELSE IF "%1"=="-n" (
goto set_config_name
) ELSE IF "%1"=="-r" (
@@ -1561,13 +1571,22 @@ IF "!ZK_OP!"=="upconfig" (
org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE!
) ELSE IF "!ZK_OP!"=="ls" (
IF "%ZK_SRC"=="" (
- set ERROR_MSG="Zookeeper path to remove must be specified when using the 'rm' command"
+ set ERROR_MSG="Zookeeper path to remove must be specified when using the 'ls' command"
goto zk_short_usage
)
"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
-Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE!
+) ELSE IF "!ZK_OP!"=="mkroot" (
+ IF "%ZK_SRC"=="" (
+ set ERROR_MSG="Zookeeper path to create must be specified when using the 'mkroot' command"
+ goto zk_short_usage
+ )
+ "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^
+ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
+ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
+ org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC!
) ELSE (
set ERROR_MSG="Unknown zk option !ZK_OP!"
goto zk_short_usage
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cb266d5f/solr/core/src/java/org/apache/solr/util/SolrCLI.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
index 4979848..bb2d554 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
@@ -364,6 +364,8 @@ public class SolrCLI {
return new ZkCpTool();
else if ("ls".equals(toolType))
return new ZkLsTool();
+ else if ("mkroot".equals(toolType))
+ return new ZkMkrootTool();
else if ("assert".equals(toolType))
return new AssertTool();
else if ("utils".equals(toolType))
@@ -1986,7 +1988,7 @@ public class SolrCLI {
if (zkHost == null) {
throw new IllegalStateException("Solr at " + cli.getOptionValue("zkHost") +
- " is running in standalone server mode, 'zk rm' can only be used when running in SolrCloud mode.\n");
+ " is running in standalone server mode, 'zk ls' can only be used when running in SolrCloud mode.\n");
}
@@ -1999,12 +2001,71 @@ public class SolrCLI {
" recurse: " + Boolean.toString(recurse));
stdout.print(zkClient.listZnode(znode, recurse));
} catch (Exception e) {
- log.error("Could not complete rm operation for reason: " + e.getMessage());
+ log.error("Could not complete ls operation for reason: " + e.getMessage());
throw (e);
}
}
} // End zkLsTool class
+
+ public static class ZkMkrootTool extends ToolBase {
+
+ public ZkMkrootTool() {
+ this(System.out);
+ }
+
+ public ZkMkrootTool(PrintStream stdout) {
+ super(stdout);
+ }
+
+ @SuppressWarnings("static-access")
+ public Option[] getOptions() {
+ return new Option[]{
+ OptionBuilder
+ .withArgName("path")
+ .hasArg()
+ .isRequired(true)
+ .withDescription("Path to create")
+ .create("path"),
+ OptionBuilder
+ .withArgName("HOST")
+ .hasArg()
+ .isRequired(true)
+ .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST)
+ .create("zkHost")
+ };
+ }
+
+ public String getName() {
+ return "mkroot";
+ }
+
+ protected void runImpl(CommandLine cli) throws Exception {
+
+ String zkHost = getZkHost(cli);
+
+ if (zkHost == null) {
+ throw new IllegalStateException("Solr at " + cli.getOptionValue("zkHost") +
+ " is running in standalone server mode, 'zk mkroot' can only be used when running in SolrCloud mode.\n");
+ }
+
+
+ try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) {
+ echo("\nConnecting to ZooKeeper at " + zkHost + " ...");
+
+ String znode = cli.getOptionValue("path");
+ echo("Creating Zookeeper path " + znode + " on ZooKeeper at " + zkHost);
+ zkClient.makePath(znode, true);
+ } catch (Exception e) {
+ log.error("Could not complete mkroot operation for reason: " + e.getMessage());
+ throw (e);
+ }
+ }
+ } // End zkMkrootTool class
+
+
+
+
public static class ZkCpTool extends ToolBase {
public ZkCpTool() {