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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1651231 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2015-01-12 23:33:34 +00:00
parent 5326c924d2
commit c36180cdf8
6 changed files with 348 additions and 209 deletions

View File

@ -856,7 +856,7 @@ def testSolrExample(unpackPath, javaPath, isSrc):
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')

View File

@ -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

View File

@ -32,32 +32,28 @@ To start Solr for the first time after installation, simply do:
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:
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
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:
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 start -cloud
After starting Solr in cloud mode, you can create a new collection for indexing
your data by doing:
bin/solr create_collection -n <name>
To see all available options for starting Solr, please do:
bin/solr start -help
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 -n <name>
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 create -help
After starting Solr, direct your Web browser to the Solr Admin Console at:
http://localhost:8983/solr/
@ -98,18 +94,6 @@ For more information about Solr examples please read...
* 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

View File

@ -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,21 +209,37 @@ 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"
@ -231,19 +247,30 @@ function print_usage() {
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 ""
@ -486,32 +513,36 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; then
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" || "$SCRIPT_CMD" == "create_collection" ]];
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" || "$SCRIPT_CMD" == "create_collection" ]];
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,19 +1249,12 @@ 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
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
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
fi
if [ "$EXAMPLE" == "techproducts" ]; then
echo "Indexing tech product example docs from $SOLR_TIP/example/exampledocs"
@ -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

View File

@ -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_usage
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,19 +194,40 @@ 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 -n name Name of core to create
echo -c name 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, 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_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.
@ -209,17 +236,31 @@ 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
@ -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"
-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
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" (

View File

@ -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,20 +996,7 @@ public class SolrCLI {
}
} // end HealthcheckTool
/**
* Supports create_collection command in the bin/solr script.
*/
public static class CreateCollectionTool implements Tool {
@Override
public String getName() {
return "create_collection";
}
@SuppressWarnings("static-access")
@Override
public Option[] getOptions() {
return new Option[] {
private static final Option[] CREATE_COLLECTION_OPTIONS = new Option[] {
OptionBuilder
.withArgName("HOST")
.hasArg()
@ -1047,8 +1037,14 @@ public class SolrCLI {
.withArgName("NAME")
.hasArg()
.isRequired(false)
.withDescription("Name of the configuration for this collection; default is "+DEFAULT_CONFIG_SET)
.create("config"),
.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()
@ -1056,6 +1052,22 @@ public class SolrCLI {
.withDescription("Path to configsets directory on the local system.")
.create("configsetsDir")
};
/**
* Supports create_collection command in the bin/solr script.
*/
public static class CreateCollectionTool implements Tool {
@Override
public String getName() {
return "create_collection";
}
@SuppressWarnings("static-access")
@Override
public Option[] getOptions() {
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,14 +1164,19 @@ public class SolrCLI {
maxShardsPerNode = ((numShards*replicationFactor)+numNodes-1)/numNodes;
}
String configSet = cli.getOptionValue("config", DEFAULT_CONFIG_SET);
String configSetNameInZk = configSet;
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 {
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;
configSetNameInZk = possibleConfigDir.getName();
} else {
File configsetsDir = new File(cli.getOptionValue("configsetsDir"));
if (!configsetsDir.isDirectory())
@ -1184,14 +1203,12 @@ public class SolrCLI {
}
// test to see if that config exists in ZK
if (!cloudSolrClient.getZkStateReader().getZkClient().exists("/configs/"+configSetNameInZk, true)) {
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
}