From b67424ee5875f4b2028763a17fc0f446e460a9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Tue, 22 Aug 2017 12:50:53 +0200 Subject: [PATCH] SOLR-10628: Less verbose output from bin/solr commands --- solr/CHANGES.txt | 2 + solr/bin/solr | 87 +++++-- solr/bin/solr.cmd | 77 +++++-- .../solr/servlet/SolrDispatchFilter.java | 2 + .../java/org/apache/solr/util/SolrCLI.java | 213 ++++++++++++------ .../StartupLoggingUtils.java | 15 +- 6 files changed, 284 insertions(+), 112 deletions(-) rename solr/core/src/java/org/apache/solr/{servlet => util}/StartupLoggingUtils.java (91%) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a042d1cae94..070b61cad76 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -150,6 +150,8 @@ Other Changes * SOLR-5129: Timeout property for waiting ZK get started. (Cao Manh Dat, Hrishikesh Gadre, Varun Thacker) +* SOLR-10628: Less verbose output from bin/solr commands. (Jason Gerlowski, janhoy) + ================== 7.0.0 ================== Versions of Major Components diff --git a/solr/bin/solr b/solr/bin/solr index c80c4fef4cc..bc2abcadfa9 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -380,12 +380,14 @@ function print_usage() { echo "" elif [ "$CMD" == "healthcheck" ]; then echo "" - echo "Usage: solr healthcheck [-c collection] [-z zkHost]" + echo "Usage: solr healthcheck [-c collection] [-z zkHost] [-V]" echo "" echo " -c Collection to run healthcheck against." echo "" echo " -z Zookeeper connection string; default is localhost:9983" echo "" + echo " -V Enable more verbose output" + echo "" elif [ "$CMD" == "status" ]; then echo "" echo "Usage: solr status" @@ -394,7 +396,7 @@ function print_usage() { echo "" elif [ "$CMD" == "create" ]; then echo "" - echo "Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]" + echo "Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port] [-V]" echo "" echo " Create a core or collection depending on whether Solr is running in standalone (core) or SolrCloud" echo " mode (collection). In other words, this action detects which mode Solr is running in, and then takes" @@ -408,7 +410,7 @@ function print_usage() { echo "" elif [ "$CMD" == "delete" ]; then echo "" - echo "Usage: solr delete [-c name] [-deleteConfig true|false] [-p port]" + echo "Usage: solr delete [-c name] [-deleteConfig true|false] [-p port] [-V]" echo "" echo " Deletes a core or collection depending on whether Solr is running in standalone (core) or SolrCloud" echo " mode (collection). If you're deleting a collection in SolrCloud mode, the default behavior is to also" @@ -423,9 +425,11 @@ function print_usage() { echo " If not specified, the script will search the local system for a running" echo " Solr instance and will use the port of the first server it finds." echo "" + echo " -V Enables more verbose output." + echo "" elif [ "$CMD" == "create_core" ]; then echo "" - echo "Usage: solr create_core [-c core] [-d confdir] [-p port]" + echo "Usage: solr create_core [-c core] [-d confdir] [-p port] [-V]" echo "" echo " -c Name of core to create" echo "" @@ -444,9 +448,11 @@ function print_usage() { echo " If not specified, the script will search the local system for a running" echo " Solr instance and will use the port of the first server it finds." echo "" + echo " -V Enable more verbose output." + echo "" elif [ "$CMD" == "create_collection" ]; then echo "" - echo "Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]" + echo "Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port] [-V]" echo "" echo " -c Name of collection to create" echo "" @@ -478,6 +484,8 @@ function print_usage() { echo " If not specified, the script will search the local system for a running" echo " Solr instance and will use the port of the first server it finds." echo "" + echo " -V Enable more verbose output." + echo "" elif [ "$CMD" == "zk" ]; then print_short_zk_usage "" echo " Be sure to check the Solr logs in case of errors." @@ -485,6 +493,8 @@ function print_usage() { echo " -z zkHost Optional Zookeeper connection string for all commands. If specified it" echo " overrides the 'ZK_HOST=...'' defined in solr.in.sh." echo "" + echo " -V Enable more verbose output." + echo "" echo " upconfig uploads a configset from the local machine to Zookeeper. (Backcompat: -upconfig)" echo "" echo " downconfig downloads a configset from Zookeeper to the local machine. (Backcompat: -downconfig)" @@ -554,10 +564,10 @@ function print_usage() { echo "" elif [ "$CMD" == "auth" ]; then echo "" - echo "Usage: solr auth enable [-type basicAuth] -credentials user:pass [-blockUnknown ] [-updateIncludeFileOnly ]" - echo " solr auth enable [-type basicAuth] -prompt [-blockUnknown ] [-updateIncludeFileOnly ]" - echo " solr auth enable -type kerberos -config \"\" [-updateIncludeFileOnly ]" - echo " solr auth disable [-updateIncludeFileOnly ]" + echo "Usage: solr auth enable [-type basicAuth] -credentials user:pass [-blockUnknown ] [-updateIncludeFileOnly ] [-V]" + echo " solr auth enable [-type basicAuth] -prompt [-blockUnknown ] [-updateIncludeFileOnly ] [-V]" + echo " solr auth enable -type kerberos -config \"\" [-updateIncludeFileOnly ] [-V]" + echo " solr auth disable [-updateIncludeFileOnly ] [-V]" echo "" echo " -type The authentication mechanism (basicAuth or kerberos) to enable. Defaults to 'basicAuth'." echo "" @@ -584,6 +594,8 @@ function print_usage() { echo " -s Specify the Solr home directory. This is where any credentials or authentication" echo " configuration files (e.g. basicAuth.conf) would be placed." echo "" + echo " -V Enable more verbose output." + echo "" fi } # end print_usage @@ -811,6 +823,8 @@ fi # run a healthcheck and exit if requested if [ "$SCRIPT_CMD" == "healthcheck" ]; then + VERBOSE="" + if [ $# -gt 0 ]; then while true; do case "$1" in @@ -834,6 +848,10 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; then print_usage "$SCRIPT_CMD" exit 0 ;; + -V|--verbose) + VERBOSE="-verbose" + shift + ;; --) shift break @@ -860,7 +878,7 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; then exit 1 fi - run_tool healthcheck -zkHost "$ZK_HOST" -collection "$HEALTHCHECK_COLLECTION" + run_tool healthcheck -zkHost "$ZK_HOST" -collection "$HEALTHCHECK_COLLECTION" $VERBOSE exit $? fi @@ -871,6 +889,7 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM CREATE_NUM_SHARDS=1 CREATE_REPFACT=1 FORCE=false + VERBOSE="" if [ $# -gt 0 ]; then while true; do @@ -923,6 +942,10 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM CREATE_PORT="$2" shift 2 ;; + -V|--verbose) + VERBOSE="-verbose" + shift + ;; -force) FORCE=true shift @@ -994,13 +1017,15 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM fi if [ "$SCRIPT_CMD" == "create_core" ]; then run_tool create_core -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \ - -confdir "$CREATE_CONFDIR" -configsetsDir "$SOLR_TIP/server/solr/configsets" + -confdir "$CREATE_CONFDIR" -configsetsDir "$SOLR_TIP/server/solr/configsets" \ + $VERBOSE exit $? else run_tool "$SCRIPT_CMD" -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \ -shards "$CREATE_NUM_SHARDS" -replicationFactor "$CREATE_REPFACT" \ -confname "$CREATE_CONFNAME" -confdir "$CREATE_CONFDIR" \ - -configsetsDir "$SOLR_TIP/server/solr/configsets" + -configsetsDir "$SOLR_TIP/server/solr/configsets" \ + $VERBOSE exit $? fi fi @@ -1008,6 +1033,8 @@ fi # delete a core or collection if [[ "$SCRIPT_CMD" == "delete" ]]; then + VERBOSE="" + if [ $# -gt 0 ]; then while true; do case "$1" in @@ -1035,6 +1062,10 @@ if [[ "$SCRIPT_CMD" == "delete" ]]; then DELETE_CONFIG="$2" shift 2 ;; + -V|--verbose) + VERBOSE="-verbose" + shift + ;; -help|-usage) print_usage "$SCRIPT_CMD" exit 0 @@ -1083,7 +1114,8 @@ if [[ "$SCRIPT_CMD" == "delete" ]]; then fi run_tool delete -name "$DELETE_NAME" -deleteConfig "$DELETE_CONFIG" \ - -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$DELETE_PORT/solr" + -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$DELETE_PORT/solr" \ + $VERBOSE exit $? fi @@ -1093,6 +1125,8 @@ ZK_RECURSE=false # necessary for back-compat if [[ "$SCRIPT_CMD" == "zk" ]]; then + VERBOSE="" + if [ $# -gt 0 ]; then while true; do case "$1" in @@ -1129,6 +1163,10 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then ZK_RECURSE="true" shift ;; + -V|--verbose) + VERBOSE="-verbose" + shift + ;; -help|-usage|-h) print_usage "$SCRIPT_CMD" exit 0 @@ -1192,34 +1230,34 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then case "$ZK_OP" in upconfig) - run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" -configsetsDir "$SOLR_TIP/server/solr/configsets" + run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" -configsetsDir "$SOLR_TIP/server/solr/configsets" $VERBOSE ;; downconfig) - run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" + run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" $VERBOSE ;; rm) if [ -z "$ZK_SRC" ]; then print_short_zk_usage "Zookeeper path to remove must be specified when using the 'rm' command" fi - run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST" -recurse "$ZK_RECURSE" + run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST" -recurse "$ZK_RECURSE" $VERBOSE ;; mv) - run_tool "$ZK_OP" -src "$ZK_SRC" -dst "$ZK_DST" -zkHost "$ZK_HOST" + run_tool "$ZK_OP" -src "$ZK_SRC" -dst "$ZK_DST" -zkHost "$ZK_HOST" $VERBOSE ;; cp) - run_tool "$ZK_OP" -src "$ZK_SRC" -dst "$ZK_DST" -zkHost "$ZK_HOST" -recurse "$ZK_RECURSE" + run_tool "$ZK_OP" -src "$ZK_SRC" -dst "$ZK_DST" -zkHost "$ZK_HOST" -recurse "$ZK_RECURSE" $VERBOSE ;; ls) if [ -z "$ZK_SRC" ]; then print_short_zk_usage "Zookeeper path to list must be specified when using the 'ls' command" fi - run_tool "$ZK_OP" -path "$ZK_SRC" -recurse "$ZK_RECURSE" -zkHost "$ZK_HOST" + run_tool "$ZK_OP" -path "$ZK_SRC" -recurse "$ZK_RECURSE" -zkHost "$ZK_HOST" $VERBOSE ;; mkroot) if [ -z "$ZK_SRC" ]; then print_short_zk_usage "Zookeeper path to list must be specified when using the 'mkroot' command" fi - run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST" + run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST" $VERBOSE ;; *) print_short_zk_usage "Unrecognized Zookeeper operation $ZK_OP" @@ -1230,6 +1268,9 @@ if [[ "$SCRIPT_CMD" == "zk" ]]; then fi if [[ "$SCRIPT_CMD" == "auth" ]]; then + + VERBOSE="" + declare -a AUTH_PARAMS if [ $# -gt 0 ]; then while true; do @@ -1277,6 +1318,10 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then shift break ;; + -V|--verbose) + VERBOSE="-verbose" + shift + ;; -d|-dir) if [[ -z "$2" || "${2:0:1}" == "-" ]]; then print_usage "$SCRIPT_CMD" "Server directory is required when using the $1 option!" @@ -1358,7 +1403,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then fi done fi - run_tool auth ${AUTH_PARAMS[@]} -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$AUTH_PORT/solr" -authConfDir "$SOLR_HOME" + run_tool auth ${AUTH_PARAMS[@]} -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$AUTH_PORT/solr" -authConfDir "$SOLR_HOME" $VERBOSE exit $? fi diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 8baff8008f6..57e2e6218c7 100644 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -360,11 +360,13 @@ goto done @echo. @echo -z zkHost Zookeeper connection string; default is localhost:9983 @echo. +@echo -V Enable more verbose output +@echo. goto done :create_usage echo. -echo Usage: solr create [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor #] [-p port] +echo Usage: solr create [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor #] [-p port] [-V] echo. echo Create a core or collection depending on whether Solr is running in standalone (core) or SolrCloud echo mode (collection). In other words, this action detects which mode Solr is running in, and then takes @@ -380,7 +382,7 @@ goto done :delete_usage echo. -echo Usage: solr delete [-c name] [-deleteConfig boolean] [-p port] +echo Usage: solr delete [-c name] [-deleteConfig boolean] [-p port] [-V] echo. echo Deletes a core or collection depending on whether Solr is running in standalone (core) or SolrCloud echo mode (collection). If you're deleting a collection in SolrCloud mode, the default behavior is to also @@ -395,11 +397,13 @@ echo -p port Port of a local Solr instance where you want to create the ne echo If not specified, the script will search the local system for a running echo Solr instance and will use the port of the first server it finds. echo. +echo -V Enable more verbose output. +echo. goto done :create_core_usage echo. -echo Usage: solr create_core [-c name] [-d confdir] [-p port] +echo Usage: solr create_core [-c name] [-d confdir] [-p port] [-V] echo. echo -c name Name of core to create echo. @@ -418,11 +422,13 @@ echo -p port Port of a local Solr instance where you want to create the ne echo If not specified, the script will search the local system for a running echo Solr instance and will use the port of the first server it finds. echo. +echo -V Enable more verbose output. +echo. goto done :create_collection_usage echo. -echo Usage: solr create_collection [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor #] [-p port] +echo Usage: solr create_collection [-c name] [-d confdir] [-n confname] [-shards #] [-replicationFactor #] [-p port] [-V] echo. echo -c name Name of collection to create echo. @@ -454,6 +460,8 @@ echo -p port Port of a local Solr instance where you want to cre echo If not specified, the script will search the local system for a running echo Solr instance and will use the port of the first server it finds. echo. +echo -V Enable more verbose output. +echo. goto done :zk_usage @@ -465,6 +473,8 @@ echo. echo -z zkHost Optional Zookeeper connection string for all commands. If specified it echo overrides the 'ZK_HOST=...'' defined in solr.in.sh. echo. +echo -V Enable more verbose output. +echo. echo upconfig uploads a configset from the local machine to Zookeeper. (Backcompat: -upconfig) echo. echo downconfig downloads a configset from Zookeeper to the local machine. (Backcompat: -downconfig) @@ -554,9 +564,9 @@ IF "%ZK_FULL%"=="true" ( goto done :auth_usage -echo Usage: solr auth enable [-type basicAuth] -credentials user:pass [-blockUnknown ^] [-updateIncludeFileOnly ^] -echo solr auth enable [-type basicAuth] -prompt ^ [-blockUnknown ^] [-updateIncludeFileOnly ^] -echo solr auth disable [-updateIncludeFileOnly ^] +echo Usage: solr auth enable [-type basicAuth] -credentials user:pass [-blockUnknown ^] [-updateIncludeFileOnly ^] [-V] +echo solr auth enable [-type basicAuth] -prompt ^ [-blockUnknown ^] [-updateIncludeFileOnly ^] [-V] +echo solr auth disable [-updateIncludeFileOnly ^] [-V] echo echo -type ^ The authentication mechanism to enable. Defaults to 'basicAuth'. echo @@ -581,6 +591,8 @@ echo echo -s Specify the Solr home directory. This is where any credentials or authentication" echo configuration files (e.g. basicAuth.conf) would be placed." echo +echo -V Enable more verbose output +echo goto done REM Really basic command-line arg parsing @@ -1292,6 +1304,7 @@ goto done :parse_healthcheck_args IF [%1]==[] goto run_healthcheck +IF "%1"=="-V" goto set_healthcheck_verbose IF "%1"=="-c" goto set_healthcheck_collection IF "%1"=="-collection" goto set_healthcheck_collection IF "%1"=="-z" goto set_healthcheck_zk @@ -1301,6 +1314,11 @@ IF "%1"=="-usage" goto usage IF "%1"=="/?" goto usage goto run_healthcheck +:set_healthcheck_verbose +set HEALTHCHECK_VERBOSE="-verbose" +SHIFT +goto parse_healthcheck_args + :set_healthcheck_collection set HEALTHCHECK_COLLECTION=%~2 SHIFT @@ -1315,11 +1333,12 @@ goto parse_healthcheck_args :run_healthcheck IF NOT DEFINED HEALTHCHECK_COLLECTION goto healthcheck_usage +IF NOT DEFINED HEALTHCHECK_VERBOSE set "HEALTHCHECK_VERBOSE=" IF NOT DEFINED HEALTHCHECK_ZK_HOST set "HEALTHCHECK_ZK_HOST=localhost:9983" "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI healthcheck -collection !HEALTHCHECK_COLLECTION! -zkHost !HEALTHCHECK_ZK_HOST! + org.apache.solr.util.SolrCLI healthcheck -collection !HEALTHCHECK_COLLECTION! -zkHost !HEALTHCHECK_ZK_HOST! %HEALTHCHECK_VERBOSE% goto done :run_assert @@ -1354,6 +1373,7 @@ goto done :parse_create_args IF [%1]==[] goto run_create +IF "%1"=="-V" goto set_create_verbose IF "%1"=="-c" goto set_create_name IF "%1"=="-core" goto set_create_name IF "%1"=="-collection" goto set_create_name @@ -1372,6 +1392,12 @@ IF "%1"=="-usage" goto usage IF "%1"=="/?" goto usage goto run_create + +:set_create_verbose +set CREATE_VERBOSE="-verbose" +SHIFT +goto parse_create_args + :set_create_name set CREATE_NAME=%~2 SHIFT @@ -1413,6 +1439,7 @@ IF "!CREATE_NAME!"=="" ( set "SCRIPT_ERROR=Name (-c) is a required parameter for %SCRIPT_CMD%" goto invalid_cmd_line ) +IF NOT DEFINED CREATE_VERBOSE set "CREATE_VERBOSE=" IF "!CREATE_CONFDIR!"=="" set CREATE_CONFDIR=_default IF "!CREATE_NUM_SHARDS!"=="" set CREATE_NUM_SHARDS=1 IF "!CREATE_REPFACT!"=="" set CREATE_REPFACT=1 @@ -1447,20 +1474,21 @@ if "%SCRIPT_CMD%"=="create_core" ( -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ org.apache.solr.util.SolrCLI create_core -name !CREATE_NAME! -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!CREATE_PORT!/solr ^ - -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" + -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" %CREATE_VERBOSE% ) else ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%"^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ org.apache.solr.util.SolrCLI create -name !CREATE_NAME! -shards !CREATE_NUM_SHARDS! -replicationFactor !CREATE_REPFACT! ^ -confname !CREATE_CONFNAME! -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" ^ - -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!CREATE_PORT!/solr + -solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!CREATE_PORT!/solr %CREATE_VERBOSE% ) goto done :parse_delete_args IF [%1]==[] goto run_delete +IF "%1"=="-V" goto set_delete_verbose IF "%1"=="-c" goto set_delete_name IF "%1"=="-core" goto set_delete_name IF "%1"=="-collection" goto set_delete_name @@ -1472,6 +1500,11 @@ IF "%1"=="-usage" goto usage IF "%1"=="/?" goto usage goto run_delete +:set_delete_verbose +set DELETE_VERBOSE="-verbose" +SHIFT +goto parse_delete_args + :set_delete_name set DELETE_NAME=%~2 SHIFT @@ -1491,6 +1524,7 @@ SHIFT goto parse_delete_args :run_delete +IF NOT DEFINED DELETE_VERBOSE set "DELETE_VERBOSE=" IF "!DELETE_NAME!"=="" ( set "SCRIPT_ERROR=Name (-c) is a required parameter for %SCRIPT_CMD%" goto invalid_cmd_line @@ -1521,7 +1555,7 @@ if "!DELETE_CONFIG!"=="" ( -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ org.apache.solr.util.SolrCLI delete -name !DELETE_NAME! -deleteConfig !DELETE_CONFIG! ^ --solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!DELETE_PORT!/solr +-solrUrl !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:!DELETE_PORT!/solr %DELETE_VERBOSE% goto done @@ -1529,6 +1563,8 @@ REM Clumsy to do the state machine thing for -d and -n, but that's required for :parse_zk_args IF "%1"=="-upconfig" ( goto set_zk_op +) ELSE IF "%1"=="-V" ( + goto set_zk_verbose ) ELSE IF "%1"=="upconfig" ( goto set_zk_op ) ELSE IF "%1"=="-downconfig" ( @@ -1586,6 +1622,11 @@ set ZK_OP=%~1 SHIFT goto parse_zk_args +:set_zk_verbose +set ZK_VERBOSE="-verbose" +SHIFT +goto parse_zk_args + :set_config_name set CONFIGSET_NAME=%~2 SHIFT @@ -1649,7 +1690,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -confname !CONFIGSET_NAME! -confdir !CONFIGSET_DIR! -zkHost !ZK_HOST! ^ + org.apache.solr.util.SolrCLI !ZK_OP! -confname !CONFIGSET_NAME! -confdir !CONFIGSET_DIR! -zkHost !ZK_HOST! %ZK_VERBOSE%^ -configsetsDir "%SOLR_TIP%/server/solr/configsets" ) ELSE IF "!ZK_OP!"=="downconfig" ( IF "!CONFIGSET_NAME!"=="" ( @@ -1663,7 +1704,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -confname !CONFIGSET_NAME! -confdir !CONFIGSET_DIR! -zkHost !ZK_HOST! + org.apache.solr.util.SolrCLI !ZK_OP! -confname !CONFIGSET_NAME! -confdir !CONFIGSET_DIR! -zkHost !ZK_HOST! %ZK_VERBOSE% ) ELSE IF "!ZK_OP!"=="cp" ( IF "%ZK_SRC%"=="" ( set ERROR_MSG=" must be specified for 'cp' command" @@ -1682,7 +1723,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -src !ZK_SRC! -dst !ZK_DST! -recurse !ZK_RECURSE! + org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -src !ZK_SRC! -dst !ZK_DST! -recurse !ZK_RECURSE! %ZK_VERBOSE% ) ELSE IF "!ZK_OP!"=="mv" ( IF "%ZK_SRC%"=="" ( set ERROR_MSG=" must be specified for 'mv' command" @@ -1695,7 +1736,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -src !ZK_SRC! -dst !ZK_DST! + org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -src !ZK_SRC! -dst !ZK_DST! %ZK_VERBOSE% ) ELSE IF "!ZK_OP!"=="rm" ( IF "%ZK_SRC"=="" ( set ERROR_MSG="Zookeeper path to remove must be specified when using the 'rm' command" @@ -1704,7 +1745,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE! + org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE! %ZK_VERBOSE% ) ELSE IF "!ZK_OP!"=="ls" ( IF "%ZK_SRC"=="" ( set ERROR_MSG="Zookeeper path to remove must be specified when using the 'ls' command" @@ -1713,7 +1754,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE! + org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! -recurse !ZK_RECURSE! %ZK_VERBOSE% ) ELSE IF "!ZK_OP!"=="mkroot" ( IF "%ZK_SRC"=="" ( set ERROR_MSG="Zookeeper path to create must be specified when using the 'mkroot' command" @@ -1722,7 +1763,7 @@ IF "!ZK_OP!"=="upconfig" ( "%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^ -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^ - org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! + org.apache.solr.util.SolrCLI !ZK_OP! -zkHost !ZK_HOST! -path !ZK_SRC! %ZK_VERBOSE% ) ELSE ( set ERROR_MSG="Unknown zk option !ZK_OP!" goto zk_short_usage diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java index bdae9ed8cf3..17c3b56920b 100644 --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java @@ -73,6 +73,7 @@ import org.apache.solr.request.SolrRequestInfo; import org.apache.solr.security.AuthenticationPlugin; import org.apache.solr.security.PKIAuthenticationPlugin; import org.apache.solr.util.SolrFileCleaningTracker; +import org.apache.solr.util.StartupLoggingUtils; import org.apache.solr.util.configuration.SSLConfigurationsFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -159,6 +160,7 @@ public class SolrDispatchFilter extends BaseSolrFilter { } String logLevel = System.getProperty(SOLR_LOG_LEVEL); if (logLevel != null) { + log.info("Log level override, property solr.log.level=" + logLevel); StartupLoggingUtils.changeLogLevel(logLevel); } diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java index e696019f73a..021f364dd40 100644 --- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java @@ -153,6 +153,12 @@ public class SolrCLI { protected ToolBase(PrintStream stdout) { this.stdout = stdout; } + + protected void echoIfVerbose(final String msg, CommandLine cli) { + if (cli.hasOption("verbose")) { + echo(msg); + } + } protected void echo(final String msg) { stdout.println(msg); @@ -192,6 +198,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { + raiseLogLevelUnlessVerbose(cli); String zkHost = cli.getOptionValue("zkHost", ZK_HOST); log.debug("Connecting to Solr cluster: " + zkHost); @@ -230,7 +237,11 @@ public class SolrCLI { .hasArg() .isRequired(false) .withDescription("Name of collection; no default") - .create("collection") + .create("collection"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; private static void exit(int exitStatus) { @@ -322,6 +333,12 @@ public class SolrCLI { } } + private static void raiseLogLevelUnlessVerbose(CommandLine cli) { + if (! cli.hasOption("verbose")) { + StartupLoggingUtils.changeLogLevel("WARN"); + } + } + /** * Support options common to all tools. */ @@ -1160,7 +1177,7 @@ public class SolrCLI { @Override protected void runCloudTool(CloudSolrClient cloudSolrClient, CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String collection = cli.getOptionValue("collection"); if (collection == null) throw new IllegalArgumentException("Must provide a collection to run a healthcheck against!"); @@ -1335,7 +1352,12 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Path to configsets directory on the local system.") - .create("configsetsDir") + .create("configsetsDir"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") + }; /** @@ -1462,9 +1484,11 @@ public class SolrCLI { public Option[] getOptions() { return CREATE_COLLECTION_OPTIONS; } + + protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { throw new IllegalStateException("Solr at "+cli.getOptionValue("solrUrl")+ @@ -1473,7 +1497,7 @@ public class SolrCLI { } try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { - echo("\nConnecting to ZooKeeper at " + zkHost+" ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost+" ...", cli); cloudSolrClient.connect(); runCloudTool(cloudSolrClient, cli); } @@ -1521,8 +1545,8 @@ public class SolrCLI { Path confPath = ZkConfigManager.getConfigsetPath(confdir, configsetsDir); - echo("Uploading " + confPath.toAbsolutePath().toString() + - " for config " + confname + " to ZooKeeper at " + cloudSolrClient.getZkHost()); + echoIfVerbose("Uploading " + confPath.toAbsolutePath().toString() + + " for config " + confname + " to ZooKeeper at " + cloudSolrClient.getZkHost(), cli); ((ZkClientClusterStateProvider) cloudSolrClient.getClusterStateProvider()).uploadConfig(confPath, confname); } @@ -1547,7 +1571,7 @@ public class SolrCLI { createCollectionUrl = createCollectionUrl + String.format(Locale.ROOT, "&collection.configName=%s", confname); } - echo("\nCreating new collection '"+collectionName+"' using command:\n"+createCollectionUrl+"\n"); + echoIfVerbose("\nCreating new collection '"+collectionName+"' using command:\n"+createCollectionUrl+"\n", cli); Map json = null; try { @@ -1556,9 +1580,19 @@ public class SolrCLI { throw new Exception("Failed to create collection '"+collectionName+"' due to: "+sse.getMessage()); } - CharArr arr = new CharArr(); - new JSONWriter(arr, 2).write(json); - echo(arr.toString()); + if (cli.hasOption("verbose")) { + CharArr arr = new CharArr(); + new JSONWriter(arr, 2).write(json); + echo(arr.toString()); + } else { + String endMessage = String.format(Locale.ROOT, "Created collection '%s' with %d shard(s), %d replica(s)", + collectionName, numShards, replicationFactor); + if (confname != null && !"".equals(confname.trim())) { + endMessage += String.format(Locale.ROOT, " with config-set '%s'", confname); + } + + echo(endMessage); + } } protected int optionAsInt(CommandLine cli, String option, int defaultVal) { @@ -1601,12 +1635,15 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Path to configsets directory on the local system.") - .create("configsetsDir") + .create("configsetsDir"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } protected void runImpl(CommandLine cli) throws Exception { - String solrUrl = cli.getOptionValue("solrUrl", DEFAULT_SOLR_URL); if (!solrUrl.endsWith("/")) solrUrl += "/"; @@ -1673,7 +1710,7 @@ public class SolrCLI { throw new IllegalArgumentException("\n"+configSetDir.getAbsolutePath()+" doesn't contain a conf subdirectory or solrconfig.xml\n"); } } - echo("\nCopying configuration to new core instance directory:\n" + coreInstanceDir.getAbsolutePath()); + echoIfVerbose("\nCopying configuration to new core instance directory:\n" + coreInstanceDir.getAbsolutePath(), cli); } String createCoreUrl = @@ -1683,14 +1720,18 @@ public class SolrCLI { coreName, coreName); - echo("\nCreating new core '" + coreName + "' using command:\n" + createCoreUrl + "\n"); + echoIfVerbose("\nCreating new core '" + coreName + "' using command:\n" + createCoreUrl + "\n", cli); try { Map json = getJson(createCoreUrl); - CharArr arr = new CharArr(); - new JSONWriter(arr, 2).write(json); - echo(arr.toString()); - echo("\n"); + if (cli.hasOption("verbose")) { + CharArr arr = new CharArr(); + new JSONWriter(arr, 2).write(json); + echo(arr.toString()); + echo("\n"); + } else { + echo(String.format(Locale.ROOT, "\nCreated new core '%s'", coreName)); + } } catch (Exception e) { /* create-core failed, cleanup the copied configset before propagating the error. */ FileUtils.deleteDirectory(coreInstanceDir); @@ -1714,7 +1755,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String solrUrl = cli.getOptionValue("solrUrl", DEFAULT_SOLR_URL); if (!solrUrl.endsWith("/")) solrUrl += "/"; @@ -1774,7 +1815,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -1784,6 +1829,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { throw new IllegalStateException("Solr at " + cli.getOptionValue("solrUrl") + @@ -1792,7 +1838,7 @@ public class SolrCLI { String confName = cli.getOptionValue("confname"); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); Path confPath = ZkConfigManager.getConfigsetPath(cli.getOptionValue("confdir"), cli.getOptionValue("configsetsDir")); echo("Uploading " + confPath.toAbsolutePath().toString() + @@ -1803,7 +1849,6 @@ public class SolrCLI { log.error("Could not complete upconfig operation for reason: " + e.getMessage()); throw (e); } - } } @@ -1837,7 +1882,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -1846,7 +1895,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { throw new IllegalStateException("Solr at " + cli.getOptionValue("solrUrl") + @@ -1855,7 +1904,7 @@ public class SolrCLI { try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); String confName = cli.getOptionValue("confname"); String confDir = cli.getOptionValue("confdir"); Path configSetPath = Paths.get(confDir); @@ -1909,7 +1958,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -1918,7 +1971,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { @@ -1935,7 +1988,7 @@ public class SolrCLI { if (znode.equals("/")) { throw new SolrServerException("You may not remove the root ZK node ('/')!"); } - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { if (recurse == false && zkClient.getChildren(znode, null, true).size() != 0) { throw new SolrServerException("Zookeeper node " + znode + " has children and recurse has NOT been specified"); @@ -1982,7 +2035,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -1991,7 +2048,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { @@ -2001,12 +2058,12 @@ public class SolrCLI { try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); String znode = cli.getOptionValue("path"); Boolean recurse = Boolean.parseBoolean(cli.getOptionValue("recurse")); - echo("Getting listing for Zookeeper node " + znode + " from ZooKeeper at " + zkHost + - " recurse: " + Boolean.toString(recurse)); + echoIfVerbose("Getting listing for Zookeeper node " + znode + " from ZooKeeper at " + zkHost + + " recurse: " + Boolean.toString(recurse), cli); stdout.print(zkClient.listZnode(znode, recurse)); } catch (Exception e) { log.error("Could not complete ls operation for reason: " + e.getMessage()); @@ -2040,7 +2097,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -2049,7 +2110,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { @@ -2059,7 +2120,7 @@ public class SolrCLI { try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); String znode = cli.getOptionValue("path"); echo("Creating Zookeeper path " + znode + " on ZooKeeper at " + zkHost); @@ -2110,7 +2171,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -2119,7 +2184,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { throw new IllegalStateException("Solr at " + cli.getOptionValue("solrUrl") + @@ -2127,7 +2192,7 @@ public class SolrCLI { } try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); String src = cli.getOptionValue("src"); String dst = cli.getOptionValue("dst"); Boolean recurse = Boolean.parseBoolean(cli.getOptionValue("recurse")); @@ -2190,7 +2255,11 @@ public class SolrCLI { .hasArg() .isRequired(true) .withDescription("Address of the Zookeeper ensemble; defaults to: " + ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @@ -2199,7 +2268,7 @@ public class SolrCLI { } protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String zkHost = getZkHost(cli); if (zkHost == null) { throw new IllegalStateException("Solr at " + cli.getOptionValue("solrUrl") + @@ -2208,7 +2277,7 @@ public class SolrCLI { try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); + echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); String src = cli.getOptionValue("src"); String dst = cli.getOptionValue("dst"); @@ -2276,12 +2345,16 @@ public class SolrCLI { .hasArg() .isRequired(false) .withDescription("Address of the Zookeeper ensemble; defaults to: "+ZK_HOST) - .create("zkHost") + .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } - + protected void runImpl(CommandLine cli) throws Exception { - + raiseLogLevelUnlessVerbose(cli); String solrUrl = cli.getOptionValue("solrUrl", DEFAULT_SOLR_URL); if (!solrUrl.endsWith("/")) solrUrl += "/"; @@ -2303,7 +2376,7 @@ public class SolrCLI { protected void deleteCollection(CommandLine cli) throws Exception { String zkHost = getZkHost(cli); try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { - echo("Connecting to ZooKeeper at " + zkHost); + echoIfVerbose("Connecting to ZooKeeper at " + zkHost, cli); cloudSolrClient.connect(); deleteCollection(cloudSolrClient, cli); } @@ -2357,7 +2430,7 @@ public class SolrCLI { baseUrl, collectionName); - echo("\nDeleting collection '" + collectionName + "' using command:\n" + deleteCollectionUrl + "\n"); + echoIfVerbose("\nDeleting collection '" + collectionName + "' using command:\n" + deleteCollectionUrl + "\n", cli); Map json = null; try { @@ -2371,7 +2444,7 @@ public class SolrCLI { try { zkStateReader.getZkClient().clean(configZnode); } catch (Exception exc) { - System.err.println("\nWARNING: Failed to delete configuration directory "+configZnode+" in ZooKeeper due to: "+ + echo("\nWARNING: Failed to delete configuration directory "+configZnode+" in ZooKeeper due to: "+ exc.getMessage()+"\nYou'll need to manually delete this znode using the zkcli script."); } } @@ -2382,6 +2455,8 @@ public class SolrCLI { echo(arr.toString()); echo("\n"); } + + echo("Deleted collection '" + collectionName + "' using command:\n" + deleteCollectionUrl); } protected void deleteCore(CommandLine cli, CloseableHttpClient httpClient, String solrUrl) throws Exception { @@ -2404,8 +2479,8 @@ public class SolrCLI { if (json != null) { CharArr arr = new CharArr(); new JSONWriter(arr, 2).write(json); - echo(arr.toString()); - echo("\n"); + echoIfVerbose(arr.toString(), cli); + echoIfVerbose("\n", cli); } } } // end DeleteTool class @@ -3597,11 +3672,16 @@ public class SolrCLI { .hasArg() .withDescription("ZooKeeper host") .create("zkHost"), + OptionBuilder + .isRequired(false) + .withDescription("Enable more verbose command output.") + .create("verbose") }; } @Override public int runTool(CommandLine cli) throws Exception { + raiseLogLevelUnlessVerbose(cli); if (cli.getOptions().length == 0 || cli.getArgs().length == 0 || cli.getArgs().length > 1 || cli.hasOption("h")) { new HelpFormatter().printHelp("bin/solr auth [OPTIONS]", getToolOptions(this)); return 1; @@ -3674,7 +3754,7 @@ public class SolrCLI { if (!updateIncludeFileOnly) { if (!zkInaccessible) { - System.out.println("Uploading following security.json: " + securityJson); + echoIfVerbose("Uploading following security.json: " + securityJson, cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true); } catch (Exception ex) { @@ -3702,8 +3782,8 @@ public class SolrCLI { } // update the solr.in.sh file to contain the necessary authentication lines - updateIncludeFileEnableAuth(includeFile, null, config); - System.out.println("Please restart any running Solr nodes."); + updateIncludeFileEnableAuth(includeFile, null, config, cli); + echo("Successfully enabled Kerberos authentication; please restart any running Solr nodes."); return 0; case "disable": @@ -3714,7 +3794,7 @@ public class SolrCLI { exit(1); } - System.out.println("Uploading following security.json: {}"); + echoIfVerbose("Uploading following security.json: {}", cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8), true); @@ -3730,7 +3810,7 @@ public class SolrCLI { } // update the solr.in.sh file to comment out the necessary authentication lines - updateIncludeFileDisableAuth(includeFile); + updateIncludeFileDisableAuth(includeFile, cli); return 0; default: @@ -3824,7 +3904,7 @@ public class SolrCLI { "\n}"; if (!updateIncludeFileOnly) { - System.out.println("Uploading following security.json: " + securityJson); + echoIfVerbose("Uploading following security.json: " + securityJson, cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true); } @@ -3850,7 +3930,10 @@ public class SolrCLI { "httpBasicAuthUser=" + username + "\nhttpBasicAuthPassword=" + password, StandardCharsets.UTF_8); // update the solr.in.sh file to contain the necessary authentication lines - updateIncludeFileEnableAuth(includeFile, basicAuthConfFile.getAbsolutePath(), null); + updateIncludeFileEnableAuth(includeFile, basicAuthConfFile.getAbsolutePath(), null, cli); + final String successMessage = String.format(Locale.ROOT, + "Successfully enabled basic auth with username [%s] and password [%s].", username, password); + echo(successMessage); return 0; case "disable": @@ -3861,7 +3944,7 @@ public class SolrCLI { exit(1); } - System.out.println("Uploading following security.json: {}"); + echoIfVerbose("Uploading following security.json: {}", cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8), true); @@ -3877,7 +3960,7 @@ public class SolrCLI { } // update the solr.in.sh file to comment out the necessary authentication lines - updateIncludeFileDisableAuth(includeFile); + updateIncludeFileDisableAuth(includeFile, cli); return 0; default: @@ -3918,7 +4001,7 @@ public class SolrCLI { * @param basicAuthConfFile If basicAuth, the path of the file containing credentials. If not, null. * @param kerberosConfig If kerberos, the config string containing startup parameters. If not, null. */ - private void updateIncludeFileEnableAuth(File includeFile, String basicAuthConfFile, String kerberosConfig) throws IOException { + private void updateIncludeFileEnableAuth(File includeFile, String basicAuthConfFile, String kerberosConfig, CommandLine cli) throws IOException { assert !(basicAuthConfFile != null && kerberosConfig != null); // only one of the two needs to be populated List includeFileLines = FileUtils.readLines(includeFile, StandardCharsets.UTF_8); for (int i=0; i includeFileLines = FileUtils.readLines(includeFile, StandardCharsets.UTF_8); boolean hasChanged = false; for (int i=0; i * WARNING: This class should only be used during startup. For modifying log levels etc * during runtime, SLF4J and LogWatcher must be used. *

*/ -final class StartupLoggingUtils { +public final class StartupLoggingUtils { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final static StaticLoggerBinder binder = StaticLoggerBinder.getSingleton(); /** * Checks whether mandatory log dir is given */ - static void checkLogDir() { + public static void checkLogDir() { if (System.getProperty("solr.log.dir") == null) { log.error("Missing Java Option solr.log.dir. Logging may be missing or incomplete."); } @@ -55,7 +55,7 @@ final class StartupLoggingUtils { * @return true if ok or else false if something happened, e.g. log4j classes were not in classpath */ @SuppressForbidden(reason = "Legitimate log4j access") - static boolean muteConsole() { + public static boolean muteConsole() { try { if (!isLog4jActive()) { logNotSupported("Could not mute logging to console."); @@ -83,13 +83,12 @@ final class StartupLoggingUtils { * @return true if ok or else false if something happened, e.g. log4j classes were not in classpath */ @SuppressForbidden(reason = "Legitimate log4j access") - static boolean changeLogLevel(String logLevel) { + public static boolean changeLogLevel(String logLevel) { try { if (!isLog4jActive()) { - logNotSupported("Could not mute logging to console."); + logNotSupported("Could not change log level."); return false; } - log.info("Log level override, property solr.log.level=" + logLevel); LogManager.getRootLogger().setLevel(Level.toLevel(logLevel, Level.INFO)); return true; } catch (Exception e) {