Skip to content

Commit

Permalink
SOLR-17556: Examples should run with the standard & recommended Solr …
Browse files Browse the repository at this point in the history
…home and solr data dir (#2861)

* Have techproducts, films, and schemaless all start in the normal solr home.
Only -e cloud generates it's individual node files in ./example/cloud/node1, node2 etc...

* Update the ref guide to consistently use -Dsolr.modules settings instead of relying on  on the <lib/> declaration.
---------

Co-authored-by: Houston Putman <houston@apache.org>
  • Loading branch information
epugh and HoustonPutman authored Nov 22, 2024
1 parent 621165a commit 620175a
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 125 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ led to the suppression of exceptions. (Andrey Bozhko)

* SOLR-17504: CoreContainer calls UpdateHandler.commit when closing a read-only core (Bruno Roustant)

* SOLR-17556: "home" and "data" directories used by Solr examples have been updated to align with documented best practices. (Eric Pugh, Houston Putman)

================== 9.7.1 ==================
Bug Fixes
---------------------
Expand Down
19 changes: 9 additions & 10 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.common.SolrException;
import org.noggit.CharArr;
import org.noggit.JSONWriter;
Expand Down Expand Up @@ -266,7 +265,6 @@ public void runImpl(CommandLine cli) throws Exception {
}

protected void runExample(CommandLine cli, String exampleName) throws Exception {
File exDir = setupExampleDir(serverDir, exampleDir, exampleName);
String collectionName = "schemaless".equals(exampleName) ? "gettingstarted" : exampleName;
String configSet =
"techproducts".equals(exampleName) ? "sample_techproducts_configs" : "_default";
Expand All @@ -277,9 +275,9 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
Integer.parseInt(
cli.getOptionValue(PORT_OPTION, System.getenv().getOrDefault("SOLR_PORT", "8983")));
Map<String, Object> nodeStatus =
startSolr(new File(exDir, "solr"), isCloudMode, cli, port, zkHost, 30);
startSolr(new File(serverDir, "solr"), isCloudMode, cli, port, zkHost, 30);

String solrUrl = (String) nodeStatus.get("baseUrl");
String solrUrl = CLIUtils.normalizeSolrUrl((String) nodeStatus.get("baseUrl"));

// If the example already exists then let the user know they should delete it, or
// they may get unusual behaviors.
Expand Down Expand Up @@ -310,7 +308,7 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
echo(
"You may want to run 'bin/solr delete -c "
+ collectionName
+ "' first before running the example to ensure a fresh state.");
+ " --delete-config' first before running the example to ensure a fresh state.");
}

