6
6
package org .elasticsearch .xpack .watcher ;
7
7
8
8
import org .apache .logging .log4j .Logger ;
9
+ import org .apache .lucene .util .SetOnce ;
9
10
import org .elasticsearch .action .ActionRequest ;
10
11
import org .elasticsearch .action .ActionResponse ;
11
12
import org .elasticsearch .bootstrap .BootstrapCheck ;
38
39
import org .elasticsearch .node .Node ;
39
40
import org .elasticsearch .plugins .ActionPlugin ;
40
41
import org .elasticsearch .plugins .Plugin ;
42
+ import org .elasticsearch .plugins .ReloadablePlugin ;
41
43
import org .elasticsearch .plugins .ScriptPlugin ;
42
44
import org .elasticsearch .rest .RestController ;
43
45
import org .elasticsearch .rest .RestHandler ;
123
125
import org .elasticsearch .xpack .watcher .input .simple .SimpleInputFactory ;
124
126
import org .elasticsearch .xpack .watcher .input .transform .TransformInput ;
125
127
import org .elasticsearch .xpack .watcher .input .transform .TransformInputFactory ;
128
+ import org .elasticsearch .xpack .watcher .notification .NotificationService ;
126
129
import org .elasticsearch .xpack .watcher .notification .email .Account ;
127
130
import org .elasticsearch .xpack .watcher .notification .email .EmailService ;
128
131
import org .elasticsearch .xpack .watcher .notification .email .HtmlSanitizer ;
194
197
195
198
import static java .util .Collections .emptyList ;
196
199
197
- public class Watcher extends Plugin implements ActionPlugin , ScriptPlugin {
200
+ public class Watcher extends Plugin implements ActionPlugin , ScriptPlugin , ReloadablePlugin {
198
201
199
202
// This setting is only here for backward compatibility reasons as 6.x indices made use of it. It can be removed in 8.x.
200
203
@ Deprecated
@@ -221,6 +224,11 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin {
221
224
protected final boolean transportClient ;
222
225
protected final boolean enabled ;
223
226
protected final Environment env ;
227
+ private SetOnce <EmailService > emailService = new SetOnce <>();
228
+ private SetOnce <HipChatService > hipChatService = new SetOnce <>();
229
+ private SetOnce <JiraService > jiraService = new SetOnce <>();
230
+ private SetOnce <SlackService > slackService = new SetOnce <>();
231
+ private SetOnce <PagerDutyService > pagerDutyService = new SetOnce <>();
224
232
225
233
public Watcher (final Settings settings ) {
226
234
this .settings = settings ;
@@ -269,11 +277,11 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
269
277
httpClient = new HttpClient (settings , httpAuthRegistry , getSslService ());
270
278
271
279
// notification
272
- EmailService emailService = new EmailService (settings , cryptoService , clusterService .getClusterSettings ());
273
- HipChatService hipChatService = new HipChatService (settings , httpClient , clusterService .getClusterSettings ());
274
- JiraService jiraService = new JiraService (settings , httpClient , clusterService .getClusterSettings ());
275
- SlackService slackService = new SlackService (settings , httpClient , clusterService .getClusterSettings ());
276
- PagerDutyService pagerDutyService = new PagerDutyService (settings , httpClient , clusterService .getClusterSettings ());
280
+ emailService . set ( new EmailService (settings , cryptoService , clusterService .getClusterSettings () ));
281
+ hipChatService . set ( new HipChatService (settings , httpClient , clusterService .getClusterSettings () ));
282
+ jiraService . set ( new JiraService (settings , httpClient , clusterService .getClusterSettings () ));
283
+ slackService . set ( new SlackService (settings , httpClient , clusterService .getClusterSettings () ));
284
+ pagerDutyService . set ( new PagerDutyService (settings , httpClient , clusterService .getClusterSettings () ));
277
285
278
286
TextTemplateEngine templateEngine = new TextTemplateEngine (settings , scriptService );
279
287
Map <String , EmailAttachmentParser > emailAttachmentParsers = new HashMap <>();
@@ -300,14 +308,15 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
300
308
301
309
// actions
302
310
final Map <String , ActionFactory > actionFactoryMap = new HashMap <>();
303
- actionFactoryMap .put (EmailAction .TYPE , new EmailActionFactory (settings , emailService , templateEngine , emailAttachmentsParser ));
311
+ actionFactoryMap .put (EmailAction .TYPE , new EmailActionFactory (settings , emailService .get (), templateEngine ,
312
+ emailAttachmentsParser ));
304
313
actionFactoryMap .put (WebhookAction .TYPE , new WebhookActionFactory (settings , httpClient , httpTemplateParser , templateEngine ));
305
314
actionFactoryMap .put (IndexAction .TYPE , new IndexActionFactory (settings , client ));
306
315
actionFactoryMap .put (LoggingAction .TYPE , new LoggingActionFactory (settings , templateEngine ));
307
- actionFactoryMap .put (HipChatAction .TYPE , new HipChatActionFactory (settings , templateEngine , hipChatService ));
308
- actionFactoryMap .put (JiraAction .TYPE , new JiraActionFactory (settings , templateEngine , jiraService ));
309
- actionFactoryMap .put (SlackAction .TYPE , new SlackActionFactory (settings , templateEngine , slackService ));
310
- actionFactoryMap .put (PagerDutyAction .TYPE , new PagerDutyActionFactory (settings , templateEngine , pagerDutyService ));
316
+ actionFactoryMap .put (HipChatAction .TYPE , new HipChatActionFactory (settings , templateEngine , hipChatService . get () ));
317
+ actionFactoryMap .put (JiraAction .TYPE , new JiraActionFactory (settings , templateEngine , jiraService . get () ));
318
+ actionFactoryMap .put (SlackAction .TYPE , new SlackActionFactory (settings , templateEngine , slackService . get () ));
319
+ actionFactoryMap .put (PagerDutyAction .TYPE , new PagerDutyActionFactory (settings , templateEngine , pagerDutyService . get () ));
311
320
final ActionRegistry registry = new ActionRegistry (actionFactoryMap , conditionRegistry , transformRegistry , getClock (),
312
321
getLicenseState ());
313
322
@@ -367,7 +376,8 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
367
376
368
377
return Arrays .asList (registry , inputRegistry , historyStore , triggerService , triggeredWatchParser ,
369
378
watcherLifeCycleService , executionService , triggerEngineListener , watcherService , watchParser ,
370
- configuredTriggerEngine , triggeredWatchStore , watcherSearchTemplateService , slackService , pagerDutyService , hipChatService );
379
+ configuredTriggerEngine , triggeredWatchStore , watcherSearchTemplateService , slackService .get (), pagerDutyService .get (),
380
+ hipChatService .get ());
371
381
}
372
382
373
383
protected TriggerEngine getTriggerEngine (Clock clock , ScheduleRegistry scheduleRegistry ) {
@@ -613,4 +623,33 @@ public List<ScriptContext> getContexts() {
613
623
public void close () throws IOException {
614
624
IOUtils .closeWhileHandlingException (httpClient );
615
625
}
626
+
627
+ /**
628
+ * Used to detect which {@link NotificationService} get reloaded. Also useful for testing the reload in tests.
629
+ * @return
630
+ */
631
+ protected List <NotificationService > getReloadableServices () {
632
+ return Arrays .asList (
633
+ emailService .get (),
634
+ hipChatService .get (),
635
+ jiraService .get (),
636
+ slackService .get (),
637
+ pagerDutyService .get ());
638
+ }
639
+
640
+ /**
641
+ * Reloads all reloadable services' settings.
642
+ * @param settings
643
+ * Settings used while reloading the plugin. All values are
644
+ * retrievable, including the values stored in the node's keystore.
645
+ * The setting values are the initial ones, from when the node has be
646
+ * started, i.e. they don't follow dynamic updates.
647
+ * @throws Exception
648
+ */
649
+ @ Override
650
+ public void reload (Settings settings ) throws Exception {
651
+ for (NotificationService service : getReloadableServices ()) {
652
+ service .loadSettings (settings );
653
+ }
654
+ }
616
655
}
0 commit comments