SOLR-7847: Implement run example logic in Java instead of OS-specific scripts in bin/solr

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1694083 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2015-08-04 16:32:12 +00:00
parent 92900dd203
commit c1522a9c75
11 changed files with 1846 additions and 792 deletions

View File

@ -96,6 +96,7 @@ com.sun.jersey.version = 1.9
/org.apache.ant/ant = 1.8.2
/org.apache.avro/avro = 1.7.5
/org.apache.commons/commons-compress = 1.8.1
/org.apache.commons/commons-exec = 1.3
/org.apache.commons/commons-math3 = 3.4.1
org.apache.curator.version = 2.8.0

View File

@ -405,6 +405,9 @@ Other Changes
* SOLR-7832: bin/post now allows either -url or -c, rather than requiring both. (ehatcher)
* SOLR-7847: Implement run example logic in Java instead of OS-specific scripts in
bin/solr and bin\solr.cmd (Timothy Potter)
================== 5.2.1 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -809,12 +809,14 @@ fi
FG="false"
noprompt=false
SOLR_OPTS=($SOLR_OPTS)
PASS_TO_RUN_EXAMPLE=
if [ $# -gt 0 ]; then
while true; do
case "$1" in
-c|-cloud)
SOLR_MODE="solrcloud"
PASS_TO_RUN_EXAMPLE+=" -c"
shift
;;
-d|-dir)
@ -864,6 +866,7 @@ if [ $# -gt 0 ]; then
exit 1
fi
SOLR_HOST="$2"
PASS_TO_RUN_EXAMPLE+=" -h $SOLR_HOST"
shift 2
;;
-m|-memory)
@ -872,6 +875,7 @@ if [ $# -gt 0 ]; then
exit 1
fi
SOLR_HEAP="$2"
PASS_TO_RUN_EXAMPLE+=" -m $SOLR_HEAP"
shift 2
;;
-p|-port)
@ -880,6 +884,7 @@ if [ $# -gt 0 ]; then
exit 1
fi
SOLR_PORT="$2"
PASS_TO_RUN_EXAMPLE+=" -p $SOLR_PORT"
shift 2
;;
-z|-zkhost)
@ -889,10 +894,12 @@ if [ $# -gt 0 ]; then
fi
ZK_HOST="$2"
SOLR_MODE="solrcloud"
PASS_TO_RUN_EXAMPLE+=" -z $ZK_HOST"
shift 2
;;
-a|-addlopts)
ADDITIONAL_CMD_OPTS="$2"
PASS_TO_RUN_EXAMPLE+=" -a \"$ADDITIONAL_CMD_OPTS\""
shift 2
;;
-k|-key)
@ -905,10 +912,12 @@ if [ $# -gt 0 ]; then
;;
-noprompt)
noprompt=true
PASS_TO_RUN_EXAMPLE+=" -noprompt"
shift
;;
-V|-verbose)
verbose=true
PASS_TO_RUN_EXAMPLE+=" --verbose"
shift
;;
-all)
@ -923,6 +932,7 @@ if [ $# -gt 0 ]; then
if [ "${1:0:2}" == "-D" ]; then
# pass thru any opts that begin with -D (java system props)
SOLR_OPTS+=("$1")
PASS_TO_RUN_EXAMPLE+=" $1"
shift
else
if [ "$1" != "" ]; then
@ -937,6 +947,31 @@ if [ $# -gt 0 ]; then
done
fi
if [ -z "$SOLR_SERVER_DIR" ]; then
SOLR_SERVER_DIR="$DEFAULT_SERVER_DIR"
fi
if [ ! -e "$SOLR_SERVER_DIR" ]; then
echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"
exit 1
fi
if [[ "$FG" == 'true' && "$EXAMPLE" != "" ]]; then
FG='false'
echo -e "\nWARNING: Foreground mode (-f) not supported when running examples.\n"
fi
#
# If the user specified an example to run, invoke the run_example tool (Java app) and exit
# otherwise let this script proceed to process the user request
#
if [ -n "$EXAMPLE" ] && [ "$SCRIPT_CMD" == "start" ]; then
run_tool run_example -e $EXAMPLE -d "$SOLR_SERVER_DIR" -urlScheme $SOLR_URL_SCHEME $PASS_TO_RUN_EXAMPLE
exit $?
fi
############# start/stop logic below here ################
if $verbose ; then
echo "Using Solr root directory: $SOLR_TIP"
echo "Using Java: $JAVA"
@ -949,137 +984,6 @@ else
SOLR_HOST_ARG=()
fi
if [ -z "$SOLR_SERVER_DIR" ]; then
SOLR_SERVER_DIR="$DEFAULT_SERVER_DIR"
fi
if [ ! -e "$SOLR_SERVER_DIR" ]; then
echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"
exit 1
fi
CLOUD_NUM_NODES=2
declare -a CLOUD_PORTS=('8983' '7574' '8984' '7575');
# select solr.solr.home based on the desired example
if [ "$EXAMPLE" != "" ]; then
case $EXAMPLE in
cloud)
#
# Engage in an interactive session with user to setup the SolrCloud example
#
echo -e "\nWelcome to the SolrCloud example!\n\n"
if $noprompt ; then
CLOUD_NUM_NODES=2
echo -e "Starting up $CLOUD_NUM_NODES Solr nodes for your example SolrCloud cluster."
else
echo -e "This interactive session will help you launch a SolrCloud cluster on your local workstation.\n"
read -e -p "To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2] " USER_INPUT
while true
do
CLOUD_NUM_NODES=`echo $USER_INPUT | tr -d ' '`
if [ -z "$CLOUD_NUM_NODES" ]; then
CLOUD_NUM_NODES=2
fi
if [[ $CLOUD_NUM_NODES > 4 || $CLOUD_NUM_NODES < 1 ]]; then
read -e -p "Please provide a node count between 1 and 4 [2] " USER_INPUT
else
break;
fi
done
echo -e "Ok, let's start up $CLOUD_NUM_NODES Solr nodes for your example SolrCloud cluster.\n"
for (( s=0; s<$CLOUD_NUM_NODES; s++ ))
do
read -e -p "Please enter the port for node$[$s+1] [${CLOUD_PORTS[$s]}] " USER_INPUT
while true
do
# trim whitespace out of the user input
CLOUD_PORT=`echo $USER_INPUT | tr -d ' '`
# handle the default selection or empty input
if [ -z "$CLOUD_PORT" ]; then
CLOUD_PORT=${CLOUD_PORTS[$s]}
fi
# check to see if something is already bound to that port
if hash lsof 2>/dev/null ; then # hash returns true if lsof is on the path
PORT_IN_USE=`lsof -PniTCP:$CLOUD_PORT -sTCP:LISTEN`
if [ "$PORT_IN_USE" != "" ]; then
read -e -p "Oops! Looks like port $CLOUD_PORT is already being used by another process. Please choose a different port. " USER_INPUT
else
CLOUD_PORTS[$s]=$CLOUD_PORT
echo $CLOUD_PORT
break;
fi
else
CLOUD_PORTS[$s]=$CLOUD_PORT
echo $CLOUD_PORT
break;
fi
done
done
fi
# setup a unqiue solr.solr.home directory for each node
CLOUD_EXAMPLE_DIR="$SOLR_TIP/example/cloud"
if [ ! -d "$CLOUD_EXAMPLE_DIR/node1/solr" ]; then
echo "Creating Solr home directory $CLOUD_EXAMPLE_DIR/node1/solr"
mkdir -p "$CLOUD_EXAMPLE_DIR/node1/solr"
cp "$DEFAULT_SERVER_DIR/solr/solr.xml" "$CLOUD_EXAMPLE_DIR/node1/solr/"
cp "$DEFAULT_SERVER_DIR/solr/zoo.cfg" "$CLOUD_EXAMPLE_DIR/node1/solr/"
fi
for (( s=1; s<$CLOUD_NUM_NODES; s++ ))
do
ndx=$[$s+1]
if [ ! -d "$CLOUD_EXAMPLE_DIR/node$ndx" ]; then
echo "Cloning Solr home directory $CLOUD_EXAMPLE_DIR/node1 into $CLOUD_EXAMPLE_DIR/node$ndx"
cp -r "$CLOUD_EXAMPLE_DIR/node1" "$CLOUD_EXAMPLE_DIR/node$ndx"
fi
done
SOLR_MODE="solrcloud"
SOLR_SERVER_DIR="$SOLR_TIP/server"
SOLR_HOME="$CLOUD_EXAMPLE_DIR/node1/solr"
SOLR_PORT="${CLOUD_PORTS[0]}"
shift
;;
techproducts)
SOLR_HOME="$SOLR_TIP/example/techproducts/solr"
mkdir -p "$SOLR_HOME"
if [ ! -f "$SOLR_HOME/solr.xml" ]; then
cp "$DEFAULT_SERVER_DIR/solr/solr.xml" "$SOLR_HOME/solr.xml"
cp "$DEFAULT_SERVER_DIR/solr/zoo.cfg" "$SOLR_HOME/zoo.cfg"
fi
EXAMPLE_CONFIGSET='sample_techproducts_configs'
shift
;;
dih)
SOLR_HOME="$SOLR_TIP/example/example-DIH/solr"
shift
;;
schemaless)
SOLR_HOME="$SOLR_TIP/example/schemaless/solr"
mkdir -p "$SOLR_HOME"
if [ ! -f "$SOLR_HOME/solr.xml" ]; then
cp "$DEFAULT_SERVER_DIR/solr/solr.xml" "$SOLR_HOME/solr.xml"
cp "$DEFAULT_SERVER_DIR/solr/zoo.cfg" "$SOLR_HOME/zoo.cfg"
fi
EXAMPLE_CONFIGSET='data_driven_schema_configs'
shift
;;
*)
print_usage "start" "Unsupported example $EXAMPLE! Please choose one of: cloud, dih, schemaless, or techproducts"
exit 1
;;
esac
fi
if [[ "$FG" == 'true' && "$EXAMPLE" != "" ]]; then
FG='false'
echo -e "\nWARNING: Foreground mode (-f) not supported when running examples.\n"
fi
if [ -z "$STOP_KEY" ]; then
STOP_KEY='solrrocks'
fi
@ -1409,7 +1313,7 @@ function launch_solr() {
# no lsof on cygwin though
if hash lsof 2>/dev/null ; then # hash returns true if lsof is on the path
echo -n "Waiting to see Solr listening on port $SOLR_PORT"
echo -n "Waiting up to 30 seconds to see Solr running on port $SOLR_PORT"
# Launch in a subshell to show the spinner
(loops=0
while true
@ -1441,152 +1345,6 @@ function launch_solr() {
fi
}
if [ "$EXAMPLE" != "cloud" ]; then
launch_solr "$FG" "$ADDITIONAL_CMD_OPTS"
# create the core/collection for the requested example after launching Solr
if [[ "$EXAMPLE" == "schemaless" || "$EXAMPLE" == "techproducts" ]]; then
if [ "$EXAMPLE" == "schemaless" ]; then
EXAMPLE_NAME=gettingstarted
else
EXAMPLE_NAME="$EXAMPLE"
fi
run_tool create -name "$EXAMPLE_NAME" -shards 1 -replicationFactor 1 \
-confname "$EXAMPLE_NAME" -confdir "$EXAMPLE_CONFIGSET" \
-configsetsDir "$SOLR_TIP/server/solr/configsets" -solrUrl $SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$SOLR_PORT/solr
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$EXAMPLE" == "techproducts" ]; then
echo "Indexing tech product example docs from $SOLR_TIP/example/exampledocs"
"$JAVA" $SOLR_SSL_OPTS -Durl="$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$SOLR_PORT/solr/$EXAMPLE/update" \
-jar "$SOLR_TIP/example/exampledocs/post.jar" "$SOLR_TIP/example/exampledocs"/*.xml
fi
echo -e "\nSolr $EXAMPLE example launched successfully. Direct your Web browser to $SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$SOLR_PORT/solr to visit the Solr Admin UI\n"
fi
else
#
# SolrCloud example is a bit involved so needs special handling here
#
SOLR_SERVER_DIR="$SOLR_TIP/server"
SOLR_HOME="$SOLR_TIP/example/cloud/node1/solr"
SOLR_PORT="${CLOUD_PORTS[0]}"
if [ "$ZK_HOST" != "" ]; then
DASHZ="-z $ZK_HOST"
fi
if [ "$SOLR_HEAP" != "" ]; then
DASHM="-m $SOLR_HEAP"
fi
if [ "$ADDITIONAL_CMD_OPTS" != "" ]; then
DASHA="-a $ADDITIONAL_CMD_OPTS"
fi
echo -e "\nStarting up SolrCloud node1 on port ${CLOUD_PORTS[0]} using command:\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"
# if user did not define a specific -z parameter, assume embedded in first cloud node we launched above
zk_host="$ZK_HOST"
if [ -z "$zk_host" ]; then
zk_port=$[$SOLR_PORT+1000]
zk_host="localhost:$zk_port"
fi
for (( s=1; s<$CLOUD_NUM_NODES; s++ ))
do
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 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
# TODO: better (shorter) name??
CLOUD_COLLECTION='gettingstarted'
if $noprompt ; then
CLOUD_NUM_SHARDS=2
CLOUD_REPFACT=2
CLOUD_CONFIG='data_driven_schema_configs'
else
echo -e "\nNow let's create a new collection for indexing documents in your $CLOUD_NUM_NODES-node cluster.\n"
read -e -p "Please provide a name for your new collection: [gettingstarted] " USER_INPUT
# trim whitespace out of the user input
CLOUD_COLLECTION=`echo "$USER_INPUT" | tr -d ' '`
# handle the default selection or empty input
if [ -z "$CLOUD_COLLECTION" ]; then
CLOUD_COLLECTION='gettingstarted'
fi
echo $CLOUD_COLLECTION
USER_INPUT=
read -e -p "How many shards would you like to split $CLOUD_COLLECTION into? [2] " USER_INPUT
# trim whitespace out of the user input
CLOUD_NUM_SHARDS=`echo "$USER_INPUT" | tr -d ' '`
# handle the default selection or empty input
if [ -z "$CLOUD_NUM_SHARDS" ]; then
CLOUD_NUM_SHARDS=2
fi
echo $CLOUD_NUM_SHARDS
USER_INPUT=
read -e -p "How many replicas per shard would you like to create? [2] " USER_INPUT
# trim whitespace out of the user input
CLOUD_REPFACT=`echo $USER_INPUT | tr -d ' '`
# handle the default selection or empty input
if [ -z "$CLOUD_REPFACT" ]; then
CLOUD_REPFACT=2
fi
echo $CLOUD_REPFACT
USER_INPUT=
echo "Please choose a configuration for the $CLOUD_COLLECTION collection, available options are:"
read -e -p "basic_configs, data_driven_schema_configs, or sample_techproducts_configs [data_driven_schema_configs] " USER_INPUT
while true
do
# trim whitespace out of the user input
CLOUD_CONFIG=`echo "$USER_INPUT" | tr -d ' '`
# handle the default selection or empty input
if [ -z "$CLOUD_CONFIG" ]; then
CLOUD_CONFIG='data_driven_schema_configs'
fi
# 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
CLOUD_CONFIG=
else
break;
fi
done
fi
run_tool create_collection -name "$CLOUD_COLLECTION" -shards $CLOUD_NUM_SHARDS -replicationFactor $CLOUD_REPFACT \
-confname "$CLOUD_COLLECTION" -confdir "$CLOUD_CONFIG" \
-configsetsDir "$SOLR_TIP/server/solr/configsets" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$SOLR_PORT/solr"
# enable soft-autocommits for the gettingstarted collection
echo -e "\nEnabling auto soft-commits with maxTime 3 secs using the Config API"
run_tool config -collection "$CLOUD_COLLECTION" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$SOLR_PORT/solr" \
-property updateHandler.autoSoftCommit.maxTime -value 3000
echo -e "\n\nSolrCloud example running, please visit $SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$SOLR_PORT/solr \n\n"
fi
launch_solr "$FG" "$ADDITIONAL_CMD_OPTS"
exit $?

View File

@ -18,6 +18,8 @@
IF "%OS%"=="Windows_NT" setlocal enabledelayedexpansion enableextensions
set "PASS_TO_RUN_EXAMPLE="
REM Determine top-level Solr directory
set SDIR=%~dp0
IF "%SDIR:~-1%"=="\" set SDIR=%SDIR:~0,-1%
@ -378,6 +380,7 @@ goto parse_args
:set_verbose
set verbose=1
set "PASS_TO_RUN_EXAMPLE=--verbose !PASS_TO_RUN_EXAMPLE!"
SHIFT
goto parse_args
@ -461,6 +464,7 @@ IF "%firstChar%"=="-" (
)
set SOLR_HEAP=%~2
set "PASS_TO_RUN_EXAMPLE=-m %~2 !PASS_TO_RUN_EXAMPLE!"
SHIFT
SHIFT
goto parse_args
@ -479,6 +483,7 @@ IF "%firstChar%"=="-" (
)
set SOLR_HOST=%~2
set "PASS_TO_RUN_EXAMPLE=-h %~2 !PASS_TO_RUN_EXAMPLE!"
SHIFT
SHIFT
goto parse_args
@ -497,6 +502,7 @@ IF "%firstChar%"=="-" (
)
set SOLR_PORT=%~2
set "PASS_TO_RUN_EXAMPLE=-p %~2 !PASS_TO_RUN_EXAMPLE!"
SHIFT
SHIFT
goto parse_args
@ -538,6 +544,7 @@ IF "%firstChar%"=="-" (
)
set "ZK_HOST=%~2"
set "PASS_TO_RUN_EXAMPLE=-z %~2 !PASS_TO_RUN_EXAMPLE!"
SHIFT
SHIFT
goto parse_args
@ -556,12 +563,15 @@ IF NOT "%SOLR_OPTS%"=="" (
) ELSE (
set "SOLR_OPTS=%PASSTHRU%"
)
set "PASS_TO_RUN_EXAMPLE=%PASSTHRU% !PASS_TO_RUN_EXAMPLE!"
SHIFT
SHIFT
goto parse_args
:set_noprompt
set NO_USER_PROMPT=1
set "PASS_TO_RUN_EXAMPLE=-noprompt !PASS_TO_RUN_EXAMPLE!"
SHIFT
goto parse_args
@ -588,37 +598,7 @@ IF NOT EXIST "%SOLR_SERVER_DIR%" (
goto err
)
IF "%EXAMPLE%"=="" (
REM SOLR_HOME just becomes serverDir/solr
) ELSE IF "%EXAMPLE%"=="techproducts" (
mkdir "%SOLR_TIP%\example\techproducts\solr"
set "SOLR_HOME=%SOLR_TIP%\example\techproducts\solr"
IF NOT EXIST "!SOLR_HOME!\solr.xml" (
copy "%DEFAULT_SERVER_DIR%\solr\solr.xml" "!SOLR_HOME!\solr.xml"
)
IF NOT EXIST "!SOLR_HOME!\zoo.cfg" (
copy "%DEFAULT_SERVER_DIR%\solr\zoo.cfg" "!SOLR_HOME!\zoo.cfg"
)
) ELSE IF "%EXAMPLE%"=="cloud" (
set SOLR_MODE=solrcloud
goto cloud_example_start
) ELSE IF "%EXAMPLE%"=="dih" (
set "SOLR_HOME=%SOLR_TIP%\example\example-DIH\solr"
) ELSE IF "%EXAMPLE%"=="schemaless" (
mkdir "%SOLR_TIP%\example\schemaless\solr"
set "SOLR_HOME=%SOLR_TIP%\example\schemaless\solr"
IF NOT EXIST "!SOLR_HOME!\solr.xml" (
copy "%DEFAULT_SERVER_DIR%\solr\solr.xml" "!SOLR_HOME!\solr.xml"
)
IF NOT EXIST "!SOLR_HOME!\zoo.cfg" (
copy "%DEFAULT_SERVER_DIR%\solr\zoo.cfg" "!SOLR_HOME!\zoo.cfg"
)
) ELSE (
@echo.
@echo 'Unrecognized example %EXAMPLE%!'
@echo.
goto start_usage
)
IF NOT "%EXAMPLE%"=="" goto run_example
:start_solr
IF "%SOLR_HOME%"=="" set "SOLR_HOME=%SOLR_SERVER_DIR%\solr"
@ -900,9 +880,6 @@ IF "%JAVA_VENDOR%" == "IBM J9" (
set "GCLOG_OPT=-Xloggc"
)
@echo.
CALL :safe_echo "Starting Solr on port %SOLR_PORT% from %SOLR_SERVER_DIR%"
@echo.
IF "%FG%"=="1" (
REM run solr in the foreground
title "Solr-%SOLR_PORT%"
@ -913,211 +890,25 @@ IF "%FG%"=="1" (
START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" "%JAVA%" %SERVEROPT% -Xss256k %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!"/solr_gc.log -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
-Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar "%SOLR_JETTY_CONFIG%" > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-console.log"
echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
)
set EXAMPLE_NAME=%EXAMPLE%
set CREATE_EXAMPLE_CONFIG=
IF "%EXAMPLE%"=="schemaless" (
set EXAMPLE_NAME=gettingstarted
set CREATE_EXAMPLE_CONFIG=data_driven_schema_configs
REM now wait to see Solr come online ...
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI status -maxWaitSecs 30 -solr !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr
)
IF "%EXAMPLE%"=="techproducts" (
set CREATE_EXAMPLE_CONFIG=sample_techproducts_configs
)
IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
timeout /T 10
IF "%SOLR_MODE%"=="solrcloud" (
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI create_collection -name !EXAMPLE_NAME! -shards 1 -replicationFactor 1 ^
-confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr
) ELSE (
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI create_core -name !EXAMPLE_NAME! -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr ^
-confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
)
)
IF "%EXAMPLE%"=="techproducts" (
@echo.
@echo Indexing tech product example docs from "%SOLR_TIP%\example\exampledocs"
"%JAVA%" %SOLR_SSL_OPTS% -Durl=!SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr/%EXAMPLE%/update -jar "%SOLR_TIP%/example/exampledocs/post.jar" "%SOLR_TIP%/example/exampledocs/*.xml"
)
@echo.
IF NOT "%EXAMPLE%"=="" (
@echo Solr %EXAMPLE% example launched successfully.
)
@echo Direct your Web browser to !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr to visit the Solr Admin UI
@echo.
goto done
:cloud_example_start
REM Launch interactive session to guide the user through the SolrCloud example
:run_example
REM Run the requested example
CLS
@echo.
@echo Welcome to the SolrCloud example
@echo.
@echo.
IF "%NO_USER_PROMPT%"=="1" (
set CLOUD_NUM_NODES=2
@echo Starting up %CLOUD_NUM_NODES% Solr nodes for your example SolrCloud cluster.
goto start_cloud_nodes
) ELSE (
@echo This interactive session will help you launch a SolrCloud cluster on your local workstation.
@echo.
SET /P "USER_INPUT=To begin, how many Solr nodes would you like to run in your local cluster (specify 1-4 nodes) [2]: "
goto while_num_nodes_not_valid
)
:while_num_nodes_not_valid
IF "%USER_INPUT%"=="" set USER_INPUT=2
SET /A INPUT_AS_NUM=!USER_INPUT!*1
IF %INPUT_AS_NUM% GEQ 1 IF %INPUT_AS_NUM% LEQ 4 set CLOUD_NUM_NODES=%INPUT_AS_NUM%
IF NOT DEFINED CLOUD_NUM_NODES (
SET USER_INPUT=
SET /P "USER_INPUT=Please enter a number between 1 and 4 [2]: "
goto while_num_nodes_not_valid
)
@echo Ok, let's start up %CLOUD_NUM_NODES% Solr nodes for your example SolrCloud cluster.
:start_cloud_nodes
set "CLOUD_EXAMPLE_DIR=%SOLR_TIP%\example\cloud"
@echo Creating Solr home "%CLOUD_EXAMPLE_DIR%\node1\solr"
mkdir "%CLOUD_EXAMPLE_DIR%\node1\solr"
copy "%DEFAULT_SERVER_DIR%\solr\solr.xml" "%CLOUD_EXAMPLE_DIR%\node1\solr\solr.xml"
copy "%DEFAULT_SERVER_DIR%\solr\zoo.cfg" "%CLOUD_EXAMPLE_DIR%\node1\solr\zoo.cfg"
for /l %%x in (2, 1, !CLOUD_NUM_NODES!) do (
IF NOT EXIST "%SOLR_TIP%\node%%x" (
@echo Cloning "%CLOUD_EXAMPLE_DIR%\node1" into "%CLOUD_EXAMPLE_DIR%\node%%x"
xcopy /Q /E /I "%CLOUD_EXAMPLE_DIR%\node1" "%CLOUD_EXAMPLE_DIR%\node%%x"
)
)
for /l %%x in (1, 1, !CLOUD_NUM_NODES!) do (
set USER_INPUT=
set /A idx=%%x-1
set DEF_PORT=8983
IF %%x EQU 2 (
set DEF_PORT=7574
) ELSE (
IF %%x EQU 3 (
set DEF_PORT=8984
) ELSE (
IF %%x EQU 4 (
set DEF_PORT=7575
)
)
)
IF "%NO_USER_PROMPT%"=="1" (
set NODE_PORT=!DEF_PORT!
) ELSE (
set /P "USER_INPUT=Please enter the port for node%%x [!DEF_PORT!]: "
IF "!USER_INPUT!"=="" set USER_INPUT=!DEF_PORT!
set NODE_PORT=!USER_INPUT!
echo node%%x port: !NODE_PORT!
@echo.
)
IF NOT "!SOLR_HEAP!"=="" (
set "DASHM=-m !SOLR_HEAP!"
) ELSE (
set "DASHM="
)
IF %%x EQU 1 (
set EXAMPLE=
IF NOT "!ZK_HOST!"=="" (
set "DASHZ=-z !ZK_HOST!"
) ELSE (
set "DASHZ="
)
@echo Starting node1 on port !NODE_PORT! using command:
@echo solr -cloud -p !NODE_PORT! -s example\node1\solr !DASHZ! !DASHM!
START "Solr-!NODE_PORT!" /D "%SDIR%" solr -f -cloud -p !NODE_PORT! !DASHZ! !DASHM! -s "%CLOUD_EXAMPLE_DIR%\node1\solr"
set NODE1_PORT=!NODE_PORT!
echo !NODE_PORT!>"%SOLR_TIP%"\bin\solr-!NODE_PORT!.port
) ELSE (
IF "!ZK_HOST!"=="" (
set /A ZK_PORT=!NODE1_PORT!+1000
set "ZK_HOST=localhost:!ZK_PORT!"
)
@echo Starting node%%x on port !NODE_PORT! using command:
@echo solr -cloud -p !NODE_PORT! -s example\node%%x\solr -z !ZK_HOST! !DASHM!
START "Solr-!NODE_PORT!" /D "%SDIR%" solr -f -cloud -p !NODE_PORT! -z !ZK_HOST! !DASHM! -s "%CLOUD_EXAMPLE_DIR%\node%%x\solr"
echo !NODE_PORT!>"%SOLR_TIP%"\bin\solr-!NODE_PORT!.port
)
timeout /T 10
)
set USER_INPUT=
echo.
echo Now let's create a new collection for indexing documents in your %CLOUD_NUM_NODES%-node cluster.
IF "%NO_USER_PROMPT%"=="1" (
set CLOUD_COLLECTION=gettingstarted
set CLOUD_NUM_SHARDS=2
set CLOUD_REPFACT=2
set CLOUD_CONFIG=data_driven_schema_configs
goto create_collection
) ELSE (
goto get_create_collection_params
)
:get_create_collection_params
set /P "USER_INPUT=Please provide a name for your new collection: [gettingstarted] "
IF "!USER_INPUT!"=="" set USER_INPUT=gettingstarted
set CLOUD_COLLECTION=!USER_INPUT!
echo !CLOUD_COLLECTION!
set USER_INPUT=
echo.
set /P "USER_INPUT=How many shards would you like to split !CLOUD_COLLECTION! into? [2] "
IF "!USER_INPUT!"=="" set USER_INPUT=2
set CLOUD_NUM_SHARDS=!USER_INPUT!
echo !CLOUD_NUM_SHARDS!
set USER_INPUT=
echo.
set /P "USER_INPUT=How many replicas per shard would you like to create? [2] "
IF "!USER_INPUT!"=="" set USER_INPUT=2
set CLOUD_REPFACT=!USER_INPUT!
echo !CLOUD_REPFACT!
set USER_INPUT=
echo.
set /P "USER_INPUT=Please choose a configuration for the !CLOUD_COLLECTION! collection, available options are: basic_configs, data_driven_schema_configs, or sample_techproducts_configs [data_driven_schema_configs]"
IF "!USER_INPUT!"=="" set USER_INPUT=data_driven_schema_configs
set CLOUD_CONFIG=!USER_INPUT!
echo !CLOUD_CONFIG!
goto create_collection
:create_collection
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI create_collection -name !CLOUD_COLLECTION! -shards !CLOUD_NUM_SHARDS! -replicationFactor !CLOUD_REPFACT! ^
-confdir !CLOUD_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -zkHost %zk_host%
org.apache.solr.util.SolrCLI run_example -script "%SDIR%\solr.cmd" -e %EXAMPLE% -d "%SOLR_SERVER_DIR%" -urlScheme !SOLR_URL_SCHEME! !PASS_TO_RUN_EXAMPLE!
@echo.
echo Enabling auto soft-commits with maxTime 3 secs using the Config API
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI config -collection !CLOUD_COLLECTION! -property updateHandler.autoSoftCommit.maxTime -value 3000 -zkHost %zk_host%
echo.
echo SolrCloud example is running, please visit !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%NODE1_PORT%/solr"
echo.
REM End of interactive cloud example
REM End of run_example
goto done
:get_info
REM Find all Java processes, correlate with those listening on a port
REM and then try to contact via that port using the status tool
@ -1383,10 +1174,8 @@ goto done
exit /b 1
:done
ENDLOCAL
GOTO :eof
exit /b 0
REM Tests what Java we have and sets some global variables
:resolve_java_info

View File

@ -31,6 +31,7 @@
<dependencies>
<dependency org="commons-codec" name="commons-codec" rev="${/commons-codec/commons-codec}" conf="compile"/>
<dependency org="org.apache.commons" name="commons-exec" rev="${/org.apache.commons/commons-exec}" conf="compile"/>
<dependency org="commons-fileupload" name="commons-fileupload" rev="${/commons-fileupload/commons-fileupload}" conf="compile"/>
<dependency org="commons-cli" name="commons-cli" rev="${/commons-cli/commons-cli}" conf="compile"/>
<dependency org="commons-lang" name="commons-lang" rev="${/commons-lang/commons-lang}" conf="compile"/>

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,6 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
// create the gettingstarted collection just like the bin/solr script would do
String[] args = new String[] {
"create_collection",
"-name", testCollectionName,
"-shards", "2",
"-replicationFactor", "2",
@ -78,6 +77,9 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
"-configsetsDir", data_driven_schema_configs.getParentFile().getParentFile().getAbsolutePath(),
"-solrUrl", solrUrl
};
// NOTE: not calling SolrCLI.main as the script does because it calls System.exit which is a no-no in a JUnit test
SolrCLI.CreateCollectionTool tool = new SolrCLI.CreateCollectionTool();
CommandLine cli = SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args);
log.info("Creating the '"+testCollectionName+"' collection using SolrCLI with: "+solrUrl);
@ -147,7 +149,6 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
protected void doTestHealthcheck(String testCollectionName, String zkHost) throws Exception {
String[] args = new String[]{
"healthcheck",
"-collection", testCollectionName,
"-zkHost", zkHost
};
@ -159,7 +160,6 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
protected void doTestDeleteAction(String testCollectionName, String solrUrl) throws Exception {
String[] args = new String[] {
"delete",
"-name", testCollectionName,
"-solrUrl", solrUrl
};
@ -186,7 +186,6 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
String prop = "updateHandler.autoSoftCommit.maxTime";
Long maxTime = new Long(3000L);
String[] args = new String[]{
"config",
"-collection", testCollectionName,
"-property", prop,
"-value", maxTime.toString(),

View File

@ -0,0 +1,485 @@
package org.apache.solr.util;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteResultHandler;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.embedded.JettyConfig;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.common.SolrInputDocument;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tests the SolrCLI.RunExampleTool implementation that supports bin/solr -e [example]
*/
@LuceneTestCase.Slow
@SolrTestCaseJ4.SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
protected static final transient Logger log = LoggerFactory.getLogger(TestSolrCLIRunExample.class);
/**
* Overrides the call to exec bin/solr to start Solr nodes to start them using the Solr test-framework
* instead of the script, since the script depends on a full build.
*/
private class RunExampleExecutor extends DefaultExecutor implements Closeable {
private PrintStream stdout;
private List<org.apache.commons.exec.CommandLine> commandsExecuted = new ArrayList<>();
private MiniSolrCloudCluster solrCloudCluster;
private JettySolrRunner standaloneSolr;
RunExampleExecutor(PrintStream stdout) {
super();
this.stdout = stdout;
}
/**
* Override the call to execute a command asynchronously to occur synchronously during a unit test.
*/
@Override
public void execute(org.apache.commons.exec.CommandLine cmd, Map<String,String> env, ExecuteResultHandler erh) throws IOException {
int code = execute(cmd);
if (code != 0) throw new RuntimeException("Failed to execute cmd: "+joinArgs(cmd.getArguments()));
}
@Override
public int execute(org.apache.commons.exec.CommandLine cmd) throws IOException {
// collect the commands as they are executed for analysis by the test
commandsExecuted.add(cmd);
String exe = cmd.getExecutable();
if (exe.endsWith("solr")) {
String[] args = cmd.getArguments();
if ("start".equals(args[0])) {
if (!hasFlag("-cloud", args) && !hasFlag("-c", args))
return startStandaloneSolr(args);
File baseDir = createTempDir().toFile();
File solrHomeDir = new File(getArg("-s", args));
int port = Integer.parseInt(getArg("-p", args));
JettyConfig jettyConfig =
JettyConfig.builder().setContext("/solr").setPort(port).build();
try {
if (solrCloudCluster == null) {
System.setProperty("host", "localhost");
System.setProperty("jetty.port", String.valueOf(port));
solrCloudCluster =
new MiniSolrCloudCluster(1, baseDir, new File(solrHomeDir, "solr.xml"), jettyConfig);
} else {
// another member of this cluster -- not supported yet, due to how MiniSolrCloudCluster works
throw new IllegalArgumentException("Only launching one SolrCloud node is supported by this test!");
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
} else if ("stop".equals(args[0])) {
int port = Integer.parseInt(getArg("-p", args));
// stop the requested node
if (standaloneSolr != null) {
int localPort = standaloneSolr.getLocalPort();
if (port == localPort) {
try {
standaloneSolr.stop();
log.info("Stopped standalone Solr instance running on port "+port);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
} else {
throw new IllegalArgumentException("No Solr is running on port "+port);
}
} else {
if (solrCloudCluster != null) {
try {
solrCloudCluster.shutdown();
log.info("Stopped SolrCloud test cluster");
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
} else {
throw new IllegalArgumentException("No Solr nodes found to stop!");
}
}
}
} else {
String cmdLine = joinArgs(cmd.getArguments());
if (cmdLine.indexOf("post.jar") != -1) {
// invocation of the post.jar file ... we'll just hit the SimplePostTool directly vs. trying to invoke another JVM
List<String> argsToSimplePostTool = new ArrayList<String>();
boolean afterPostJarArg = false;
for (String arg : cmd.getArguments()) {
if (arg.startsWith("-D")) {
arg = arg.substring(2);
int eqPos = arg.indexOf("=");
System.setProperty(arg.substring(0,eqPos), arg.substring(eqPos+1));
} else {
if (arg.endsWith("post.jar")) {
afterPostJarArg = true;
} else {
if (afterPostJarArg) {
argsToSimplePostTool.add(arg);
}
}
}
}
SimplePostTool.main(argsToSimplePostTool.toArray(new String[0]));
} else {
log.info("Executing command: "+cmdLine);
try {
return super.execute(cmd);
} catch (Exception exc) {
log.error("Execute command ["+cmdLine+"] failed due to: "+exc, exc);
throw exc;
}
}
}
return 0;
}
protected String joinArgs(String[] args) {
if (args == null || args.length == 0)
return "";
StringBuilder sb = new StringBuilder();
for (int a=0; a < args.length; a++) {
if (a > 0) sb.append(' ');
sb.append(args[a]);
}
return sb.toString();
}
protected int startStandaloneSolr(String[] args) {
if (standaloneSolr != null) {
throw new IllegalStateException("Test is already running a standalone Solr instance "+
standaloneSolr.getBaseUrl()+"! This indicates a bug in the unit test logic.");
}
if (solrCloudCluster != null) {
throw new IllegalStateException("Test is already running a mini SolrCloud cluster! "+
"This indicates a bug in the unit test logic.");
}
int port = Integer.parseInt(getArg("-p", args));
File solrHomeDir = new File(getArg("-s", args));
System.setProperty("host", "localhost");
System.setProperty("jetty.port", String.valueOf(port));
standaloneSolr = new JettySolrRunner(solrHomeDir.getAbsolutePath(), "/solr", port);
Thread bg = new Thread() {
public void run() {
try {
standaloneSolr.start();
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
}
};
bg.start();
return 0;
}
protected String getArg(String arg, String[] args) {
for (int a=0; a < args.length; a++) {
if (arg.equals(args[a])) {
if (a+1 >= args.length)
throw new IllegalArgumentException("Missing required value for the "+arg+" option!");
return args[a + 1];
}
}
throw new IllegalArgumentException("Missing required arg "+arg+
" needed to execute command: "+commandsExecuted.get(commandsExecuted.size()-1));
}
protected boolean hasFlag(String flag, String[] args) {
for (String arg : args) {
if (flag.equals(arg))
return true;
}
return false;
}
@Override
public void close() throws IOException {
if (solrCloudCluster != null) {
try {
solrCloudCluster.shutdown();
} catch (Exception e) {
log.warn("Failed to shutdown MiniSolrCloudCluster due to: " + e);
}
}
if (standaloneSolr != null) {
try {
standaloneSolr.stop();
} catch (Exception exc) {
log.warn("Failed to shutdown standalone Solr due to: " + exc);
}
standaloneSolr = null;
}
}
}
protected List<Closeable> closeables = new ArrayList<>();
@After
public void tearDown() throws Exception {
super.tearDown();
if (closeables != null) {
for (Closeable toClose : closeables) {
try {
toClose.close();
} catch (Exception ignore) {}
}
closeables.clear();
closeables = null;
}
}
@Test
public void testTechproductsExample() throws Exception {
testExample("techproducts");
}
@Test
public void testSchemalessExample() throws Exception {
testExample("schemaless");
}
protected void testExample(String exampleName) throws Exception {
File solrHomeDir = new File(ExternalPaths.SERVER_HOME);
if (!solrHomeDir.isDirectory())
fail(solrHomeDir.getAbsolutePath()+" not found and is required to run this test!");
Path tmpDir = createTempDir();
File solrExampleDir = tmpDir.toFile();
File solrServerDir = solrHomeDir.getParentFile();
// need a port to start the example server on
int bindPort = -1;
try (ServerSocket socket = new ServerSocket(0)) {
bindPort = socket.getLocalPort();
}
log.info("Selected port "+bindPort+" to start "+exampleName+" example Solr instance on ...");
String[] toolArgs = new String[] {
"-e", exampleName,
"-serverDir", solrServerDir.getAbsolutePath(),
"-exampleDir", solrExampleDir.getAbsolutePath(),
"-p", String.valueOf(bindPort)
};
// capture tool output to stdout
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
RunExampleExecutor executor = new RunExampleExecutor(stdoutSim);
closeables.add(executor);
SolrCLI.RunExampleTool tool = new SolrCLI.RunExampleTool(executor, System.in, stdoutSim);
try {
tool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), toolArgs));
} catch (Exception e) {
log.error("RunExampleTool failed due to: " + e +
"; stdout from tool prior to failure: " + baos.toString(StandardCharsets.UTF_8.name()));
throw e;
}
String toolOutput = baos.toString(StandardCharsets.UTF_8.name());
// dump all the output written by the SolrCLI commands to stdout
//System.out.println("\n\n"+toolOutput+"\n\n");
File exampleSolrHomeDir = new File(solrExampleDir, exampleName+"/solr");
assertTrue(exampleSolrHomeDir.getAbsolutePath() + " not found! run " +
exampleName + " example failed; output: " + toolOutput,
exampleSolrHomeDir.isDirectory());
if ("techproducts".equals(exampleName)) {
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:" + bindPort + "/solr/" + exampleName);
SolrQuery query = new SolrQuery("*:*");
QueryResponse qr = solrClient.query(query);
long numFound = qr.getResults().getNumFound();
assertTrue("expected 32 docs in the "+exampleName+" example but found " + numFound + ", output: " + toolOutput,
numFound == 32);
}
// stop the test instance
executor.execute(org.apache.commons.exec.CommandLine.parse("bin/solr stop -p " + bindPort));
}
/**
* Tests the interactive SolrCloud example; we cannot test the non-interactive because we need control over
* the port and can only test with one node since the test relies on setting the host and jetty.port system
* properties, i.e. there is no test coverage for the -noprompt option.
*/
@Test
public void testInteractiveSolrCloudExample() throws Exception {
File solrHomeDir = new File(ExternalPaths.SERVER_HOME);
if (!solrHomeDir.isDirectory())
fail(solrHomeDir.getAbsolutePath()+" not found and is required to run this test!");
Path tmpDir = createTempDir();
File solrExampleDir = tmpDir.toFile();
File solrServerDir = solrHomeDir.getParentFile();
String[] toolArgs = new String[] {
"-example", "cloud",
"-serverDir", solrServerDir.getAbsolutePath(),
"-exampleDir", solrExampleDir.getAbsolutePath()
};
int bindPort = -1;
try (ServerSocket socket = new ServerSocket(0)) {
bindPort = socket.getLocalPort();
}
String collectionName = "testCloudExamplePrompt";
// sthis test only support launching one SolrCloud node due to how MiniSolrCloudCluster works
// and the need for setting the host and port system properties ...
String userInput = "1\n"+bindPort+"\n"+collectionName+"\n2\n2\ndata_driven_schema_configs\n";
// simulate user input from stdin
InputStream userInputSim = new ByteArrayInputStream(userInput.getBytes(StandardCharsets.UTF_8));
// capture tool output to stdout
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
RunExampleExecutor executor = new RunExampleExecutor(stdoutSim);
closeables.add(executor);
SolrCLI.RunExampleTool tool = new SolrCLI.RunExampleTool(executor, userInputSim, stdoutSim);
try {
tool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), toolArgs));
} catch (Exception e) {
System.err.println("RunExampleTool failed due to: " + e +
"; stdout from tool prior to failure: " + baos.toString(StandardCharsets.UTF_8.name()));
throw e;
}
String toolOutput = baos.toString(StandardCharsets.UTF_8.name());
// verify Solr is running on the expected port and verify the collection exists
String solrUrl = "http://localhost:"+bindPort+"/solr";
String collectionListUrl = solrUrl+"/admin/collections?action=list";
if (!SolrCLI.safeCheckCollectionExists(collectionListUrl, collectionName)) {
fail("After running Solr cloud example, test collection '"+collectionName+
"' not found in Solr at: "+solrUrl+"; tool output: "+toolOutput);
}
// index some docs - to verify all is good for both shards
CloudSolrClient cloudClient = null;
try {
cloudClient = new CloudSolrClient(executor.solrCloudCluster.getZkServer().getZkAddress());
cloudClient.connect();
cloudClient.setDefaultCollection(collectionName);
int numDocs = 10;
for (int d=0; d < numDocs; d++) {
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "doc"+d);
doc.setField("str_s", "a");
cloudClient.add(doc);
}
cloudClient.commit();
QueryResponse qr = cloudClient.query(new SolrQuery("str_s:a"));
if (qr.getResults().getNumFound() != numDocs) {
fail("Expected "+numDocs+" to be found in the "+collectionName+
" collection but only found "+qr.getResults().getNumFound());
}
} finally {
if (cloudClient != null) {
try {
cloudClient.close();
} catch (Exception ignore){}
}
}
File node1SolrHome = new File(solrExampleDir, "cloud/node1/solr");
if (!node1SolrHome.isDirectory()) {
fail(node1SolrHome.getAbsolutePath()+" not found! run cloud example failed; tool output: "+toolOutput);
}
// delete the collection
SolrCLI.DeleteTool deleteTool = new SolrCLI.DeleteTool(stdoutSim);
String[] deleteArgs = new String[] { "-name", collectionName, "-solrUrl", solrUrl };
deleteTool.runTool(
SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(deleteTool.getOptions()), deleteArgs));
// dump all the output written by the SolrCLI commands to stdout
//System.out.println(toolOutput);
// stop the test instance
executor.execute(org.apache.commons.exec.CommandLine.parse("bin/solr stop -p "+bindPort));
}
}

