Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog/unreleased/SOLR-18118.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 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.
title: Script creating a cluster using bin/solr start -e cloud with --script-inputs option.
type: added # added, changed, fixed, deprecated, removed, dependency_update, security, other
authors:
- name: Eric Pugh
Expand Down
10 changes: 5 additions & 5 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ function print_usage() {
echo ""
echo " -y/--no-prompt Don't prompt for input; accept all defaults when running examples that accept user input."
echo ""
echo " --prompt-inputs <values> Don't prompt for input; comma delimited list of inputs read when running examples that accept user input."
echo " --script-inputs <values> Don't prompt for input; comma delimited list of inputs read when running examples that accept user input."
echo ""
echo " --force If attempting to start Solr as the root user, the script will exit with a warning that running Solr as \"root\" can cause problems."
echo " It is possible to override this warning with the '--force' parameter."
Expand Down Expand Up @@ -835,14 +835,14 @@ if [ $# -gt 0 ]; then
PASS_TO_RUN_EXAMPLE+=("--no-prompt")
shift
;;
--prompt-inputs)
--script-inputs)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Prompt values are required when using the $1 option!"
print_usage "$SCRIPT_CMD" "Session input values are required when using the $1 option!"
exit 1
fi
PASS_TO_RUN_EXAMPLE+=("--prompt-inputs" "$2")
PASS_TO_RUN_EXAMPLE+=("--script-inputs" "$2")
shift 2
;;
;;
--verbose)
verbose=true
SOLR_LOG_LEVEL=DEBUG
Expand Down
8 changes: 4 additions & 4 deletions solr/bin/solr.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ goto err
@echo.
@echo -y/--no-prompt Don't prompt for input; accept all defaults when running examples that accept user input
@echo.
@echo --prompt-inputs values Don't prompt for input; comma delimited list of inputs read when running examples that accept user input.
@echo --script-inputs 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.
Expand Down Expand Up @@ -404,7 +404,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-inputs" goto set_prompt_inputs
IF "%1"=="--script-inputs" goto set_script_inputs

REM Skip stop arg parsing if not stop command
IF NOT "%SCRIPT_CMD%"=="stop" goto parse_general_args
Expand Down Expand Up @@ -715,8 +715,8 @@ set "PASS_TO_RUN_EXAMPLE=--no-prompt !PASS_TO_RUN_EXAMPLE!"
SHIFT
goto parse_args

:set_prompt_inputs
set "PASS_TO_RUN_EXAMPLE=--prompt-inputs %~2 !PASS_TO_RUN_EXAMPLE!"
:set_script_inputs
set "PASS_TO_RUN_EXAMPLE=--script-inputs %~2 !PASS_TO_RUN_EXAMPLE!"

SHIFT
SHIFT
Expand Down
49 changes: 25 additions & 24 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public class RunExampleTool extends ToolBase {
"Don't prompt for input; accept all defaults when running examples that accept user input.")
.get();

private static final Option PROMPT_INPUTS_OPTION =
private static final Option SCRIPT_INPUTS_OPTION =
Option.builder()
.longOpt("prompt-inputs")
.longOpt("script-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")
"Provide comma-separated values for the interactive session's prompts. Same as --no-prompt but uses provided values instead of defaults. "
+ "Example: --script-inputs 3,8983,8984,8985,\"gettingstarted\",2,2,_default")
.build();

