Skip to content

Commit 77f5943

Browse files
committed
SOLR-17450 StatusTool with pure Java code (apache#2712)
Co-authored-by: Christos Malliaridis <[email protected]> (cherry picked from commit 2391f49)
1 parent 77e2ca8 commit 77f5943

File tree

9 files changed

+677
-136
lines changed

9 files changed

+677
-136
lines changed

gradle/testing/randomization/policies/solr-tests.policy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ grant {
109109
permission java.lang.RuntimePermission "writeFileDescriptor";
110110
// needed by hadoop http
111111
permission java.lang.RuntimePermission "getProtectionDomain";
112+
// SolrProcessMgr to list processes
113+
permission java.lang.RuntimePermission "manageProcess";
112114

113115
// These two *have* to be spelled out a separate
114116
permission java.lang.management.ManagementPermission "control";
@@ -250,6 +252,10 @@ grant {
250252

251253
// expanded to a wildcard if set, allows all networking everywhere
252254
permission java.net.SocketPermission "${solr.internal.network.permission}", "accept,listen,connect,resolve";
255+
256+
// Run java
257+
permission java.io.FilePermission "${java.home}${/}-", "execute";
258+
permission java.io.FilePermission "C:\\Windows\\*\\wmic.exe", "execute";
253259
};
254260

255261
// Grant all permissions to Gradle test runner classes.

solr/bin/solr

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -512,54 +512,13 @@ function run_tool() {
512512

513513
# shellcheck disable=SC2086
514514
"$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS ${SOLR_ZK_CREDS_AND_ACLS:-} ${SOLR_TOOL_OPTS:-} -Dsolr.install.dir="$SOLR_TIP" \
515-
-Dlog4j.configurationFile="$DEFAULT_SERVER_DIR/resources/log4j2-console.xml" \
515+
-Dlog4j.configurationFile="$DEFAULT_SERVER_DIR/resources/log4j2-console.xml" -Dsolr.pid.dir="$SOLR_PID_DIR" \
516516
-classpath "$DEFAULT_SERVER_DIR/solr-webapp/webapp/WEB-INF/lib/*:$DEFAULT_SERVER_DIR/lib/ext/*:$DEFAULT_SERVER_DIR/lib/*" \
517517
org.apache.solr.cli.SolrCLI "$@"
518518

519519
return $?
520520
} # end run_tool function
521521

522-
# get status about any Solr nodes running on this host
523-
function get_status() {
524-
# first, see if Solr is running
525-
numSolrs=$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' ')
526-
if [ "$numSolrs" != "0" ]; then
527-
echo -e "\nFound $numSolrs Solr nodes: "
528-
while read PIDF
529-
do
530-
ID=$(cat "$PIDF")
531-
port=$(jetty_port "$ID")
532-
if [ "$port" != "" ]; then
533-
echo -e "\nSolr process $ID running on port $port"
534-
run_tool status --solr-url "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr" "$@"
535-
echo ""
536-
else
537-
echo -e "\nSolr process $ID from $PIDF not found."
538-
fi
539-
done < <(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)
540-
else
541-
# no pid files but check using ps just to be sure
542-
numSolrs=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//')
543-
if [ "$numSolrs" != "0" ]; then
544-
echo -e "\nFound $numSolrs Solr nodes: "
545-
PROCESSES=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | awk '{print $2}' | sort -r)
546-
for ID in $PROCESSES
547-
do
548-
port=$(jetty_port "$ID")
549-
if [ "$port" != "" ]; then
550-
echo ""
551-
echo "Solr process $ID running on port $port"
552-
run_tool status --solr-url "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr" "$@"
553-
echo ""
554-
fi
555-
done
556-
else
557-
echo -e "\nNo Solr nodes are running.\n"
558-
fi
559-
fi
560-
561-
} # end get_status
562-
563522
# tries to gracefully stop Solr using the Jetty
564523
# stop command and if that fails, then uses kill -9
565524
# (will attempt to thread dump before killing)
@@ -659,16 +618,6 @@ else
659618
exit
660619
fi
661620

