From 620175a5626e69823b5aec8e20734a6352195000 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 22 Nov 2024 06:58:31 -0500 Subject: [PATCH] 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 declaration. --------- Co-authored-by: Houston Putman --- solr/CHANGES.txt | 2 + .../org/apache/solr/cli/RunExampleTool.java | 19 +++---- .../solr/cli/TestSolrCLIRunExample.java | 9 --- solr/server/resources/log4j2-console.xml | 4 +- solr/server/resources/log4j2.xml | 4 +- .../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 ea10c72378b..666958c64da 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 --------------------- 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 fff3c04f5c5..4f0346c6079 100644 --- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java +++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java @@ -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; @@ -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"; @@ -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 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. @@ -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) { @@ -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()) { @@ -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, @@ -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[] { @@ -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); 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 da279a12301..6da81edaa29 100644 --- a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java +++ b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java @@ -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)) { 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. --> - - + 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. --> - + @@ -62,7 +62,7 @@ - + diff --git a/solr/server/solr/configsets/_default/conf/solrconfig.xml b/solr/server/solr/configsets/_default/conf/solrconfig.xml index 5bc2cf13415..3cec6a4e578 100644 --- a/solr/server/solr/configsets/_default/conf/solrconfig.xml +++ b/solr/server/solr/configsets/_default/conf/solrconfig.xml @@ -37,51 +37,6 @@ --> 9.11 - - - - - - - - 9.11 - - - - - - - - - - - - - - - -