diff --git a/README.md b/README.md index cf08fa329a5..24d419bd472 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Solr is the blazing-fast, open source, multi-modal search platform built on [Apa It powers full-text, vector, and geospatial search at many of the world's largest organizations. [![Build Status](https://ci-builds.apache.org/job/Solr/job/Solr-Artifacts-main/badge/icon?subject=Solr%20Artifacts)](https://ci-builds.apache.org/job/Solr/job/Solr-Artifacts-main/) -[![Build Status](https://ci-builds.apache.org/job/Solr/job/Solr-Check-main/badge/icon?subject=Solr%20Check)](https://ci-builds.apache.org/job/Solr/job/Solr-Check-main/) +[![Build Status](https://ci-builds.apache.org/job/Solr/job/Solr-Lint-main/badge/icon?subject=Solr%20Lint)](https://ci-builds.apache.org/job/Solr/job/Solr-Lint-main/) For a complete description of the Solr project, team composition, source code repositories, and other details, please see the Solr web site at diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java index 88d91028552..adb8f3eaf07 100644 --- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java +++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -54,7 +54,7 @@ public static void main(String[] args) { } public static void checkVersion() { - int major = Runtime.getRuntime().version().feature(); + int major = Runtime.version().feature(); if (major < 21 || major > 23) { throw new IllegalStateException( "java version must be between 21 and 23, your version: " + major); @@ -89,12 +89,12 @@ public void run(Path destination) throws IOException, NoSuchAlgorithmException { } } - URL url = - new URL( + URI uri = + URI.create( "https://raw.githubusercontent.com/gradle/gradle/v" + wrapperVersion + "/gradle/wrapper/gradle-wrapper.jar"); - System.err.println("Downloading gradle-wrapper.jar from " + url); + System.err.println("Downloading gradle-wrapper.jar from " + uri); // Zero-copy save the jar to a temp file Path temp = Files.createTempFile(destination.getParent(), ".gradle-wrapper", ".tmp"); @@ -103,7 +103,7 @@ public void run(Path destination) throws IOException, NoSuchAlgorithmException { int retryDelay = 30; HttpURLConnection connection; while (true) { - connection = (HttpURLConnection) url.openConnection(); + connection = (HttpURLConnection) uri.toURL().openConnection(); try { connection.connect(); } catch (IOException e) { diff --git a/dev-docs/asf-jenkins.adoc b/dev-docs/asf-jenkins.adoc index b4d01bb3964..b3c59b6fd9e 100644 --- a/dev-docs/asf-jenkins.adoc +++ b/dev-docs/asf-jenkins.adoc @@ -10,13 +10,14 @@ This file aims to document our [ASF Jenkins](https://ci-builds.apache.org/job/So We run a number of jobs on Jenkins, each validating an overlapping set of concerns: * `Solr-Artifacts-*` - daily jobs that run `./gradlew assemble` to ensure that build artifacts (except docker images) can be created successfully -* `Solr-check-*` - "hourly" jobs that run all project tests and static analysis (i.e. `test`, `integrationTest`, and `check`) +* `Solr-Lint-*` - daily jobs that run static analysis (i.e. `precommit` and `check -x test`) on a branch +* `Solr-Test-*` - "hourly" jobs that run all (non-integration) tests (i.e. `./gradlew test`) +* `Solr-TestIntegration-*` - daily jobs that run project integration tests (i.e. `./gradlew integrationTests`) * `Solr-Docker-Nightly-*` - daily jobs that `./gradlew testDocker dockerPush` to validate docker image packaging. Snapshot images are pushed to hub.docker.com -* `Solr-reference-guide-*` - hourly jobs that build the Solr reference guide via `./gradlew checkSite` and push the resulting artifact to the staging/preview site `nightlies.apache.org` +* `Solr-reference-guide-*` - daily jobs that build the Solr reference guide via `./gradlew checkSite` and push the resulting artifact to the staging/preview site `nightlies.apache.org` * `Solr-Smoketest-*` - daily jobs that produce a snapshot release (via the `assembleRelease` task) and run the release smoketester Most jobs that validate particular build artifacts are run "daily", which is sufficient to prevent any large breaks from creeping into the build. - On the other hand, jobs that run tests are triggered "hourly" in order to squeeze as many test runs as possible out of our Jenkins hardware. This is a necessary consequence of Solr's heavy use of randomization in its test-suite. "Hourly" scheduling ensures that a test run is either currently running or in the build queue at all times, and enables us to get the maximum data points from our hardware. diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 751e19073fd..244f68171b7 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -26,6 +26,10 @@ Improvements * SOLR-16116: Apache Curator is now used to manage all Solr Zookeeper interactions. This should provide more stability in the Solr-Zookeeper interactions. The solrj-zookeeper module, now has a dependency on curator. (Houston Putman, Kevin Risden, Mike Drob, David Smiley) +* SOLR-17544: Solr CLI will now stop when you combine mutually exclusive options. Combining -s and -z options is a common example. (Eric Pugh, Christos Malliaridis) + +* SOLR-17495: Change Solr CLI delete command to not delete configs by default. Decouple lifecycle of collections from configsets. (Eric Pugh) + Optimizations --------------------- (No changes) @@ -141,7 +145,7 @@ Improvements when PKI is used between nodes. (Jason Gerlowski) * SOLR-17383: Resolved overlapping arguments in the Solr CLI. Removed duplicative but differing arguments, - consolidated use of short form arguments -v to not have differing meanings based on tool. Provide deprecation warning + consolidated use of short form arguments -v to not have differing meanings based on tool. Provide deprecation warning in command line when deprecated arguments are used. (Eric Pugh, Christos Malliaridis) * SOLR-17256: Deprecate SolrRequest `setBasePath` and `getBasePath` methods. SolrJ users wishing to temporarily @@ -179,6 +183,8 @@ Optimizations * SOLR-16503: Switched from HTTP1 to HTTP2 in SolrClientCloudManager by replacing CloudLegacySolrClient with CloudHttp2SolrClient. (Sanjay Dutt, David Smiley) +* SOLR-17453: Leverage waitForState() instead of busy waiting in CREATE, MIGRATE, REINDEXCOLLECTION, MOVEREPLICA commands, and in some tests. (Pierre Salagnac) + Bug Fixes --------------------- * SOLR-12429: Uploading a configset with a symbolic link produces a IOException. Now a error message to user generated instead. (Eric Pugh) @@ -221,6 +227,8 @@ led to the suppression of exceptions. (Andrey Bozhko) * SOLR-17534: Introduce ClusterState.getCollectionNames, a convenience method (David Smiley) +* SOLR-17535: Introduce ClusterState.collectionStream to replace getCollectionStates and getCollectionsMap (David Smiley) + * SOLR-17545: Upgrade to Gradle 8.10 (Houston Putman) ================== 9.7.1 ================== diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 783a4feed00..5fd6ec44aea 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -54,7 +54,11 @@ IF NOT DEFINED JAVA_HOME ( set "JAVA_HOME=%%B" ) ) -IF NOT DEFINED JAVA_HOME goto need_java_home +IF NOT DEFINED JAVA_HOME ( + REM Need java home + @echo "Please set the JAVA_HOME environment variable to the path where you installed Java !REQUIRED_JAVA_VERSION!+" + goto done +) set JAVA_HOME=%JAVA_HOME:"=% IF %JAVA_HOME:~-1%==\ SET JAVA_HOME=%JAVA_HOME:~0,-1% IF NOT EXIST "%JAVA_HOME%\bin\java.exe" ( @@ -244,59 +248,36 @@ IF "%SOLR_JETTY_HOST%"=="" ( set "SOLR_JETTY_HOST=127.0.0.1" ) -set FIRST_ARG=%1 - -IF [%1]==[] goto usage -IF "%1"=="-h" goto run_solrcli -IF "%1"=="--help" goto run_solrcli -IF "%1"=="status" goto run_solrcli -IF "%1"=="version" goto run_solrcli -IF "%1"=="-v" goto run_solrcli -IF "%1"=="--version" goto run_solrcli -IF "%1"=="assert" goto run_solrcli -IF "%1"=="zk" goto run_solrcli -IF "%1"=="export" goto run_solrcli -IF "%1"=="package" goto run_solrcli -IF "%1"=="api" goto run_solrcli -IF "%1"=="post" goto run_solrcli - -REM Only allow the command to be the first argument, assume start if not supplied +REM Handle special commands IF "%1"=="start" goto set_script_cmd IF "%1"=="stop" goto set_script_cmd IF "%1"=="restart" goto set_script_cmd -IF "%1"=="healthcheck" goto run_solrcli -IF "%1"=="create" goto run_solrcli -IF "%1"=="delete" goto run_solrcli -IF "%1"=="postlogs" goto run_solrcli +IF "%1"=="auth" goto set_script_cmd -IF "%1"=="auth" ( - set SCRIPT_CMD=auth - SHIFT - goto run_auth +REM Handle all other commands by simply running SolrCLI +"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^ + -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^ + -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ + org.apache.solr.cli.SolrCLI %* +if errorlevel 1 ( + exit /b 1 ) -IF "%1"=="config" goto run_solrcli +goto done +:set_script_cmd +set SCRIPT_CMD=%1 +SHIFT +IF "%SCRIPT_CMD%"=="auth" goto run_auth goto parse_args :usage IF NOT "%SCRIPT_ERROR%"=="" ECHO %SCRIPT_ERROR% -IF [%FIRST_ARG%]==[] goto run_solrcli -IF "%FIRST_ARG%"=="-h" goto run_solrcli -IF "%FIRST_ARG%"=="--help" goto run_solrcli 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 run_solrcli -IF "%SCRIPT_CMD%"=="create" goto run_solrcli -IF "%SCRIPT_CMD%"=="delete" goto run_solrcli -IF "%SCRIPT_CMD%"=="cluster" goto run_solrcli -IF "%SCRIPT_CMD%"=="zk" goto run_solrcli -IF "%SCRIPT_CMD%"=="auth" goto run_solrcli -IF "%SCRIPT_CMD%"=="package" goto run_solrcli -IF "%SCRIPT_CMD%"=="status" goto run_solrcli -IF "%SCRIPT_CMD%"=="postlogs" goto run_solrcli -goto done +REM Should not be reachable, but just in case +goto err :start_usage @echo. @@ -374,16 +355,19 @@ goto done @echo. goto done - -REM Really basic command-line arg parsing +REM Parse arguments for special commands (start, stop, restart) :parse_args set "arg=%~1" set "firstTwo=%arg:~0,2%" -IF "%SCRIPT_CMD%"=="" set SCRIPT_CMD=start -IF [%1]==[] goto process_script_cmd -IF "%1"=="--help" goto usage -IF "%1"=="-h" goto usage + +REM In case no arguments left, run special command +IF [%1]==[] goto run_special_command + +REM Skip start / restart arguments if stop command +IF "%SCRIPT_CMD%"=="stop" goto parse_stop_args + +:parse_start_args IF "%1"=="-f" goto set_foreground_mode IF "%1"=="--foreground" goto set_foreground_mode IF "%1"=="--verbose" goto set_verbose @@ -398,8 +382,6 @@ IF "%1"=="--example" goto set_example IF "%1"=="--host" goto set_host IF "%1"=="-m" goto set_memory IF "%1"=="--memory" goto set_memory -IF "%1"=="-p" goto set_port -IF "%1"=="--port" goto set_port IF "%1"=="-z" goto set_zookeeper IF "%1"=="--zk-host" goto set_zookeeper IF "%1"=="-s" goto set_solr_url @@ -407,20 +389,33 @@ IF "%1"=="--solr-url" goto set_solr_url IF "%1"=="--jvm-opts" goto set_jvm_opts IF "%1"=="-j" goto set_addl_jetty_config IF "%1"=="--jettyconfig" goto set_addl_jetty_config -IF "%1"=="--no-prompt" goto set_noprompt IF "%1"=="-y" goto set_noprompt +IF "%1"=="--no-prompt" goto set_noprompt + +REM Skip stop arg parsing if not stop command +IF NOT "%SCRIPT_CMD%"=="stop" goto parse_general_args + +:parse_stop_args IF "%1"=="-k" goto set_stop_key IF "%1"=="--key" goto set_stop_key IF "%1"=="--all" goto set_stop_all + +:parse_general_args + +REM Print usage of command in case help option included +IF "%1"=="--help" goto usage +IF "%1"=="-h" goto usage + +REM other args supported by all special commands +IF "%1"=="-p" goto set_port +IF "%1"=="--port" goto set_port IF "%firstTwo%"=="-D" goto set_passthru + +REM Argument not supported / found IF NOT "%1"=="" goto invalid_cmd_line +REM Not reachable, but just in case goto invalid_cmd_line -:set_script_cmd -set SCRIPT_CMD=%1 -SHIFT -goto parse_args - :set_foreground_mode set FG=1 SHIFT @@ -670,8 +665,27 @@ set "PASS_TO_RUN_EXAMPLE=--no-prompt !PASS_TO_RUN_EXAMPLE!" SHIFT goto parse_args -REM Perform the requested command after processing args -:process_script_cmd +REM Handle invalid arguments passed to special commands (start, stop, restart) +:invalid_cmd_line +@echo. +IF "!SCRIPT_ERROR!"=="" ( + @echo Invalid command-line option: %1 +) ELSE ( + @echo ERROR: !SCRIPT_ERROR! +) +@echo. +IF "%SCRIPT_CMD%"=="start" ( + goto start_usage +) ELSE IF "%SCRIPT_CMD%"=="restart" ( + goto start_usage +) ELSE IF "%SCRIPT_CMD%"=="stop" ( + goto stop_usage +) +REM Not reachable, but just in case +goto err + +REM Process special commands (start, stop, restart) +:run_special_command IF "%verbose%"=="1" ( CALL :safe_echo "Using Solr root directory: %SOLR_TIP%" @@ -712,36 +726,20 @@ IF NOT EXIST "%SOLR_SERVER_DIR%" ( goto err ) -IF NOT "%EXAMPLE%"=="" goto run_example - -:start_solr -IF "%SOLR_HOME%"=="" set "SOLR_HOME=%SOLR_SERVER_DIR%\solr" -IF EXIST "%cd%\%SOLR_HOME%" set "SOLR_HOME=%cd%\%SOLR_HOME%" - -IF NOT EXIST "%SOLR_HOME%\" ( - IF EXIST "%SOLR_SERVER_DIR%\%SOLR_HOME%" ( - set "SOLR_HOME=%SOLR_SERVER_DIR%\%SOLR_HOME%" - ) ELSE ( - set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!" - goto err - ) -) - IF "%STOP_KEY%"=="" set STOP_KEY=solrrocks -@REM This is quite hacky, but examples rely on a different log4j2.xml -@REM so that we can write logs for examples to %SOLR_HOME%\..\logs -IF [%SOLR_LOGS_DIR%] == [] ( - set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs" -) ELSE ( - set SOLR_LOGS_DIR=%SOLR_LOGS_DIR:"=% -) +IF NOT "%EXAMPLE%"=="" ( + REM Run the requested example -set "EXAMPLE_DIR=%SOLR_TIP%\example" -set TMP_SOLR_HOME=!SOLR_HOME:%EXAMPLE_DIR%=! -IF NOT "%TMP_SOLR_HOME%"=="%SOLR_HOME%" ( - set "SOLR_LOGS_DIR=%SOLR_HOME%\..\logs" - set "LOG4J_CONFIG=%SOLR_SERVER_DIR%\resources\log4j2.xml" + "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^ + -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^ + -Dsolr.install.symDir="%SOLR_TIP%" ^ + -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ + org.apache.solr.cli.SolrCLI run_example --script "%SDIR%\solr.cmd" -e %EXAMPLE% --server-dir "%SOLR_SERVER_DIR%" ^ + --url-scheme !SOLR_URL_SCHEME! !PASS_TO_RUN_EXAMPLE! + + REM End of run_example + goto done ) set IS_RESTART=0 @@ -754,77 +752,112 @@ IF "%SCRIPT_CMD%"=="restart" ( set IS_RESTART=1 ) +REM Skipt to start if not stop or restart (that executes stop first) +IF "%SCRIPT_CMD%"=="start" goto start_solr + @REM stop logic here +:stop_solr IF "%SOLR_STOP_WAIT%"=="" ( set SOLR_STOP_WAIT=180 ) -IF "%SCRIPT_CMD%"=="stop" ( - IF "%SOLR_PORT%"=="" ( - IF "%STOP_ALL%"=="1" ( - set found_it=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 ('type "%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 "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do ( - @REM j is the ip:port and k is the pid - IF NOT "%%k"=="0" ( - IF "%%j"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" ( - set found_it=1 - @echo Stopping Solr process %%k running on port !SOME_SOLR_PORT! - IF "%STOP_PORT%"=="" ( - set /A LOCAL_STOP_PORT=!SOME_SOLR_PORT! - 1000 - ) else ( - set LOCAL_STOP_PORT=%STOP_PORT% - ) - "%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!LOCAL_STOP_PORT! STOP.KEY=%STOP_KEY% --stop - del "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port - REM wait for the process to terminate - CALL :wait_for_process_exit %%k !SOLR_STOP_WAIT! - REM Kill it if it is still running after the graceful shutdown - IF EXIST "%JAVA_HOME%\bin\jstack.exe" ( - qprocess "%%k" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%k && taskkill /f /PID %%k - ) else ( - qprocess "%%k" >nul 2>nul && taskkill /f /PID %%k - ) +IF "%SOLR_PORT%"=="" ( + IF "%STOP_ALL%"=="1" ( + REM Stop all running Solr instances + set found_it=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 ('type "%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 "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do ( + @REM j is the ip:port and k is the pid + IF NOT "%%k"=="0" ( + IF "%%j"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" ( + set found_it=1 + @echo Stopping Solr process %%k running on port !SOME_SOLR_PORT! + IF "%STOP_PORT%"=="" ( + set /A LOCAL_STOP_PORT=!SOME_SOLR_PORT! - 1000 + ) else ( + set LOCAL_STOP_PORT=%STOP_PORT% + ) + "%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!LOCAL_STOP_PORT! STOP.KEY=%STOP_KEY% --stop + del "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port + REM wait for the process to terminate + CALL :wait_for_process_exit %%k !SOLR_STOP_WAIT! + REM Kill it if it is still running after the graceful shutdown + IF EXIST "%JAVA_HOME%\bin\jstack.exe" ( + qprocess "%%k" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%k && taskkill /f /PID %%k + ) else ( + qprocess "%%k" >nul 2>nul && taskkill /f /PID %%k ) ) ) ) ) - if "!found_it!"=="0" echo No Solr nodes found to stop. - ) ELSE ( - set "SCRIPT_ERROR=Must specify the port when trying to stop Solr, or use --all to stop all running nodes on this host." - goto err ) + if "!found_it!"=="0" echo No Solr nodes found to stop. ) ELSE ( - set found_it=0 - For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do ( - IF NOT "%%N"=="0" ( - IF "%%M"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" ( - set found_it=1 - @echo Stopping Solr process %%N running on port %SOLR_PORT% - IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000 - "%JAVA%" %SOLR_SSL_OPTS% %SOLR_TOOL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" %SOLR_JETTY_CONFIG% STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop - del "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port - REM wait for the process to terminate - CALL :wait_for_process_exit %%N !SOLR_STOP_WAIT! - REM Kill it if it is still running after the graceful shutdown - IF EXIST "%JAVA_HOME%\bin\jstack.exe" ( - qprocess "%%N" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%N && taskkill /f /PID %%N - ) else ( - qprocess "%%N" >nul 2>nul && taskkill /f /PID %%N - ) + set "SCRIPT_ERROR=Must specify the port when trying to stop Solr, or use --all to stop all running nodes on this host." + goto err + ) +) ELSE ( + REM Stop Solr running on specific port + set found_it=0 + For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do ( + IF NOT "%%N"=="0" ( + IF "%%M"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" ( + set found_it=1 + @echo Stopping Solr process %%N running on port %SOLR_PORT% + IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000 + "%JAVA%" %SOLR_SSL_OPTS% %SOLR_TOOL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" %SOLR_JETTY_CONFIG% STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop + del "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port + REM wait for the process to terminate + CALL :wait_for_process_exit %%N !SOLR_STOP_WAIT! + REM Kill it if it is still running after the graceful shutdown + IF EXIST "%JAVA_HOME%\bin\jstack.exe" ( + qprocess "%%N" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%N && taskkill /f /PID %%N + ) else ( + qprocess "%%N" >nul 2>nul && taskkill /f /PID %%N ) ) ) - if "!found_it!"=="0" echo No Solr found running on port %SOLR_PORT% ) + if "!found_it!"=="0" echo No Solr found running on port %SOLR_PORT% +) + +IF "!IS_RESTART!"=="0" goto done + +REM Clean state here, continue with starting (start or restart) +set SCRIPT_CMD=start + +:start_solr +REM Prepare for starting Solr +IF "%SOLR_HOME%"=="" set "SOLR_HOME=%SOLR_SERVER_DIR%\solr" +IF EXIST "%cd%\%SOLR_HOME%" set "SOLR_HOME=%cd%\%SOLR_HOME%" + +IF NOT EXIST "%SOLR_HOME%\" ( + IF EXIST "%SOLR_SERVER_DIR%\%SOLR_HOME%" ( + set "SOLR_HOME=%SOLR_SERVER_DIR%\%SOLR_HOME%" + ) ELSE ( + set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!" + goto err + ) +) + +@REM This is quite hacky, but examples rely on a different log4j2.xml +@REM so that we can write logs for examples to %SOLR_HOME%\..\logs +IF [%SOLR_LOGS_DIR%] == [] ( + set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs" +) ELSE ( + set SOLR_LOGS_DIR=%SOLR_LOGS_DIR:"=% +) - IF "!IS_RESTART!"=="0" goto done +set "EXAMPLE_DIR=%SOLR_TIP%\example" +set TMP_SOLR_HOME=!SOLR_HOME:%EXAMPLE_DIR%=! +IF NOT "%TMP_SOLR_HOME%"=="%SOLR_HOME%" ( + set "SOLR_LOGS_DIR=%SOLR_HOME%\..\logs" + set "LOG4J_CONFIG=%SOLR_SERVER_DIR%\resources\log4j2.xml" ) -IF "!IS_RESTART!"=="1" set SCRIPT_CMD=start IF "%SOLR_PORT%"=="" set SOLR_PORT=8983 IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000 @@ -841,21 +874,19 @@ IF DEFINED SOLR_ZK_EMBEDDED_HOST ( set "SCRIPT_SOLR_OPTS=%SCRIPT_SOLR_OPTS% -Dsolr.zk.embedded.host=%SOLR_ZK_EMBEDDED_HOST%" ) -IF "%SCRIPT_CMD%"=="start" ( - REM see if Solr is already running using netstat - For /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do ( - IF NOT "%%k"=="0" ( - IF "%%j"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" ( - set "SCRIPT_ERROR=Process %%k is already listening on port %SOLR_PORT%. If this is Solr, please stop it first before starting (or use restart). If this is not Solr, then please choose a different port using -p PORT" - goto err - ) +REM Make sure Solr is not running using netstat +For /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do ( + IF NOT "%%k"=="0" ( + IF "%%j"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" ( + set "SCRIPT_ERROR=Process %%k is already listening on port %SOLR_PORT%. If this is Solr, please stop it first before starting (or use restart). If this is not Solr, then please choose a different port using -p PORT" + goto err ) ) +) - IF "%EMPTY_ADDL_JVM_ARGS%"=="true" ( - set "SCRIPT_ERROR=JVM options are required when using the -a or --jvm-opts option!" - goto err - ) +IF "%EMPTY_ADDL_JVM_ARGS%"=="true" ( + set "SCRIPT_ERROR=JVM options are required when using the -a or --jvm-opts option!" + goto err ) @REM determine if -server flag is supported by current JVM @@ -1131,50 +1162,6 @@ IF "%FG%"=="1" ( goto done -:run_example -REM Run the requested example - -"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^ - -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^ - -Dsolr.install.symDir="%SOLR_TIP%" ^ - -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.cli.SolrCLI run_example --script "%SDIR%\solr.cmd" -e %EXAMPLE% --server-dir "%SOLR_SERVER_DIR%" ^ - --url-scheme !SOLR_URL_SCHEME! !PASS_TO_RUN_EXAMPLE! - -REM End of run_example -goto done - -:run_solrcli -"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^ - -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^ - -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.cli.SolrCLI %* -if errorlevel 1 ( - exit /b 1 -) -goto done - -:parse_config_args -IF [%1]==[] goto run_config -IF "%1"=="-z" goto set_config_zk -IF "%1"=="--zk-host" goto set_config_zk -IF "%1"=="--scheme" goto set_config_url_scheme -set "CONFIG_ARGS=!CONFIG_ARGS! %1" -SHIFT -goto parse_config_args - -:set_config_zk -set ZK_HOST=%~2 -SHIFT -SHIFT -goto parse_config_args - -:set_config_url_scheme -set SOLR_URL_SCHEME=%~2 -SHIFT -SHIFT -goto parse_config_args - :run_auth REM Options parsing. REM Note: With the following technique of parsing, it is not possible @@ -1231,49 +1218,12 @@ if "!AUTH_PORT!"=="" ( --solr-url !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!AUTH_PORT! goto done - -:invalid_cmd_line -@echo. -IF "!SCRIPT_ERROR!"=="" ( - @echo Invalid command-line option: %1 -) ELSE ( - @echo ERROR: !SCRIPT_ERROR! -) -@echo. -IF "%FIRST_ARG%"=="start" ( - goto start_usage -) ELSE IF "%FIRST_ARG:~0,1%" == "-" ( - goto start_usage -) ELSE IF "%FIRST_ARG%"=="restart" ( - goto start_usage -) ELSE IF "%FIRST_ARG%"=="stop" ( - goto stop_usage -) ELSE IF "%FIRST_ARG%"=="healthcheck" ( - goto run_solrcli -) ELSE IF "%FIRST_ARG%"=="create" ( - goto run_solrcli -) ELSE IF "%FIRST_ARG%"=="zk" ( - goto run_solrcli -) ELSE IF "%FIRST_ARG%"=="auth" ( - goto run_solrcli -) ELSE IF "%FIRST_ARG%"=="status" ( - goto run_solrcli -) - -:need_java_home -@echo Please set the JAVA_HOME environment variable to the path where you installed Java 21+ -goto done - :err @echo. @echo ERROR: !SCRIPT_ERROR! @echo. exit /b 1 -:done -ENDLOCAL -exit /b 0 - REM Tests what Java we have and sets some global variables :resolve_java_info @@ -1347,3 +1297,7 @@ GOTO :eof ) ) GOTO :eof + +:done +ENDLOCAL +exit /b 0 diff --git a/solr/core/src/java/org/apache/solr/cli/ApiTool.java b/solr/core/src/java/org/apache/solr/cli/ApiTool.java index 923505c8310..ede4de68971 100644 --- a/solr/core/src/java/org/apache/solr/cli/ApiTool.java +++ b/solr/core/src/java/org/apache/solr/cli/ApiTool.java @@ -19,9 +19,9 @@ import java.io.PrintStream; import java.net.URI; -import java.util.List; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.impl.JsonMapResponseParser; import org.apache.solr.client.solrj.request.GenericSolrRequest; @@ -36,6 +36,16 @@ *

Used to send an arbitrary HTTP request to a Solr API endpoint. */ public class ApiTool extends ToolBase { + + private static final Option SOLR_URL_OPTION = + Option.builder("s") + .longOpt("solr-url") + .hasArg() + .argName("URL") + .required() + .desc("Send a GET request to a Solr API endpoint.") + .build(); + public ApiTool() { this(CLIO.getOutStream()); } @@ -50,22 +60,16 @@ public String getName() { } @Override - public List