662-
# status tool
663-
if [ "$SCRIPT_CMD" == "status" ]; then
664-
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "-help" ]; then
665-
print_usage status
666-
else
667-
get_status
668-
fi
669-
exit $?
670-
fi
671-
672621
# configure authentication
673622
if [[ "$SCRIPT_CMD" == "auth" ]]; then
674623
: "${SOLR_SERVER_DIR:=$DEFAULT_SERVER_DIR}"
@@ -1186,7 +1135,7 @@ if [ "${SOLR_MODE:-}" == 'solrcloud' ]; then
11861135
CLOUD_MODE_OPTS=("-DzkClientTimeout=$ZK_CLIENT_TIMEOUT")
11871136

11881137
echo -e "\nSolr will start in SolrCloud mode by default in version 10, even if no -c or --cloud flag is specified.\n"
1189-
1138+
11901139
if [ -n "${ZK_HOST:-}" ]; then
11911140
CLOUD_MODE_OPTS+=("-DzkHost=$ZK_HOST")
11921141
else
@@ -1218,7 +1167,7 @@ else
12181167
echo -e "\nSolr home directory $SOLR_HOME must contain a solr.xml file!\n"
12191168
exit 1
12201169
fi
1221-
1170+
12221171
echo -e "\nSolr will start in SolrCloud mode by default in version 10. You will need to pass in --user-managed flag to run in User Managed (aka Standalone) mode.\n"
12231172
fi
12241173

solr/bin/solr.cmd

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ IF "%1"=="-usage" goto run_solrcli
252252
IF "%1"=="-h" goto run_solrcli
253253
IF "%1"=="--help" goto run_solrcli
254254
IF "%1"=="/?" goto run_solrcli
255-
IF "%1"=="status" goto get_status
255+
IF "%1"=="status" goto run_solrcli
256256
IF "%1"=="version" goto run_solrcli
257257
IF "%1"=="-v" goto run_solrcli
258258
IF "%1"=="-version" goto run_solrcli
@@ -1255,34 +1255,6 @@ REM Run the requested example
12551255
REM End of run_example
12561256
goto done
12571257

1258-
:get_status
1259-
REM Find all Java processes, correlate with those listening on a port
1260-
REM and then try to contact via that port using the status tool
1261-
for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
1262-
set SOME_SOLR_PORT=
1263-
For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
1264-
if NOT "!SOME_SOLR_PORT!"=="" (
1265-
for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
1266-
IF NOT "%%k"=="0" (
1267-
if "%%j"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" (
1268-
@echo.
1269-
set has_info=1
1270-
echo Found Solr process %%k running on port !SOME_SOLR_PORT!
1271-
REM Passing in %2 (-h or --help) directly is captured by a custom help path for usage output
1272-
"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^
1273-
-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
1274-
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
1275-
org.apache.solr.cli.SolrCLI status --solr-url !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!SOME_SOLR_PORT! %2
1276-
@echo.
1277-
)
1278-
)
1279-
)
1280-
)
1281-
)
1282-
if NOT "!has_info!"=="1" echo No running Solr nodes found.
1283-
set has_info=
1284-
goto done
1285-
12861258
:parse_healthcheck_args
12871259
IF [%1]==[] goto run_healthcheck
12881260
IF "%1"=="-V" goto set_healthcheck_verbose

solr/core/src/java/org/apache/solr/cli/SolrCLI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ public static String getOptionWithDeprecatedAndDefault(
451451
// TODO: SOLR-17429 - remove the custom logic when Commons CLI is upgraded and
452452
// makes stderr the default, or makes Option.toDeprecatedString() public.
453453
private static void deprecatedHandlerStdErr(Option o) {
454-
if (o.isDeprecated()) {
454+
// Deprecated options without a description act as "stealth" options
455+
if (o.isDeprecated() && !o.getDeprecated().getDescription().isBlank()) {
455456
final StringBuilder buf =
456457
new StringBuilder().append("Option '-").append(o.getOpt()).append('\'');
457458
if (o.getLongOpt() != null) {

0 commit comments

Comments
 (0)