SOLR-5556: Allow CollectionsHandler and InfoHandler classes to be specified in solr.xml

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1552044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alan Woodward 2013-12-18 17:35:24 +00:00
parent a18470e858
commit 25b53be6f9
8 changed files with 87 additions and 17 deletions

View File

@ -129,6 +129,9 @@ New Features
* SOLR-1871: The 'map' function query accepts a ValueSource as target and * SOLR-1871: The 'map' function query accepts a ValueSource as target and
default value. (Chris Harris, shalin) default value. (Chris Harris, shalin)
* SOLR-5556: Allow class of CollectionsHandler and InfoHandler to be specified
in solr.xml. (Gregory Chanan, Alan Woodward)
Bug Fixes Bug Fixes
---------------------- ----------------------

View File

@ -187,6 +187,14 @@ public abstract class ConfigSolr {
return get(CfgProp.SOLR_ADMINHANDLER, "org.apache.solr.handler.admin.CoreAdminHandler"); return get(CfgProp.SOLR_ADMINHANDLER, "org.apache.solr.handler.admin.CoreAdminHandler");
} }
public String getCollectionsHandlerClass() {
return get(CfgProp.SOLR_COLLECTIONSHANDLER, "org.apache.solr.handler.admin.CollectionsHandler");
}
public String getInfoHandlerClass() {
return get(CfgProp.SOLR_INFOHANDLER, "org.apache.solr.handler.admin.InfoHandler");
}
public boolean hasSchemaCache() { public boolean hasSchemaCache() {
return getBool(ConfigSolr.CfgProp.SOLR_SHARESCHEMA, false); return getBool(ConfigSolr.CfgProp.SOLR_SHARESCHEMA, false);
} }
@ -211,6 +219,7 @@ public abstract class ConfigSolr {
// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x. // Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.
protected static enum CfgProp { protected static enum CfgProp {
SOLR_ADMINHANDLER, SOLR_ADMINHANDLER,
SOLR_COLLECTIONSHANDLER,
SOLR_CORELOADTHREADS, SOLR_CORELOADTHREADS,
SOLR_COREROOTDIRECTORY, SOLR_COREROOTDIRECTORY,
SOLR_DISTRIBUPDATECONNTIMEOUT, SOLR_DISTRIBUPDATECONNTIMEOUT,
@ -220,6 +229,7 @@ public abstract class ConfigSolr {
SOLR_HOST, SOLR_HOST,
SOLR_HOSTCONTEXT, SOLR_HOSTCONTEXT,
SOLR_HOSTPORT, SOLR_HOSTPORT,
SOLR_INFOHANDLER,
SOLR_LEADERVOTEWAIT, SOLR_LEADERVOTEWAIT,
SOLR_LOGGING_CLASS, SOLR_LOGGING_CLASS,
SOLR_LOGGING_ENABLED, SOLR_LOGGING_ENABLED,

View File

@ -103,6 +103,8 @@ public class ConfigSolrXml extends ConfigSolr {
private void fillPropMap() { private void fillPropMap() {
propMap.put(CfgProp.SOLR_ADMINHANDLER, doSub("solr/str[@name='adminHandler']")); propMap.put(CfgProp.SOLR_ADMINHANDLER, doSub("solr/str[@name='adminHandler']"));
propMap.put(CfgProp.SOLR_COLLECTIONSHANDLER, doSub("solr/str[@name='collectionsHandler']"));
propMap.put(CfgProp.SOLR_INFOHANDLER, doSub("solr/str[@name='infoHandler']"));
propMap.put(CfgProp.SOLR_CORELOADTHREADS, doSub("solr/int[@name='coreLoadThreads']")); propMap.put(CfgProp.SOLR_CORELOADTHREADS, doSub("solr/int[@name='coreLoadThreads']"));
propMap.put(CfgProp.SOLR_COREROOTDIRECTORY, doSub("solr/str[@name='coreRootDirectory']")); propMap.put(CfgProp.SOLR_COREROOTDIRECTORY, doSub("solr/str[@name='coreRootDirectory']"));
propMap.put(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, doSub("solr/solrcloud/int[@name='distribUpdateConnTimeout']")); propMap.put(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, doSub("solr/solrcloud/int[@name='distribUpdateConnTimeout']"));

View File

@ -141,6 +141,8 @@ public class ConfigSolrXmlOld extends ConfigSolr {
propMap.put(CfgProp.SOLR_ADMINHANDLER, propMap.put(CfgProp.SOLR_ADMINHANDLER,
config.getVal("solr/cores/@adminHandler", false)); config.getVal("solr/cores/@adminHandler", false));
propMap.put(CfgProp.SOLR_COLLECTIONSHANDLER, config.getVal("solr/cores/@collectionsHandler", false));
propMap.put(CfgProp.SOLR_INFOHANDLER, config.getVal("solr/cores/@infoHandler", false));
propMap.put(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, propMap.put(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT,
config.getVal("solr/cores/@distribUpdateConnTimeout", false)); config.getVal("solr/cores/@distribUpdateConnTimeout", false));
propMap.put(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, propMap.put(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT,

View File

@ -214,9 +214,9 @@ public class CoreContainer {
zkSys.initZooKeeper(this, solrHome, cfg); zkSys.initZooKeeper(this, solrHome, cfg);
collectionsHandler = new CollectionsHandler(this); collectionsHandler = createHandler(cfg.getCollectionsHandlerClass(), CollectionsHandler.class);
infoHandler = new InfoHandler(this); infoHandler = createHandler(cfg.getInfoHandlerClass(), InfoHandler.class);
coreAdminHandler = createMultiCoreHandler(cfg.getCoreAdminHandlerClass()); coreAdminHandler = createHandler(cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
containerProperties = cfg.getSolrProperties("solr"); containerProperties = cfg.getSolrProperties("solr");
@ -851,13 +851,10 @@ public class CoreContainer {
return core; return core;
} }
// ---------------- Multicore self related methods --------------- // ---------------- CoreContainer request handlers --------------
/**
* Creates a CoreAdminHandler for this MultiCore. protected <T> T createHandler(String handlerClass, Class<T> clazz) {
* @return a CoreAdminHandler return loader.newInstance(handlerClass, clazz, null, new Class[] { CoreContainer.class }, new Object[] { this });
*/
protected CoreAdminHandler createMultiCoreHandler(final String adminHandlerClass) {
return loader.newAdminHandlerInstance(CoreContainer.this, adminHandlerClass);
} }
public CoreAdminHandler getMultiCoreHandler() { public CoreAdminHandler getMultiCoreHandler() {
@ -872,6 +869,8 @@ public class CoreContainer {
return infoHandler; return infoHandler;
} }
// ---------------- Multicore self related methods ---------------
/** /**
* the default core name, or null if there is no default core name * the default core name, or null if there is no default core name
*/ */

View File

@ -17,8 +17,10 @@
<solr> <solr>
<str name="adminHandler">testAdminHandler</str> <str name="adminHandler">testAdminHandler</str>
<str name="collectionsHandler">testCollectionsHandler</str>
<int name="coreLoadThreads">11</int> <int name="coreLoadThreads">11</int>
<str name="coreRootDirectory">${coreRootDirectory:testCoreRootDirectory}</str> <str name="coreRootDirectory">${coreRootDirectory:testCoreRootDirectory}</str>
<str name="infoHandler">testInfoHandler</str>
<str name="managementPath">testManagementPath</str> <str name="managementPath">testManagementPath</str>
<str name="sharedLib">testSharedLib</str> <str name="sharedLib">testSharedLib</str>
<str name="shareSchema">${shareSchema:testShareSchema}</str> <str name="shareSchema">${shareSchema:testShareSchema}</str>

View File

@ -21,6 +21,9 @@ import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util._TestUtil; import org.apache.lucene.util._TestUtil;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.admin.CollectionsHandler;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.handler.admin.InfoHandler;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -37,6 +40,9 @@ import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
public class TestCoreContainer extends SolrTestCaseJ4 { public class TestCoreContainer extends SolrTestCaseJ4 {
private static String oldSolrHome; private static String oldSolrHome;
@ -287,4 +293,48 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
private static final String EMPTY_SOLR_XML2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + private static final String EMPTY_SOLR_XML2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<solr>\n" + "<solr>\n" +
"</solr>"; "</solr>";
private static final String CUSTOM_HANDLERS_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<solr>" +
" <str name=\"collectionsHandler\">" + CustomCollectionsHandler.class.getName() + "</str>" +
" <str name=\"infoHandler\">" + CustomInfoHandler.class.getName() + "</str>" +
" <str name=\"adminHandler\">" + CustomCoreAdminHandler.class.getName() + "</str>" +
"</solr>";
public static class CustomCollectionsHandler extends CollectionsHandler {
public CustomCollectionsHandler(CoreContainer cc) {
super(cc);
}
}
public static class CustomInfoHandler extends InfoHandler {
public CustomInfoHandler(CoreContainer cc) {
super(cc);
}
}
public static class CustomCoreAdminHandler extends CoreAdminHandler {
public CustomCoreAdminHandler(CoreContainer cc) {
super(cc);
}
}
@Test
public void testCustomHandlers() throws Exception {
ConfigSolr config = ConfigSolr.fromString(CUSTOM_HANDLERS_SOLR_XML);
SolrResourceLoader loader = new SolrResourceLoader("solr/collection1");
CoreContainer cc = new CoreContainer(loader, config);
try {
cc.load();
assertThat(cc.getCollectionsHandler(), is(instanceOf(CustomCollectionsHandler.class)));
assertThat(cc.getInfoHandler(), is(instanceOf(CustomInfoHandler.class)));
assertThat(cc.getMultiCoreHandler(), is(instanceOf(CustomCoreAdminHandler.class)));
}
finally {
cc.shutdown();
}
}
} }

View File

@ -47,6 +47,8 @@ public class TestSolrXml extends SolrTestCaseJ4 {
ConfigSolr cfg = ConfigSolr.fromSolrHome(loader, solrHome.getAbsolutePath()); ConfigSolr cfg = ConfigSolr.fromSolrHome(loader, solrHome.getAbsolutePath());
assertEquals("Did not find expected value", cfg.get(ConfigSolr.CfgProp.SOLR_ADMINHANDLER, null), "testAdminHandler"); assertEquals("Did not find expected value", cfg.get(ConfigSolr.CfgProp.SOLR_ADMINHANDLER, null), "testAdminHandler");
assertEquals("Did not find expected value", cfg.get(ConfigSolr.CfgProp.SOLR_COLLECTIONSHANDLER, null), "testCollectionsHandler");
assertEquals("Did not find expected value", cfg.get(ConfigSolr.CfgProp.SOLR_INFOHANDLER, null), "testInfoHandler");
assertEquals("Did not find expected value", cfg.getInt(ConfigSolr.CfgProp.SOLR_CORELOADTHREADS, 0), 11); assertEquals("Did not find expected value", cfg.getInt(ConfigSolr.CfgProp.SOLR_CORELOADTHREADS, 0), 11);
assertEquals("Did not find expected value", cfg.get(ConfigSolr.CfgProp.SOLR_COREROOTDIRECTORY, null), "testCoreRootDirectory"); assertEquals("Did not find expected value", cfg.get(ConfigSolr.CfgProp.SOLR_COREROOTDIRECTORY, null), "testCoreRootDirectory");
assertEquals("Did not find expected value", cfg.getInt(ConfigSolr.CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, 0), 22); assertEquals("Did not find expected value", cfg.getInt(ConfigSolr.CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, 0), 22);