From 3bda78e43b125a678778fe175c2b3fc623e0c515 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 9 Jun 2015 09:45:18 +0200 Subject: [PATCH] ResourceWatcher: Rename settings to prevent watcher clash The ResourceWatcher used settings prefixed `watcher.`, which potentially could clash with the watcher plugin. In order to prevent confusion, the settings have been renamed to `resource.reload` prefixes. This also uses the deprecation logging infrastructure introduced in #11033 to log deprecated settings and their alternative at startup. Closes #11175 --- .../common/component/AbstractComponent.java | 19 ++++++++++++++++ .../watcher/ResourceWatcherService.java | 22 ++++++++++++------- .../watcher/ResourceWatcherServiceTests.java | 8 +++---- docs/reference/migration/migrate_2_0.asciidoc | 11 ++++++++++ docs/reference/modules/scripting.asciidoc | 2 +- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/component/AbstractComponent.java b/core/src/main/java/org/elasticsearch/common/component/AbstractComponent.java index a31bf119402..bed1f06676a 100644 --- a/core/src/main/java/org/elasticsearch/common/component/AbstractComponent.java +++ b/core/src/main/java/org/elasticsearch/common/component/AbstractComponent.java @@ -19,6 +19,7 @@ package org.elasticsearch.common.component; +import com.google.common.base.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -51,4 +52,22 @@ public abstract class AbstractComponent { public final String nodeName() { return settings.get("name", ""); } + + /** + * Checks for a deprecated setting and logs the correct alternative + */ + protected void logDeprecatedSetting(String settingName, String alternativeName) { + if (!Strings.isNullOrEmpty(settings.get(settingName))) { + deprecationLogger.deprecated("Setting [{}] is deprecated, use [{}] instead", settingName, alternativeName); + } + } + + /** + * Checks for a removed setting and logs the correct alternative + */ + protected void logRemovedSetting(String settingName, String alternativeName) { + if (!Strings.isNullOrEmpty(settings.get(settingName))) { + deprecationLogger.deprecated("Setting [{}] has been removed, use [{}] instead", settingName, alternativeName); + } + } } diff --git a/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java b/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java index ebb5bb84623..4719bd997d7 100644 --- a/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java +++ b/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java @@ -35,12 +35,12 @@ import java.util.concurrent.ScheduledFuture; * * Other elasticsearch services can register their resource watchers with this service using {@link #add(ResourceWatcher)} * method. This service will call {@link org.elasticsearch.watcher.ResourceWatcher#checkAndNotify()} method of all - * registered watcher periodically. The frequency of checks can be specified using {@code watcher.interval} setting, which - * defaults to {@code 60s}. The service can be disabled by setting {@code watcher.enabled} setting to {@code false}. + * registered watcher periodically. The frequency of checks can be specified using {@code resource.reload.interval} setting, which + * defaults to {@code 60s}. The service can be disabled by setting {@code resource.reload.enabled} setting to {@code false}. */ public class ResourceWatcherService extends AbstractLifecycleComponent { - public static enum Frequency { + public enum Frequency { /** * Defaults to 5 seconds @@ -59,7 +59,7 @@ public class ResourceWatcherService extends AbstractLifecycleComponent