-
Notifications
You must be signed in to change notification settings - Fork 809
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 all 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,9 @@ | ||
| # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc | ||
| title: Script creating a cluster using bin/solr start -e cloud with --prompt-inputs option. | ||
| type: added # added, changed, fixed, deprecated, removed, dependency_update, security, other | ||
| authors: | ||
| - name: Eric Pugh | ||
| - name: Rahul Goswami | ||
| links: | ||
| - name: SOLR-18118 | ||
| url: https://issues.apache.org/jira/browse/SOLR-18118 |
| 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 PROMPT_INPUTS_OPTION = | ||||||||||||||||||||||||||||||||||
| Option.builder() | ||||||||||||||||||||||||||||||||||
| .longOpt("prompt-inputs") | ||||||||||||||||||||||||||||||||||
| .hasArg() | ||||||||||||||||||||||||||||||||||
| .argName("VALUES") | ||||||||||||||||||||||||||||||||||
| .desc( | ||||||||||||||||||||||||||||||||||
| "Provide comma-separated values for prompts. Same as --no-prompt but uses provided values instead of defaults. " | ||||||||||||||||||||||||||||||||||
| + "Example: --prompt-inputs 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 usingPromptInputs = 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(PROMPT_INPUTS_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(EXAMPLE_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(SCRIPT_OPTION) | ||||||||||||||||||||||||||||||||||
| .addOption(SERVER_DIR_OPTION) | ||||||||||||||||||||||||||||||||||
|
|
@@ -214,6 +226,12 @@ public Options getOptions() { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||
| public void runImpl(CommandLine cli) throws Exception { | ||||||||||||||||||||||||||||||||||
| if (cli.hasOption(NO_PROMPT_OPTION) && cli.hasOption(PROMPT_INPUTS_OPTION)) { | ||||||||||||||||||||||||||||||||||
| throw new IllegalArgumentException( | ||||||||||||||||||||||||||||||||||
| "Cannot use both --no-prompt and --prompt-inputs options together. " | ||||||||||||||||||||||||||||||||||
| + "Use --no-prompt to accept defaults, or --prompt-inputs to provide specific values."); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| this.urlScheme = cli.getOptionValue(URL_SCHEME_OPTION, "http"); | ||||||||||||||||||||||||||||||||||
| String exampleType = cli.getOptionValue(EXAMPLE_OPTION); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -515,6 +533,7 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| protected void runCloudExample(CommandLine cli) throws Exception { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| usingPromptInputs = cli.hasOption(PROMPT_INPUTS_OPTION); | ||||||||||||||||||||||||||||||||||
| boolean prompt = !cli.hasOption(NO_PROMPT_OPTION); | ||||||||||||||||||||||||||||||||||
| int numNodes = 2; | ||||||||||||||||||||||||||||||||||
| int[] cloudPorts = new int[] {8983, 7574, 8984, 7575}; | ||||||||||||||||||||||||||||||||||
|
|
@@ -530,10 +549,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 (usingPromptInputs) { | ||||||||||||||||||||||||||||||||||
| // Create a scanner from the provided prompts | ||||||||||||||||||||||||||||||||||
| String promptsValue = cli.getOptionValue(PROMPT_INPUTS_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.