use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class SettingsTests method testLenientBooleanForPreEs6Index.
//#getAsBooleanLenientForPreEs6Indices is the test subject
@SuppressWarnings("deprecation")
public void testLenientBooleanForPreEs6Index() throws IOException {
// time to say goodbye?
assertTrue("It's time to implement #22298. Please delete this test and Settings#getAsBooleanLenientForPreEs6Indices().", Version.CURRENT.minimumCompatibilityVersion().before(Version.V_6_0_0_alpha1_UNRELEASED));
String falsy = randomFrom("false", "off", "no", "0");
String truthy = randomFrom("true", "on", "yes", "1");
Settings settings = Settings.builder().put("foo", falsy).put("bar", truthy).build();
final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("testLenientBooleanForPreEs6Index"));
assertFalse(settings.getAsBooleanLenientForPreEs6Indices(Version.V_5_0_0, "foo", null, deprecationLogger));
assertTrue(settings.getAsBooleanLenientForPreEs6Indices(Version.V_5_0_0, "bar", null, deprecationLogger));
assertTrue(settings.getAsBooleanLenientForPreEs6Indices(Version.V_5_0_0, "baz", true, deprecationLogger));
List<String> expectedDeprecationWarnings = new ArrayList<>();
if (Booleans.isBoolean(falsy) == false) {
expectedDeprecationWarnings.add("The value [" + falsy + "] of setting [foo] is not coerced into boolean anymore. Please change this value to [false].");
}
if (Booleans.isBoolean(truthy) == false) {
expectedDeprecationWarnings.add("The value [" + truthy + "] of setting [bar] is not coerced into boolean anymore. Please change this value to [true].");
}
if (expectedDeprecationWarnings.isEmpty() == false) {
assertWarnings(expectedDeprecationWarnings.toArray(new String[1]));
}
}
use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class RestControllerTests method testRegisterAsDeprecatedHandler.
public void testRegisterAsDeprecatedHandler() {
RestController controller = mock(RestController.class);
RestRequest.Method method = randomFrom(RestRequest.Method.values());
String path = "/_" + randomAsciiOfLengthBetween(1, 6);
RestHandler handler = mock(RestHandler.class);
String deprecationMessage = randomAsciiOfLengthBetween(1, 10);
DeprecationLogger logger = mock(DeprecationLogger.class);
// don't want to test everything -- just that it actually wraps the handler
doCallRealMethod().when(controller).registerAsDeprecatedHandler(method, path, handler, deprecationMessage, logger);
controller.registerAsDeprecatedHandler(method, path, handler, deprecationMessage, logger);
verify(controller).registerHandler(eq(method), eq(path), any(DeprecationRestHandler.class));
}
use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class AnalysisRegistry method build.
public IndexAnalyzers build(IndexSettings indexSettings, Map<String, AnalyzerProvider<?>> analyzerProviders, Map<String, AnalyzerProvider<?>> normalizerProviders, Map<String, TokenizerFactory> tokenizerFactoryFactories, Map<String, CharFilterFactory> charFilterFactoryFactories, Map<String, TokenFilterFactory> tokenFilterFactoryFactories) {
Index index = indexSettings.getIndex();
analyzerProviders = new HashMap<>(analyzerProviders);
Logger logger = Loggers.getLogger(getClass(), indexSettings.getSettings());
DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
Map<String, NamedAnalyzer> analyzerAliases = new HashMap<>();
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
Map<String, NamedAnalyzer> normalizers = new HashMap<>();
for (Map.Entry<String, AnalyzerProvider<?>> entry : analyzerProviders.entrySet()) {
processAnalyzerFactory(deprecationLogger, indexSettings, entry.getKey(), entry.getValue(), analyzerAliases, analyzers, tokenFilterFactoryFactories, charFilterFactoryFactories, tokenizerFactoryFactories);
}
for (Map.Entry<String, AnalyzerProvider<?>> entry : normalizerProviders.entrySet()) {
processNormalizerFactory(deprecationLogger, indexSettings, entry.getKey(), entry.getValue(), normalizers, tokenFilterFactoryFactories, charFilterFactoryFactories);
}
for (Map.Entry<String, NamedAnalyzer> entry : analyzerAliases.entrySet()) {
String key = entry.getKey();
if (analyzers.containsKey(key) && ("default".equals(key) || "default_search".equals(key) || "default_search_quoted".equals(key)) == false) {
throw new IllegalStateException("already registered analyzer with name: " + key);
} else {
NamedAnalyzer configured = entry.getValue();
analyzers.put(key, configured);
}
}
if (!analyzers.containsKey("default")) {
processAnalyzerFactory(deprecationLogger, indexSettings, "default", new StandardAnalyzerProvider(indexSettings, null, "default", Settings.Builder.EMPTY_SETTINGS), analyzerAliases, analyzers, tokenFilterFactoryFactories, charFilterFactoryFactories, tokenizerFactoryFactories);
}
if (!analyzers.containsKey("default_search")) {
analyzers.put("default_search", analyzers.get("default"));
}
if (!analyzers.containsKey("default_search_quoted")) {
analyzers.put("default_search_quoted", analyzers.get("default_search"));
}
NamedAnalyzer defaultAnalyzer = analyzers.get("default");
if (defaultAnalyzer == null) {
throw new IllegalArgumentException("no default analyzer configured");
}
if (analyzers.containsKey("default_index")) {
final Version createdVersion = indexSettings.getIndexVersionCreated();
if (createdVersion.onOrAfter(Version.V_5_0_0_alpha1)) {
throw new IllegalArgumentException("setting [index.analysis.analyzer.default_index] is not supported anymore, use [index.analysis.analyzer.default] instead for index [" + index.getName() + "]");
} else {
deprecationLogger.deprecated("setting [index.analysis.analyzer.default_index] is deprecated, use [index.analysis.analyzer.default] instead for index [{}]", index.getName());
}
}
NamedAnalyzer defaultIndexAnalyzer = analyzers.containsKey("default_index") ? analyzers.get("default_index") : defaultAnalyzer;
NamedAnalyzer defaultSearchAnalyzer = analyzers.containsKey("default_search") ? analyzers.get("default_search") : defaultAnalyzer;
NamedAnalyzer defaultSearchQuoteAnalyzer = analyzers.containsKey("default_search_quote") ? analyzers.get("default_search_quote") : defaultSearchAnalyzer;
for (Map.Entry<String, NamedAnalyzer> analyzer : analyzers.entrySet()) {
if (analyzer.getKey().startsWith("_")) {
throw new IllegalArgumentException("analyzer name must not start with '_'. got \"" + analyzer.getKey() + "\"");
}
}
return new IndexAnalyzers(indexSettings, defaultIndexAnalyzer, defaultSearchAnalyzer, defaultSearchQuoteAnalyzer, unmodifiableMap(analyzers), unmodifiableMap(normalizers));
}
use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class Setting method checkDeprecation.
/** Logs a deprecation warning if the setting is deprecated and used. */
protected void checkDeprecation(Settings settings) {
// They're using the setting, so we need to tell them to stop
if (this.isDeprecated() && this.exists(settings)) {
// It would be convenient to show its replacement key, but replacement is often not so simple
final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(getClass()));
deprecationLogger.deprecated("[{}] setting was deprecated in Elasticsearch and will be removed in a future release! " + "See the breaking changes documentation for the next major version.", getKey());
}
}
use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class RestControllerTests method testRegisterWithDeprecatedHandler.
public void testRegisterWithDeprecatedHandler() {
final RestController controller = mock(RestController.class);
final RestRequest.Method method = randomFrom(RestRequest.Method.values());
final String path = "/_" + randomAsciiOfLengthBetween(1, 6);
final RestHandler handler = mock(RestHandler.class);
final RestRequest.Method deprecatedMethod = randomFrom(RestRequest.Method.values());
final String deprecatedPath = "/_" + randomAsciiOfLengthBetween(1, 6);
final DeprecationLogger logger = mock(DeprecationLogger.class);
final String deprecationMessage = "[" + deprecatedMethod.name() + " " + deprecatedPath + "] is deprecated! Use [" + method.name() + " " + path + "] instead.";
// don't want to test everything -- just that it actually wraps the handlers
doCallRealMethod().when(controller).registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath, logger);
controller.registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath, logger);
verify(controller).registerHandler(method, path, handler);
verify(controller).registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage, logger);
}
Aggregations