lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thelabd...@apache.org
Subject svn commit: r1651231 - in /lucene/dev/trunk: dev-tools/scripts/smokeTestRelease.py solr/CHANGES.txt solr/README.txt solr/bin/solr solr/bin/solr.cmd solr/core/src/java/org/apache/solr/util/SolrCLI.java
Date Mon, 12 Jan 2015 23:33:35 GMT
Author: thelabdude
Date: Mon Jan 12 23:33:34 2015
New Revision: 1651231

URL: http://svn.apache.org/r1651231
Log:
SOLR-6952: bin/solr create action should copy configset directory instead of reusing an existing
configset in ZooKeeper by default; commit also includes fix for SOLR-6933 - create alias

Modified:
    lucene/dev/trunk/dev-tools/scripts/smokeTestRelease.py
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/README.txt
    lucene/dev/trunk/solr/bin/solr
    lucene/dev/trunk/solr/bin/solr.cmd
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java

Modified: lucene/dev/trunk/dev-tools/scripts/smokeTestRelease.py
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/scripts/smokeTestRelease.py?rev=1651231&r1=1651230&r2=1651231&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/scripts/smokeTestRelease.py (original)
+++ lucene/dev/trunk/dev-tools/scripts/smokeTestRelease.py Mon Jan 12 23:33:34 2015
@@ -856,7 +856,7 @@ def testSolrExample(unpackPath, javaPath
 
     print('      startup done')
     # Create the techproducts config (used to be collection1)
-    subprocess.call(['bin/solr','create_core','-n','techproducts','-c','sample_techproducts_configs'])
+    subprocess.call(['bin/solr','create_core','-c','techproducts','-d','sample_techproducts_configs'])
     os.chdir('example')
     print('      test utf8...')
     run('sh ./exampledocs/test_utf8.sh http://localhost:8983/solr/techproducts', 'utf8.log')

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1651231&r1=1651230&r2=1651231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Jan 12 23:33:34 2015
@@ -674,6 +674,13 @@ Other Changes
 
 * SOLR-6324: Set finite default timeouts for select and update. (Ramkumar Aiyengar via Mark
Miller)
 
+* SOLR-6952: bin/solr create action should copy configset directory instead of reusing
+  an existing configset in ZooKeeper by default (Timothy Potter)
+
+* SOLR-6933: bin/solr should provide a single "create" action that creates a core
+  or collection depending on whether Solr is running in standalone or cloud mode
+  (Timothy Potter)
+
 ==================  4.10.3 ==================
 
 Bug Fixes

Modified: lucene/dev/trunk/solr/README.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/README.txt?rev=1651231&r1=1651230&r2=1651231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/README.txt (original)
+++ lucene/dev/trunk/solr/README.txt Mon Jan 12 23:33:34 2015
@@ -32,31 +32,27 @@ To start Solr for the first time after i
 
   bin/solr start
 
-This will launch a Solr server in the background of your shell, bound
-to port 8983. After starting Solr, you can create a new core for indexing
-your data by doing:
+This will launch a standalone Solr server in the background of your shell,
+listening on port 8983. Alternatively, you can launch Solr in "cloud" mode,
+which allows you to scale out using sharding and replication. To launch Solr
+in cloud mode, do:
 
-  bin/solr create_core -n <name>
-
-This will create a core that uses a data-driven schema which tries to guess
-the correct field type when you add documents to the index. To see all available
-options for creating a new core, execute:
-
-  bin/solr create_core -help
+  bin/solr start -cloud
 
-Alternatively, you can launch Solr in "cloud" mode, which allows you to scale
-out using sharding and replication. To launch Solr in cloud mode, do:
+To see all available options for starting Solr, please do:
 
-  bin/solr start -cloud
+  bin/solr start -help
 
-After starting Solr in cloud mode, you can create a new collection for indexing
-your data by doing:
+After starting Solr, create either a core or collection depending on whether
+Solr is running in standalone (core) or SolrCloud mode (collection) by doing:
 
-  bin/solr create_collection -n <name>
+  bin/solr create -n <name>
 
-To see all available options for starting Solr, please do:
+This will create a collection that uses a data-driven schema which tries to guess
+the correct field type when you add documents to the index. To see all available
+options for creating a new collection, execute:
 
-  bin/solr start -help
+  bin/solr create -help
 
 After starting Solr, direct your Web browser to the Solr Admin Console at:
 
@@ -98,18 +94,6 @@ For more information about Solr examples
  * http://wiki.apache.org/solr/SolrResources
    For a list of other tutorials and introductory articles.
 
-
-In addition, Solr ships with several example configurations that
-help you learn about Solr. To run one of the examples, you would do:
-
-  bin/solr -e <EXAMPLE> where <EXAMPLE> is one of:
-
-    cloud        : SolrCloud example
-    dih          : Data Import Handler (rdbms, mail, rss, tika)
-    schemaless   : Schema-less example (schema is inferred from data during indexing)
-    techproducts : Kitchen sink example providing comprehensive examples of Solr features
-
-
 A tutorial is available at:
 
    http://lucene.apache.org/solr/tutorial.html

Modified: lucene/dev/trunk/solr/bin/solr
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/bin/solr?rev=1651231&r1=1651230&r2=1651231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/bin/solr (original)
+++ lucene/dev/trunk/solr/bin/solr Mon Jan 12 23:33:34 2015
@@ -123,7 +123,7 @@ function print_usage() {
   if [ -z "$CMD" ]; then
     echo ""
     echo "Usage: solr COMMAND OPTIONS"
-    echo "       where COMMAND is one of: start, stop, restart, status, healthcheck, create_core,
create_collection"
+    echo "       where COMMAND is one of: start, stop, restart, status, healthcheck, create,
create_core, create_collection"
     echo ""
     echo "  Standalone server example (start Solr running in the background on port 8984):"
     echo ""
@@ -209,49 +209,76 @@ function print_usage() {
     echo ""
     echo "  NOTE: This command will show the status of all running Solr servers"
     echo ""
+  elif [ "$CMD" == "create" ]; then
+    echo ""
+    echo "Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor
#] [-p port]"
+    echo ""
+    echo "  Create a core or collection depending on whether Solr is running in standalone
(core) or SolrCloud"
+    echo "  mode (collection). In other words, this action detects which mode Solr is running
in, and then takes"
+    echo "  the appropriate action (either create_core or create_collection). For detailed
usage instructions, do:"
+    echo ""
+    echo "    bin/solr create_core -help"
+    echo ""
+    echo "       or"
+    echo ""
+    echo "    bin/solr create_collection -help"
+    echo ""
   elif [ "$CMD" == "create_core" ]; then
     echo ""
-    echo "Usage: solr create_core [-n name] [-c configset]"
+    echo "Usage: solr create_core [-c core] [-d confdir] [-p port]"
     echo ""
-    echo "  -n <name>       Name of core to create"
+    echo "  -c <core>     Name of core to create"
+    echo ""
+    echo "  -d <confdir>  Configuration directory to copy when creating the new core,
built-in options are:"
     echo ""
-    echo "  -c <configset>  Name of configuration directory to use, built-in options
are:"
     echo "      basic_configs: Minimal Solr configuration"
     echo "      data_driven_schema_configs: Managed schema with field-guessing support enabled"
     echo "      sample_techproducts_configs: Example configuration with many optional features
enabled to"
     echo "         demonstrate the full power of Solr"
+    echo ""
     echo "      If not specified, default is: data_driven_schema_configs"
     echo ""
     echo "      Alternatively, you can pass the path to your own configuration directory
instead of using"
-    echo "      one of the built-in configurations, such as: bin/solr create_core -n mycore
-c /tmp/myconfig"
+    echo "      one of the built-in configurations, such as: bin/solr create_core -c mycore
-d /tmp/myconfig"
     echo ""
-    echo "  -p <port>       Port of a local Solr instance where you want to create
the new core"
-    echo "                    If not specified, the script will search the local system for
a running"
-    echo "                    Solr instance and will use the port of the first server it
finds."
+    echo "  -p <port>     Port of a local Solr instance where you want to create the
new core"
+    echo "                  If not specified, the script will search the local system for
a running"
+    echo "                  Solr instance and will use the port of the first server it finds."
     echo ""
   elif [ "$CMD" == "create_collection" ]; then
     echo ""
-    echo "Usage: solr create_collection [-n name] [-c configset] [-shards #] [-replicationFactor
#]"
+    echo "Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards
#] [-replicationFactor #] [-p port]"
     echo ""
-    echo "  -n <name>               Name of collection to create"
+    echo "  -c <collection>         Name of collection to create"
+    echo ""
+    echo "  -d <confdir>            Configuration directory to copy when creating the
new collection, built-in options are:"
     echo ""
-    echo "  -c <configset>          Name of configuration directory to use, built-in
options are:"
     echo "      basic_configs: Minimal Solr configuration"
     echo "      data_driven_schema_configs: Managed schema with field-guessing support enabled"
     echo "      sample_techproducts_configs: Example configuration with many optional features
enabled to"
     echo "         demonstrate the full power of Solr"
+    echo ""
     echo "      If not specified, default is: data_driven_schema_configs"
     echo ""
     echo "      Alternatively, you can pass the path to your own configuration directory
instead of using"
-    echo "      one of the built-in configurations, such as: bin/solr create_collection -n
mycoll -c /tmp/myconfig"
+    echo "      one of the built-in configurations, such as: bin/solr create_collection -c
mycoll -d /tmp/myconfig"
+    echo ""
+    echo "      By default the script will upload the specified confdir directory into ZooKeeper
using the same"
+    echo "      name as the collection (-c) option. Alternatively, if you want to reuse an
existing directory"
+    echo "      or create a confdir in ZooKeeper that can be shared by multiple collections,
use the -n option"
+    echo ""
+    echo "  -n <configName>         Name the configuration directory in ZooKeeper;
by default, the configuration"
+    echo "                            will be uploaded to ZooKeeper using the collection
name (-c), but if you want"
+    echo "                            to use an existing directory or override the name of
the configuration in"
+    echo "                            ZooKeeper, then use the -c option."
     echo ""
     echo "  -shards <#>             Number of shards to split the collection into;
default is 1"
     echo ""
     echo "  -replicationFactor <#>  Number of copies of each document in the collection,
default is 1 (no replication)"
     echo ""
-    echo "  -p <port>       Port of a local Solr instance where you want to create
the new collection"
-    echo "                    If not specified, the script will search the local system for
a running"
-    echo "                    Solr instance and will use the port of the first server it
finds."
+    echo "  -p <port>               Port of a local Solr instance where you want to
create the new collection"
+    echo "                            If not specified, the script will search the local
system for a running"
+    echo "                            Solr instance and will use the port of the first server
it finds."
     echo ""
   fi
 } # end print_usage
@@ -486,32 +513,36 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; t
 fi
 
 # create a core or collection
-if [[ "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CMD" == "create_collection" ]]; then
+if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CMD" == "create_collection"
]]; then
 
-  CREATE_TYPE=collection
   CREATE_NUM_SHARDS=1
   CREATE_REPFACT=1
-  if [ "$SCRIPT_CMD" == "create_core" ]; then
-    CREATE_TYPE=core
-  fi
 
   if [ $# -gt 0 ]; then
     while true; do
       case $1 in
-          -n|-name)
+          -c|-core|-collection)
               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
-                print_usage "$SCRIPT_CMD" "$CREATE_TYPE name is required when using the $1
option!"
+                print_usage "$SCRIPT_CMD" "name is required when using the $1 option!"
                 exit 1
               fi
               CREATE_NAME=$2
               shift 2
           ;;
-          -c|-configset)
+          -n|-confname)
               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
-                print_usage "$SCRIPT_CMD" "Configset name is required when using the $1 option!"
+                print_usage "$SCRIPT_CMD" "Configuration name is required when using the
$1 option!"
                 exit 1
               fi
-              CREATE_CONFIGSET="$2"
+              CREATE_CONFNAME="$2"
+              shift 2
+          ;;
+          -d|-confdir)
+              if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
+                print_usage "$SCRIPT_CMD" "Configuration directory is required when using
the $1 option!"
+                exit 1
+              fi
+              CREATE_CONFDIR="$2"
               shift 2
           ;;
           -s|-shards)
