Apache Solr open-source search software
SOLR-15199: Pass thru all command actions not explicitly handled by the bin/solr script, such as 'api', to the SolrCLI Java app (#441)
Timothy Potterb144f7341837
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 8820b02b31a..c6c68d8d313 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -464,6 +464,8 @@ Bug Fixes* SOLR-15828: AuthTool (in SolrCLI) should include the config-read, collection-admin-read, core-admin-read, and all permissions in the initial security.jsonto avoid warnings in the security UI (Timothy Potter)+* SOLR-15199: Pass thru all command actions not explicitly handled by the bin/solr script, such as 'api', to the SolrCLI Java app (Timothy Potter)+================== 8.11.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.diff --git a/solr/bin/solr b/solr/bin/solrindex 20b337b3fa7..4d609ad374e 100755--- a/solr/bin/solr+++ b/solr/bin/solr@@ -334,7 +334,7 @@ function print_usage() {if [ -z "$CMD" ]; thenecho ""echo "Usage: solr COMMAND OPTIONS"- echo " where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, export"+ echo " where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, export, api, package"echo ""echo " Standalone server example (start Solr running in the background on port 8984):"echo ""@@ -1575,8 +1575,9 @@ fi# verify the command given is supportedif [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "restart" ] && [ "$SCRIPT_CMD" != "status" ] && [ "$SCRIPT_CMD" != "assert" ]; then- print_usage "" "$SCRIPT_CMD is not a valid command!"- exit 1+ # handoff this command to the SolrCLI and let it handle the option parsing and validation+ run_tool $SCRIPT_CMD "$@"+ exit $?fi#Check current Ulimits for Open Files and Max Processes. Warn if they are below the recommended values.diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex bcd5eec336d..2526f28aa70 100755--- a/solr/bin/solr.cmd+++ b/solr/bin/solr.cmd@@ -228,9 +228,10 @@ IF "%1"=="status" goto get_infoIF "%1"=="version" goto get_versionIF "%1"=="-v" goto get_versionIF "%1"=="-version" goto get_version-IF "%1"=="assert" goto run_assert-IF "%1"=="export" goto run_export-IF "%1"=="package" goto run_package+IF "%1"=="assert" goto run_solrcli+IF "%1"=="export" goto run_solrcli+IF "%1"=="package" goto run_solrcli+IF "%1"=="api" goto run_solrcliREM Only allow the command to be the first argument, assume start if not suppliedIF "%1"=="start" goto set_script_cmd@@ -307,7 +308,7 @@ goto done:script_usage@echo.@echo Usage: solr COMMAND OPTIONS-@echo where COMMAND is one of: start, stop, restart, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, export+@echo where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, export, api, package@echo.@echo Standalone server example (start Solr running in the background on port 8984):@echo.@@ -1459,32 +1460,16 @@ echo ZK_HOST: !ZK_HOST!org.apache.solr.util.SolrCLI healthcheck -collection !HEALTHCHECK_COLLECTION! -zkHost !ZK_HOST! %HEALTHCHECK_VERBOSE%goto done-:run_assert+:run_solrcli"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -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.util.SolrCLI %*+ org.apache.solr.util.SolrCLI %*if errorlevel 1 (exit /b 1)goto done-:run_export-"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -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.util.SolrCLI %*-goto done:--:run_package-REM TODO: Compute the running Solr URL and populate it as a parameter (as has been done for the shell script)-REM Without that, users will have to supply -solrUrl parameter in every request. Life can be so hard for Windows users!-"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -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.util.SolrCLI %*-goto done:-:parse_config_argsIF [%1]==[] goto run_configIF "%1"=="-z" goto set_config_zk@@ -2049,10 +2034,8 @@ FOR /f "usebackq tokens=3" %%a IN (`^""%JAVA%" -version 2^>^&1 ^| findstr "versiREM Remove surrounding quotesset JAVA_VERSION_INFO=!JAVA_VERSION_INFO:"=!- echo "java version info is !JAVA_VERSION_INFO!"REM Extract the major Java version, e.g. 7, 8, 9, 10 ...for /f "tokens=1,2 delims=._-" %%a in ("!JAVA_VERSION_INFO!") do (- echo "Extracted major version is %%a"if %%a GEQ 9 (set JAVA_MAJOR_VERSION=%%a) else (diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.javaindex 5ef7618b128..bd83ffa455b 100755--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java@@ -274,8 +274,14 @@ public class SolrCLI implements CLIO {SSLConfigurationsFactory.current().init();- Tool tool = findTool(args);- CommandLine cli = parseCmdLine(args, tool.getOptions());+ Tool tool = null;+ try {+ tool = findTool(args);+ } catch (IllegalArgumentException iae) {+ CLIO.err(iae.getMessage());+ System.exit(1);+ }+ CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());System.exit(tool.runTool(cli));}@@ -284,7 +290,15 @@ public class SolrCLI implements CLIO {return newTool(toolType);}+ /**+ * @deprecated Use the method that takes a tool name as the first argument instead.+ */+ @Deprecatedpublic static CommandLine parseCmdLine(String[] args, Option[] toolOptions) throws Exception {+ return parseCmdLine(SolrCLI.class.getName(), args, toolOptions);+ }++ public static CommandLine parseCmdLine(String toolName, String[] args, Option[] toolOptions) throws Exception {// the parser doesn't like -D propsList<String> toolArgList = new ArrayList<String>();List<String> dashDList = new ArrayList<String>();@@ -300,7 +314,7 @@ public class SolrCLI implements CLIO {// process command-line args to configure this applicationCommandLine cli =- processCommandLineArgs(joinCommonAndToolOptions(toolOptions), toolArgs);+ processCommandLineArgs(toolName, joinCommonAndToolOptions(toolOptions), toolArgs);List<String> argList = cli.getArgList();argList.addAll(dashDList);@@ -400,7 +414,7 @@ public class SolrCLI implements CLIO {return tool;}- throw new IllegalArgumentException(toolType + " not supported!");+ throw new IllegalArgumentException(toolType + " is not a valid command!");}private static void displayToolOptions() throws Exception {@@ -459,11 +473,18 @@ public class SolrCLI implements CLIO {return options.toArray(new Option[0]);}+ /**+ * @deprecated Use the method that takes a tool name as the first argument instead.+ */+ @Deprecated+ public static CommandLine processCommandLineArgs(Option[] customOptions, String[] args) {+ return processCommandLineArgs(SolrCLI.class.getName(), customOptions, args);+ }/*** Parses the command-line arguments passed by the user.*/- public static CommandLine processCommandLineArgs(Option[] customOptions, String[] args) {+ public static CommandLine processCommandLineArgs(String toolName, Option[] customOptions, String[] args) {Options options = new Options();options.addOption("help", false, "Print this message");@@ -492,13 +513,13 @@ public class SolrCLI implements CLIO {+ exp.getMessage());}HelpFormatter formatter = new HelpFormatter();- formatter.printHelp(SolrCLI.class.getName(), options);+ formatter.printHelp(toolName, options);exit(1);}if (cli.hasOption("help")) {HelpFormatter formatter = new HelpFormatter();- formatter.printHelp(SolrCLI.class.getName(), options);+ formatter.printHelp(toolName, options);exit(0);}@@ -995,7 +1016,7 @@ public class SolrCLI implements CLIO {Option.builder("get").argName("URL").hasArg()- .required(false)+ .required(true).desc("Send a GET request to a Solr API endpoint.").build()};@@ -2807,7 +2828,7 @@ public class SolrCLI implements CLIO {};CreateTool createTool = new CreateTool(stdout);int createCode =- createTool.runTool(processCommandLineArgs(joinCommonAndToolOptions(createTool.getOptions()), createArgs));+ createTool.runTool(processCommandLineArgs(createTool.getName(), joinCommonAndToolOptions(createTool.getOptions()), createArgs));if (createCode != 0)throw new Exception("Failed to create "+collectionName+" using command: "+ Arrays.asList(createArgs));}@@ -2945,7 +2966,7 @@ public class SolrCLI implements CLIO {// let's not fail if we get this far ... just report error and finish uptry {- configTool.runTool(processCommandLineArgs(joinCommonAndToolOptions(configTool.getOptions()), configArgs));+ configTool.runTool(processCommandLineArgs(configTool.getName(), joinCommonAndToolOptions(configTool.getOptions()), configArgs));} catch (Exception exc) {CLIO.err("Failed to update '"+propName+"' property due to: "+exc);}@@ -3203,7 +3224,7 @@ public class SolrCLI implements CLIO {CreateCollectionTool createCollectionTool = new CreateCollectionTool(stdout);int createCode =createCollectionTool.runTool(- processCommandLineArgs(joinCommonAndToolOptions(createCollectionTool.getOptions()), createArgs));+ processCommandLineArgs(createCollectionTool.getName(), joinCommonAndToolOptions(createCollectionTool.getOptions()), createArgs));if (createCode != 0)throw new Exception("Failed to create collection using command: "+ Arrays.asList(createArgs));diff --git a/solr/core/src/test/org/apache/solr/util/AuthToolTest.java b/solr/core/src/test/org/apache/solr/util/AuthToolTest.javaindex b35dc12e4ed..81a79c594e8 100644--- a/solr/core/src/test/org/apache/solr/util/AuthToolTest.java+++ b/solr/core/src/test/org/apache/solr/util/AuthToolTest.java@@ -73,7 +73,7 @@ public class AuthToolTest extends SolrCloudTestCase {private int runTool(String[] args) throws Exception {SolrCLI.Tool tool = findTool(args);assertTrue(tool instanceof SolrCLI.AuthTool);- CommandLine cli = parseCmdLine(args, tool.getOptions());+ CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());return tool.runTool(cli);}}diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.javaindex 1a5bf9836d1..cdb975c5719 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java@@ -347,7 +347,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTesSolrCLI.ConfigSetUploadTool tool = new SolrCLI.ConfigSetUploadTool();- int res = tool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args));+ int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args));assertEquals("Tool should have returned 0 for success, returned: " + res, res, 0);}