SOLR-6365 "implicit requesthandler (specifiedin code) takes lower precedence over <initParams>"

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1640594 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2014-11-19 16:47:19 +00:00
parent 570058d937
commit 58d913b6e5
4 changed files with 26 additions and 5 deletions

View File

@ -78,10 +78,16 @@ public class InitParams {
}
public void apply(NamedList initArgs) {
merge( (NamedList) initArgs.get(PluginInfo.DEFAULTS), defaults,initArgs, PluginInfo.DEFAULTS, false);
merge((NamedList) initArgs.get(PluginInfo.INVARIANTS), invariants, initArgs, PluginInfo.INVARIANTS, false);
merge((NamedList) initArgs.get(PluginInfo.APPENDS), appends, initArgs, PluginInfo.APPENDS, true);
public void apply(PluginInfo info) {
if (info.isFromSolrConfig) {
//if this is a component implicitly defined in code it should be overridden by initPrams
merge(defaults, (NamedList) info.initArgs.get(PluginInfo.DEFAULTS) ,info.initArgs, PluginInfo.DEFAULTS, false);
} else {
//if the args is initialized from solrconfig.xml inside the requesthHandler it should be taking precedence over initParams
merge( (NamedList) info.initArgs.get(PluginInfo.DEFAULTS), defaults,info.initArgs, PluginInfo.DEFAULTS, false);
}
merge((NamedList) info.initArgs.get(PluginInfo.INVARIANTS), invariants, info.initArgs, PluginInfo.INVARIANTS, false);
merge((NamedList) info.initArgs.get(PluginInfo.APPENDS), appends, info.initArgs, PluginInfo.APPENDS, true);
}
private static void merge(NamedList first, NamedList second, NamedList sink, String name, boolean appends) {

View File

@ -34,6 +34,7 @@ public class PluginInfo implements MapSerializable{
public final NamedList initArgs;
public final Map<String, String> attributes;
public final List<PluginInfo> children;
public final boolean isFromSolrConfig;
public PluginInfo(String type, Map<String, String> attrs ,NamedList initArgs, List<PluginInfo> children) {
this.type = type;
@ -42,6 +43,7 @@ public class PluginInfo implements MapSerializable{
this.initArgs = initArgs;
attributes = unmodifiableMap(attrs);
this.children = children == null ? Collections.<PluginInfo>emptyList(): unmodifiableList(children);
isFromSolrConfig = false;
}
@ -52,6 +54,7 @@ public class PluginInfo implements MapSerializable{
initArgs = DOMUtil.childNodesToNamedList(node);
attributes = unmodifiableMap(DOMUtil.toMap(node.getAttributes()));
children = loadSubPlugins(node);
isFromSolrConfig = true;
}
private List<PluginInfo> loadSubPlugins(Node node) {

View File

@ -212,7 +212,7 @@ public final class RequestHandlers {
if(!ags.isEmpty()){
info = new PluginInfo(info.type, info.attributes, info.initArgs.clone(), info.children);
for (InitParams initParam : ags) {
initParam.apply(info.initArgs);
initParam.apply(info);
}
}
return info;

View File

@ -18,6 +18,7 @@ package org.apache.solr.core;
*/
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
@ -25,6 +26,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashMap;
import static java.util.Collections.singletonMap;
public class TestInitParams extends SolrTestCaseJ4 {
@BeforeClass
@ -46,6 +50,14 @@ public class TestInitParams extends SolrTestCaseJ4 {
def = (NamedList) nl.get(PluginInfo.APPENDS);
assertEquals("C", def.get("c"));
}
InitParams initParams = h.getCore().getSolrConfig().getInitParams().get("a");
PluginInfo pluginInfo = new PluginInfo("requestHandler",
new HashMap<String, String>(),
new NamedList<>(singletonMap("defaults", new NamedList(ZkNodeProps.makeMap("a", "A1")))), null);
initParams.apply(pluginInfo);
assertEquals( "A",initParams.defaults.get("a"));
}
@Test