private static final Option EXAMPLE_OPTION =
Expand Down Expand Up @@ -186,7 +186,7 @@ public class RunExampleTool extends ToolBase {
protected Path exampleDir;
protected Path solrHomeDir;
protected String urlScheme;
private boolean usingPromptInputs = false;
private boolean usingScriptInputs = false;

/**
* Parameters consumed when starting a single Solr node via the bin/solr script, common to all
Expand Down Expand Up @@ -214,12 +214,13 @@ record RunExampleParams(boolean isCloudMode, String zkHost, int port, StartSolrP
/**
* Parameters for running the multi-node cloud example, independent of the command line parser.
*
* @param promptInputs comma-separated prompt answers, or null when prompting interactively
* @param scriptInputs comma-separated answers to the example's prompts, or null to run the
* interactive session instead
* @param zkHost ZooKeeper connection string resolved from option or sysprop, or null
* @param basePort first node port; remaining nodes use basePort+1..+3 unless prompted otherwise
*/
record CloudExampleParams(
boolean noPrompt, String promptInputs, String zkHost, int basePort, StartSolrParams start) {}
boolean noPrompt, String scriptInputs, String zkHost, int basePort, StartSolrParams start) {}

/** Default constructor used by the framework when running as a command-line application. */
public RunExampleTool(ToolRuntime runtime) {
Expand All @@ -241,7 +242,7 @@ public String getName() {
public Options getOptions() {
return super.getOptions()
.addOption(NO_PROMPT_OPTION)
.addOption(PROMPT_INPUTS_OPTION)
.addOption(SCRIPT_INPUTS_OPTION)
.addOption(EXAMPLE_OPTION)
.addOption(SCRIPT_OPTION)
.addOption(SERVER_DIR_OPTION)
Expand All @@ -259,10 +260,10 @@ public Options getOptions() {

@Override
public void runImpl(CommandLine cli) throws Exception {
if (cli.hasOption(NO_PROMPT_OPTION) && cli.hasOption(PROMPT_INPUTS_OPTION)) {
if (cli.hasOption(NO_PROMPT_OPTION) && cli.hasOption(SCRIPT_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.");
"Cannot use both --no-prompt and --script-inputs options together. "
+ "Use --no-prompt to accept defaults, or --script-inputs to provide specific values.");
}

this.urlScheme = cli.getOptionValue(URL_SCHEME_OPTION, "http");
Expand Down Expand Up @@ -315,7 +316,7 @@ public void runImpl(CommandLine cli) throws Exception {
runCloudExample(
new CloudExampleParams(
cli.hasOption(NO_PROMPT_OPTION),
cli.getOptionValue(PROMPT_INPUTS_OPTION),
cli.getOptionValue(SCRIPT_INPUTS_OPTION),
zkHost,
port,
startParams));
Expand Down Expand Up @@ -608,7 +609,7 @@ void runExample(RunExampleParams params) throws Exception {

void runCloudExample(CloudExampleParams params) throws Exception {

usingPromptInputs = params.promptInputs() != null;
usingScriptInputs = params.scriptInputs() != null;
boolean prompt = !params.noPrompt();
int numNodes = 2;
int[] cloudPorts = new int[] {8983, 7574, 8984, 7575};
Expand All @@ -622,20 +623,20 @@ void runCloudExample(CloudExampleParams params) throws Exception {
echo("\nWelcome to the SolrCloud example!\n");

Scanner readInput = null;
if (usingPromptInputs) {
// Create a scanner from the provided prompts
String promptsValue = params.promptInputs();
InputStream promptsStream =
new ByteArrayInputStream(promptsValue.getBytes(StandardCharsets.UTF_8));
readInput = new Scanner(promptsStream, StandardCharsets.UTF_8);
if (usingScriptInputs) {
// Create a scanner from the provided script inputs
String scriptInputsValue = params.scriptInputs();
InputStream scriptInputsStream =
new ByteArrayInputStream(scriptInputsValue.getBytes(StandardCharsets.UTF_8));
readInput = new Scanner(scriptInputsStream, StandardCharsets.UTF_8);
readInput.useDelimiter(",");
prompt = true; // Enable prompting code path, but reading from prompts instead of user
prompt = true; // Enable prompting code path, but reading from script inputs instead of user
} else if (prompt) {
readInput = new Scanner(userInput, StandardCharsets.UTF_8);
}

if (prompt) {
if (!usingPromptInputs) {
if (!usingScriptInputs) {
echo(
"This interactive session will help you launch a SolrCloud cluster on your local workstation.");
}
Expand Down Expand Up @@ -1225,10 +1226,10 @@ protected String prompt(Scanner s, String prompt) {
protected String prompt(Scanner s, String prompt, String defaultValue) {
echo(prompt);
String nextInput;
if (usingPromptInputs) {
// Reading from prompts option - use next() instead of nextLine()
if (usingScriptInputs) {
// Reading from script-inputs option - use next() instead of nextLine()
nextInput = s.hasNext() ? s.next() : null;
// Echo the value being used from prompts
// Echo the value being used from script inputs
if (nextInput != null) {
echo(nextInput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,11 @@ public void testInteractiveSolrCloudExample() throws Exception {
}

/**
* Test the --prompt-inputs option that allows providing all prompt values as a comma-separated
* Test the --script-inputs option that allows providing all prompt values as a comma-separated
* string without requiring interactive input.
*/
@Test
public void testSolrCloudExampleWithPrompts() throws Exception {
public void testSolrCloudExampleWithScriptInputs() throws Exception {
Path solrHomeDir = ExternalPaths.SERVER_HOME;
if (!Files.isDirectory(solrHomeDir))
fail(solrHomeDir + " not found and is required to run this test!");
Expand All @@ -539,11 +539,11 @@ public void testSolrCloudExampleWithPrompts() throws Exception {
bindPort = socket.getLocalPort();
}

String collectionName = "testCloudExampleWithPrompts";
String collectionName = "testCloudExampleWithScriptInputs";

// Provide all prompt values via --prompt-inputs option:
// Provide all prompt values via --script-inputs option:
// numNodes, port1, collectionName, numShards, replicationFactor, configName
String promptsValue = "1," + bindPort + ",\"" + collectionName + "\",2,2,_default";
String scriptInputsValue = "1," + bindPort + ",\"" + collectionName + "\",2,2,_default";

String[] toolArgs =
new String[] {
Expand All @@ -553,8 +553,8 @@ public void testSolrCloudExampleWithPrompts() throws Exception {
solrServerDir.toString(),
"--example-dir",
solrExampleDir.toString(),
"--prompt-inputs",
promptsValue
"--script-inputs",
scriptInputsValue
};

// capture tool output to stdout
Expand All @@ -581,7 +581,7 @@ public void testSolrCloudExampleWithPrompts() throws Exception {
String solrUrl = "http://localhost:" + bindPort + "/solr";
if (!CLIUtils.safeCheckCollectionExists(solrUrl, collectionName, null)) {
fail(
"After running Solr cloud example with --prompt-inputs, test collection '"
"After running Solr cloud example with --script-inputs, test collection '"
+ collectionName
+ "' not found in Solr at: "
+ solrUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ If you want to accept all of the defaults, you can simply add the `--no-prompt`
+
*Example*: `bin/solr start -e cloud --no-prompt`

`--prompt-inputs <values>`::
`--script-inputs <values>`::
+
[%autowidth,frame=none]
|===
Expand All @@ -286,11 +286,11 @@ If you want to accept all of the defaults, you can simply add the `--no-prompt`
+
Don't prompt for input; instead supply ordered answers in comma delimited format when running examples that accept input.
+
For example, when using the "cloud" example, you can answer the prompts non-interactively to start a three node cluster on specific ports:
For example, when using the "cloud" example, you can answer the interactive session's questions non-interactively to start a three node cluster on specific ports:
+
*Example*: `bin/solr start -e cloud --prompt-inputs 3,9000,9001,9002,"mycollection",2,2,_default`
*Example*: `bin/solr start -e cloud --script-inputs 3,9000,9001,9002,"mycollection",2,2,_default`

On Windows please wrap the prompts value in double quotes to preserve the comma delimited format.
On Windows please wrap the script-inputs value in double quotes to preserve the comma delimited format.

It is not necessary to define all of the options when starting if the defaults are fine for your needs.

Expand Down
Loading