This is an automated email from the ASF dual-hosted git repository. epugh pushed a commit to branch branch_9x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 98bf0497efd98e6f1c640173038d635a5f99362e Author: Eric Pugh <[email protected]> AuthorDate: Fri Nov 22 06:58:31 2024 -0500 SOLR-17556: Examples should run with the standard & recommended Solr 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 <[email protected]> (cherry picked from commit 620175a5626e69823b5aec8e20734a6352195000) --- solr/CHANGES.txt | 2 + .../java/org/apache/solr/cli/RunExampleTool.java | 19 ++++---- .../org/apache/solr/cli/TestSolrCLIRunExample.java | 9 ---- solr/server/resources/log4j2-console.xml | 4 +- solr/server/resources/log4j2.xml | 4 +- .../solr/configsets/_default/conf/solrconfig.xml | 45 ------------------ .../conf/solrconfig.xml | 55 ---------------------- .../query-guide/pages/learning-to-rank.adoc | 2 +- .../query-guide/pages/result-clustering.adoc | 2 +- 9 files changed, 17 insertions(+), 125 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 8530533df59..d6f48884ade 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -131,6 +131,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 --------------------- diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java index 0f27fe4e79b..d0b336e74ff 100644 --- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java +++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java @@ -47,7 +47,6 @@ import org.apache.commons.exec.environment.EnvironmentUtils; 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; @@ -254,7 +253,6 @@ public class RunExampleTool extends ToolBase { } 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"; @@ -265,9 +263,9 @@ public class RunExampleTool extends ToolBase { Integer.parseInt( cli.getOptionValue('p', 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. @@ -296,7 +294,7 @@ public class RunExampleTool extends ToolBase { 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) { @@ -319,7 +317,7 @@ public class RunExampleTool extends ToolBase { 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()) { @@ -350,7 +348,9 @@ public class RunExampleTool extends ToolBase { "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, @@ -410,7 +410,7 @@ public class RunExampleTool extends ToolBase { + " }\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[] { @@ -535,8 +535,7 @@ public class RunExampleTool extends ToolBase { 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); diff --git a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java index d17bf8fea36..f17901b8275 100644 --- a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java +++ b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java @@ -395,15 +395,6 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 { // 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)) { diff --git a/solr/server/resources/log4j2-console.xml b/solr/server/resources/log4j2-console.xml index c33c93c9327..2d5b8690bf6 100644 --- a/solr/server/resources/log4j2-console.xml +++ b/solr/server/resources/log4j2-console.xml @@ -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"> diff --git a/solr/server/resources/log4j2.xml b/solr/server/resources/log4j2.xml index 006de0c965c..f5b373338b7 100644 --- a/solr/server/resources/log4j2.xml +++ b/solr/server/resources/log4j2.xml @@ -16,7 +16,7 @@ limitations under the License. --> -<!-- Default production configuration is asnychronous logging --> +<!-- Default production configuration is asynchronous logging --> <Configuration> <Appenders> @@ -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"/> diff --git a/solr/server/solr/configsets/_default/conf/solrconfig.xml b/solr/server/solr/configsets/_default/conf/solrconfig.xml index eba9d30126a..1df8df43c37 100644 --- a/solr/server/solr/configsets/_default/conf/solrconfig.xml +++ b/solr/server/solr/configsets/_default/conf/solrconfig.xml @@ -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 diff --git a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml index c8250755dc7..17d07d3c23c 100644 --- a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml +++ b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml @@ -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 diff --git a/solr/solr-ref-guide/modules/query-guide/pages/learning-to-rank.adoc b/solr/solr-ref-guide/modules/query-guide/pages/learning-to-rank.adoc index ef4c519c34f..1d3f575ba03 100644 --- a/solr/solr-ref-guide/modules/query-guide/pages/learning-to-rank.adoc +++ b/solr/solr-ref-guide/modules/query-guide/pages/learning-to-rank.adoc @@ -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 diff --git a/solr/solr-ref-guide/modules/query-guide/pages/result-clustering.adoc b/solr/solr-ref-guide/modules/query-guide/pages/result-clustering.adoc index 11433c6fa7c..541ea99c363 100644 --- a/solr/solr-ref-guide/modules/query-guide/pages/result-clustering.adoc +++ b/solr/solr-ref-guide/modules/query-guide/pages/result-clustering.adoc @@ -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:
