-
Notifications
You must be signed in to change notification settings - Fork 815
SOLR-18118: Add in --prompt-inputs to bin/solr start -e cloud to programatically respond to input prompts #4127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
04ca619
0e87157
2a7b1e4
f5a2c4e
b4e4332
3a05407
e3f6106
66b631e
077f4f7
6a34214
64c2a3c
5236af7
874798c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc | ||
| title: Script creating a cluster using bin/solr start -e cloud with --prompts option. | ||
| type: added # added, changed, fixed, deprecated, removed, dependency_update, security, other | ||
| authors: | ||
| - name: Eric Pugh | ||
| links: | ||
| - name: SOLR-18118 | ||
| url: https://issues.apache.org/jira/browse/SOLR-18118 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,12 +325,6 @@ goto err | |
| @echo --data-home dir Sets the solr.data.home system property, where Solr will store index data in ^<instance_dir^>/data subdirectories. | ||
| @echo If not set, Solr uses solr.solr.home for both config and data. | ||
| @echo. | ||
| @echo -e/--example name Name of the example to run; available examples: | ||
| @echo cloud: SolrCloud example | ||
| @echo techproducts: Comprehensive example illustrating many of Solr's core capabilities | ||
| @echo schemaless: Schema-less example (schema is inferred from data during indexing) | ||
| @echo films: Example of starting with _default configset and defining explicit fields dynamically | ||
| @echo. | ||
| @echo --jvm-opts opts Additional parameters to pass to the JVM when starting Solr, such as to setup | ||
| @echo Java debug options. For example, to enable a Java debugger to attach to the Solr JVM | ||
| @echo you could pass: --jvm-opts "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983" | ||
|
|
@@ -341,8 +335,16 @@ goto err | |
| @echo you could pass: -j "--include-jetty-dir=/etc/jetty/custom/server/" | ||
| @echo In most cases, you should wrap the additional parameters in double quotes. | ||
| @echo. | ||
| @echo -e/--example name Name of the example to run; available examples: | ||
| @echo cloud: SolrCloud example | ||
| @echo techproducts: Comprehensive example illustrating many of Solr's core capabilities | ||
| @echo schemaless: Schema-less example (schema is inferred from data during indexing) | ||
| @echo films: Example of starting with _default configset and defining explicit fields dynamically | ||
| @echo. | ||
| @echo -y/--no-prompt Don't prompt for input; accept all defaults when running examples that accept user input | ||
| @echo. | ||
| @echo --prompts "values" Don't prompt for input; comma delimited list of inputs read when running examples that accept user input. | ||
|
||
| @echo. | ||
| @echo --verbose and -q/--quiet Verbose or quiet logging. Sets default log level to DEBUG or WARN instead of INFO | ||
| @echo. | ||
| goto done | ||
|
|
@@ -399,6 +401,7 @@ IF "%1"=="-j" goto set_addl_jetty_config | |
| IF "%1"=="--jettyconfig" goto set_addl_jetty_config | ||
| IF "%1"=="-y" goto set_noprompt | ||
| IF "%1"=="--no-prompt" goto set_noprompt | ||
| IF "%1"=="--prompt"s goto set_prompts | ||
|
||
|
|
||
| REM Skip stop arg parsing if not stop command | ||
| IF NOT "%SCRIPT_CMD%"=="stop" goto parse_general_args | ||
|
|
@@ -695,6 +698,13 @@ set "PASS_TO_RUN_EXAMPLE=--no-prompt !PASS_TO_RUN_EXAMPLE!" | |
| SHIFT | ||
| goto parse_args | ||
|
|
||
| :set_prompts | ||
| set "PASS_TO_RUN_EXAMPLE=--prompts %~2 !PASS_TO_RUN_EXAMPLE!" | ||
|
|
||
| SHIFT | ||
| SHIFT | ||
| goto parse_args | ||
|
|
||
| REM Handle invalid arguments passed to special commands (start, stop, restart) | ||
| :invalid_cmd_line | ||
| @echo. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,16 @@ public class RunExampleTool extends ToolBase { | |||||||||||||||||||||||||||||||||
| "Don't prompt for input; accept all defaults when running examples that accept user input.") | ||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private static final Option PROMPTS_OPTION = | ||||||||||||||||||||||||||||||||||
| Option.builder() | ||||||||||||||||||||||||||||||||||
| .longOpt("prompts") | ||||||||||||||||||||||||||||||||||
| .hasArg() | ||||||||||||||||||||||||||||||||||
| .argName("VALUES") | ||||||||||||||||||||||||||||||||||
| .desc( | ||||||||||||||||||||||||||||||||||
| "Provide comma-separated values for prompts. Same as --no-prompt but uses provided values instead of defaults. " | ||||||||||||||||||||||||||||||||||
| + "Example: --prompts 3,8983,8984,8985,\"gettingstarted\",2,2,_default") | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private static final Option EXAMPLE_OPTION = | ||||||||||||||||||||||||||||||||||
| Option.builder("e") | ||||||||||||||||||||||||||||||||||
| .longOpt("example") | ||||||||||||||||||||||||||||||||||
|
|
@@ -176,6 +186,7 @@ public class RunExampleTool extends ToolBase { | |||||||||||||||||||||||||||||||||
| protected Path exampleDir; | ||||||||||||||||||||||||||||||||||
| protected Path solrHomeDir; | ||||||||||||||||||||||||||||||||||
| protected String urlScheme; | ||||||||||||||||||||||||||||||||||
| private boolean usingPrompts = false; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** Default constructor used by the framework when running as a command-line application. */ | ||||||||||||||||||||||||||||||||||
| public RunExampleTool(ToolRuntime runtime) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -197,6 +208,7 @@ public String getName() { | |||||||||||||||||||||||||||||||||
| public Options getOptions() { | ||||||||||||||||||||||||||||||||||
| return super.getOptions() | ||||||||||||||||||||||||||||||||||
| .addOption(NO_PROMPT_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(PROMPTS_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(EXAMPLE_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(SCRIPT_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(SERVER_DIR_OPTION) | ||||||||||||||||||||||||||||||||||
|
|
@@ -214,6 +226,13 @@ public Options getOptions() { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||
| public void runImpl(CommandLine cli) throws Exception { | ||||||||||||||||||||||||||||||||||
| // Validate that --no-prompt and --prompts are not used together | ||||||||||||||||||||||||||||||||||
| if (cli.hasOption(NO_PROMPT_OPTION) && cli.hasOption(PROMPTS_OPTION)) { | ||||||||||||||||||||||||||||||||||
| throw new IllegalArgumentException( | ||||||||||||||||||||||||||||||||||
| "Cannot use both --no-prompt and --prompts options together. " | ||||||||||||||||||||||||||||||||||
| + "Use --no-prompt to accept defaults, or --prompts to provide specific values."); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| this.urlScheme = cli.getOptionValue(URL_SCHEME_OPTION, "http"); | ||||||||||||||||||||||||||||||||||
| String exampleType = cli.getOptionValue(EXAMPLE_OPTION); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -515,6 +534,7 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| protected void runCloudExample(CommandLine cli) throws Exception { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| usingPrompts = cli.hasOption(PROMPTS_OPTION); | ||||||||||||||||||||||||||||||||||
| boolean prompt = !cli.hasOption(NO_PROMPT_OPTION); | ||||||||||||||||||||||||||||||||||
| int numNodes = 2; | ||||||||||||||||||||||||||||||||||
| int[] cloudPorts = new int[] {8983, 7574, 8984, 7575}; | ||||||||||||||||||||||||||||||||||
|
|
@@ -530,10 +550,24 @@ protected void runCloudExample(CommandLine cli) throws Exception { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| echo("\nWelcome to the SolrCloud example!\n"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Scanner readInput = prompt ? new Scanner(userInput, StandardCharsets.UTF_8) : null; | ||||||||||||||||||||||||||||||||||
| Scanner readInput = null; | ||||||||||||||||||||||||||||||||||
| if (usingPrompts) { | ||||||||||||||||||||||||||||||||||
| // Create a scanner from the provided prompts | ||||||||||||||||||||||||||||||||||
| String promptsValue = cli.getOptionValue(PROMPTS_OPTION); | ||||||||||||||||||||||||||||||||||
| InputStream promptsStream = | ||||||||||||||||||||||||||||||||||
| new java.io.ByteArrayInputStream(promptsValue.getBytes(StandardCharsets.UTF_8)); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+556
to
+557
|
||||||||||||||||||||||||||||||||||
| InputStream promptsStream = | |
| new java.io.ByteArrayInputStream(promptsValue.getBytes(StandardCharsets.UTF_8)); | |
| // Preserve empty fields so that users can "accept default" for a prompt | |
| // while still providing values for later prompts. | |
| String[] promptTokens = promptsValue.split(",", -1); | |
| for (int i = 0; i < promptTokens.length; i++) { | |
| if (promptTokens[i].isEmpty()) { | |
| // Use a single space so that Scanner produces a token, which the | |
| // prompting logic can then trim() back to an empty string. | |
| promptTokens[i] = " "; | |
| } | |
| } | |
| String processedPromptsValue = String.join(",", promptTokens); | |
| InputStream promptsStream = | |
| new java.io.ByteArrayInputStream( | |
| processedPromptsValue.getBytes(StandardCharsets.UTF_8)); |
epugh marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to print here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with and without and it looks much better with! Plus you can debug it. I was hoping that https://clig.dev/#interactivity would give some specific advice on formatting, but it didn't hold any wisdom...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest moving echo(prompt); from the first line of the method to over here. It would be fair to expect the CLI output for --prompt-inputs to be similar to that of --no-prompt, aka without lines asking for inputs, since we are already providing them in one shot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like seeing the lines because it helps me with debugging... I did defaultss instead of default for a configset name and this let me see the error.
Uh oh!
There was an error while loading. Please reload this page.