SOLR-6365 lazy loaded components did not have initParams applied

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1646401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2014-12-18 08:25:32 +00:00
parent 5a876e47ad
commit e23993550e
5 changed files with 62 additions and 17 deletions

View File

@ -79,7 +79,7 @@ public class InitParams {
}
public void apply(PluginInfo info) {
if (info.isFromSolrConfig) {
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 {

View File

@ -38,7 +38,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;
private boolean isFromSolrConfig;
public PluginInfo(String type, Map<String, String> attrs ,NamedList initArgs, List<PluginInfo> children) {
this.type = type;
@ -156,4 +156,14 @@ public class PluginInfo implements MapSerializable{
public static final String DEFAULTS = "defaults";
public static final String APPENDS = "appends";
public static final String INVARIANTS = "invariants";
public boolean isFromSolrConfig(){
return isFromSolrConfig;
}
public PluginInfo copy() {
PluginInfo result = new PluginInfo(type, attributes, initArgs.clone(), children);
result.isFromSolrConfig = isFromSolrConfig;
return result;
}
}

View File

@ -160,7 +160,7 @@ public final class RequestHandlers {
if( startup != null ) {
if( "lazy".equals(startup) ) {
log.info("adding lazy requestHandler: " + info.className);
requestHandler = new LazyRequestHandlerWrapper( core, info.className, info.initArgs );
requestHandler = new LazyRequestHandlerWrapper( core, info.className);
} else {
throw new Exception( "Unknown startup value: '"+startup+"' for: "+info.className );
}
@ -214,7 +214,7 @@ public final class RequestHandlers {
for (InitParams args : config.getInitParams().values())
if(args.matchPath(info.name)) ags.add(args);
if(!ags.isEmpty()){
info = new PluginInfo(info.type, info.attributes, info.initArgs.clone(), info.children);
info = info.copy();
for (InitParams initParam : ags) {
initParam.apply(info);
}
@ -242,29 +242,25 @@ public final class RequestHandlers {
*
* @since solr 1.2
*/
public static final class LazyRequestHandlerWrapper implements SolrRequestHandler
public static final class LazyRequestHandlerWrapper implements SolrRequestHandler , PluginInfoInitialized
{
private final SolrCore core;
private String _className;
private NamedList _args;
private SolrRequestHandler _handler;
private PluginInfo _pluginInfo;
public LazyRequestHandlerWrapper( SolrCore core, String className, NamedList args )
public LazyRequestHandlerWrapper( SolrCore core, String className )
{
this.core = core;
_className = className;
_args = args;
_handler = null; // don't initialize
}
/**
* In normal use, this function will not be called
*/
@Override
public void init(NamedList args) {
// do nothing
}
public void init(NamedList args) { }
/**
* Wait for the first request before initializing the wrapped handler
*/
@ -282,7 +278,13 @@ public final class RequestHandlers {
if( _handler == null ) {
try {
SolrRequestHandler handler = core.createRequestHandler(_className);
handler.init( _args );
if (handler instanceof PluginInfoInitialized) {
((PluginInfoInitialized) handler).init(_pluginInfo);
} else {
handler.init( _pluginInfo.initArgs );
}
if( handler instanceof SolrCoreAware ) {
((SolrCoreAware)handler).inform( core );
@ -353,6 +355,12 @@ public final class RequestHandlers {
lst.add("note", "not initialized yet" );
return lst;
}
@Override
public void init(PluginInfo info) {
_pluginInfo = info;
}
}
}

View File

@ -67,6 +67,23 @@
</lst>
</requestHandler>
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
<lst name="defaults">
<str name="df">text</str>
</lst>
</initParams>
<requestHandler name="/elevate" class="DumpRequestHandler" startup="lazy">
<lst name="defaults">
<str name="echoParams">explicit</str>
</lst>
<arr name="last-components">
<str>elevator</str>
</arr>
</requestHandler>
</config>

View File

@ -109,6 +109,16 @@ public class TestInitParams extends SolrTestCaseJ4 {
assertNull(h.getCore().getRequestHandler("/greedypath/unknownpath"));
}
public void testElevateExample(){
SolrRequestHandler handler = h.getCore().getRequestHandler("/elevate");
SolrQueryResponse rsp = new SolrQueryResponse();
handler.handleRequest(req("initArgs", "true"), rsp);
NamedList nl = (NamedList) rsp.getValues().get("initArgs");
NamedList def = (NamedList) nl.get(PluginInfo.DEFAULTS);
assertEquals("text" ,def.get("df"));
}