@@ -558,22 +589,27 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
     done
   fi
 
-  if [ -z "$CREATE_CONFIGSET" ]; then
-    CREATE_CONFIGSET=data_driven_schema_configs
+  if [ -z "$CREATE_CONFDIR" ]; then
+    CREATE_CONFDIR=data_driven_schema_configs
   fi
 
-  # validate the configset arg
-  if [[ ! -d "$SOLR_TIP/server/solr/configsets/$CREATE_CONFIGSET" && ! -d "$CREATE_CONFIGSET"
]]; then
-    echo -e "\nSpecified configset $CREATE_CONFIGSET not found!\n"
+  # validate the confdir arg
+  if [[ ! -d "$SOLR_TIP/server/solr/configsets/$CREATE_CONFDIR" && ! -d "$CREATE_CONFDIR"
]]; then
+    echo -e "\nSpecified configuration directory $CREATE_CONFDIR not found!\n"
     exit 1
   fi
 
   if [ -z "$CREATE_NAME" ]; then
-    echo "$CREATE_TYPE name is required!"
+    echo "Name (-c) argument is required!"
     print_usage "$SCRIPT_CMD"
     exit 1
   fi
 
+  # If not defined, use the collection name for the name of the configuration in ZooKeeper
+  if [ -z "$CREATE_CONFNAME" ]; then
+    CREATE_CONFNAME=$CREATE_NAME
+  fi
+
   if [ -z "$CREATE_PORT" ]; then
     for ID in `ps auxww | grep java | grep start.jar | awk '{print $2}' | sort -r`
       do
@@ -586,17 +622,19 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
   fi
 
   if [ -z "$CREATE_PORT" ]; then
-    echo "Failed to determine the port of a local Solr instance, cannot create $CREATE_TYPE
$CREATE_NAME"
+    echo "Failed to determine the port of a local Solr instance, cannot create $CREATE_NAME!"
     exit 1
   fi
 
-  if [ "$SCRIPT_CMD" == "create_collection" ]; then
-    run_tool create_collection -name $CREATE_NAME -shards $CREATE_NUM_SHARDS -replicationFactor
$CREATE_REPFACT \
-      -config $CREATE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl
http://localhost:$CREATE_PORT/solr
+  if [ "$SCRIPT_CMD" == "create_core" ]; then
+    run_tool create_core -name $CREATE_NAME -solrUrl http://localhost:$CREATE_PORT/solr \
+      -confdir $CREATE_CONFDIR -configsetsDir $SOLR_TIP/server/solr/configsets
     exit $?
   else
-    run_tool create_core -name $CREATE_NAME -solrUrl http://localhost:$CREATE_PORT/solr \
-      -config $CREATE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets
+    run_tool $SCRIPT_CMD -name $CREATE_NAME -shards $CREATE_NUM_SHARDS -replicationFactor
$CREATE_REPFACT \
+      -confname $CREATE_CONFNAME -confdir $CREATE_CONFDIR \
+      -configsetsDir $SOLR_TIP/server/solr/configsets \
+      -solrUrl http://localhost:$CREATE_PORT/solr
     exit $?
   fi
 fi
@@ -1211,18 +1249,11 @@ if [ "$EXAMPLE" != "cloud" ]; then
       EXAMPLE_NAME=$EXAMPLE
     fi
 
-    if [ "$SOLR_MODE" == "solrcloud" ]; then
-      run_tool create_collection -name $EXAMPLE_NAME -shards 1 -replicationFactor 1 \
-        -config $EXAMPLE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl
http://localhost:$SOLR_PORT/solr
-      if [ $? -ne 0 ]; then
-        exit 1
-      fi
-    else
-      run_tool create_core -name $EXAMPLE_NAME -solrUrl http://localhost:$SOLR_PORT/solr
\
-        -config $EXAMPLE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets
-      if [ $? -ne 0 ]; then
-        exit 1
-      fi
+    run_tool create -name $EXAMPLE_NAME -shards 1 -replicationFactor 1 \
+      -confname $EXAMPLE_NAME -confdir $EXAMPLE_CONFIGSET \
+      -configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl http://localhost:$SOLR_PORT/solr
+    if [ $? -ne 0 ]; then
+      exit 1
     fi
 
     if [ "$EXAMPLE" == "techproducts" ]; then
