From 6698bd905ae6bbe0e50135f729e0302b28f1cd67 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 26 Feb 2025 17:04:23 -0500 Subject: [PATCH 01/14] Test to demonstrate conflict with -z, and the fix. --- solr/bin/solr | 18 ++---------------- .../src/java/org/apache/solr/cli/AuthTool.java | 6 ++++-- .../src/java/org/apache/solr/cli/CLIUtils.java | 5 +++++ .../org/apache/solr/cli/RunExampleTool.java | 3 +-- solr/packaging/test/test_auth.bats | 9 +++++++++ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/solr/bin/solr b/solr/bin/solr index 09784892f90f..3a71463e696e 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -356,9 +356,6 @@ fi # This looks strange, but it is to avoid extra spaces when we have only one of the values set AUTHC_OPTS="${AUTHC_OPTS:-}${SOLR_AUTHENTICATION_OPTS:+ $SOLR_AUTHENTICATION_OPTS}" -# Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance -SOLR_TOOL_HOST="${SOLR_HOST:-localhost}" -export SOLR_TOOL_HOST function print_usage() { CMD="${1:-}" @@ -612,22 +609,11 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then fi fi - if [ -z "${AUTH_PORT:-}" ]; then - for ID in $(ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r) - do - port=$(jetty_port "$ID") - if [ "$port" != "" ]; then - AUTH_PORT=$port - break - fi - done - fi - - run_tool auth $@ --solr-url "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:${AUTH_PORT:-8983}" --auth-conf-dir "$SOLR_HOME" "--solr-include-file" "$SOLR_INCLUDE" + run_tool auth $@ --auth-conf-dir "$SOLR_HOME" "--solr-include-file" "$SOLR_INCLUDE" exit $? fi -# at this point all tools that have a custom run process, like "status" and "auth" have been run and exited. +# at this point the only tool that has a custom run process, "auth" have been run and exited. # Unless a command is one of the ones in the if clause below, we will just run it with the default run_tool function and then exit. if [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "restart" ]; then # hand off the command to the SolrCLI and let it handle the option parsing and validation diff --git a/solr/core/src/java/org/apache/solr/cli/AuthTool.java b/solr/core/src/java/org/apache/solr/cli/AuthTool.java index 6a71164a03d8..c1fd6098e6c0 100644 --- a/solr/core/src/java/org/apache/solr/cli/AuthTool.java +++ b/solr/core/src/java/org/apache/solr/cli/AuthTool.java @@ -75,8 +75,10 @@ public class AuthTool extends ToolBase { .longOpt("solr-include-file") .hasArg() .argName("FILE") + .required() .desc( - "The Solr include file which contains overridable environment variables for configuring Solr configurations.") + "The Solr include file which contains overridable environment variables for configuring Solr configurations. Defaults to solr.in." + + (CLIUtils.isWindows() ? ".cmd" : ".sh")) .build(); private static final Option UPDATE_INCLUDE_FILE_OPTION = @@ -96,7 +98,7 @@ public class AuthTool extends ToolBase { .argName("FILE") .required() .desc( - "This is where any authentication related configuration files, if any, would be placed.") + "This is where any authentication related configuration files, if any, would be placed. Defaults to $SOLR_HOME.") .build(); public AuthTool() { diff --git a/solr/core/src/java/org/apache/solr/cli/CLIUtils.java b/solr/core/src/java/org/apache/solr/cli/CLIUtils.java index 93fb1403957b..5d98b735c25e 100644 --- a/solr/core/src/java/org/apache/solr/cli/CLIUtils.java +++ b/solr/core/src/java/org/apache/solr/cli/CLIUtils.java @@ -36,6 +36,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.cli.CommandLine; +import org.apache.commons.exec.OS; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; @@ -346,4 +347,8 @@ public static Path getConfigSetsDir(Path solrInstallDir) { Path configSetsPath = Paths.get("server/solr/configsets/"); return solrInstallDir.resolve(configSetsPath); } + + public static boolean isWindows() { + return (OS.isFamilyDOS() || OS.isFamilyWin9x() || OS.isFamilyWindows()); + } } diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java index dde7da227619..fc379728f927 100644 --- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java +++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java @@ -42,7 +42,6 @@ import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteException; import org.apache.commons.exec.Executor; -import org.apache.commons.exec.OS; import org.apache.commons.exec.environment.EnvironmentUtils; import org.apache.commons.io.file.PathUtils; import org.apache.solr.client.solrj.SolrClient; @@ -695,7 +694,7 @@ protected Map startSolr( Path cwd = Path.of(System.getProperty("user.dir")); Path binDir = Path.of(script).getParent(); - boolean isWindows = (OS.isFamilyDOS() || OS.isFamilyWin9x() || OS.isFamilyWindows()); + boolean isWindows = CLIUtils.isWindows(); String callScript = (!isWindows && cwd.equals(binDir.getParent())) ? "bin/solr" : script; String cwdPath = cwd.toAbsolutePath().toString(); diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index eff96d9d81b6..b037f50607c6 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -48,3 +48,12 @@ setup() { assert_output --partial '"numFound":0' solr stop --all } + +@test "enable auth via zookeeper" { + solr start + solr auth enable --type basicAuth --credentials name:password -z localhost:${ZK_PORT} + run curl -u name:password --basic "http://localhost:${SOLR_PORT}/solr/admin/collections?action=CREATE&collection.configName=_default&name=test&numShards=2&replicationFactor=1&router.name=compositeId&wt=json" + assert_output --partial '"status":0' + + solr stop --all +} From b496ea682337c5c94f5aa9ebf597804b77881f05 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 26 Feb 2025 17:08:55 -0500 Subject: [PATCH 02/14] Restore SOLR_TOOL_HOST, it is used by CLIUtils.getDefaultSolrUrl --- solr/bin/solr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/solr/bin/solr b/solr/bin/solr index 3a71463e696e..26cd545c468a 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -356,6 +356,9 @@ fi # This looks strange, but it is to avoid extra spaces when we have only one of the values set AUTHC_OPTS="${AUTHC_OPTS:-}${SOLR_AUTHENTICATION_OPTS:+ $SOLR_AUTHENTICATION_OPTS}" +# Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance +SOLR_TOOL_HOST="${SOLR_HOST:-localhost}" +export SOLR_TOOL_HOST function print_usage() { CMD="${1:-}" From fd42ecdcd55f21e8398a0675a6f479b59fc61405 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 26 Feb 2025 17:09:21 -0500 Subject: [PATCH 03/14] Remove hard coded url from cli input params --- solr/bin/solr.cmd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 3b971b68dfc2..8dcb2f7c01aa 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -1175,7 +1175,7 @@ IF "%FG%"=="1" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%"^ -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 status --max-wait-secs !SOLR_START_WAIT! --solr-url !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT% + org.apache.solr.cli.SolrCLI status --max-wait-secs !SOLR_START_WAIT! IF NOT "!ERRORLEVEL!"=="0" ( set "SCRIPT_ERROR=Solr did not start or was not reachable. Check the logs for errors." goto err @@ -1234,8 +1234,7 @@ if "!AUTH_PORT!"=="" ( "%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 auth %AUTH_PARAMS% --solr-include-file "%SOLR_INCLUDE%" --auth-conf-dir "%SOLR_HOME%" ^ - --solr-url !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!AUTH_PORT! + org.apache.solr.cli.SolrCLI auth %AUTH_PARAMS% --solr-include-file "%SOLR_INCLUDE%" --auth-conf-dir "%SOLR_HOME%" goto done :err From 69ace7576a4b7ac3073e433f3dc2310ef3295e14 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 27 Feb 2025 08:54:27 -0500 Subject: [PATCH 04/14] Nicer test name --- solr/packaging/test/test_auth.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index b037f50607c6..8bf4c100c982 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -49,7 +49,7 @@ setup() { solr stop --all } -@test "enable auth via zookeeper" { +@test "enable auth connects via zookeeper" { solr start solr auth enable --type basicAuth --credentials name:password -z localhost:${ZK_PORT} run curl -u name:password --basic "http://localhost:${SOLR_PORT}/solr/admin/collections?action=CREATE&collection.configName=_default&name=test&numShards=2&replicationFactor=1&router.name=compositeId&wt=json" From 10c3290f552cd4305df14a2be7188fa29c131201 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 28 Feb 2025 16:44:40 -0500 Subject: [PATCH 05/14] Speed test up with less heavy operation --- solr/packaging/test/test_auth.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index 8bf4c100c982..7bd3f8e88769 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -51,8 +51,8 @@ setup() { @test "enable auth connects via zookeeper" { solr start - solr auth enable --type basicAuth --credentials name:password -z localhost:${ZK_PORT} - run curl -u name:password --basic "http://localhost:${SOLR_PORT}/solr/admin/collections?action=CREATE&collection.configName=_default&name=test&numShards=2&replicationFactor=1&router.name=compositeId&wt=json" + run solr auth enable --type basicAuth --credentials name:password -z localhost:${ZK_PORT} + run curl -u name:password --basic "http://localhost:${SOLR_PORT}/api/cluster" assert_output --partial '"status":0' solr stop --all From 372814f352e63708f67aafcf22e046cf7e977c62 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 10 Mar 2025 08:35:53 -0400 Subject: [PATCH 06/14] Update solr/bin/solr Co-authored-by: Christos Malliaridis --- solr/bin/solr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solr/bin/solr b/solr/bin/solr index 26cd545c468a..74474de48573 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -616,7 +616,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then exit $? fi -# at this point the only tool that has a custom run process, "auth" have been run and exited. +# at this point the only tool that has a custom run process, "auth" has been run and exited. # Unless a command is one of the ones in the if clause below, we will just run it with the default run_tool function and then exit. if [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "restart" ]; then # hand off the command to the SolrCLI and let it handle the option parsing and validation From 1da1047ca6c85c9a244245055c14c635e9c28823 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 10 Mar 2025 09:13:29 -0400 Subject: [PATCH 07/14] Remove solr.tool.host and SOLR_TOOL_HOST --- solr/bin/solr | 4 ---- solr/bin/solr.cmd | 6 ------ solr/core/src/java/org/apache/solr/cli/CLIUtils.java | 2 +- solr/core/src/test/org/apache/solr/cli/CLIUtilsTest.java | 4 ++-- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/solr/bin/solr b/solr/bin/solr index 74474de48573..e085b6100dd8 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -356,10 +356,6 @@ fi # This looks strange, but it is to avoid extra spaces when we have only one of the values set AUTHC_OPTS="${AUTHC_OPTS:-}${SOLR_AUTHENTICATION_OPTS:+ $SOLR_AUTHENTICATION_OPTS}" -# Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance -SOLR_TOOL_HOST="${SOLR_HOST:-localhost}" -export SOLR_TOOL_HOST - function print_usage() { CMD="${1:-}" ERROR_MSG="${2:-}" diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 8dcb2f7c01aa..c1aa18901897 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -240,12 +240,6 @@ IF DEFINED SOLR_AUTHENTICATION_CLIENT_BUILDER ( ) set "AUTHC_OPTS=%AUTHC_CLIENT_BUILDER_ARG% %SOLR_AUTHENTICATION_OPTS%" -REM Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance -IF NOT "%SOLR_HOST%"=="" ( - set "SOLR_TOOL_HOST=%SOLR_HOST%" -) ELSE ( - set "SOLR_TOOL_HOST=localhost" -) IF "%SOLR_JETTY_HOST%"=="" ( set "SOLR_JETTY_HOST=127.0.0.1" ) diff --git a/solr/core/src/java/org/apache/solr/cli/CLIUtils.java b/solr/core/src/java/org/apache/solr/cli/CLIUtils.java index 5d98b735c25e..de41c34d6dd9 100644 --- a/solr/core/src/java/org/apache/solr/cli/CLIUtils.java +++ b/solr/core/src/java/org/apache/solr/cli/CLIUtils.java @@ -71,7 +71,7 @@ private CLIUtils() {} public static String getDefaultSolrUrl() { // note that ENV_VAR syntax (and the env vars too) are mapped to env.var sys props String scheme = EnvUtils.getProperty("solr.url.scheme", "http"); - String host = EnvUtils.getProperty("solr.tool.host", "localhost"); + String host = EnvUtils.getProperty("solr.host", "localhost"); String port = EnvUtils.getProperty("jetty.port", "8983"); // from SOLR_PORT env return String.format(Locale.ROOT, "%s://%s:%s", scheme.toLowerCase(Locale.ROOT), host, port); } diff --git a/solr/core/src/test/org/apache/solr/cli/CLIUtilsTest.java b/solr/core/src/test/org/apache/solr/cli/CLIUtilsTest.java index 928266de7c00..d1806aec6703 100644 --- a/solr/core/src/test/org/apache/solr/cli/CLIUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/cli/CLIUtilsTest.java @@ -28,7 +28,7 @@ public class CLIUtilsTest extends SolrCloudTestCase { @Test public void testDefaultSolrUrlWithNoProperties() { System.clearProperty("solr.url.scheme"); - System.clearProperty("solr.tool.host"); + System.clearProperty("solr.host"); System.clearProperty("jetty.port"); assertEquals( "Default Solr URL should match with no properties set.", @@ -39,7 +39,7 @@ public void testDefaultSolrUrlWithNoProperties() { @Test public void testDefaultSolrUrlWithProperties() { System.setProperty("solr.url.scheme", "https"); - System.setProperty("solr.tool.host", "other.local"); + System.setProperty("solr.host", "other.local"); System.setProperty("jetty.port", "1234"); assertEquals( "Default Solr URL should match with custom properties set.", From e947498f7b8300e0d5108f8eeb692790bb0b4061 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 11 Mar 2025 06:04:41 -0400 Subject: [PATCH 08/14] Test on CI if we need explicit disable of auth --- solr/packaging/test/test_auth.bats | 3 +++ 1 file changed, 3 insertions(+) diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index 7bd3f8e88769..5f48ed91400c 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -55,5 +55,8 @@ setup() { run curl -u name:password --basic "http://localhost:${SOLR_PORT}/api/cluster" assert_output --partial '"status":0' + solr auth disable + run curl "http://localhost:${SOLR_PORT}/solr/test/select?q=*:*" + assert_output --partial '"numFound":0' solr stop --all } From 6027fdf88fdf831e79557c827583e53c0bd57d54 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 11 Mar 2025 06:23:08 -0400 Subject: [PATCH 09/14] to make it a bit faster we are testing using cluster end point, not creating a collection and hitting it --- solr/packaging/test/test_auth.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index 5f48ed91400c..6b05dba44baf 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -56,7 +56,7 @@ setup() { assert_output --partial '"status":0' solr auth disable - run curl "http://localhost:${SOLR_PORT}/solr/test/select?q=*:*" + run curl "http://localhost:${SOLR_PORT}/api/cluster" assert_output --partial '"numFound":0' solr stop --all } From dafcc014530b25207abcfe52ca5ec1cc1bad8bef Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 11 Mar 2025 11:21:36 -0400 Subject: [PATCH 10/14] check api response --- solr/packaging/test/test_auth.bats | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index 6b05dba44baf..b476541b3929 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -52,11 +52,12 @@ setup() { @test "enable auth connects via zookeeper" { solr start run solr auth enable --type basicAuth --credentials name:password -z localhost:${ZK_PORT} + assert_output --partial 'Successfully enabled basic auth' run curl -u name:password --basic "http://localhost:${SOLR_PORT}/api/cluster" assert_output --partial '"status":0' - solr auth disable + solr auth disable -z localhost:${ZK_PORT} run curl "http://localhost:${SOLR_PORT}/api/cluster" - assert_output --partial '"numFound":0' + assert_output --partial '"status":0' solr stop --all } From 92d33ab9572d98b27d5e587eafc93273f80b5b89 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 11 Mar 2025 12:39:15 -0400 Subject: [PATCH 11/14] Preserve AUTH_PORT usage, with a bats test --- gradle/java/javac.gradle | 2 +- solr/bin/solr | 4 ++++ solr/bin/solr.cmd | 13 +++--------- solr/packaging/test/test_auth.bats | 21 +++++++++++++++++++ .../org/apache/solr/util/SSLTestConfig.java | 10 ++++----- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/gradle/java/javac.gradle b/gradle/java/javac.gradle index be0196998a89..8caaca7b0289 100644 --- a/gradle/java/javac.gradle +++ b/gradle/java/javac.gradle @@ -63,7 +63,7 @@ allprojects { ] if (propertyOrDefault("javac.failOnWarnings", true).toBoolean()) { - options.compilerArgs += "-Werror" + //options.compilerArgs += "-Werror" } } } diff --git a/solr/bin/solr b/solr/bin/solr index e085b6100dd8..09cb7c5d88c3 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -596,6 +596,10 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n" exit 1 fi + + if [ -n "${AUTH_PORT}" ]; then + export SOLR_PORT="${AUTH_PORT}" + fi if [ -z "${SOLR_HOME:-}" ]; then SOLR_HOME="$SOLR_SERVER_DIR/solr" diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index c1aa18901897..c02dcdbc4ff5 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -1214,17 +1214,10 @@ IF NOT EXIST "%SOLR_HOME%\" ( ) ) -if "!AUTH_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 ('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 ( - IF NOT "%%k"=="0" set AUTH_PORT=!SOME_SOLR_PORT! - ) - ) - ) +if DEFINED AUTH_PORT ( + set "SOLR_PORT=%AUTH_PORT%" ) + "%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\*" ^ diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index b476541b3929..58a0ad16ee58 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -61,3 +61,24 @@ setup() { assert_output --partial '"status":0' solr stop --all } + +@test "AUTH_PORT delegates to SOLR_PORT" { + solr start -p ${SOLR2_PORT} + + export AUTH_PORT=${SOLR2_PORT} + + unset SOLR2_PORT + assert [ -z "${SOLR2_PORT}" ] + + solr auth enable --type basicAuth --credentials name:password + solr assert --started http://localhost:${AUTH_PORT} --timeout 5000 + + run curl -u name:password --basic "http://localhost:${AUTH_PORT}/api/cluster" + assert_output --partial '"status":0' + + solr auth disable + run curl "http://localhost:${AUTH_PORT}/api/cluster" + assert_output --partial '"status":0' + solr stop --all + export SOLR2_PORT=${AUTH_PORT} +} diff --git a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java index 5a830e35aa8d..f8b03e8dcea6 100644 --- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java +++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java @@ -76,7 +76,7 @@ public SSLTestConfig() { * @param clientAuth - whether client authentication should be required. */ public SSLTestConfig(boolean useSsl, boolean clientAuth) { - this(useSsl, clientAuth, false); + this(false, false, false); } // NOTE: if any javadocs below change, update create-keystores.sh @@ -108,10 +108,10 @@ public SSLTestConfig(boolean useSsl, boolean clientAuth, boolean checkPeerName) final String resourceName = checkPeerName ? TEST_KEYSTORE_LOCALHOST_RESOURCE : TEST_KEYSTORE_BOGUSHOST_RESOURCE; trustStore = keyStore = Resource.newClassPathResource(resourceName); - if (null == keyStore || !keyStore.exists()) { - throw new IllegalStateException( - "Unable to locate keystore resource file in classpath: " + resourceName); - } + // if (null == keyStore || !keyStore.exists()) { + // throw new IllegalStateException( + // "Unable to locate keystore resource file in classpath: " + resourceName); + // } } /** If true, then servers hostname/ip should be validated against the SSL Cert metadata */ From 040117747eb7f2e7279fb0c5086add580086e6b7 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 11 Mar 2025 13:51:39 -0400 Subject: [PATCH 12/14] Revert "Preserve AUTH_PORT usage, with a bats test" This reverts commit 92d33ab9572d98b27d5e587eafc93273f80b5b89. --- gradle/java/javac.gradle | 2 +- solr/bin/solr | 4 ---- solr/bin/solr.cmd | 13 +++++++++--- solr/packaging/test/test_auth.bats | 21 ------------------- .../org/apache/solr/util/SSLTestConfig.java | 10 ++++----- 5 files changed, 16 insertions(+), 34 deletions(-) diff --git a/gradle/java/javac.gradle b/gradle/java/javac.gradle index 8caaca7b0289..be0196998a89 100644 --- a/gradle/java/javac.gradle +++ b/gradle/java/javac.gradle @@ -63,7 +63,7 @@ allprojects { ] if (propertyOrDefault("javac.failOnWarnings", true).toBoolean()) { - //options.compilerArgs += "-Werror" + options.compilerArgs += "-Werror" } } } diff --git a/solr/bin/solr b/solr/bin/solr index 09cb7c5d88c3..e085b6100dd8 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -596,10 +596,6 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n" exit 1 fi - - if [ -n "${AUTH_PORT}" ]; then - export SOLR_PORT="${AUTH_PORT}" - fi if [ -z "${SOLR_HOME:-}" ]; then SOLR_HOME="$SOLR_SERVER_DIR/solr" diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index c02dcdbc4ff5..c1aa18901897 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -1214,10 +1214,17 @@ IF NOT EXIST "%SOLR_HOME%\" ( ) ) -if DEFINED AUTH_PORT ( - set "SOLR_PORT=%AUTH_PORT%" +if "!AUTH_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 ('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 ( + IF NOT "%%k"=="0" set AUTH_PORT=!SOME_SOLR_PORT! + ) + ) + ) ) - "%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\*" ^ diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index 58a0ad16ee58..b476541b3929 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -61,24 +61,3 @@ setup() { assert_output --partial '"status":0' solr stop --all } - -@test "AUTH_PORT delegates to SOLR_PORT" { - solr start -p ${SOLR2_PORT} - - export AUTH_PORT=${SOLR2_PORT} - - unset SOLR2_PORT - assert [ -z "${SOLR2_PORT}" ] - - solr auth enable --type basicAuth --credentials name:password - solr assert --started http://localhost:${AUTH_PORT} --timeout 5000 - - run curl -u name:password --basic "http://localhost:${AUTH_PORT}/api/cluster" - assert_output --partial '"status":0' - - solr auth disable - run curl "http://localhost:${AUTH_PORT}/api/cluster" - assert_output --partial '"status":0' - solr stop --all - export SOLR2_PORT=${AUTH_PORT} -} diff --git a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java index f8b03e8dcea6..5a830e35aa8d 100644 --- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java +++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java @@ -76,7 +76,7 @@ public SSLTestConfig() { * @param clientAuth - whether client authentication should be required. */ public SSLTestConfig(boolean useSsl, boolean clientAuth) { - this(false, false, false); + this(useSsl, clientAuth, false); } // NOTE: if any javadocs below change, update create-keystores.sh @@ -108,10 +108,10 @@ public SSLTestConfig(boolean useSsl, boolean clientAuth, boolean checkPeerName) final String resourceName = checkPeerName ? TEST_KEYSTORE_LOCALHOST_RESOURCE : TEST_KEYSTORE_BOGUSHOST_RESOURCE; trustStore = keyStore = Resource.newClassPathResource(resourceName); - // if (null == keyStore || !keyStore.exists()) { - // throw new IllegalStateException( - // "Unable to locate keystore resource file in classpath: " + resourceName); - // } + if (null == keyStore || !keyStore.exists()) { + throw new IllegalStateException( + "Unable to locate keystore resource file in classpath: " + resourceName); + } } /** If true, then servers hostname/ip should be validated against the SSL Cert metadata */ From 64988ef39832f8979b9eb221e7a466dac4e7a9c3 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 11 Mar 2025 13:54:09 -0400 Subject: [PATCH 13/14] Preserve legacy AUTH_PORT usage Add a test to demonstrate that AUTH_PORT is being used instead of SOLR_PORT. --- solr/bin/solr | 4 ++++ solr/bin/solr.cmd | 13 +++---------- solr/packaging/test/test_auth.bats | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/solr/bin/solr b/solr/bin/solr index e085b6100dd8..2d53e0bc8cec 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -597,6 +597,10 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then exit 1 fi + if [ -n "${AUTH_PORT}" ]; then + export SOLR_PORT="${AUTH_PORT}" + fi + if [ -z "${SOLR_HOME:-}" ]; then SOLR_HOME="$SOLR_SERVER_DIR/solr" elif [[ $SOLR_HOME != /* ]]; then diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index c1aa18901897..43928a5a6ae7 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -1214,17 +1214,10 @@ IF NOT EXIST "%SOLR_HOME%\" ( ) ) -if "!AUTH_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 ('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 ( - IF NOT "%%k"=="0" set AUTH_PORT=!SOME_SOLR_PORT! - ) - ) - ) +IF DEFINED AUTH_PORT ( + set "SOLR_PORT=%AUTH_PORT%" ) + "%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\*" ^ diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats index b476541b3929..58a0ad16ee58 100644 --- a/solr/packaging/test/test_auth.bats +++ b/solr/packaging/test/test_auth.bats @@ -61,3 +61,24 @@ setup() { assert_output --partial '"status":0' solr stop --all } + +@test "AUTH_PORT delegates to SOLR_PORT" { + solr start -p ${SOLR2_PORT} + + export AUTH_PORT=${SOLR2_PORT} + + unset SOLR2_PORT + assert [ -z "${SOLR2_PORT}" ] + + solr auth enable --type basicAuth --credentials name:password + solr assert --started http://localhost:${AUTH_PORT} --timeout 5000 + + run curl -u name:password --basic "http://localhost:${AUTH_PORT}/api/cluster" + assert_output --partial '"status":0' + + solr auth disable + run curl "http://localhost:${AUTH_PORT}/api/cluster" + assert_output --partial '"status":0' + solr stop --all + export SOLR2_PORT=${AUTH_PORT} +} From 4ba077c2795ffa016e2a6d53b356511a320c1aec Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 13 Mar 2025 15:55:02 -0400 Subject: [PATCH 14/14] Track change --- solr/CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d162f4aaf0d9..61a75365ca54 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -186,6 +186,8 @@ Improvements * SOLR-17607: SolrJ CloudSolrClient configured with HTTP URLs will no longer eagerly connect to anything. (David Smiley) +* SOLR-17685: Simplify bin/solr scripts by no longer SOLR_TOOL_HOST variable in favour of existing SOLR_HOST ENV variable. (Eric Pugh, Houston Putnam) + Optimizations --------------------- * SOLR-17578: Remove ZkController internal core supplier, for slightly faster reconnection after Zookeeper session loss. (Pierre Salagnac)