Better error messaging when postings_format can be resolved or when a custom postings_format type can't be instantiated.
Relates to #2893
This commit is contained in:
parent
9a1c03408b
commit
bcc16654d2
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Scopes;
|
import org.elasticsearch.common.inject.Scopes;
|
||||||
import org.elasticsearch.common.inject.assistedinject.FactoryProvider;
|
import org.elasticsearch.common.inject.assistedinject.FactoryProvider;
|
||||||
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
||||||
|
import org.elasticsearch.common.settings.NoClassSettingsException;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.codec.postingsformat.PostingFormats;
|
import org.elasticsearch.index.codec.postingsformat.PostingFormats;
|
||||||
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
||||||
|
@ -92,13 +93,17 @@ public class CodecModule extends AbstractModule {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
Settings settings = entry.getValue();
|
Settings settings = entry.getValue();
|
||||||
|
|
||||||
Class<? extends PostingsFormatProvider> type =
|
String sType = settings.get("type");
|
||||||
settings.getAsClass("type", null, "org.elasticsearch.index.codec.postingsformat.", "PostingsFormatProvider");
|
if (sType == null || sType.trim().isEmpty()) {
|
||||||
|
|
||||||
if (type == null) {
|
|
||||||
// nothing found, see if its in bindings as a binding name
|
|
||||||
throw new ElasticSearchIllegalArgumentException("PostingsFormat Factory [" + name + "] must have a type associated with it");
|
throw new ElasticSearchIllegalArgumentException("PostingsFormat Factory [" + name + "] must have a type associated with it");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Class<? extends PostingsFormatProvider> type;
|
||||||
|
try {
|
||||||
|
type = settings.getAsClass("type", null, "org.elasticsearch.index.codec.postingsformat.", "PostingsFormatProvider");
|
||||||
|
} catch (NoClassSettingsException e) {
|
||||||
|
throw new ElasticSearchIllegalArgumentException("The specified type [" + sType + "] for postingsFormat Factory [" + name + "] can't be found");
|
||||||
|
}
|
||||||
postingFormatProviders.put(name, type);
|
postingFormatProviders.put(name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class PostingsFormatService extends AbstractIndexComponent {
|
||||||
|
|
||||||
public PostingsFormatProvider get(String name) throws ElasticSearchIllegalArgumentException {
|
public PostingsFormatProvider get(String name) throws ElasticSearchIllegalArgumentException {
|
||||||
PostingsFormatProvider provider = providers.get(name);
|
PostingsFormatProvider provider = providers.get(name);
|
||||||
if (name == null) {
|
if (provider == null) {
|
||||||
throw new ElasticSearchIllegalArgumentException("failed to find postings_format [" + name + "]");
|
throw new ElasticSearchIllegalArgumentException("failed to find postings_format [" + name + "]");
|
||||||
}
|
}
|
||||||
return provider;
|
return provider;
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
|
|
||||||
package org.elasticsearch.indices;
|
package org.elasticsearch.indices;
|
||||||
|
|
||||||
|
import org.elasticsearch.ElasticSearchWrapperException;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.IndexException;
|
import org.elasticsearch.index.IndexException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class IndexCreationException extends IndexException {
|
public class IndexCreationException extends IndexException implements ElasticSearchWrapperException {
|
||||||
|
|
||||||
public IndexCreationException(Index index, Throwable cause) {
|
public IndexCreationException(Index index, Throwable cause) {
|
||||||
super(index, "failed to create index", cause);
|
super(index, "failed to create index", cause);
|
||||||
|
|
Loading…
Reference in New Issue