mirror of https://github.com/apache/lucene.git
SOLR-4672: Requests attempting to use SolrCores which had init failures now result in 500 error responses with the details about the init failure, instead of 404 error responses
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1465749 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9dc0040467
commit
71397bebd4
|
@ -200,6 +200,12 @@ Other Changes
|
|||
Existing solr.xml files that do not have these options explicitly specified
|
||||
should be updated accordingly. (hossman)
|
||||
|
||||
* SOLR-4672: Requests attempting to use SolrCores which had init failures
|
||||
(that would be reported by CoreAdmin STATUS requests) now result in 500
|
||||
error responses with the details about the init failure, instead of 404
|
||||
error responses. (hossman)
|
||||
|
||||
|
||||
================== 4.2.1 ==================
|
||||
|
||||
Versions of Major Components
|
||||
|
|
|
@ -1138,10 +1138,13 @@ public class CoreContainer
|
|||
}
|
||||
}
|
||||
}
|
||||
/** Gets a core by name and increase its refcount.
|
||||
/**
|
||||
* Gets a core by name and increase its refcount.
|
||||
*
|
||||
* @see SolrCore#close()
|
||||
* @param name the core name
|
||||
* @return the core if found
|
||||
* @return the core if found, null if a SolrCore by this name does not exist
|
||||
* @exception SolrException if a SolrCore with this name failed to be initialized
|
||||
*/
|
||||
public SolrCore getCore(String name) {
|
||||
|
||||
|
@ -1157,6 +1160,16 @@ public class CoreContainer
|
|||
// OK, it's not presently in any list, is it in the list of dynamic cores but not loaded yet? If so, load it.
|
||||
CoreDescriptor desc = coreMaps.getDynamicDescriptor(name);
|
||||
if (desc == null) { //Nope, no transient core with this name
|
||||
|
||||
// if there was an error initalizing this core, throw a 500
|
||||
// error with the details for clients attempting to access it.
|
||||
Exception e = getCoreInitFailures().get(name);
|
||||
if (null != e) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR, "SolrCore '" + name +
|
||||
"' is not available due to init failure: " +
|
||||
e.getMessage(), e);
|
||||
}
|
||||
// otherwise the user is simply asking for something that doesn't exist.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,21 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
|
||||
0 < fail.getCause().getMessage().indexOf("bogus_path"));
|
||||
|
||||
// check that we get null accessing a non-existent core
|
||||
assertNull(cc.getCore("does_not_exist"));
|
||||
// check that we get a 500 accessing the core with an init failure
|
||||
try {
|
||||
SolrCore c = cc.getCore("bogus");
|
||||
fail("Failed to get Exception on accessing core with init failure");
|
||||
} catch (SolrException ex) {
|
||||
assertEquals(500, ex.code());
|
||||
// double wrapped
|
||||
String cause = ex.getCause().getCause().getMessage();
|
||||
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
||||
0 < cause.indexOf("bogus_path"));
|
||||
|
||||
}
|
||||
|
||||
// let the test end here, with some recorded failures, and let cleanUp()
|
||||
// verify that there is no problem shuting down CoreContainer with known
|
||||
// SolrCore failures
|
||||
|
@ -167,6 +182,19 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
assertTrue("init failure doesn't mention problem: " + fail.getMessage(),
|
||||
0 < fail.getMessage().indexOf("DummyMergePolicy"));
|
||||
|
||||
// check that we get null accessing a non-existent core
|
||||
assertNull(cc.getCore("does_not_exist"));
|
||||
// check that we get a 500 accessing the core with an init failure
|
||||
try {
|
||||
SolrCore c = cc.getCore("col_bad");
|
||||
fail("Failed to get Exception on accessing core with init failure");
|
||||
} catch (SolrException ex) {
|
||||
assertEquals(500, ex.code());
|
||||
// double wrapped
|
||||
String cause = ex.getCause().getCause().getMessage();
|
||||
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
||||
0 < cause.indexOf("DummyMergePolicy"));
|
||||
}
|
||||
|
||||
// -----
|
||||
// "fix" the bad collection
|
||||
|
@ -217,6 +245,19 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
|
||||
0 < fail.getCause().getMessage().indexOf("bogus_path"));
|
||||
|
||||
// check that we get null accessing a non-existent core
|
||||
assertNull(cc.getCore("does_not_exist"));
|
||||
// check that we get a 500 accessing the core with an init failure
|
||||
try {
|
||||
SolrCore c = cc.getCore("bogus");
|
||||
fail("Failed to get Exception on accessing core with init failure");
|
||||
} catch (SolrException ex) {
|
||||
assertEquals(500, ex.code());
|
||||
// double wrapped
|
||||
String cause = ex.getCause().getCause().getMessage();
|
||||
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
||||
0 < cause.indexOf("bogus_path"));
|
||||
}
|
||||
|
||||
// -----
|
||||
// register bogus as an alias for col_ok and confirm failure goes away
|
||||
|
@ -281,7 +322,6 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
assertTrue("init failure doesn't mention problem: " + fail.toString(),
|
||||
0 < ((SAXParseException)fail).getSystemId().indexOf("solrconfig.xml"));
|
||||
|
||||
|
||||
// ----
|
||||
// fix col_bad's config (again) and RELOAD to fix failure
|
||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-basic.xml"),
|
||||
|
|
Loading…
Reference in New Issue