You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2014/11/27 00:12:09 UTC
svn commit: r1641961 - in /lucene/dev/trunk/solr: bin/solr bin/solr.cmd
core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
core/src/java/org/apache/solr/util/SolrCLI.java
Author: thelabdude
Date: Wed Nov 26 23:12:08 2014
New Revision: 1641961
URL: http://svn.apache.org/r1641961
Log:
SOLR-3619: clone configsets when starting examples or creating cores instead of using configsets directly; selectively clone the server directory when creating node1 for the cloud example; fix script error reporting
Modified:
lucene/dev/trunk/solr/bin/solr
lucene/dev/trunk/solr/bin/solr.cmd
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java
Modified: lucene/dev/trunk/solr/bin/solr
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/bin/solr?rev=1641961&r1=1641960&r2=1641961&view=diff
==============================================================================
--- lucene/dev/trunk/solr/bin/solr (original)
+++ lucene/dev/trunk/solr/bin/solr Wed Nov 26 23:12:08 2014
@@ -409,17 +409,17 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; t
case $1 in
-c|-collection)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected collection name but found $2 instead!"
- exit 1
+ print_usage "$SCRIPT_CMD" "Collection name is required when using the $1 option!"
+ exit 1
fi
HEALTHCHECK_COLLECTION=$2
shift 2
;;
-z|-zkhost)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected a ZooKeeper connection string but found $2 instead!"
- exit 1
- fi
+ print_usage "$SCRIPT_CMD" "ZooKeepeer connection string is required when using the $1 option!"
+ exit 1
+ fi
ZK_HOST="$2"
shift 2
;;
@@ -473,7 +473,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
case $1 in
-n|-name)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected $CREATE_TYPE name but found $2 instead!"
+ print_usage "$SCRIPT_CMD" "$CREATE_TYPE name is required when using the $1 option!"
exit 1
fi
CREATE_NAME=$2
@@ -481,7 +481,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
;;
-c|-configset)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected configset name but found $2 instead!"
+ print_usage "$SCRIPT_CMD" "Configset name is required when using the $1 option!"
exit 1
fi
CREATE_CONFIGSET="$2"
@@ -489,7 +489,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
;;
-shards)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected shard count but found $2 instead!"
+ print_usage "$SCRIPT_CMD" "Shard count is required when using the $1 option!"
exit 1
fi
CREATE_NUM_SHARDS="$2"
@@ -497,12 +497,20 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
;;
-replicationFactor)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected replication factor but found $2 instead!"
+ print_usage "$SCRIPT_CMD" "Replication factor is required when using the $1 option!"
exit 1
fi
CREATE_REPFACT="$2"
shift 2
;;
+ -p|-port)
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
+ print_usage "$SCRIPT_CMD" "Solr port is required when using the $1 option!"
+ exit 1
+ fi
+ CREATE_PORT="$2"
+ shift 2
+ ;;
-help|-usage)
print_usage "$SCRIPT_CMD"
exit 0
@@ -533,41 +541,28 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
exit 1
fi
- for ID in `ps auxww | grep java | grep start.jar | awk '{print $2}' | sort -r`
- do
- port=`jetty_port "$ID"`
- if [ "$port" != "" ]; then
- CREATE_PORT=$port
- break
- fi
- done
-
if [ "$CREATE_PORT" == "" ]; then
- echo "Failed to determine the port of a local Solr instance, cannot create $CREATE_TYPE!"
- exit 1
+ for ID in `ps auxww | grep java | grep start.jar | awk '{print $2}' | sort -r`
+ do
+ port=`jetty_port "$ID"`
+ if [ "$port" != "" ]; then
+ CREATE_PORT=$port
+ break
+ fi
+ done
fi
- STATUS_INFO=`run_tool status -solr http://localhost:$CREATE_PORT/solr | tr -d ' '`
- IS_CLOUD=`echo $STATUS_INFO | grep $'"cloud":' | tr -d ' '`
- if [ "$IS_CLOUD" != "" ]; then
- if [ "$SCRIPT_CMD" == "create_core" ]; then
- echo -e "\nERROR: Solr running on port $CREATE_PORT is running in SolrCloud mode, please use create_collection command instead.\n"
- exit 1
- fi
- else
- if [ "$SCRIPT_CMD" == "create_collection" ]; then
- echo -e "\nERROR: Solr running on port $CREATE_PORT is running in standalone server mode, please use the create_core command instead\ncreate_collection can only be used when running in SolrCloud mode.\n"
- exit 1
- fi
+ if [ "$CREATE_PORT" == "" ]; then
+ echo "Failed to determine the port of a local Solr instance, cannot create $CREATE_TYPE $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
else
- CREATE_URL="http://localhost:$CREATE_PORT/solr/admin/cores?action=CREATE&name=$CREATE_NAME&configSet=$CREATE_CONFIGSET"
- echo -e "Creating new core using command:\n$CREATE_URL\n"
- run_tool api -get $CREATE_URL
+ run_tool create_core -name $CREATE_NAME -solrUrl http://localhost:$CREATE_PORT/solr \
+ -config $CREATE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets
fi
exit $?
@@ -576,7 +571,7 @@ fi
# verify the command given is supported
if [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "restart" ]; then
- print_usage "" "$SCRIPT_CMD not supported!"
+ print_usage "" "$SCRIPT_CMD is not a valid command!"
exit 1
fi
@@ -593,8 +588,8 @@ if [ $# -gt 0 ]; then
;;
-d|-dir)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected directory but found $2 instead!"
- exit 1
+ print_usage "$SCRIPT_CMD" "Server directory is required when using the $1 option!"
+ exit 1
fi
# see if the arg value is relative to the tip vs full path
@@ -607,7 +602,7 @@ if [ $# -gt 0 ]; then
;;
-s|-solr.home)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected directory but found $2 instead!"
+ print_usage "$SCRIPT_CMD" "Solr home directory is required when using the $1 option!"
exit 1
fi
@@ -616,8 +611,8 @@ if [ $# -gt 0 ]; then
;;
-e|-example)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected example name but found $2 instead!"
- exit 1
+ print_usage "$SCRIPT_CMD" "Example name is required when using the $1 option!"
+ exit 1
fi
EXAMPLE="$2"
shift 2
@@ -628,34 +623,33 @@ if [ $# -gt 0 ]; then
;;
-h|-host)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected hostname but found $2 instead!"
- exit 1
+ print_usage "$SCRIPT_CMD" "Hostname is required when using the $1 option!"
+ exit 1
fi
SOLR_HOST="$2"
shift 2
;;
-m|-memory)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected memory setting but found $2 instead!"
- exit 1
- fi
+ print_usage "$SCRIPT_CMD" "Memory setting is required when using the $1 option!"
+ exit 1
+ fi
SOLR_HEAP="$2"
shift 2
;;
-p|-port)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected port number but found $2 instead!"
- exit 1
- fi
+ print_usage "$SCRIPT_CMD" "Port number is required when using the $1 option!"
+ exit 1
+ fi
SOLR_PORT="$2"
shift 2
;;
-z|-zkhost)
if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
- print_usage "$SCRIPT_CMD" "Expected ZooKeeper connection string but found $2 instead!"
- exit 1
+ print_usage "$SCRIPT_CMD" "ZooKeeper connection string is required when using the $1 option!"
+ exit 1
fi
-
ZK_HOST="$2"
shift 2
;;
@@ -689,7 +683,7 @@ if [ $# -gt 0 ]; then
;;
*)
if [ "$1" != "" ]; then
- print_usage "$SCRIPT_CMD" "Error parsing argument $1!"
+ print_usage "$SCRIPT_CMD" "$1 is not supported by this script"
exit 1
else
break # out-of-args, stop looping
@@ -782,15 +776,32 @@ if [ "$EXAMPLE" != "" ]; then
done
done
fi
-
- for (( s=0; s<$CLOUD_NUM_NODES; s++ ))
+
+ # first, clone the server directory (w/o pulling over existing cores)
+ if [ ! -d "$SOLR_TIP/node1" ]; then
+ echo "Cloning $DEFAULT_SERVER_DIR into $SOLR_TIP/node1"
+ mkdir -p $SOLR_TIP/node1
+ cp -r $DEFAULT_SERVER_DIR/contexts $SOLR_TIP/node1/
+ cp -r $DEFAULT_SERVER_DIR/etc $SOLR_TIP/node1/
+ cp -r $DEFAULT_SERVER_DIR/lib $SOLR_TIP/node1/
+ cp -r $DEFAULT_SERVER_DIR/resources $SOLR_TIP/node1/
+ cp -r $DEFAULT_SERVER_DIR/scripts $SOLR_TIP/node1/
+ cp -r $DEFAULT_SERVER_DIR/webapps $SOLR_TIP/node1/
+ cp $DEFAULT_SERVER_DIR/start.jar $SOLR_TIP/node1/
+ mkdir -p $SOLR_TIP/node1/solr-webapp
+ mkdir -p $SOLR_TIP/node1/solr
+ cp -r $DEFAULT_SERVER_DIR/solr/configsets $SOLR_TIP/node1/solr/
+ cp $DEFAULT_SERVER_DIR/solr/solr.xml $SOLR_TIP/node1/solr/
+ cp $DEFAULT_SERVER_DIR/solr/zoo.cfg $SOLR_TIP/node1/solr/
+ fi
+
+ for (( s=1; s<$CLOUD_NUM_NODES; s++ ))
do
ndx=$[$s+1]
if [ ! -d "$SOLR_TIP/node$ndx" ]; then
- echo "Cloning $DEFAULT_SERVER_DIR into $SOLR_TIP/node$ndx"
- cp -r $DEFAULT_SERVER_DIR $SOLR_TIP/node$ndx
- rm -rf $SOLR_TIP/node$ndx/solr/zoo_data
- fi
+ echo "Cloning $SOLR_TIP/node1 into $SOLR_TIP/node$ndx"
+ cp -r $SOLR_TIP/node1 $SOLR_TIP/node$ndx
+ fi
done
SOLR_MODE="solrcloud"
SOLR_SERVER_DIR="$SOLR_TIP/node1"
@@ -1094,9 +1105,8 @@ if [ "$EXAMPLE" != "cloud" ]; then
run_tool create_collection -name $EXAMPLE -shards 1 -replicationFactor 1 \
-config $EXAMPLE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl http://localhost:$SOLR_PORT/solr
else
- CREATE_URL="http://localhost:$SOLR_PORT/solr/admin/cores?action=CREATE&name=$EXAMPLE&configSet=$EXAMPLE_CONFIGSET"
- echo -e "Creating new core using command:\n$CREATE_URL\n"
- run_tool api -get $CREATE_URL
+ run_tool create_core -name $EXAMPLE -solrUrl http://localhost:$SOLR_PORT/solr \
+ -config $EXAMPLE_CONFIGSET -configsetsDir $SOLR_TIP/server/solr/configsets
fi
if [ "$EXAMPLE" == "techproducts" ]; then
Modified: lucene/dev/trunk/solr/bin/solr.cmd
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/bin/solr.cmd?rev=1641961&r1=1641960&r2=1641961&view=diff
==============================================================================
--- lucene/dev/trunk/solr/bin/solr.cmd (original)
+++ lucene/dev/trunk/solr/bin/solr.cmd Wed Nov 26 23:12:08 2014
@@ -458,7 +458,6 @@ IF NOT "%SOLR_HOST%"=="" (
set SOLR_HOST_ARG=
)
-REM TODO: Change this to "server" when we resolve SOLR-3619
IF "%SOLR_SERVER_DIR%"=="" set SOLR_SERVER_DIR=%DEFAULT_SERVER_DIR%
IF NOT EXIST "%SOLR_SERVER_DIR%" (
@@ -660,6 +659,11 @@ IF NOT "%SOLR_HOST_ARG%"=="" set START_O
IF NOT "%SOLR_OPTS%"=="" set START_OPTS=%START_OPTS% %SOLR_OPTS%
cd "%SOLR_SERVER_DIR%"
+
+IF NOT EXIST "%SOLR_SERVER_DIR%\logs" (
+ mkdir "%SOLR_SERVER_DIR%\logs"
+)
+
@echo.
@echo Starting Solr on port %SOLR_PORT% from %SOLR_SERVER_DIR%
@echo.
@@ -685,21 +689,17 @@ IF "%EXAMPLE%"=="techproducts" (
)
IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
- timeout /T 5
+ timeout /T 10
IF "%SOLR_MODE%"=="solrcloud" (
"%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! -shards 1 -replicationFactor 1 ^
-config !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -solrUrl http://localhost:%SOLR_PORT%/solr
) ELSE (
- set "CREATE_URL=http://localhost:%SOLR_PORT%/solr/admin/cores?action=CREATE&name=%EXAMPLE%&configSet=!CREATE_EXAMPLE_CONFIG!"
- @echo.
- @echo Creating new core using command:
- @echo !CREATE_URL!
- @echo.
"%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 api -get "!CREATE_URL!"
+ org.apache.solr.util.SolrCLI create_core -name !EXAMPLE! -solrUrl http://localhost:%SOLR_PORT%/solr ^
+ -config !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
)
)
@@ -750,6 +750,30 @@ IF NOT DEFINED CLOUD_NUM_NODES (
@echo Ok, let's start up %CLOUD_NUM_NODES% Solr nodes for your example SolrCloud cluster.
:start_cloud_nodes
+
+@echo Cloning %DEFAULT_SERVER_DIR% into %SOLR_TIP%\node1
+mkdir "%SOLR_TIP%\node1"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\contexts" "%SOLR_TIP%\node1\contexts"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\etc" "%SOLR_TIP%\node1\etc"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\lib" "%SOLR_TIP%\node1\lib"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\resources" "%SOLR_TIP%\node1\resources"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\scripts" "%SOLR_TIP%\node1\scripts"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\webapps" "%SOLR_TIP%\node1\webapps"
+copy "%DEFAULT_SERVER_DIR%\start.jar" "%SOLR_TIP%\node1\start.jar"
+mkdir "%SOLR_TIP%\node1\solr-webapp"
+mkdir "%SOLR_TIP%\node1\solr"
+mkdir "%SOLR_TIP%\node1\logs"
+xcopy /Q /E /I "%DEFAULT_SERVER_DIR%\solr\configsets" "%SOLR_TIP%\node1\solr\configsets"
+copy "%DEFAULT_SERVER_DIR%\solr\solr.xml" "%SOLR_TIP%\node1\solr\solr.xml"
+copy "%DEFAULT_SERVER_DIR%\solr\zoo.cfg" "%SOLR_TIP%\node1\solr\zoo.cfg"
+
+for /l %%x in (2, 1, !CLOUD_NUM_NODES!) do (
+ IF NOT EXIST "%SOLR_TIP%\node%%x" (
+ @echo Cloning %SOLR_TIP%\node1 into %SOLR_TIP%\node%%x
+ xcopy /Q /E /I "%SOLR_TIP%\node1" "%SOLR_TIP%\node%%x"
+ )
+)
+
for /l %%x in (1, 1, !CLOUD_NUM_NODES!) do (
set USER_INPUT=
set /A idx=%%x-1
@@ -776,11 +800,6 @@ for /l %%x in (1, 1, !CLOUD_NUM_NODES!)
@echo.
)
- IF NOT EXIST "%SOLR_TIP%\node%%x" (
- @echo Cloning %DEFAULT_SERVER_DIR% into %SOLR_TIP%\node%%x
- xcopy /Q /E /I "%DEFAULT_SERVER_DIR%" "%SOLR_TIP%\node%%x"
- )
-
IF NOT "!SOLR_HEAP!"=="" (
set "DASHM=-m !SOLR_HEAP!"
) ELSE (
@@ -928,6 +947,7 @@ IF "%1"=="-n" goto set_create_name
IF "%1"=="-name" goto set_create_name
IF "%1"=="-shards" goto set_create_shards
IF "%1"=="-replicationFactor" goto set_create_rf
+IF "%1"=="-p" goto set_create_port
IF "%1"=="-help" goto usage
IF "%1"=="-usage" goto usage
IF "%1"=="/?" goto usage
@@ -945,6 +965,12 @@ SHIFT
SHIFT
goto parse_create_args
+:set_create_port
+set CREATE_PORT=%~2
+SHIFT
+SHIFT
+goto parse_create_args
+
:set_create_shards
set CREATE_NUM_SHARDS=%~2
SHIFT
@@ -967,61 +993,34 @@ IF "!CREATE_NUM_SHARDS!"=="" set CREATE_
IF "!CREATE_REPFACT!"=="" set CREATE_REPFACT=1
REM Find a port that Solr is running on
-set CREATE_PORT=0
-for /f "usebackq" %%i in (`dir /b %SOLR_TIP\bin% ^| findstr /i "^solr-.*\.port$"`) do (
- set SOME_SOLR_PORT=
- For /F "Delims=" %%J In (%SOLR_TIP%\bin\%%i) do set SOME_SOLR_PORT=%%~J
- if NOT "!SOME_SOLR_PORT!"=="" (
- for /f "tokens=2,5" %%j in ('netstat -aon ^| find /i "listening" ^| find /i "!SOME_SOLR_PORT!"') do (
- set CREATE_PORT=!SOME_SOLR_PORT!
+if "!CREATE_PORT!"=="" (
+ for /f "usebackq" %%i in (`dir /b %SOLR_TIP\bin% ^| findstr /i "^solr-.*\.port$"`) do (
+ set SOME_SOLR_PORT=
+ For /F "Delims=" %%J In (%SOLR_TIP%\bin\%%i) do set SOME_SOLR_PORT=%%~J
+ if NOT "!SOME_SOLR_PORT!"=="" (
+ for /f "tokens=2,5" %%j in ('netstat -aon ^| find /i "listening" ^| find /i "!SOME_SOLR_PORT!"') do (
+ set CREATE_PORT=!SOME_SOLR_PORT!
+ )
)
)
)
-if "!CREATE_PORT!" EQU "0" (
- set "SCRIPT_ERROR=Could not find a running Solr instance on this host!"
+if "!CREATE_PORT!"=="" (
+ set "SCRIPT_ERROR=Could not find a running Solr instance on this host! Please use the -p option to specify the port."
goto err
)
@echo Found Solr node running on port !CREATE_PORT!
-@REM Determine if the Solr node is in cloud or standalone server mode
-"%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 status -solr http://localhost:!CREATE_PORT!/solr > solr_status.txt
-set /p VAR=<solr_status.txt
-del solr_status.txt
-if "!VAR!"=="!VAR:ZooKeeper=!" (
- @REM Not in CloudMode - create core
- if "%SCRIPT_CMD%"=="create_core" (
- set "CREATE_URL=http://localhost:!CREATE_PORT!/solr/admin/cores?action=CREATE&name=!CREATE_NAME!&configSet=!CREATE_CONFIGSET!"
- @echo.
- @echo Creating new core using command:
- @echo !CREATE_URL!
- @echo.
- "%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 api -get "!CREATE_URL!"
- ) else (
- @echo.
- @echo ERROR: Solr running on port !CREATE_PORT! is running in standalone server mode, please use the create_core command instead.
- @echo %SCRIPT_CMD% can only be used when running in SolrCloud mode.
- @echo.
- goto done
- )
-) ELSE (
- @REM In CloudMode - create collection
- if "%SCRIPT_CMD%"=="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 !CREATE_NAME! -shards !CREATE_NUM_SHARDS! -replicationFactor !CREATE_REPFACT! ^
- -config !CREATE_CONFIGSET! -configsetsDir "%SOLR_TIP%\server\solr\configsets" -solrUrl http://localhost:!CREATE_PORT!/solr
- ) else (
- @echo.
- @echo ERROR: Solr running on port !CREATE_PORT! is running in SolrCloud mode, please use the create_collection command instead.
- @echo %SCRIPT_CMD% can only be used when running in standalone server mode.
- @echo.
- goto done
- )
+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"
+) 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
)
goto done
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java?rev=1641961&r1=1641960&r2=1641961&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java Wed Nov 26 23:12:08 2014
@@ -95,6 +95,7 @@ public class SystemInfoHandler extends R
if (solrCloudMode) {
rsp.add("zkHost", getCoreContainer(req, core).getZkController().getZkServerAddress());
}
+ rsp.add( "solr_home", cc.getSolrHome());
rsp.add( "lucene", getLuceneInfo() );
rsp.add( "jvm", getJvmInfo() );
rsp.add( "system", getSystemInfo() );
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=1641961&r1=1641960&r2=1641961&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 Wed Nov 26 23:12:08 2014
@@ -43,6 +43,7 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NoHttpResponseException;
@@ -54,7 +55,6 @@ import org.apache.http.client.ResponseHa
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ConnectTimeoutException;
-import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
@@ -204,6 +204,8 @@ public class SolrCLI {
return new ApiTool();
else if ("create_collection".equals(toolType))
return new CreateCollectionTool();
+ else if ("create_core".equals(toolType))
+ return new CreateCoreTool();
// If you add a built-in tool to this class, add it here to avoid
// classpath scanning
@@ -223,6 +225,7 @@ public class SolrCLI {
formatter.printHelp("status", getToolOptions(new StatusTool()));
formatter.printHelp("api", getToolOptions(new ApiTool()));
formatter.printHelp("create_collection", getToolOptions(new CreateCollectionTool()));
+ formatter.printHelp("create_core", getToolOptions(new CreateCoreTool()));
List<Class<Tool>> toolClasses = findToolClassesInPackage("org.apache.solr.util");
for (Class<Tool> next : toolClasses) {
@@ -701,13 +704,13 @@ public class SolrCLI {
}
} // end ApiTool class
+ private static final String DEFAULT_CONFIG_SET = "data_driven_schema_configs";
+
/**
* Supports create_collection command in the bin/solr script.
*/
public static class CreateCollectionTool implements Tool {
- private static final String DEFAULT_CONFIG_SET = "data_driven_schema_configs";
-
@Override
public String getName() {
return "create_collection";
@@ -796,8 +799,12 @@ public class SolrCLI {
Map<String,Object> status = statusTool.reportStatus(solrUrl, systemInfo, httpClient);
Map<String,Object> cloud = (Map<String, Object>)status.get("cloud");
- if (cloud == null)
- throw new IllegalArgumentException("Solr server at "+solrUrl+" not running in SolrCloud mode!");
+ if (cloud == null) {
+ System.err.println("\nERROR: Solr at "+solrUrl+
+ " is running in standalone server mode, please use the create_core command instead;\n" +
+ "create_collection can only be used when running in SolrCloud mode.\n");
+ return 1;
+ }
String zookeeper = (String) cloud.get("ZooKeeper");
if (zookeeper.endsWith("(embedded)")) {
@@ -883,6 +890,7 @@ public class SolrCLI {
CharArr arr = new CharArr();
new JSONWriter(arr, 2).write(json);
System.out.println(arr.toString());
+ System.out.println();
}
protected int optionAsInt(CommandLine cli, String option, int defaultVal) {
@@ -1164,5 +1172,112 @@ public class SolrCLI {
new JSONWriter(arr, 2).write(report);
System.out.println(arr.toString());
}
- } // end HealthcheckTool
+ } // end HealthcheckTool
+
+ public static class CreateCoreTool implements Tool {
+
+ @Override
+ public String getName() {
+ return "create_core";
+ }
+
+ @SuppressWarnings("static-access")
+ @Override
+ public Option[] getOptions() {
+ return new Option[] {
+ OptionBuilder
+ .withArgName("URL")
+ .hasArg()
+ .isRequired(false)
+ .withDescription("Base Solr URL, default is http://localhost:8983/solr")
+ .create("solrUrl"),
+ OptionBuilder
+ .withArgName("NAME")
+ .hasArg()
+ .isRequired(true)
+ .withDescription("Name of the core to create.")
+ .create("name"),
+ OptionBuilder
+ .withArgName("CONFIG")
+ .hasArg()
+ .isRequired(false)
+ .withDescription("Name of the configuration for this core; default is "+DEFAULT_CONFIG_SET)
+ .create("config"),
+ OptionBuilder
+ .withArgName("DIR")
+ .hasArg()
+ .isRequired(true)
+ .withDescription("Path to configsets directory on the local system.")
+ .create("configsetsDir")
+ };
+ }
+
+ @Override
+ public int runTool(CommandLine cli) throws Exception {
+
+ String solrUrl = cli.getOptionValue("solrUrl", "http://localhost:8983/solr");
+ if (!solrUrl.endsWith("/"))
+ solrUrl += "/";
+
+ File configsetsDir = new File(cli.getOptionValue("configsetsDir"));
+ if (!configsetsDir.isDirectory())
+ throw new FileNotFoundException(configsetsDir.getAbsolutePath()+" not found!");
+
+ String configSet = cli.getOptionValue("config", DEFAULT_CONFIG_SET);
+ File 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");
+
+ String coreName = cli.getOptionValue("name");
+
+ String systemInfoUrl = solrUrl+"admin/info/system";
+ HttpClient httpClient = getHttpClient();
+ String solrHome = null;
+ try {
+ Map<String,Object> systemInfo = getJson(httpClient, systemInfoUrl, 2);
+ if ("solrcloud".equals(systemInfo.get("mode"))) {
+ System.err.println("\nERROR: Solr at "+solrUrl+
+ " is running in SolrCloud mode, please use create_collection command instead.\n");
+ return 1;
+ }
+
+ // convert raw JSON into user-friendly output
+ solrHome = (String)systemInfo.get("solr_home");
+ if (solrHome == null) {
+ solrHome = configsetsDir.getParentFile().getAbsolutePath();
+ }
+ } finally {
+ closeHttpClient(httpClient);
+ }
+
+ File coreInstanceDir = new File(solrHome, coreName);
+ if (!coreInstanceDir.isDirectory()) {
+ coreInstanceDir.mkdirs();
+ if (!coreInstanceDir.isDirectory())
+ throw new IOException("Failed to create new core instance directory: "+coreInstanceDir.getAbsolutePath());
+ }
+
+ FileUtils.copyDirectoryToDirectory(confDir, coreInstanceDir);
+
+ String createCoreUrl =
+ String.format(Locale.ROOT,
+ "%sadmin/cores?action=CREATE&name=%s&instanceDir=%s",
+ solrUrl,
+ coreName,
+ coreName);
+
+ System.out.println("Creating new core '"+coreName+"' using command:\n\n"+createCoreUrl+"\n");
+
+ Map<String,Object> json = getJson(createCoreUrl);
+ CharArr arr = new CharArr();
+ new JSONWriter(arr, 2).write(json);
+ System.out.println(arr.toString());
+ System.out.println();
+
+ return 0;
+ }
+ } // end CreateCoreTool class
}