Skip to content

Commit

Permalink
Merge branch 'main' into SOLR-17489
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh authored Oct 12, 2024
2 parents b1e1045 + 8ea6525 commit a608978
Show file tree
Hide file tree
Showing 51 changed files with 121 additions and 113 deletions.
4 changes: 2 additions & 2 deletions dev-docs/running-in-docker.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To run Solr in a container and expose the Solr port, run:
In order to start Solr in cloud mode, run the following.
`docker run -p 8983:8983 solr solr-fg -c`
`docker run -p 8983:8983 solr solr-fg`
For documentation on using the official docker builds, please refer to the https://hub.docker.com/_/solr[DockerHub page].
Up-to-date documentation for running locally built images of this branch can be found in the xref:_running_solr_in_docker[local reference guide].
Expand All @@ -30,4 +30,4 @@ For more info on building an image, run:
`./gradlew helpDocker`

== Additional Information
You can find additional information in the https://solr.apache.org/guide/solr/latest/deployment-guide/solr-in-docker.html[Solr Ref Guide Docker Page]
You can find additional information in the https://solr.apache.org/guide/solr/latest/deployment-guide/solr-in-docker.html[Solr Ref Guide Docker Page]
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ New Features
---------------------
* SOLR-14496: Solr CLI commands now can interact with a Solr secured using Basic Authentication. (Eric Pugh)

* SOLR-17467: Solr CLI bin/solr start defaults to starting Solr in Cloud mode, use --user-managed switch for User Managed (aka Standalone) mode. (Eric Pugh)

Improvements
---------------------

