mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 05:15:04 +00:00
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:
parent
dc869aa149
commit
e65115ae5a
@ -7,11 +7,14 @@ package org.elasticsearch.xpack.watcher.notification;
|
||||
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
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.SettingsException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@ -25,7 +28,14 @@ public abstract class NotificationService<Account> extends AbstractComponent {
|
||||
private Map<String, Account> accounts;
|
||||
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);
|
||||
this.type = type;
|
||||
}
|
||||
|
@ -94,9 +94,8 @@ public class EmailService extends NotificationService<Account> {
|
||||
private final CryptoService cryptoService;
|
||||
|
||||
public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) {
|
||||
super(settings, "email");
|
||||
super(settings, "email", clusterSettings, EmailService.getSettings());
|
||||
this.cryptoService = cryptoService;
|
||||
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
|
||||
// ensure logging of setting changes
|
||||
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
|
||||
clusterSettings.addAffixUpdateConsumer(SETTING_PROFILE, (s, o) -> {}, (s, o) -> {});
|
||||
|
@ -65,9 +65,8 @@ public class HipChatService extends NotificationService<HipChatAccount> {
|
||||
private HipChatServer defaultServer;
|
||||
|
||||
public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||
super(settings, "hipchat");
|
||||
super(settings, "hipchat", clusterSettings, HipChatService.getSettings());
|
||||
this.httpClient = httpClient;
|
||||
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
|
||||
// ensure logging of setting changes
|
||||
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
|
||||
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_HOST, (s) -> {});
|
||||
|
@ -60,9 +60,8 @@ public class JiraService extends NotificationService<JiraAccount> {
|
||||
private final HttpClient httpClient;
|
||||
|
||||
public JiraService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||
super(settings, "jira");
|
||||
super(settings, "jira", clusterSettings, JiraService.getSettings());
|
||||
this.httpClient = httpClient;
|
||||
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
|
||||
// ensure logging of setting changes
|
||||
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
|
||||
clusterSettings.addAffixUpdateConsumer(SETTING_ALLOW_HTTP, (s, o) -> {}, (s, o) -> {});
|
||||
|
@ -39,7 +39,7 @@ public class PagerDutyService extends NotificationService<PagerDutyAccount> {
|
||||
private final HttpClient httpClient;
|
||||
|
||||
public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||
super(settings, "pagerduty");
|
||||
super(settings, "pagerduty", clusterSettings, PagerDutyService.getSettings());
|
||||
this.httpClient = httpClient;
|
||||
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
|
||||
clusterSettings.addAffixUpdateConsumer(SETTING_SERVICE_API_KEY, (s, o) -> {}, (s, o) -> {});
|
||||
|
@ -39,9 +39,8 @@ public class SlackService extends NotificationService<SlackAccount> {
|
||||
private final HttpClient httpClient;
|
||||
|
||||
public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||
super(settings, "slack");
|
||||
super(settings, "slack", clusterSettings, SlackService.getSettings());
|
||||
this.httpClient = httpClient;
|
||||
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
|
||||
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
|
||||
clusterSettings.addAffixUpdateConsumer(SETTING_URL, (s, o) -> {}, (s, o) -> {});
|
||||
clusterSettings.addAffixUpdateConsumer(SETTING_URL_SECURE, (s, o) -> {}, (s, o) -> {});
|
||||
|
@ -3,7 +3,7 @@
|
||||
* or more contributor license agreements. Licensed under 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.SettingsException;
|
||||
@ -90,4 +90,4 @@ public class NotificationServiceTests extends ESTestCase {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user