Consolidate watcher setting update registration (#31762)

Previously the call to register a listener for settings updates was in
each individual service, rather than in the notification service
itself. This change ensures that each child of the notification service
gets registered with the settings update consumer.
This commit is contained in:
Michael Basnight 2018-07-03 11:29:39 -05:00 committed by GitHub
parent dc869aa149
commit e65115ae5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 12 deletions

View File

@ -7,11 +7,14 @@ package org.elasticsearch.xpack.watcher.notification;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.settings.SettingsException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -25,7 +28,14 @@ public abstract class NotificationService<Account> extends AbstractComponent {
private Map<String, Account> accounts; private Map<String, Account> accounts;
private Account defaultAccount; private Account defaultAccount;
public NotificationService(Settings settings, String type) { public NotificationService(Settings settings, String type,
ClusterSettings clusterSettings, List<Setting<?>> pluginSettings) {
this(settings, type);
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, pluginSettings);
}
// Used for testing only
NotificationService(Settings settings, String type) {
super(settings); super(settings);
this.type = type; this.type = type;
} }

View File

@ -94,9 +94,8 @@ public class EmailService extends NotificationService<Account> {
private final CryptoService cryptoService; private final CryptoService cryptoService;
public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) { public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) {
super(settings, "email"); super(settings, "email", clusterSettings, EmailService.getSettings());
this.cryptoService = cryptoService; this.cryptoService = cryptoService;
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
// ensure logging of setting changes // ensure logging of setting changes
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {}); clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
clusterSettings.addAffixUpdateConsumer(SETTING_PROFILE, (s, o) -> {}, (s, o) -> {}); clusterSettings.addAffixUpdateConsumer(SETTING_PROFILE, (s, o) -> {}, (s, o) -> {});

View File

@ -65,9 +65,8 @@ public class HipChatService extends NotificationService<HipChatAccount> {
private HipChatServer defaultServer; private HipChatServer defaultServer;
public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
super(settings, "hipchat"); super(settings, "hipchat", clusterSettings, HipChatService.getSettings());
this.httpClient = httpClient; this.httpClient = httpClient;
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
// ensure logging of setting changes // ensure logging of setting changes
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {}); clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_HOST, (s) -> {}); clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_HOST, (s) -> {});

View File

@ -60,9 +60,8 @@ public class JiraService extends NotificationService<JiraAccount> {
private final HttpClient httpClient; private final HttpClient httpClient;
public JiraService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { public JiraService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
super(settings, "jira"); super(settings, "jira", clusterSettings, JiraService.getSettings());
this.httpClient = httpClient; this.httpClient = httpClient;
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
// ensure logging of setting changes // ensure logging of setting changes
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {}); clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
clusterSettings.addAffixUpdateConsumer(SETTING_ALLOW_HTTP, (s, o) -> {}, (s, o) -> {}); clusterSettings.addAffixUpdateConsumer(SETTING_ALLOW_HTTP, (s, o) -> {}, (s, o) -> {});

View File

@ -39,7 +39,7 @@ public class PagerDutyService extends NotificationService<PagerDutyAccount> {
private final HttpClient httpClient; private final HttpClient httpClient;
public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
super(settings, "pagerduty"); super(settings, "pagerduty", clusterSettings, PagerDutyService.getSettings());
this.httpClient = httpClient; this.httpClient = httpClient;
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {}); clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
clusterSettings.addAffixUpdateConsumer(SETTING_SERVICE_API_KEY, (s, o) -> {}, (s, o) -> {}); clusterSettings.addAffixUpdateConsumer(SETTING_SERVICE_API_KEY, (s, o) -> {}, (s, o) -> {});

View File

@ -39,9 +39,8 @@ public class SlackService extends NotificationService<SlackAccount> {
private final HttpClient httpClient; private final HttpClient httpClient;
public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
super(settings, "slack"); super(settings, "slack", clusterSettings, SlackService.getSettings());
this.httpClient = httpClient; this.httpClient = httpClient;
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {}); clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
clusterSettings.addAffixUpdateConsumer(SETTING_URL, (s, o) -> {}, (s, o) -> {}); clusterSettings.addAffixUpdateConsumer(SETTING_URL, (s, o) -> {}, (s, o) -> {});
clusterSettings.addAffixUpdateConsumer(SETTING_URL_SECURE, (s, o) -> {}, (s, o) -> {}); clusterSettings.addAffixUpdateConsumer(SETTING_URL_SECURE, (s, o) -> {}, (s, o) -> {});

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.notification; package org.elasticsearch.xpack.watcher.notification;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.settings.SettingsException;
@ -90,4 +90,4 @@ public class NotificationServiceTests extends ESTestCase {
return name; return name;
} }
} }
} }