if (!alreadyExists) {
Expand All @@ -333,7 +331,7 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception

if ("techproducts".equals(exampleName) && !alreadyExists) {

File exampledocsDir = new File(exampleDir, "exampledocs");
File exampledocsDir = new File(this.exampleDir, "exampledocs");
if (!exampledocsDir.isDirectory()) {
File readOnlyExampleDir = new File(serverDir.getParentFile(), "example");
if (readOnlyExampleDir.isDirectory()) {
Expand Down Expand Up @@ -364,7 +362,9 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
"exampledocs directory not found, skipping indexing step for the techproducts example");
}
} else if ("films".equals(exampleName) && !alreadyExists) {
try (SolrClient solrClient = new Http2SolrClient.Builder(solrUrl).build()) {
try (SolrClient solrClient =
CLIUtils.getSolrClient(
solrUrl, cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION))) {
echo("Adding dense vector field type to films schema");
SolrCLI.postJsonToSolr(
solrClient,
Expand Down Expand Up @@ -424,7 +424,7 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
+ " }\n"
+ " }\n");

File filmsJsonFile = new File(exampleDir, "films/films.json");
File filmsJsonFile = new File(this.exampleDir, "films/films.json");
echo("Indexing films example docs from " + filmsJsonFile.getAbsolutePath());
String[] args =
new String[] {
Expand Down Expand Up @@ -549,8 +549,7 @@ protected void runCloudExample(CommandLine cli) throws Exception {
new File(cloudDir, "node" + (n + 1) + "/solr"), true, cli, cloudPorts[n], zkHost, 30);
}

String solrUrl = (String) nodeStatus.get("baseUrl");
if (solrUrl.endsWith("/")) solrUrl = solrUrl.substring(0, solrUrl.length() - 1);
String solrUrl = CLIUtils.normalizeSolrUrl((String) nodeStatus.get("baseUrl"), false);

// wait until live nodes == numNodes
waitToSeeLiveNodes(zkHost, numNodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,6 @@ protected void testExample(String exampleName) throws Exception {
// dump all the output written by the SolrCLI commands to stdout
// System.out.println("\n\n"+toolOutput+"\n\n");

File exampleSolrHomeDir = new File(solrExampleDir, exampleName + "/solr");
assertTrue(
exampleSolrHomeDir.getAbsolutePath()
+ " not found! run "
+ exampleName
+ " example failed; output: "
+ toolOutput,
exampleSolrHomeDir.isDirectory());

if ("techproducts".equals(exampleName)) {
try (SolrClient solrClient =
getHttpSolrClient("http://localhost:" + bindPort + "/solr", exampleName)) {
Expand Down
4 changes: 2 additions & 2 deletions solr/server/resources/log4j2-console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
limitations under the License.
-->

<!-- Use this file for logging exlusively to the console, useful for
<!-- Use this file for logging exclusively to the console, useful for
some development tasks. Should not be used for production -->
<!-- Default production configuration is asnychronous logging -->
<!-- Default production configuration is asynchronous logging -->
<Configuration>
<Appenders>
<Console name="STDERR" target="SYSTEM_ERR">
Expand Down
4 changes: 2 additions & 2 deletions solr/server/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
-->

<!-- Default production configuration is asnychronous logging -->
<!-- Default production configuration is asynchronous logging -->
<Configuration>
<Appenders>

Expand Down Expand Up @@ -62,7 +62,7 @@

</Appenders>
<Loggers>
<!-- Use <AsyncLogger/<AsyncRoot and <Logger/<Root for asynchronous logging or synchonous logging respectively -->
<!-- Use <AsyncLogger/<AsyncRoot and <Logger/<Root for asynchronous logging or synchronous logging respectively -->
<AsyncLogger name="org.apache.hadoop" level="warn"/>
<AsyncLogger name="org.apache.solr.update.LoggingInfoStream" level="off"/>
<AsyncLogger name="org.apache.zookeeper" level="warn"/>
Expand Down
45 changes: 0 additions & 45 deletions solr/server/solr/configsets/_default/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,51 +37,6 @@
-->
<luceneMatchVersion>9.11</luceneMatchVersion>

<!-- <lib/> directives can be used to instruct Solr to load any Jars
identified and use them to resolve any "plugins" specified in
your solrconfig.xml or schema.xml (ie: Analyzers, Request
Handlers, etc...).
All directories and paths are resolved relative to the
instanceDir.
Please note that <lib/> directives are processed in the order
that they appear in your solrconfig.xml file, and are "stacked"
on top of each other when building a ClassLoader - so if you have
plugin jars with dependencies on other jars, the "lower level"
dependency jars should be loaded first.
If a "./lib" directory exists in your instanceDir, all files
found in it are included as if you had used the following
syntax...
<lib dir="./lib" />
-->

<!-- A 'dir' option by itself adds any files found in the directory
to the classpath, this is useful for including all jars in a
directory.
When a 'regex' is specified in addition to a 'dir', only the
files in that directory which completely match the regex
(anchored on both ends) will be included.
If a 'dir' option (with or without a regex) is used and nothing
is found that matches, a warning will be logged.
The example below can be used to load a Solr Module along
with their external dependencies.
-->
<!-- <lib dir="${solr.install.dir:../../../..}/modules/ltr/lib" regex=".*\.jar" /> -->

<!-- an exact 'path' can be used instead of a 'dir' to specify a
specific jar file. This will cause a serious error to be logged
if it can't be loaded.
-->
<!--
<lib path="../a-jar-that-does-not-exist.jar" />
-->

<!-- Data Directory
Used to specify an alternate directory to hold all index data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,61 +37,6 @@
-->
<luceneMatchVersion>9.11</luceneMatchVersion>

<!-- <lib/> directives can be used to instruct Solr to load any Jars
identified and use them to resolve any "plugins" specified in
your solrconfig.xml or schema.xml (ie: Analyzers, Request
Handlers, etc...).
All directories and paths are resolved relative to the
instanceDir.
Please note that <lib/> directives are processed in the order
that they appear in your solrconfig.xml file, and are "stacked"
on top of each other when building a ClassLoader - so if you have
plugin jars with dependencies on other jars, the "lower level"
dependency jars should be loaded first.
If a "./lib" directory exists in your instanceDir, all files
found in it are included as if you had used the following
syntax...
<lib dir="./lib" />
-->

<!-- A 'dir' option by itself adds any files found in the directory
to the classpath, this is useful for including all jars in a
directory.
When a 'regex' is specified in addition to a 'dir', only the
files in that directory which completely match the regex
(anchored on both ends) will be included.
If a 'dir' option (with or without a regex) is used and nothing
is found that matches, a warning will be logged.
The examples below can be used to load some Solr Modules along
with their external dependencies as an alternative to using a
startup parameter to define the modules to load globally. For more info
see https://solr.apache.org/guide/solr/latest/configuration-guide/solr-modules.html.
-->
<lib dir="${solr.install.dir:../../../..}/modules/extraction/lib" regex=".*\.jar" />

<lib dir="${solr.install.dir:../../../..}/modules/clustering/lib/" regex=".*\.jar" />

<lib dir="${solr.install.dir:../../../..}/modules/langid/lib/" regex=".*\.jar" />

<lib dir="${solr.install.dir:../../../..}/modules/ltr/lib/" regex=".*\.jar" />

<lib dir="${solr.install.dir:../../../..}/modules/scripting/lib/" regex=".*\.jar" />

<!-- an exact 'path' can be used instead of a 'dir' to specify a
specific jar file. This will cause a serious error to be logged
if it can't be loaded.
-->
<!--
<lib path="../a-jar-that-does-not-exist.jar" />
-->

<!-- Data Directory
Used to specify an alternate directory to hold all index data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ To enable the plugins, please specify the `solr.ltr.enabled` JVM System Property

[source,bash]
----
bin/solr start -e techproducts -Dsolr.ltr.enabled=true
bin/solr start -e techproducts -Dsolr.modules=ltr -Dsolr.ltr.enabled=true
----

=== Uploading Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ To enable the clustering component extension and the dedicated search handler co

[source,bash]
----
bin/solr start -e techproducts -Dsolr.clustering.enabled=true
bin/solr start -e techproducts -Dsolr.modules=clustering -Dsolr.clustering.enabled=true
----

You can now try out the clustering handler by opening the following URL in a browser:
Expand Down

0 comments on commit 620175a

Please sign in to comment.