Skip to content

Commit 7efc856

Browse files
committed
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.
1 parent b924b0c commit 7efc856

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/NotificationService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
import org.elasticsearch.common.collect.Tuple;
99
import org.elasticsearch.common.component.AbstractComponent;
10+
import org.elasticsearch.common.settings.ClusterSettings;
11+
import org.elasticsearch.common.settings.Setting;
1012
import org.elasticsearch.common.settings.Settings;
1113
import org.elasticsearch.common.settings.SettingsException;
1214

1315
import java.util.Collections;
1416
import java.util.HashMap;
17+
import java.util.List;
1518
import java.util.Map;
1619
import java.util.function.BiFunction;
1720

@@ -25,7 +28,14 @@ public abstract class NotificationService<Account> extends AbstractComponent {
2528
private Map<String, Account> accounts;
2629
private Account defaultAccount;
2730

28-
public NotificationService(Settings settings, String type) {
31+
public NotificationService(Settings settings, String type,
32+
ClusterSettings clusterSettings, List<Setting<?>> pluginSettings) {
33+
this(settings, type);
34+
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, pluginSettings);
35+
}
36+
37+
// Used for testing only
38+
NotificationService(Settings settings, String type) {
2939
super(settings);
3040
this.type = type;
3141
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/email/EmailService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ public class EmailService extends NotificationService<Account> {
9494
private final CryptoService cryptoService;
9595

9696
public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) {
97-
super(settings, "email");
97+
super(settings, "email", clusterSettings, EmailService.getSettings());
9898
this.cryptoService = cryptoService;
99-
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
10099
// ensure logging of setting changes
101100
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
102101
clusterSettings.addAffixUpdateConsumer(SETTING_PROFILE, (s, o) -> {}, (s, o) -> {});

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/hipchat/HipChatService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ public class HipChatService extends NotificationService<HipChatAccount> {
6464
private HipChatServer defaultServer;
6565

6666
public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
67-
super(settings, "hipchat");
67+
super(settings, "hipchat", clusterSettings, HipChatService.getSettings());
6868
this.httpClient = httpClient;
69-
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
7069
// ensure logging of setting changes
7170
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
7271
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_HOST, (s) -> {});

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/jira/JiraService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ public class JiraService extends NotificationService<JiraAccount> {
6060
private final HttpClient httpClient;
6161

6262
public JiraService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
63-
super(settings, "jira");
63+
super(settings, "jira", clusterSettings, JiraService.getSettings());
6464
this.httpClient = httpClient;
65-
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
6665
// ensure logging of setting changes
6766
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
6867
clusterSettings.addAffixUpdateConsumer(SETTING_ALLOW_HTTP, (s, o) -> {}, (s, o) -> {});

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/pagerduty/PagerDutyService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class PagerDutyService extends NotificationService<PagerDutyAccount> {
3939
private final HttpClient httpClient;
4040

4141
public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
42-
super(settings, "pagerduty");
42+
super(settings, "pagerduty", clusterSettings, PagerDutyService.getSettings());
4343
this.httpClient = httpClient;
4444
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
4545
clusterSettings.addAffixUpdateConsumer(SETTING_SERVICE_API_KEY, (s, o) -> {}, (s, o) -> {});

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/SlackService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ public class SlackService extends NotificationService<SlackAccount> {
3939
private final HttpClient httpClient;
4040

4141
public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
42-
super(settings, "slack");
42+
super(settings, "slack", clusterSettings, SlackService.getSettings());
4343
this.httpClient = httpClient;
44-
clusterSettings.addSettingsUpdateConsumer(this::setAccountSetting, getSettings());
4544
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
4645
clusterSettings.addAffixUpdateConsumer(SETTING_URL, (s, o) -> {}, (s, o) -> {});
4746
clusterSettings.addAffixUpdateConsumer(SETTING_URL_SECURE, (s, o) -> {}, (s, o) -> {});

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/notification/NotificationServiceTests.java renamed to x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/NotificationServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.notification;
6+
package org.elasticsearch.xpack.watcher.notification;
77

88
import org.elasticsearch.common.settings.Settings;
99
import org.elasticsearch.common.settings.SettingsException;
@@ -90,4 +90,4 @@ protected String createAccount(String name, Settings accountSettings) {
9090
return name;
9191
}
9292
}
93-
}
93+
}

0 commit comments

Comments
 (0)