@@ -1253,7 +1284,7 @@ else
   fi
 
   echo -e "\nStarting up SolrCloud node1 on port ${CLOUD_PORTS[0]} using command:\n"
-  echo -e "solr start -cloud -s $SOLR_HOME -p $SOLR_PORT $DASHZ $DASHM $DASHA\n\n"
+  echo -e "solr start -cloud -s example/cloud/node1/solr -p $SOLR_PORT $DASHZ $DASHM $DASHA\n\n"
     
   # can't launch this node in the foreground else we can't run anymore commands
   launch_solr "false" "$ADDITIONAL_CMD_OPTS"
@@ -1270,7 +1301,7 @@ else
     ndx=$[$s+1]
     next_port=${CLOUD_PORTS[$s]}
     echo -e "\n\nStarting node$ndx on port $next_port using command:\n"
-    echo -e "solr start -cloud -s $SOLR_TIP/example/cloud/node$ndx/solr -p $next_port -z
$zk_host $DASHM $DASHA \n\n"
+    echo -e "solr start -cloud -s example/cloud/node$ndx/solr -p $next_port -z $zk_host $DASHM
$DASHA \n\n"
     # call this script again with correct args for next node    
     $SOLR_TIP/bin/solr start -cloud -s $SOLR_TIP/example/cloud/node$ndx/solr -p $next_port
-z $zk_host $DASHM $DASHA
   done
@@ -1329,7 +1360,7 @@ else
         CLOUD_CONFIG=data_driven_schema_configs
       fi
 
-      # validate the configset arg
+      # validate the confdir arg
       if [[ ! -d "$SOLR_TIP/server/solr/configsets/$CLOUD_CONFIG" && ! -d "$CLOUD_CONFIG"
]]; then
         echo -e "\nOops! Specified configuration $CLOUD_CONFIG not found!"
         read -e -p "Choose one of: basic_configs, data_driven_schema_configs, or sample_techproducts_configs
[data_driven_schema_configs] " USER_INPUT
@@ -1342,7 +1373,9 @@ else
   fi
    
   run_tool create_collection -name $CLOUD_COLLECTION -shards $CLOUD_NUM_SHARDS -replicationFactor
$CLOUD_REPFACT \
-    -config $CLOUD_CONFIG -configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl http://localhost:$SOLR_PORT/solr
+    -confname $CLOUD_COLLECTION -confdir $CLOUD_CONFIG \
+    -configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl http://localhost:$SOLR_PORT/solr
+
   echo -e "\n\nSolrCloud example running, please visit http://localhost:$SOLR_PORT/solr \n\n"
 fi
 

Modified: lucene/dev/trunk/solr/bin/solr.cmd
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/bin/solr.cmd?rev=1651231&r1=1651230&r2=1651231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/bin/solr.cmd (original)
+++ lucene/dev/trunk/solr/bin/solr.cmd Mon Jan 12 23:33:34 2015
@@ -76,6 +76,11 @@ IF "%1"=="healthcheck" (
   SHIFT
   goto parse_healthcheck_args
 )
