This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 1bcbcbb587b SOLR-17685: Remove script creation of solr url based on
SOLR_TOOL_HOST in favour of java code in CLI tools (#3223)
1bcbcbb587b is described below
commit 1bcbcbb587bb4599a7abc1f8e2f52dcf7f899c41
Author: Eric Pugh <[email protected]>
AuthorDate: Thu Mar 13 15:56:11 2025 -0400
SOLR-17685: Remove script creation of solr url based on SOLR_TOOL_HOST in
favour of java code in CLI tools (#3223)
* Add test to demonstrate conflict with -z, and the fix.
* Remove solr.tool.host and SOLR_TOOL_HOST
* Preserve legacy AUTH_PORT usage, with a bats test
---
solr/CHANGES.txt | 2 ++
solr/bin/solr | 23 ++++-----------
solr/bin/solr.cmd | 24 ++++-----------
.../src/java/org/apache/solr/cli/AuthTool.java | 6 ++--
.../src/java/org/apache/solr/cli/CLIUtils.java | 7 ++++-
.../java/org/apache/solr/cli/RunExampleTool.java | 3 +-
.../src/test/org/apache/solr/cli/CLIUtilsTest.java | 4 +--
solr/packaging/test/test_auth.bats | 34 ++++++++++++++++++++++
8 files changed, 60 insertions(+), 43 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f17699d1191..e263673d194 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -188,6 +188,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)
diff --git a/solr/bin/solr b/solr/bin/solr
index 09784892f90..2d53e0bc8ce 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:-}"
@@ -601,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
@@ -612,22 +612,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" 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
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 3b971b68dfc..43928a5a6ae 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"
)
@@ -1175,7 +1169,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
@@ -1220,22 +1214,14 @@ 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\*"
^
- 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
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 6a71164a03d..c1fd6098e6c 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 93fb1403957..de41c34d6dd 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.Optional;
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;
@@ -70,7 +71,7 @@ public final class 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);
}
@@ -346,4 +347,8 @@ public final class CLIUtils {
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 c5afdf06321..974039cb66f 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.DefaultExecuteResultHandler;
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 @@ public class RunExampleTool extends ToolBase {
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/core/src/test/org/apache/solr/cli/CLIUtilsTest.java
b/solr/core/src/test/org/apache/solr/cli/CLIUtilsTest.java
index 928266de7c0..d1806aec670 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 class CLIUtilsTest extends SolrCloudTestCase {
@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.",
diff --git a/solr/packaging/test/test_auth.bats
b/solr/packaging/test/test_auth.bats
index eff96d9d81b..58a0ad16ee5 100644
--- a/solr/packaging/test/test_auth.bats
+++ b/solr/packaging/test/test_auth.bats
@@ -48,3 +48,37 @@ setup() {
assert_output --partial '"numFound":0'
solr stop --all
}
+
+@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 -z localhost:${ZK_PORT}
+ run curl "http://localhost:${SOLR_PORT}/api/cluster"
+ 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}
+}