Apache Solr open-source search software
SOLR-16754: Change the bin/solr -info logic to work like other tools. (#1579)
Eric Pugh94d41851542f
diff --git a/solr/bin/solr b/solr/bin/solrindex 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 runningnumSolrs=$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' ')@@ -789,7 +789,7 @@ function get_info() {fireturn $CODE-} # end get_info+} # end get_statusfunction run_package() {runningSolrUrl=""@@ -919,10 +919,6 @@ if [ $# -eq 1 ]; thenprint_usage ""exit;;- -info|-i|status)- get_info- exit $?- ;;-version|-v|version)run_tool versionexit@@ -946,9 +942,29 @@ elsefiif [ "$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_statusexitfidiff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex 69ce6258927..4174560c577 100755--- a/solr/bin/solr.cmd+++ b/solr/bin/solr.cmd@@ -228,9 +228,7 @@ IF "%1"=="-usage" goto usageIF "%1"=="-h" goto usageIF "%1"=="--help" goto usageIF "%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_statusIF "%1"=="version" goto get_versionIF "%1"=="-v" goto get_versionIF "%1"=="-version" goto get_version@@ -1454,7 +1452,7 @@ REM Run the requested exampleREM End of run_examplegoto done-:get_info+:get_statusREM Find all Java processes, correlate with those listening on a portREM and then try to contact via that port using the status toolfor /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.javaindex 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.@Overridepublic List<Option> getOptions() {return List.of(diff --git a/solr/packaging/test/test_status.bats b/solr/packaging/test/test_status.batsnew file mode 100644index 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!"+}