+IF "%1"=="create" (
+  set SCRIPT_CMD=create
+  SHIFT
+  goto parse_create_args
+)
 IF "%1"=="create_core" (
   set SCRIPT_CMD=create_core
   SHIFT
@@ -98,6 +103,7 @@ IF "%SCRIPT_CMD%"=="start" goto start_us
 IF "%SCRIPT_CMD%"=="restart" goto start_usage
 IF "%SCRIPT_CMD%"=="stop" goto stop_usage
 IF "%SCRIPT_CMD%"=="healthcheck" goto healthcheck_usage
+IF "%SCRIPT_CMD%"=="create" goto create_usage
 IF "%SCRIPT_CMD%"=="create_core" goto create_core_usage
 IF "%SCRIPT_CMD%"=="create_collection" goto create_collection_usage
 goto done
@@ -105,7 +111,7 @@ goto done
 :script_usage
 @echo.
 @echo Usage: solr COMMAND OPTIONS
-@echo        where COMMAND is one of: start, stop, restart, healthcheck, create_core, create_collection
+@echo        where COMMAND is one of: start, stop, restart, healthcheck, create, create_core,
create_collection
 @echo.
 @echo   Standalone server example (start Solr running in the background on port 8984):
 @echo.
@@ -188,45 +194,80 @@ goto done
 @echo.
 goto done
 
+:create_usage
+echo.
+echo Usage: solr create [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor
#] [-p port]
+echo.
+echo   Create a core or collection depending on whether Solr is running in standalone (core)
or SolrCloud
+echo   mode (collection). In other words, this action detects which mode Solr is running
in, and then takes
+echo   the appropriate action (either create_core or create_collection). For detailed usage
instructions, do:
+echo.
+echo     bin\solr create_core -help
+echo.
+echo        or
+echo.
+echo     bin\solr create_collection -help
+echo.
+goto done
+
 :create_core_usage
 echo.
-echo Usage: solr create_core [-n name] [-c configset]
+echo Usage: solr create_core [-c name] [-d confdir] [-p port]
+echo.
+echo   -c name     Name of core to create
 echo.
-echo   -n name       Name of core to create
+echo   -d confdir  Configuration directory to copy when creating the new core, built-in options
are:
 echo.
-echo   -c configset  Name of configuration directory to use, valid options are:
 echo       basic_configs: Minimal Solr configuration
 echo       data_driven_schema_configs: Managed schema with field-guessing support enabled
 echo       sample_techproducts_configs: Example configuration with many optional features
enabled to
 echo          demonstrate the full power of Solr
+echo.
 echo       If not specified, default is: data_driven_schema_configs
 echo.
-echo   -p port       Port of a local Solr instance where you want to create the new core
-echo                  If not specified, the script will search the local system for a running
-echo                  Solr instance and will use the port of the first server it finds.
+echo       Alternatively, you can pass the path to your own configuration directory instead
of using
+echo       one of the built-in configurations, such as: bin\solr create_core -c mycore -d
c:/tmp/myconfig
+echo.
+echo   -p port     Port of a local Solr instance where you want to create the new core
+echo                 If not specified, the script will search the local system for a running
+echo                 Solr instance and will use the port of the first server it finds.
 echo.
 goto done
 
 :create_collection_usage
 echo.
-echo Usage: solr create_collection [-n name] [-c configset] [-shards #] [-replicationFactor
#]
+echo Usage: solr create_collection [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor
#] [-p port]
 echo.
-echo   -n name               Name of collection to create
+echo   -c name               Name of collection to create
+echo.
+echo   -d confdir            Configuration directory to copy when creating the new collection,
built-in options are:
 echo.
-echo   -c configset          Name of configuration directory to use, valid options are:
 echo       basic_configs: Minimal Solr configuration
 echo       data_driven_schema_configs: Managed schema with field-guessing support enabled
 echo       sample_techproducts_configs: Example configuration with many optional features
enabled to
 echo          demonstrate the full power of Solr
+echo.
 echo       If not specified, default is: data_driven_schema_configs
 echo.
+echo       Alternatively, you can pass the path to your own configuration directory instead
of using
+echo       one of the built-in configurations, such as: bin\solr create_collection -c mycoll
-d c:/tmp/myconfig
+echo.
+echo       By default the script will upload the specified confdir directory into ZooKeeper
using the same
+echo         name as the collection (-c) option. Alternatively, if you want to reuse an existing
directory
+echo         or create a confdir in ZooKeeper that can be shared by multiple collections,
use the -n option
+echo.
+echo   -n configName         Name the configuration directory in ZooKeeper; by default, the
configuration
+echo                             will be uploaded to ZooKeeper using the collection name
(-c), but if you want
+echo                             to use an existing directory or override the name of the
configuration in
+echo                              ZooKeeper, then use the -c option.
+echo.
 echo   -shards #             Number of shards to split the collection into
 echo.
 echo   -replicationFactor #  Number of copies of each document in the collection
 echo.
-echo   -p port       Port of a local Solr instance where you want to create the new collection
-echo                  If not specified, the script will search the local system for a running
-echo                  Solr instance and will use the port of the first server it finds.
+echo   -p port               Port of a local Solr instance where you want to create the new
collection
+echo                           If not specified, the script will search the local system
for a running
+echo                           Solr instance and will use the port of the first server it
finds.
 echo.
 goto done
 
@@ -758,12 +799,12 @@ IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
     "%JAVA%" -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 create_collection -name !EXAMPLE_NAME! -shards 1 -replicationFactor
1 ^
-      -config !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
-solrUrl http://localhost:%SOLR_PORT%/solr
+      -confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
-solrUrl http://localhost:%SOLR_PORT%/solr
   ) ELSE (
     "%JAVA%" -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 create_core -name !EXAMPLE_NAME! -solrUrl http://localhost:%SOLR_PORT%/solr
^
-      -config !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
+      -confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
   )
 )
 
@@ -929,7 +970,7 @@ goto create_collection
 "%JAVA%" -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 create_collection -name !CLOUD_COLLECTION! -shards !CLOUD_NUM_SHARDS!
-replicationFactor !CLOUD_REPFACT! ^
-  -config !CLOUD_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -zkHost %zk_host%
+  -confdir !CLOUD_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -zkHost %zk_host%
 
 echo.
 echo SolrCloud example is running, please visit http://localhost:%NODE1_PORT%/solr"
@@ -996,26 +1037,38 @@ goto done
 
 :parse_create_args
 IF [%1]==[] goto run_create
-IF "%1"=="-c" goto set_create_config
-IF "%1"=="-configset" goto set_create_config
-IF "%1"=="-n" goto set_create_name
-IF "%1"=="-name" goto set_create_name
+IF "%1"=="-c" goto set_create_name
+IF "%1"=="-core" goto set_create_name
+IF "%1"=="-collection" goto set_create_name
+IF "%1"=="-d" goto set_create_confdir
+IF "%1"=="-confdir" goto set_create_confdir
+IF "%1"=="-n" goto set_create_confname
+IF "%1"=="-confname" goto set_create_confname
+IF "%1"=="-s" goto set_create_shards
 IF "%1"=="-shards" goto set_create_shards
+IF "%1"=="-rf" goto set_create_rf
 IF "%1"=="-replicationFactor" goto set_create_rf
 IF "%1"=="-p" goto set_create_port
+IF "%1"=="-port" goto set_create_port
 IF "%1"=="-help" goto usage
 IF "%1"=="-usage" goto usage
 IF "%1"=="/?" goto usage
 goto run_create
 
-:set_create_configset
-set CREATE_CONFIGSET=%~2
+:set_create_name
+set CREATE_NAME=%~2
 SHIFT
 SHIFT
 goto parse_create_args
 
-:set_create_name
-set CREATE_NAME=%~2
+:set_create_confdir
+set CREATE_CONFDIR=%~2
+SHIFT
+SHIFT
+goto parse_create_args
+
+:set_create_confname
+set CREATE_CONFNAME=%~2
 SHIFT
 SHIFT
 goto parse_create_args
@@ -1040,12 +1093,13 @@ goto parse_create_args
 
 :run_create
 IF "!CREATE_NAME!"=="" (
-  set "SCRIPT_ERROR=Name (-n) is a required parameter for %SCRIPT_CMD%"
+  set "SCRIPT_ERROR=Name (-c) is a required parameter for %SCRIPT_CMD%"
   goto invalid_cmd_line
 )
-IF "!CREATE_CONFIGSET!"=="" set CREATE_CONFIGSET=data_driven_schema_configs
+IF "!CREATE_CONFDIR!"=="" set CREATE_CONFDIR=data_driven_schema_configs
 IF "!CREATE_NUM_SHARDS!"=="" set CREATE_NUM_SHARDS=1
 IF "!CREATE_REPFACT!"=="" set CREATE_REPFACT=1
+IF "!CREATE_CONFNAME!"=="" set CREATE_CONFNAME=!CREATE_NAME!
 
 REM Find a port that Solr is running on
 if "!CREATE_PORT!"=="" (
@@ -1064,19 +1118,18 @@ if "!CREATE_PORT!"=="" (
   goto err
 )
 
-@echo Found Solr node running on port !CREATE_PORT!
-
 if "%SCRIPT_CMD%"=="create_core" (
   "%JAVA%" -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 create_core -name !CREATE_NAME!  -solrUrl http://localhost:!CREATE_PORT!/solr
^
-    -config !CREATE_CONFIGSET! -configsetsDir "%SOLR_TIP%\server\solr\configsets"
+    org.apache.solr.util.SolrCLI create_core -name !CREATE_NAME! -solrUrl http://localhost:!CREATE_PORT!/solr
^
+    -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets"
 ) else (
   "%JAVA%" -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 create_collection -name !CREATE_NAME! -shards !CREATE_NUM_SHARDS!
-replicationFactor !CREATE_REPFACT! ^
-    -config !CREATE_CONFIGSET! -configsetsDir "%SOLR_TIP%\server\solr\configsets" -solrUrl
http://localhost:!CREATE_PORT!/solr
+  -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*"
^
+  org.apache.solr.util.SolrCLI create -name !CREATE_NAME! -shards !CREATE_NUM_SHARDS! -replicationFactor
!CREATE_REPFACT! ^
+  -confname !CREATE_CONFNAME! -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets"
-solrUrl http://localhost:!CREATE_PORT!/solr
 )
+
 goto done
 
 :invalid_cmd_line
@@ -1097,6 +1150,8 @@ IF "%FIRST_ARG%"=="start" (
   goto stop_usage
 ) ELSE IF "%FIRST_ARG%"=="healthcheck" (
   goto healthcheck_usage
+) ELSE IF "%FIRST_ARG%"=="create" (
+  goto create_usage
 ) ELSE IF "%FIRST_ARG%"=="create_core" (
   goto create_core_usage
 ) ELSE IF "%FIRST_ARG%"=="create_collection" (

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java?rev=1651231&r1=1651230&r2=1651231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java Mon Jan 12 23:33:34
2015
@@ -127,7 +127,7 @@ public class SolrCLI {
         // since this is a CLI, spare the user the stacktrace
         String excMsg = exc.getMessage();
         if (excMsg != null) {
-          System.err.println("\nERROR:"+excMsg+"\n");
+          System.err.println("\nERROR: "+excMsg+"\n");
           exitStatus = 1;
         } else {
           throw exc;
@@ -215,6 +215,8 @@ public class SolrCLI {
       return new CreateCollectionTool();
     else if ("create_core".equals(toolType))
       return new CreateCoreTool();
+    else if ("create".equals(toolType))
+      return new CreateTool();
 
     // If you add a built-in tool to this class, add it here to avoid
     // classpath scanning
@@ -235,6 +237,7 @@ public class SolrCLI {
     formatter.printHelp("api", getToolOptions(new ApiTool()));
     formatter.printHelp("create_collection", getToolOptions(new CreateCollectionTool()));
     formatter.printHelp("create_core", getToolOptions(new CreateCoreTool()));
+    formatter.printHelp("create", getToolOptions(new CreateTool()));
 
     List<Class<Tool>> toolClasses = findToolClassesInPackage("org.apache.solr.util");
     for (Class<Tool> next : toolClasses) {
@@ -993,6 +996,64 @@ public class SolrCLI {
     }
   } // end HealthcheckTool
 
+  private static final Option[] CREATE_COLLECTION_OPTIONS = new Option[] {
+    OptionBuilder
+        .withArgName("HOST")
+        .hasArg()
+        .isRequired(false)
+        .withDescription("Address of the Zookeeper ensemble; defaults to: "+ZK_HOST)
+        .create("zkHost"),
+        OptionBuilder
+            .withArgName("HOST")
+            .hasArg()
+            .isRequired(false)
+            .withDescription("Base Solr URL, which can be used to determine the zkHost if
that's not known")
+            .create("solrUrl"),
+        OptionBuilder
+            .withArgName("NAME")
+            .hasArg()
+            .isRequired(true)
+            .withDescription("Name of collection to create.")
+            .create("name"),
+        OptionBuilder
+            .withArgName("#")
+            .hasArg()
+            .isRequired(false)
+            .withDescription("Number of shards; default is 1")
+            .create("shards"),
+        OptionBuilder
+            .withArgName("#")
+            .hasArg()
+            .isRequired(false)
+            .withDescription("Number of copies of each document across the collection (replicas
per shard); default is 1")
+            .create("replicationFactor"),
+        OptionBuilder
+            .withArgName("#")
+            .hasArg()
+            .isRequired(false)
+            .withDescription("Maximum number of shards per Solr node; default is determined
based on the number of shards, replication factor, and live nodes.")
+            .create("maxShardsPerNode"),
+        OptionBuilder
+            .withArgName("NAME")
+            .hasArg()
+            .isRequired(false)
+            .withDescription("Configuration directory to copy when creating the new collection;
default is "+DEFAULT_CONFIG_SET)
+            .create("confdir"),
+        OptionBuilder
+            .withArgName("NAME")
+            .hasArg()
+            .isRequired(false)
+            .withDescription("Configuration name; default is the collection name")
+            .create("confname"),
+        OptionBuilder
+            .withArgName("DIR")
+            .hasArg()
+            .isRequired(true)
+            .withDescription("Path to configsets directory on the local system.")
+            .create("configsetsDir")
+  };
+
+
   /**
    * Supports create_collection command in the bin/solr script.
    */
@@ -1006,56 +1067,7 @@ public class SolrCLI {
     @SuppressWarnings("static-access")
     @Override
     public Option[] getOptions() {
-      return new Option[] {
-          OptionBuilder
-              .withArgName("HOST")
-              .hasArg()
-              .isRequired(false)
-              .withDescription("Address of the Zookeeper ensemble; defaults to: "+ZK_HOST)
-              .create("zkHost"),
-          OptionBuilder
-              .withArgName("HOST")
-              .hasArg()
-              .isRequired(false)
-              .withDescription("Base Solr URL, which can be used to determine the zkHost
if that's not known")
-              .create("solrUrl"),
-          OptionBuilder
-              .withArgName("NAME")
-              .hasArg()
-              .isRequired(true)
-              .withDescription("Name of collection to create.")
-              .create("name"),
-          OptionBuilder
-              .withArgName("#")
-              .hasArg()
-              .isRequired(false)
-              .withDescription("Number of shards; default is 1")
-              .create("shards"),
-          OptionBuilder
-              .withArgName("#")
-              .hasArg()
-              .isRequired(false)
-              .withDescription("Number of copies of each document across the collection (replicas
per shard); default is 1")
-              .create("replicationFactor"),
-          OptionBuilder
-              .withArgName("#")
-              .hasArg()
-              .isRequired(false)
-              .withDescription("Maximum number of shards per Solr node; default is determined
based on the number of shards, replication factor, and live nodes.")
-              .create("maxShardsPerNode"),
-          OptionBuilder
-              .withArgName("NAME")
-              .hasArg()
-              .isRequired(false)
-              .withDescription("Name of the configuration for this collection; default is
"+DEFAULT_CONFIG_SET)
-              .create("config"),
-          OptionBuilder
-              .withArgName("DIR")
-              .hasArg()
-              .isRequired(true)
-              .withDescription("Path to configsets directory on the local system.")
-              .create("configsetsDir")
-      };
+      return CREATE_COLLECTION_OPTIONS;
     }
 
     public int runTool(CommandLine cli) throws Exception {
@@ -1137,6 +1149,8 @@ public class SolrCLI {
             "there is at least 1 live node in the cluster.");
       String firstLiveNode = liveNodes.iterator().next();
 
+      String collectionName = cli.getOptionValue("name");
+
       // build a URL to create the collection
       int numShards = optionAsInt(cli, "shards", 1);
       int replicationFactor = optionAsInt(cli, "replicationFactor", 1);
@@ -1150,48 +1164,51 @@ public class SolrCLI {
         maxShardsPerNode = ((numShards*replicationFactor)+numNodes-1)/numNodes;
       }
 
-      String configSet = cli.getOptionValue("config", DEFAULT_CONFIG_SET);
-      String configSetNameInZk = configSet;
-      File configSetDir = null;
-      // we try to be flexible and allow the user to specify a configuration directory instead
of a configset name
-      File possibleConfigDir = new File(configSet);
-      if (possibleConfigDir.isDirectory()) {
-        configSetDir = possibleConfigDir;
-        configSetNameInZk = possibleConfigDir.getName();
+      String confname = cli.getOptionValue("confname", collectionName);
+      boolean configExistsInZk =
+          cloudSolrClient.getZkStateReader().getZkClient().exists("/configs/"+confname, true);
+
+      if (configExistsInZk) {
+        System.out.println("Re-using existing configuration directory "+confname);
       } else {
-        File configsetsDir = new File(cli.getOptionValue("configsetsDir"));
-        if (!configsetsDir.isDirectory())
-          throw new FileNotFoundException(configsetsDir.getAbsolutePath()+" not found!");
-
-        // upload the configset if it exists
-        configSetDir = new File(configsetsDir, configSet);
-        if (!configSetDir.isDirectory()) {
-          throw new FileNotFoundException("Specified config " + configSet +
-              " not found in " + configsetsDir.getAbsolutePath());
+        String configSet = cli.getOptionValue("confdir", DEFAULT_CONFIG_SET);
+        File configSetDir = null;
+        // we try to be flexible and allow the user to specify a configuration directory
instead of a configset name
+        File possibleConfigDir = new File(configSet);
+        if (possibleConfigDir.isDirectory()) {
+          configSetDir = possibleConfigDir;
+        } else {
+          File configsetsDir = new File(cli.getOptionValue("configsetsDir"));
+          if (!configsetsDir.isDirectory())
+            throw new FileNotFoundException(configsetsDir.getAbsolutePath()+" not found!");
+
+          // upload the configset if it exists
+          configSetDir = new File(configsetsDir, configSet);
+          if (!configSetDir.isDirectory()) {
+            throw new FileNotFoundException("Specified config " + configSet +
+                " not found in " + configsetsDir.getAbsolutePath());
+          }
         }
-      }
 
-      File confDir = new File(configSetDir, "conf");
-      if (!confDir.isDirectory()) {
-        // config dir should contain a conf sub-directory but if not and there's a solrconfig.xml,
then use it
-        if ((new File(configSetDir, "solrconfig.xml")).isFile()) {
-          confDir = configSetDir;
-        } else {
-          System.err.println("Specified configuration directory "+configSetDir.getAbsolutePath()+
-              " is invalid;\nit should contain either conf sub-directory or solrconfig.xml");
-          return 1;
+        File confDir = new File(configSetDir, "conf");
+        if (!confDir.isDirectory()) {
+          // config dir should contain a conf sub-directory but if not and there's a solrconfig.xml,
then use it
+          if ((new File(configSetDir, "solrconfig.xml")).isFile()) {
+            confDir = configSetDir;
+          } else {
+            System.err.println("Specified configuration directory "+configSetDir.getAbsolutePath()+
+                " is invalid;\nit should contain either conf sub-directory or solrconfig.xml");
+            return 1;
+          }
         }
-      }
 
-      // test to see if that config exists in ZK
-      if (!cloudSolrClient.getZkStateReader().getZkClient().exists("/configs/"+configSetNameInZk,
true)) {
+        // test to see if that config exists in ZK
         System.out.println("Uploading "+confDir.getAbsolutePath()+
-            " for config "+configSetNameInZk+" to ZooKeeper at "+cloudSolrClient.getZkHost());
-        ZkController.uploadConfigDir(cloudSolrClient.getZkStateReader().getZkClient(), confDir,
configSetNameInZk);
+            " for config "+confname+" to ZooKeeper at "+cloudSolrClient.getZkHost());
+        ZkController.uploadConfigDir(cloudSolrClient.getZkStateReader().getZkClient(), confDir,
confname);
       }
 
       String baseUrl = cloudSolrClient.getZkStateReader().getBaseUrlForNodeName(firstLiveNode);
-      String collectionName = cli.getOptionValue("name");
 
       // since creating a collection is a heavy-weight operation, check for existence first
       String collectionListUrl = baseUrl+"/admin/collections?action=list";
@@ -1211,7 +1228,7 @@ public class SolrCLI {
               numShards,
               replicationFactor,
               maxShardsPerNode,
-              configSetNameInZk);
+              confname);
 
       System.out.println("\nCreating new collection '"+collectionName+"' using command:\n"+createCollectionUrl+"\n");
 
@@ -1282,8 +1299,8 @@ public class SolrCLI {
               .withArgName("CONFIG")
               .hasArg()
               .isRequired(false)
-              .withDescription("Name of the configuration for this core; default is "+DEFAULT_CONFIG_SET)
-              .create("config"),
+              .withDescription("Configuration directory to copy when creating the new core;
default is "+DEFAULT_CONFIG_SET)
+              .create("confdir"),
           OptionBuilder
               .withArgName("DIR")
               .hasArg()
@@ -1304,7 +1321,7 @@ public class SolrCLI {
       if (!configsetsDir.isDirectory())
         throw new FileNotFoundException(configsetsDir.getAbsolutePath() + " not found!");
 
-      String configSet = cli.getOptionValue("config", DEFAULT_CONFIG_SET);
+      String configSet = cli.getOptionValue("confdir", DEFAULT_CONFIG_SET);
       File configSetDir = new File(configsetsDir, configSet);
       if (!configSetDir.isDirectory()) {
         // we allow them to pass a directory instead of a configset name
@@ -1312,7 +1329,7 @@ public class SolrCLI {
         if (possibleConfigDir.isDirectory()) {
           configSetDir = possibleConfigDir;
         } else {
-          throw new FileNotFoundException("Specified config " + configSet +
+          throw new FileNotFoundException("Specified config directory " + configSet +
               " not found in " + configsetsDir.getAbsolutePath());
         }
       }
@@ -1415,4 +1432,47 @@ public class SolrCLI {
       return exists;
     }
   } // end CreateCoreTool class
+
+  public static class CreateTool implements Tool {
+
+    @Override
+    public String getName() {
+      return "create";
+    }
+
+    @SuppressWarnings("static-access")
+    @Override
+    public Option[] getOptions() {
+      return CREATE_COLLECTION_OPTIONS;
+    }
+
+    @Override
+    public int runTool(CommandLine cli) throws Exception {
+
+      String solrUrl = cli.getOptionValue("solrUrl", "http://localhost:8983/solr");
+      if (!solrUrl.endsWith("/"))
+        solrUrl += "/";
+
+      String systemInfoUrl = solrUrl+"admin/info/system";
+      CloseableHttpClient httpClient = getHttpClient();
+
+      int result = -1;
+      Tool tool = null;
+      try {
+        Map<String,Object> systemInfo = getJson(httpClient, systemInfoUrl, 2);
+        if ("solrcloud".equals(systemInfo.get("mode"))) {
+          tool = new CreateCollectionTool();
+        } else {
+          tool = new CreateCoreTool();
+        }
+        result = tool.runTool(cli);
+      } finally {
+        closeHttpClient(httpClient);
+      }
+
+      return result;
+    }
+
+  } // end CreateTool class
+
 }



Mime
View raw message