From 8552121be990640788c242f3035b8cfee1c810b6 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 26 May 2015 18:08:58 +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 --- docs/reference/modules/scripting.asciidoc | 2 +- .../common/component/AbstractComponent.java | 10 +++++++++ .../watcher/ResourceWatcherService.java | 22 ++++++++++++------- .../watcher/ResourceWatcherServiceTests.java | 8 +++---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/docs/reference/modules/scripting.asciidoc b/docs/reference/modules/scripting.asciidoc index 750802c4ec28b..60ecccc743c19 100644 --- a/docs/reference/modules/scripting.asciidoc +++ b/docs/reference/modules/scripting.asciidoc @@ -342,7 +342,7 @@ appropriate language. The `config/scripts` directory is scanned periodically for changes. New and changed scripts are reloaded and deleted script are removed from preloaded scripts cache. The reload frequency can be specified -using `watcher.interval` setting, which defaults to `60s`. +using `resource.reload.interval` setting, which defaults to `60s`. To disable script reloading completely set `script.auto_reload_enabled` to `false`. diff --git a/src/main/java/org/elasticsearch/common/component/AbstractComponent.java b/src/main/java/org/elasticsearch/common/component/AbstractComponent.java index a31bf11940282..6f29b2ee7a38c 100644 --- a/src/main/java/org/elasticsearch/common/component/AbstractComponent.java +++ b/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,13 @@ public AbstractComponent(Settings settings, Class customClass) { 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); + } + } } diff --git a/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java b/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java index ebb5bb846232f..2fb61f8e2c81c 100644 --- a/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java +++ b/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java @@ -35,12 +35,12 @@ * * 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 static enum Frequency { final TimeValue interval; - private Frequency(TimeValue interval) { + Frequency(TimeValue interval) { this.interval = interval; } } @@ -78,15 +78,21 @@ private Frequency(TimeValue interval) { @Inject public ResourceWatcherService(Settings settings, ThreadPool threadPool) { super(settings); - this.enabled = settings.getAsBoolean("watcher.enabled", true); + this.enabled = settings.getAsBoolean("resource.reload.enabled", true); this.threadPool = threadPool; - TimeValue interval = settings.getAsTime("watcher.interval.low", Frequency.LOW.interval); + TimeValue interval = settings.getAsTime("resource.reload.interval.low", Frequency.LOW.interval); lowMonitor = new ResourceMonitor(interval, Frequency.LOW); - interval = settings.getAsTime("watcher.interval.medium", settings.getAsTime("watcher.interval", Frequency.MEDIUM.interval)); + interval = settings.getAsTime("resource.reload.interval.medium", settings.getAsTime("resource.reload.interval", Frequency.MEDIUM.interval)); mediumMonitor = new ResourceMonitor(interval, Frequency.MEDIUM); - interval = settings.getAsTime("watcher.interval.high", Frequency.HIGH.interval); + interval = settings.getAsTime("resource.reload.interval.high", Frequency.HIGH.interval); highMonitor = new ResourceMonitor(interval, Frequency.HIGH); + + logDeprecatedSetting("watcher.enabled", "resource.reload.enabled"); + logDeprecatedSetting("watcher.interval", "resource.reload.interval"); + logDeprecatedSetting("watcher.interval.low", "resource.reload.interval.low"); + logDeprecatedSetting("watcher.interval.medium", "resource.reload.interval.medium"); + logDeprecatedSetting("watcher.interval.high", "resource.reload.interval.high"); } @Override diff --git a/src/test/java/org/elasticsearch/watcher/ResourceWatcherServiceTests.java b/src/test/java/org/elasticsearch/watcher/ResourceWatcherServiceTests.java index 501289eadcd0c..ebb4cdaf768e6 100644 --- a/src/test/java/org/elasticsearch/watcher/ResourceWatcherServiceTests.java +++ b/src/test/java/org/elasticsearch/watcher/ResourceWatcherServiceTests.java @@ -45,7 +45,7 @@ public void testSettings() throws Exception { // checking bwc settings = Settings.builder() - .put("watcher.interval", "40s") // only applies to medium + .put("resource.reload.interval", "40s") // only applies to medium .build(); service = new ResourceWatcherService(settings, threadPool); assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(5).millis())); @@ -54,9 +54,9 @@ public void testSettings() throws Exception { // checking custom settings = Settings.builder() - .put("watcher.interval.high", "10s") - .put("watcher.interval.medium", "20s") - .put("watcher.interval.low", "30s") + .put("resource.reload.interval.high", "10s") + .put("resource.reload.interval.medium", "20s") + .put("resource.reload.interval.low", "30s") .build(); service = new ResourceWatcherService(settings, threadPool); assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(10).millis()));