Expand Down
22 changes: 8 additions & 14 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,13 @@ function print_usage() {

if [[ "$CMD" == "start" || "$CMD" == "restart" ]]; then
echo ""
echo "Usage: solr $CMD [-f] [-c] [--host host] [-p port] [--server-dir directory] [-z zkHost] [-m memory] [-e example] [--solr-home solr.solr.home] [--data-home solr.data.home] [--jvm-opts \"jvm-opts\"] [-V]"
echo "Usage: solr $CMD [-f] [--user-managed] [--host host] [-p port] [--server-dir directory] [-z zkHost] [-m memory] [-e example] [--solr-home solr.solr.home] [--data-home solr.data.home] [--jvm-opts \"jvm-opts\"] [--verbose]"
echo ""
echo " -f Start Solr in foreground; default starts Solr in the background"
echo " and sends stdout / stderr to solr-PORT-console.log"
echo ""
echo " -c or --cloud Start Solr in SolrCloud mode; if -z not supplied and ZK_HOST not defined in"
echo " solr.in.sh, an embedded ZooKeeper instance is started on Solr port+1000,"
echo " such as 9983 if Solr is bound to 8983"
echo " --user-managed Start Solr in user managed aka standalone mode"
echo " See the Ref Guide for more details: https://solr.apache.org/guide/solr/latest/deployment-guide/cluster-types.html"
echo ""
echo " --host <host> Specify the hostname for this Solr instance"
echo ""
Expand All @@ -385,7 +384,7 @@ function print_usage() {
echo ""
echo " --server-dir <dir> Specify the Solr server directory; defaults to server"
echo ""
echo " -z/--zk-host <zkHost> Zookeeper connection string; only used when running in SolrCloud mode using -c"
echo " -z/--zk-host <zkHost> Zookeeper connection string; ignored when running in User Managed (--user-managed) mode."
echo " If neither ZK_HOST is defined in solr.in.sh nor the -z parameter is specified,"
echo " an embedded ZooKeeper instance will be launched."
echo " Set the ZK_CREATE_CHROOT environment variable to true if your ZK host has a chroot path, and you want to create it automatically."
Expand Down Expand Up @@ -733,13 +732,14 @@ FORCE=false
SOLR_OPTS=(${SOLR_OPTS:-})
SCRIPT_SOLR_OPTS=()
PASS_TO_RUN_EXAMPLE=()
SOLR_MODE="solrcloud"

if [ $# -gt 0 ]; then
while true; do
case "${1:-}" in
-c|--cloud|-cloud)
SOLR_MODE="solrcloud"
PASS_TO_RUN_EXAMPLE+=("-c")
--user-managed)
SOLR_MODE="user-managed"
PASS_TO_RUN_EXAMPLE+=("--user-managed")
shift
;;
-d|--dir|-dir|--server-dir)
Expand Down Expand Up @@ -821,7 +821,6 @@ if [ $# -gt 0 ]; then
exit 1
fi
ZK_HOST="$2"
SOLR_MODE="solrcloud"
PASS_TO_RUN_EXAMPLE+=("-z" "$ZK_HOST")
shift 2
;;
Expand Down Expand Up @@ -1141,11 +1140,6 @@ if [ "${#GC_LOG_OPTS[@]}" -gt 0 ]; then
fi
fi

# If ZK_HOST is defined, the assume SolrCloud mode
if [[ -n "${ZK_HOST:-}" ]]; then
SOLR_MODE="solrcloud"
fi

if [ "${SOLR_MODE:-}" == 'solrcloud' ]; then
: "${ZK_CLIENT_TIMEOUT:=30000}"
CLOUD_MODE_OPTS=("-DzkClientTimeout=$ZK_CLIENT_TIMEOUT")
Expand Down
21 changes: 10 additions & 11 deletions solr/bin/solr.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,13 @@ goto done

:start_usage
@echo.
@echo Usage: solr %SCRIPT_CMD% [-f] [-c] [--host hostname] [-p port] [--server-dir directory] [-z zkHost] [-m memory] [-e example] [--solr-home solr.solr.home] [--data-home solr.data.home] [--jvm-opts "jvm-opts"] [-V]
@echo Usage: solr %SCRIPT_CMD% [-f] [--user-managed] [--host hostname] [-p port] [--server-dir directory] [-z zkHost] [-m memory] [-e example] [--solr-home solr.solr.home] [--data-home solr.data.home] [--jvm-opts "jvm-opts"] [--verbose]
@echo.
@echo -f Start Solr in foreground; default starts Solr in the background
@echo and sends stdout / stderr to solr-PORT-console.log
@echo.
@echo -c or --cloud Start Solr in SolrCloud mode; if -z not supplied and ZK_HOST not defined in
@echo solr.in.cmd, an embedded ZooKeeper instance is started on Solr port+1000,
@echo such as 9983 if Solr is bound to 8983
@echo --user-managed Start Solr in user managed aka standalone mode"
@echo See the Ref Guide for more details: https://solr.apache.org/guide/solr/latest/deployment-guide/cluster-types.html
@echo.
@echo --host host Specify the hostname for this Solr instance
@echo.
Expand Down Expand Up @@ -401,9 +400,7 @@ IF "%1"=="--verbose" goto set_verbose
IF "%1"=="-v" goto set_verbose
IF "%1"=="-q" goto set_warn
IF "%1"=="--quiet" goto set_warn
IF "%1"=="-c" goto set_cloud_mode
IF "%1"=="-cloud" goto set_cloud_mode
IF "%1"=="--cloud" goto set_cloud_mode
IF "%1"=="--user-managed" goto set_user_managed_mode
IF "%1"=="-d" goto set_server_dir
IF "%1"=="--dir" goto set_server_dir
IF "%1"=="--server-dir" goto set_server_dir
Expand Down Expand Up @@ -462,8 +459,8 @@ set SOLR_LOG_LEVEL=WARN
SHIFT
goto parse_args

:set_cloud_mode
set SOLR_MODE=solrcloud
:set_user_managed_mode
set SOLR_MODE=user-managed
SHIFT
goto parse_args

Expand Down Expand Up @@ -875,7 +872,7 @@ IF "%SCRIPT_CMD%"=="start" (
)
)
)

