diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index c333e131f2b..36fc95e0fda 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -304,6 +304,9 @@ Bug Fixes * SOLR-8206: JSON Facet API limit:0 did not always work correctly. (yonik) +* SOLR-8126: update- does not work if the component is only + present in solrconfig.xml (noble) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java index 562eef0519f..88a90f5303d 100644 --- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java @@ -444,7 +444,7 @@ public class SolrConfigHandler extends RequestHandlerBase { op.getMap(PluginInfo.APPENDS, null); if (op.hasError()) return overlay; if (!verifyClass(op, clz, info.clazz)) return overlay; - if (overlay.getNamedPlugins(info.getCleanTag()).containsKey(name)) { + if (pluginExists(info, overlay, name)) { if (isCeate) { op.addError(formatString(" ''{0}'' already exists . Do an ''{1}'' , if you want to change it ", name, "update-" + info.getTagCleanLower())); return overlay; @@ -461,6 +461,12 @@ public class SolrConfigHandler extends RequestHandlerBase { } } + private boolean pluginExists(SolrConfig.SolrPluginInfo info, ConfigOverlay overlay, String name) { + List l = req.getCore().getSolrConfig().getPluginInfos(info.clazz.getName()); + for (PluginInfo pluginInfo : l) if(name.equals( pluginInfo.name)) return true; + return overlay.getNamedPlugins(info.getCleanTag()).containsKey(name); + } + private boolean verifyClass(CommandOperation op, String clz, Class expected) { if (clz == null) return true; if (!"true".equals(String.valueOf(op.getStr("runtimeLib", null)))) { diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml index 37290a95faf..53f020df768 100644 --- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml @@ -108,6 +108,13 @@ x_x - + + + + + A + B + + diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java index 30c2b0e029b..12e67d469eb 100644 --- a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java +++ b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java @@ -49,6 +49,7 @@ import org.restlet.ext.servlet.ServerServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.solr.BaseDistributedSearchTestCase.log; import static org.apache.solr.common.util.Utils.getObjectByPath; import static org.apache.solr.handler.TestBlobHandler.getAsString; @@ -201,6 +202,22 @@ public class TestSolrConfigHandler extends RestTestBase { "b", 10); + payload = "{\n" + + "'update-requesthandler' : { 'name' : '/dump', " + + "'initParams': 'a'," + + "'class': 'org.apache.solr.handler.DumpRequestHandler' ," + + " 'defaults': {'a':'A','b':'B','c':'C'}}\n" + + "}"; + + runConfigCommand(writeHarness, "/config?wt=json", payload); + testForResponseElement(writeHarness, + testServerBaseUrl, + "/config/overlay?wt=json", + cloudSolrClient, + Arrays.asList("overlay", "requestHandler", "/dump", "defaults", "c" ), + "C", + 10); + testForResponseElement(writeHarness, testServerBaseUrl, "/x?wt=json&getdefaults=true&json.nl=map", @@ -473,7 +490,7 @@ public class TestSolrConfigHandler extends RestTestBase { 10); payload = "{\n" + - "'create-requesthandler' : { 'name' : '/dump', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + + "'create-requesthandler' : { 'name' : '/d', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + "}"; TestSolrConfigHandler.runConfigCommand(harness, "/config?wt=json", payload); @@ -483,20 +500,20 @@ public class TestSolrConfigHandler extends RestTestBase { null, "/config/overlay?wt=json", null, - Arrays.asList("overlay", "requestHandler", "/dump", "name"), - "/dump", + Arrays.asList("overlay", "requestHandler", "/d", "name"), + "/d", 10); TestSolrConfigHandler.testForResponseElement(harness, null, - "/dump?wt=json&useParams=x", + "/d?wt=json&useParams=x", null, Arrays.asList("params", "a"), "A val", 5); TestSolrConfigHandler.testForResponseElement(harness, null, - "/dump?wt=json&useParams=x&a=fomrequest", + "/d?wt=json&useParams=x&a=fomrequest", null, Arrays.asList("params", "a"), "fomrequest", diff --git a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java index 399fcb6055e..c4a4c3ac8bf 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java +++ b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java @@ -146,7 +146,7 @@ public class TestSolrConfigHandlerCloud extends AbstractFullDistribZkTestBase { compareValues(result, "B val", asList("response", "params", "x", "b")); payload = "{\n" + - "'create-requesthandler' : { 'name' : '/dump', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + + "'update-requesthandler' : { 'name' : '/dump', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + "}"; TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);