This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 98e699b7c3d SOLR-16754: Change the bin/solr -info logic to work like
other tools. (#1579)
98e699b7c3d is described below
commit 98e699b7c3df0c78840d3a66f8d7b8a07776f24b
Author: Eric Pugh <[email protected]>
AuthorDate: Tue Apr 25 10:46:11 2023 -0400
SOLR-16754: Change the bin/solr -info logic to work like other tools.
(#1579)
* remove the -i and -info cli option since we have instead the use of
status as a command
* allow bin/solr status -h and bin/solr status -help to now work.
---
solr/bin/solr | 36 ++++++++++++-----
solr/bin/solr.cmd | 6 +--
.../src/java/org/apache/solr/cli/StatusTool.java | 2 +
solr/packaging/test/test_status.bats | 46 ++++++++++++++++++++++
4 files changed, 76 insertions(+), 14 deletions(-)
diff --git a/solr/bin/solr b/solr/bin/solr
index 11f441c0059..fe91078f485 100644
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -744,8 +744,8 @@ function run_tool() {
return $?
} # end run_tool function
-# get information about any Solr nodes running on this host
-function get_info() {
+# get status about any Solr nodes running on this host
+function get_status() {
CODE=4
# first, see if Solr is running
numSolrs=$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d '
')
@@ -789,7 +789,7 @@ function get_info() {
fi
return $CODE
-} # end get_info
+} # end get_status
function run_package() {
runningSolrUrl=""
@@ -919,10 +919,6 @@ if [ $# -eq 1 ]; then
print_usage ""
exit
;;
- -info|-i|status)
- get_info
- exit $?
- ;;
-version|-v|version)
run_tool version
exit
@@ -946,9 +942,29 @@ else
fi
if [ "$SCRIPT_CMD" == "status" ]; then
- # hacky - the script hits this if the user passes additional args with the
status command,
- # which is not supported but also not worth complaining about either
- get_info
+ if [ $# -gt 0 ]; then
+ while true; do
+ case "$1" in
+ -help|-h)
+ print_usage "$SCRIPT_CMD"
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ if [ "$1" != "" ]; then
+ print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument:
$1!"
+ exit 1
+ else
+ break # out-of-args, stop looping
+ fi
+ ;;
+ esac
+ done
+ fi
+ get_status
exit
fi
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 69ce6258927..4174560c577 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -228,9 +228,7 @@ IF "%1"=="-usage" goto usage
IF "%1"=="-h" goto usage
IF "%1"=="--help" goto usage
IF "%1"=="/?" goto usage
-IF "%1"=="-i" goto get_info
-IF "%1"=="-info" goto get_info
-IF "%1"=="status" goto get_info
+IF "%1"=="status" goto get_status
IF "%1"=="version" goto get_version
IF "%1"=="-v" goto get_version
IF "%1"=="-version" goto get_version
@@ -1454,7 +1452,7 @@ REM Run the requested example
REM End of run_example
goto done
-:get_info
+:get_status
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
for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i
"^solr-.*\.port$"`) do (
diff --git a/solr/core/src/java/org/apache/solr/cli/StatusTool.java
b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
index 0a9501ec5aa..9d771e38132 100644
--- a/solr/core/src/java/org/apache/solr/cli/StatusTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
@@ -51,6 +51,8 @@ public class StatusTool extends ToolBase {
return "status";
}
+ // These options are not exposed to the end user, and are
+ // used directly by the bin/solr status CLI.
@Override
public List<Option> getOptions() {
return List.of(
diff --git a/solr/packaging/test/test_status.bats
b/solr/packaging/test/test_status.bats
new file mode 100644
index 00000000000..c1ca0c5986f
--- /dev/null
+++ b/solr/packaging/test/test_status.bats
@@ -0,0 +1,46 @@
+#!/usr/bin/env bats
+
+# 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.
+
+load bats_helper
+
+setup() {
+ common_clean_setup
+}
+
+teardown() {
+ # save a snapshot of SOLR_HOME for failed tests
+ save_home_on_failure
+
+ solr stop -all >/dev/null 2>&1
+}
+
+@test "status detects locally running solr" {
+ run solr status
+ assert_output --partial "No Solr nodes are running."
+ run solr start
+ run solr status
+ assert_output --partial "Found 1 Solr nodes:"
+ run solr stop
+ run solr status
+ assert_output --partial "No Solr nodes are running."
+
+}
+
+@test "status does not expose cli parameters to end user" {
+ run solr status -solr http://localhost:8983/solr
+ assert_output --partial "ERROR: Unrecognized or misplaced argument: -solr!"
+}