IF "%EMPTY_ADDL_JVM_ARGS%"=="true" (
set "SCRIPT_ERROR=JVM options are required when using the -a or --jvm-opts option!"
goto err
Expand Down Expand Up @@ -907,6 +904,7 @@ if !JAVA_MAJOR_VERSION! LSS 9 (
)

IF NOT "%ZK_HOST%"=="" set SOLR_MODE=solrcloud
IF NOT "%SOLR_MODE%"=="" set SOLR_MODE=solrcloud

IF "%SOLR_MODE%"=="solrcloud" (
IF "%ZK_CLIENT_TIMEOUT%"=="" set "ZK_CLIENT_TIMEOUT=30000"
Expand Down Expand Up @@ -942,7 +940,8 @@ IF "%SOLR_MODE%"=="solrcloud" (

IF EXIST "%SOLR_HOME%\collection1\core.properties" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf -DnumShards=1"
) ELSE (
set CLOUD_MODE_OPTS=
REM change Cloud mode to User Managed mode with flag
set "CLOUD_MODE_OPTS=--user-managed"
IF NOT EXIST "%SOLR_HOME%\solr.xml" (
IF "%SOLR_SOLRXML_REQUIRED%"=="true" (
set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% must contain solr.xml!"
Expand Down
15 changes: 7 additions & 8 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ public List<Option> getOptions() {
.required(false)
.desc("Specify the hostname for this Solr instance.")
.build(),
Option.builder("c")
.longOpt("cloud")
Option.builder()
.longOpt("user-managed")
.required(false)
.desc(
"Start Solr in SolrCloud mode; if -z not supplied, an embedded ZooKeeper instance is started on Solr port+1000, such as 9983 if Solr is bound to 8983.")
.desc("Start Solr in User Managed mode.")
.build(),
Option.builder("m")
.longOpt("memory")
Expand Down Expand Up @@ -263,7 +262,7 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
String configSet =
"techproducts".equals(exampleName) ? "sample_techproducts_configs" : "_default";

boolean isCloudMode = cli.hasOption('c');
boolean isCloudMode = !cli.hasOption("user-managed");
String zkHost = cli.getOptionValue('z');
int port =
Integer.parseInt(
Expand Down Expand Up @@ -538,7 +537,7 @@ protected void runCloudExample(CommandLine cli) throws Exception {
// start the other nodes
for (int n = 1; n < numNodes; n++)
startSolr(
new File(cloudDir, "node" + (n + 1) + "/solr"), true, cli, cloudPorts[n], zkHost, 30);
new File(cloudDir, "node" + (n + 1) + "/solr"), false, cli, cloudPorts[n], zkHost, 30);
}

String solrUrl = (String) nodeStatus.get("baseUrl");
Expand Down Expand Up @@ -614,9 +613,9 @@ protected Map<String, Object> startSolr(
String hostArg = (host != null && !"localhost".equals(host)) ? " --host " + host : "";
String zkHostArg = (zkHost != null) ? " -z " + zkHost : "";
String memArg = (memory != null) ? " -m " + memory : "";
String cloudModeArg = cloudMode ? "--cloud " : "";
String cloudModeArg = cloudMode ? "" : "--user-managed";
String forceArg = cli.hasOption("force") ? " --force" : "";
String verboseArg = verbose ? "-V" : "";
String verboseArg = verbose ? "--verbose" : "";

String jvmOpts =
cli.hasOption("jvm-opts") ? cli.getOptionValue("jvm-opts") : cli.getOptionValue('a');
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ private static void printHelp() {
" SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled):");
print("");
printGreen(
" ./solr start -c -m 1g -z localhost:2181 --jvm-opts \"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044\"");
" ./solr start -m 1g -z localhost:2181 --jvm-opts \"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044\"");
print("");
print(
" Omit '-z localhost:2181' from the above command if you have defined ZK_HOST in solr.in.sh.");
Expand Down
20 changes: 14 additions & 6 deletions solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public int execute(org.apache.commons.exec.CommandLine cmd) throws IOException {
if (exe.endsWith("solr")) {
String[] args = cmd.getArguments();
if ("start".equals(args[0])) {
if (!hasFlag("--cloud", args) && !hasFlag("-c", args)) {
if (hasFlag("--user-managed", args)) {
return startStandaloneSolr(args);
}

Expand Down Expand Up @@ -336,9 +336,12 @@ public void testFilmsExample() throws Exception {
}

protected void testExample(String exampleName) throws Exception {
// Occasionally we want to test in User Managed mode, not the default SolrCloud mode.
String testStandaloneMode = LuceneTestCase.rarely() ? "--user-managed" : "";
File solrHomeDir = new File(ExternalPaths.SERVER_HOME);
if (!solrHomeDir.isDirectory())
if (!solrHomeDir.isDirectory()) {
fail(solrHomeDir.getAbsolutePath() + " not found and is required to run this test!");
}

Path tmpDir = createTempDir();
File solrExampleDir = tmpDir.toFile();
Expand All @@ -355,10 +358,15 @@ protected void testExample(String exampleName) throws Exception {

String[] toolArgs =
new String[] {
"-e", exampleName,
"--server-dir", solrServerDir.getAbsolutePath(),
"--example-dir", solrExampleDir.getAbsolutePath(),
"-p", String.valueOf(bindPort)
"-e",
exampleName,
"--server-dir",
solrServerDir.getAbsolutePath(),
"--example-dir",
solrExampleDir.getAbsolutePath(),
"-p",
String.valueOf(bindPort),
testStandaloneMode
};

// capture tool output to stdout
Expand Down
4 changes: 2 additions & 2 deletions solr/docker/gradle-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ Each input tasks a comma separated list of test names.

Run specific tests:
EnvVar: SOLR_DOCKER_TESTS_INCLUDE
Gradle Property: -Psolr.docker.tests.include
Gradle Property: -Psolr.docker.tests.include=cloud_multi_node_embedded_zk,demo

Exclude specific tests:
EnvVar: SOLR_DOCKER_TESTS_EXCLUDE
Gradle Property: -Psolr.docker.tests.exclude
Gradle Property: -Psolr.docker.tests.exclude=cloud_multi_node_embedded_zk,demo

The docker tests can also be run concurrently, if explicitly specified.
The parallelization is set by the number of gradle workers you have defined, this cannot be specified separately.
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/scripts/solr-create
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ else
fi
fi

exec solr-fg
exec solr-fg --user-managed
2 changes: 1 addition & 1 deletion solr/docker/scripts/solr-demo
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ else
fi
fi

exec solr-fg
exec solr-fg --user-managed
2 changes: 1 addition & 1 deletion solr/docker/scripts/solr-precreate
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ source run-initdb

precreate-core "$@"

exec solr-fg
exec solr-fg --user-managed
2 changes: 1 addition & 1 deletion solr/docker/scripts/start-local-solr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [[ "${VERBOSE:-}" == "yes" ]]; then
fi

echo "Running solr in the background. Logs are in /var/solr/logs"
SOLR_OPTS="-Djetty.host=${SOLR_LOCAL_HOST:-localhost}" solr start
SOLR_OPTS="-Djetty.host=${SOLR_LOCAL_HOST:-localhost}" solr start --user-managed
max_try=${MAX_TRY:-12}
wait_seconds=${WAIT_SECONDS:-5}
if ! wait-for-solr.sh --max-attempts "$max_try" --wait-seconds "$wait_seconds"; then
Expand Down
4 changes: 2 additions & 2 deletions solr/docker/tests/cases/cloud_multi_node_embedded_zk/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST_DIR="${TEST_DIR:-$(dirname -- "${BASH_SOURCE[0]}")}"
source "${TEST_DIR}/../../shared.sh"

echo "Running base solr node w/embeddedZk - $container_name"
docker run --name "${container_name}" -d "$tag" solr-fg -c
docker run --name "${container_name}" -d "$tag" solr-fg

wait_for_container_and_solr "${container_name}"

Expand All @@ -32,7 +32,7 @@ container_cleanup "${container_name}-2"
echo "Running additional solr node - $container_name-2"
docker run --name "$container_name-2" -d \
--env "ZK_HOST=${solr_ip}:9983" \
"$tag" solr-fg -c
"$tag" solr-fg

wait_for_container_and_solr "${container_name}-2"

Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/prometheus-exporter-cloud/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source "${TEST_DIR}/../../shared.sh"
container_cleanup "${container_name}-solr"

echo "Running $container_name"
docker run --name "${container_name}-solr" -d "$tag" solr-fg -c
docker run --name "${container_name}-solr" -d "$tag" solr-fg

wait_for_container_and_solr "${container_name}-solr"

Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/user_volume/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ docker run \
-v "$mylogs:/var/solr/logs" \
--user "$(id -u):$(id -g)" \
--name "$container_name" \
-d "$tag"
-d "$tag" --user-managed

wait_for_container_and_solr "$container_name"

Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_adminconsole_urls.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ teardown() {
}

@test "assert able to launch solr admin console" {
run solr start -c
run solr start

run curl -s -o /dev/null -w "%{http_code}" http://localhost:${SOLR_PORT}/solr/

Expand Down
4 changes: 2 additions & 2 deletions solr/packaging/test/test_assert.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ teardown() {

@test "assert for non cloud mode" {
solr assert --not-started http://localhost:${SOLR_PORT} --timeout 5000
run solr start
run solr start --user-managed
solr assert --started http://localhost:${SOLR_PORT} --timeout 5000

run solr assert --not-cloud http://localhost:${SOLR_PORT}/solr
Expand All @@ -44,7 +44,7 @@ teardown() {
}

@test "assert for cloud mode" {
run solr start -c
run solr start
solr assert --started http://localhost:${SOLR_PORT} --timeout 5000

run solr assert --cloud http://localhost:${SOLR_PORT}
Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_auth.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ setup() {
}

@test "auth enable/disable lifecycle" {
solr start -c
solr start
solr auth enable --type basicAuth --credentials name:password
solr assert --started http://localhost:${SOLR_PORT} --timeout 5000

Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_basic_auth.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ setup() {
common_clean_setup

echo "Starting Solr"
solr start -c -Denable.packages=true
solr start -Denable.packages=true

# The auth command exports some system variables that are injected as basic auth username and password,
# however that defeats our test so fake that out via --solr-include-file param specifing a bogus path.
Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ setup_file() {
# set up paths and helpers
common_clean_setup

solr start -c -V
solr start -V
# echo $output >&3
}

Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load bats_helper

setup_file() {
common_clean_setup
solr start -c
solr start
}

teardown_file() {
Expand Down
Loading

0 comments on commit a608978

Please sign in to comment.