View File

@ -0,0 +1 @@
8dfb9facd0830a27b1b5f29f84593f0aeee7773b

View File

@ -0,0 +1,203 @@
/*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/
*
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
*
* 1. Definitions.
*
* "License" shall mean the terms and conditions for use, reproduction,
* and distribution as defined by Sections 1 through 9 of this document.
*
* "Licensor" shall mean the copyright owner or entity authorized by
* the copyright owner that is granting the License.
*
* "Legal Entity" shall mean the union of the acting entity and all
* other entities that control, are controlled by, or are under common
* control with that entity. For the purposes of this definition,
* "control" means (i) the power, direct or indirect, to cause the
* direction or management of such entity, whether by contract or
* otherwise, or (ii) ownership of fifty percent (50%) or more of the
* outstanding shares, or (iii) beneficial ownership of such entity.
*
* "You" (or "Your") shall mean an individual or Legal Entity
* exercising permissions granted by this License.
*
* "Source" form shall mean the preferred form for making modifications,
* including but not limited to software source code, documentation
* source, and configuration files.
*
* "Object" form shall mean any form resulting from mechanical
* transformation or translation of a Source form, including but
* not limited to compiled object code, generated documentation,
* and conversions to other media types.
*
* "Work" shall mean the work of authorship, whether in Source or
* Object form, made available under the License, as indicated by a
* copyright notice that is included in or attached to the work
* (an example is provided in the Appendix below).
*
* "Derivative Works" shall mean any work, whether in Source or Object
* form, that is based on (or derived from) the Work and for which the
* editorial revisions, annotations, elaborations, or other modifications
* represent, as a whole, an original work of authorship. For the purposes
* of this License, Derivative Works shall not include works that remain
* separable from, or merely link (or bind by name) to the interfaces of,
* the Work and Derivative Works thereof.
*
* "Contribution" shall mean any work of authorship, including
* the original version of the Work and any modifications or additions
* to that Work or Derivative Works thereof, that is intentionally
* submitted to Licensor for inclusion in the Work by the copyright owner
* or by an individual or Legal Entity authorized to submit on behalf of
* the copyright owner. For the purposes of this definition, "submitted"
* means any form of electronic, verbal, or written communication sent
* to the Licensor or its representatives, including but not limited to
* communication on electronic mailing lists, source code control systems,
* and issue tracking systems that are managed by, or on behalf of, the
* Licensor for the purpose of discussing and improving the Work, but
* excluding communication that is conspicuously marked or otherwise
* designated in writing by the copyright owner as "Not a Contribution."
*
* "Contributor" shall mean Licensor and any individual or Legal Entity
* on behalf of whom a Contribution has been received by Licensor and
* subsequently incorporated within the Work.
*
* 2. Grant of Copyright License. Subject to the terms and conditions of
* this License, each Contributor hereby grants to You a perpetual,
* worldwide, non-exclusive, no-charge, royalty-free, irrevocable
* copyright license to reproduce, prepare Derivative Works of,
* publicly display, publicly perform, sublicense, and distribute the
* Work and such Derivative Works in Source or Object form.
*
* 3. Grant of Patent License. Subject to the terms and conditions of
* this License, each Contributor hereby grants to You a perpetual,
* worldwide, non-exclusive, no-charge, royalty-free, irrevocable
* (except as stated in this section) patent license to make, have made,
* use, offer to sell, sell, import, and otherwise transfer the Work,
* where such license applies only to those patent claims licensable
* by such Contributor that are necessarily infringed by their
* Contribution(s) alone or by combination of their Contribution(s)
* with the Work to which such Contribution(s) was submitted. If You
* institute patent litigation against any entity (including a
* cross-claim or counterclaim in a lawsuit) alleging that the Work
* or a Contribution incorporated within the Work constitutes direct
* or contributory patent infringement, then any patent licenses
* granted to You under this License for that Work shall terminate
* as of the date such litigation is filed.
*
* 4. Redistribution. You may reproduce and distribute copies of the
* Work or Derivative Works thereof in any medium, with or without
* modifications, and in Source or Object form, provided that You
* meet the following conditions:
*
* (a) You must give any other recipients of the Work or
* Derivative Works a copy of this License; and
*
* (b) You must cause any modified files to carry prominent notices
* stating that You changed the files; and
*
* (c) You must retain, in the Source form of any Derivative Works
* that You distribute, all copyright, patent, trademark, and
* attribution notices from the Source form of the Work,
* excluding those notices that do not pertain to any part of
* the Derivative Works; and
*
* (d) If the Work includes a "NOTICE" text file as part of its
* distribution, then any Derivative Works that You distribute must
* include a readable copy of the attribution notices contained
* within such NOTICE file, excluding those notices that do not
* pertain to any part of the Derivative Works, in at least one
* of the following places: within a NOTICE text file distributed
* as part of the Derivative Works; within the Source form or
* documentation, if provided along with the Derivative Works; or,
* within a display generated by the Derivative Works, if and
* wherever such third-party notices normally appear. The contents
* of the NOTICE file are for informational purposes only and
* do not modify the License. You may add Your own attribution
* notices within Derivative Works that You distribute, alongside
* or as an addendum to the NOTICE text from the Work, provided
* that such additional attribution notices cannot be construed
* as modifying the License.
*
* You may add Your own copyright statement to Your modifications and
* may provide additional or different license terms and conditions
* for use, reproduction, or distribution of Your modifications, or
* for any such Derivative Works as a whole, provided Your use,
* reproduction, and distribution of the Work otherwise complies with
* the conditions stated in this License.
*
* 5. Submission of Contributions. Unless You explicitly state otherwise,
* any Contribution intentionally submitted for inclusion in the Work
* by You to the Licensor shall be under the terms and conditions of
* this License, without any additional terms or conditions.
* Notwithstanding the above, nothing herein shall supersede or modify
* the terms of any separate license agreement you may have executed
* with Licensor regarding such Contributions.
*
* 6. Trademarks. This License does not grant permission to use the trade
* names, trademarks, service marks, or product names of the Licensor,
* except as required for reasonable and customary use in describing the
* origin of the Work and reproducing the content of the NOTICE file.
*
* 7. Disclaimer of Warranty. Unless required by applicable law or
* agreed to in writing, Licensor provides the Work (and each
* Contributor provides its Contributions) on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied, including, without limitation, any warranties or conditions
* of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
* PARTICULAR PURPOSE. You are solely responsible for determining the
* appropriateness of using or redistributing the Work and assume any
* risks associated with Your exercise of permissions under this License.
*
* 8. Limitation of Liability. In no event and under no legal theory,
* whether in tort (including negligence), contract, or otherwise,
* unless required by applicable law (such as deliberate and grossly
* negligent acts) or agreed to in writing, shall any Contributor be
* liable to You for damages, including any direct, indirect, special,
* incidental, or consequential damages of any character arising as a
* result of this License or out of the use or inability to use the
* Work (including but not limited to damages for loss of goodwill,
* work stoppage, computer failure or malfunction, or any and all
* other commercial damages or losses), even if such Contributor
* has been advised of the possibility of such damages.
*
* 9. Accepting Warranty or Additional Liability. While redistributing
* the Work or Derivative Works thereof, You may choose to offer,
* and charge a fee for, acceptance of support, warranty, indemnity,
* or other liability obligations and/or rights consistent with this
* License. However, in accepting such obligations, You may act only
* on Your own behalf and on Your sole responsibility, not on behalf
* of any other Contributor, and only if You agree to indemnify,
* defend, and hold each Contributor harmless for any liability
* incurred by, or claims asserted against, such Contributor by reason
* of your accepting any such warranty or additional liability.
*
* END OF TERMS AND CONDITIONS
*
* APPENDIX: How to apply the Apache License to your work.
*
* To apply the Apache License to your work, attach the following
* boilerplate notice, with the fields enclosed by brackets "[]"
* replaced with your own identifying information. (Don't include
* the brackets!) The text should be enclosed in the appropriate
* comment syntax for the file format. We also recommend that a
* file or class name and description of purpose be included on the
* same "printed page" as the copyright notice for easier
* identification within third-party archives.
*
* Copyright [yyyy] [name of copyright owner]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -0,0 +1,5 @@
Apache Commons Exec
Copyright 2005-2014 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).