diff --git a/src/main/java/org/elasticsearch/alerts/Alert.java b/src/main/java/org/elasticsearch/alerts/Alert.java index 051aa121978..3067b85f100 100644 --- a/src/main/java/org/elasticsearch/alerts/Alert.java +++ b/src/main/java/org/elasticsearch/alerts/Alert.java @@ -7,6 +7,7 @@ package org.elasticsearch.alerts; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.alerts.actions.AlertAction; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.triggers.AlertTrigger; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.unit.TimeValue; diff --git a/src/main/java/org/elasticsearch/alerts/AlertAckState.java b/src/main/java/org/elasticsearch/alerts/AlertAckState.java index 141adefad60..b9bbf91ab30 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertAckState.java +++ b/src/main/java/org/elasticsearch/alerts/AlertAckState.java @@ -19,6 +19,7 @@ import java.io.IOException; * ACKED : This alert has been acknowleged, subsequent positive triggers will not cause actions to occur, a negative trigger will move the alert back into NOT_TRIGGERED state */ public enum AlertAckState implements ToXContent { + NOT_ACKABLE, ///@TODO perhaps null NEEDS_ACK, ACKED, diff --git a/src/main/java/org/elasticsearch/alerts/AlertingModule.java b/src/main/java/org/elasticsearch/alerts/AlertsModule.java similarity index 58% rename from src/main/java/org/elasticsearch/alerts/AlertingModule.java rename to src/main/java/org/elasticsearch/alerts/AlertsModule.java index 5540a894607..020298e5cfa 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertingModule.java +++ b/src/main/java/org/elasticsearch/alerts/AlertsModule.java @@ -9,48 +9,40 @@ package org.elasticsearch.alerts; import org.elasticsearch.alerts.actions.AlertActionRegistry; import org.elasticsearch.alerts.actions.AlertActionService; import org.elasticsearch.alerts.client.AlertsClientModule; -import org.elasticsearch.alerts.rest.*; -import org.elasticsearch.alerts.scheduler.AlertScheduler; +import org.elasticsearch.alerts.rest.AlertsRestModule; +import org.elasticsearch.alerts.scheduler.AlertsSchedulerModule; +import org.elasticsearch.alerts.support.TemplateUtils; import org.elasticsearch.alerts.support.init.InitializingModule; import org.elasticsearch.alerts.transport.AlertsTransportModule; -import org.elasticsearch.alerts.triggers.TriggerService; import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.SpawnModules; -public class AlertingModule extends AbstractModule implements SpawnModules { +public class AlertsModule extends AbstractModule implements SpawnModules { @Override public Iterable spawnModules() { return ImmutableList.of( new InitializingModule(), + new AlertsSchedulerModule(), new AlertsTransportModule(), - new AlertsClientModule()); + new AlertsClientModule(), + new AlertsRestModule()); } @Override protected void configure() { // Core components - bind(TemplateHelper.class).asEagerSingleton(); + bind(TemplateUtils.class).asEagerSingleton(); bind(AlertsStore.class).asEagerSingleton(); - bind(AlertService.class).asEagerSingleton(); + bind(AlertsService.class).asEagerSingleton(); bind(AlertActionService.class).asEagerSingleton(); - bind(TriggerService.class).asEagerSingleton(); - bind(AlertScheduler.class).asEagerSingleton(); bind(AlertActionRegistry.class).asEagerSingleton(); bind(ConfigurationService.class).asEagerSingleton(); - // Rest layer - bind(RestPutAlertAction.class).asEagerSingleton(); - bind(RestDeleteAlertAction.class).asEagerSingleton(); - bind(RestAlertsStatsAction.class).asEagerSingleton(); - bind(RestGetAlertAction.class).asEagerSingleton(); - bind(RestAlertServiceAction.class).asEagerSingleton(); - bind(RestConfigAlertAction.class).asEagerSingleton(); - bind(RestAckAlertAction.class).asEagerSingleton(); } } diff --git a/src/main/java/org/elasticsearch/alerts/plugin/AlertsPlugin.java b/src/main/java/org/elasticsearch/alerts/AlertsPlugin.java similarity index 73% rename from src/main/java/org/elasticsearch/alerts/plugin/AlertsPlugin.java rename to src/main/java/org/elasticsearch/alerts/AlertsPlugin.java index 9c616d0402b..d0b6a68d930 100644 --- a/src/main/java/org/elasticsearch/alerts/plugin/AlertsPlugin.java +++ b/src/main/java/org/elasticsearch/alerts/AlertsPlugin.java @@ -3,9 +3,9 @@ * 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.alerts.plugin; +package org.elasticsearch.alerts; -import org.elasticsearch.alerts.AlertingModule; +import org.elasticsearch.alerts.AlertsModule; import org.elasticsearch.alerts.support.init.InitializingService; import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.collect.Lists; @@ -20,11 +20,11 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde public class AlertsPlugin extends AbstractPlugin { - public static final String ALERT_THREAD_POOL_NAME = "alerts"; + public static final String NAME = "alerts"; public static final String SCHEDULER_THREAD_POOL_NAME = "alerts_scheduler"; @Override public String name() { - return ALERT_THREAD_POOL_NAME; + return NAME; } @Override public String description() { @@ -33,9 +33,7 @@ public class AlertsPlugin extends AbstractPlugin { @Override public Collection> modules() { - Collection> modules = Lists.newArrayList(); - modules.add(AlertingModule.class); - return modules; + return ImmutableList.>of(AlertsModule.class); } @Override @@ -50,8 +48,8 @@ public class AlertsPlugin extends AbstractPlugin { @Override public Settings additionalSettings() { return settingsBuilder() - .put("threadpool." + ALERT_THREAD_POOL_NAME + ".type", "fixed") - .put("threadpool." + ALERT_THREAD_POOL_NAME + ".size", 32) // Executing an alert involves a lot of wait time for networking (search, several index requests + optional trigger logic) + .put("threadpool." + NAME + ".type", "fixed") + .put("threadpool." + NAME + ".size", 32) // Executing an alert involves a lot of wait time for networking (search, several index requests + optional trigger logic) .put("threadpool." + SCHEDULER_THREAD_POOL_NAME + ".type", "cached") .build(); } diff --git a/src/main/java/org/elasticsearch/alerts/AlertService.java b/src/main/java/org/elasticsearch/alerts/AlertsService.java similarity index 89% rename from src/main/java/org/elasticsearch/alerts/AlertService.java rename to src/main/java/org/elasticsearch/alerts/AlertsService.java index 9f05540cf1a..5a7a2e3700d 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertService.java +++ b/src/main/java/org/elasticsearch/alerts/AlertsService.java @@ -7,6 +7,7 @@ package org.elasticsearch.alerts; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.index.IndexResponse; @@ -16,6 +17,7 @@ import org.elasticsearch.alerts.actions.AlertActionRegistry; import org.elasticsearch.alerts.actions.AlertActionService; import org.elasticsearch.alerts.actions.AlertHistory; import org.elasticsearch.alerts.scheduler.AlertScheduler; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.support.init.proxy.ClientProxy; import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.alerts.triggers.TriggerResult; @@ -45,7 +47,7 @@ import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -public class AlertService extends AbstractComponent { +public class AlertsService extends AbstractComponent { private final ClientProxy client; private final AlertScheduler scheduler; @@ -62,18 +64,18 @@ public class AlertService extends AbstractComponent { private volatile boolean manuallyStopped; @Inject - public AlertService(Settings settings, ClientProxy client, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore, - IndicesService indicesService, TriggerService triggerService, AlertActionService actionManager, - AlertActionRegistry actionRegistry, ThreadPool threadPool, ScriptServiceProxy scriptService) { + public AlertsService(Settings settings, ClientProxy client, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore, + IndicesService indicesService, TriggerService triggerService, AlertActionService actionManager, + AlertActionRegistry actionRegistry, ThreadPool threadPool, ScriptServiceProxy scriptService) { super(settings); this.client = client; this.scheduler = scheduler; this.threadPool = threadPool; - this.scheduler.setAlertService(this); + this.scheduler.setAlertsService(this); this.alertsStore = alertsStore; this.triggerService = triggerService; this.actionManager = actionManager; - this.actionManager.setAlertService(this); + this.actionManager.setAlertsService(this); this.actionRegistry = actionRegistry; this.clusterService = clusterService; this.scriptService = scriptService; @@ -379,4 +381,54 @@ public class AlertService extends AbstractComponent { } + /** + * Encapsulates the state of the alerts plugin. + */ + public static enum State { + + /** + * The alerts plugin is not running and not functional. + */ + STOPPED(0), + + /** + * The alerts plugin is performing the necessary operations to get into a started state. + */ + STARTING(1), + + /** + * The alerts plugin is running and completely functional. + */ + STARTED(2), + + /** + * The alerts plugin is shutting down and not functional. + */ + STOPPING(3); + + private final byte id; + + State(int id) { + this.id = (byte) id; + } + + public byte getId() { + return id; + } + + public static State fromId(byte id) { + switch (id) { + case 0: + return STOPPED; + case 1: + return STARTING; + case 2: + return STARTED; + case 3: + return STOPPING; + default: + throw new ElasticsearchIllegalArgumentException("Unknown id: " + id); + } + } + } } diff --git a/src/main/java/org/elasticsearch/alerts/AlertsStore.java b/src/main/java/org/elasticsearch/alerts/AlertsStore.java index 172bd3706c9..c58d0662f85 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertsStore.java +++ b/src/main/java/org/elasticsearch/alerts/AlertsStore.java @@ -18,6 +18,8 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.alerts.actions.AlertAction; import org.elasticsearch.alerts.actions.AlertActionRegistry; +import org.elasticsearch.alerts.support.AlertUtils; +import org.elasticsearch.alerts.support.TemplateUtils; import org.elasticsearch.alerts.support.init.proxy.ClientProxy; import org.elasticsearch.alerts.triggers.TriggerService; import org.elasticsearch.cluster.ClusterState; @@ -61,7 +63,7 @@ public class AlertsStore extends AbstractComponent { private final ClientProxy client; private final TriggerService triggerService; - private final TemplateHelper templateHelper; + private final TemplateUtils templateUtils; private final ConcurrentMap alertMap; private final AlertActionRegistry alertActionRegistry; private final AtomicBoolean started = new AtomicBoolean(false); @@ -71,11 +73,11 @@ public class AlertsStore extends AbstractComponent { @Inject public AlertsStore(Settings settings, ClientProxy client, AlertActionRegistry alertActionRegistry, - TriggerService triggerService, TemplateHelper templateHelper) { + TriggerService triggerService, TemplateUtils templateUtils) { super(settings); this.client = client; this.alertActionRegistry = alertActionRegistry; - this.templateHelper = templateHelper; + this.templateUtils = templateUtils; this.alertMap = ConcurrentCollections.newConcurrentMap(); this.triggerService = triggerService; // Not using component settings, to let AlertsStore and AlertActionManager share the same settings @@ -161,7 +163,7 @@ public class AlertsStore extends AbstractComponent { alertMap.clear(); return false; } - templateHelper.checkAndUploadIndexTemplate(state, "alerts"); + templateUtils.checkAndUploadIndexTemplate(state, "alerts"); started.set(true); return true; } else { @@ -170,7 +172,7 @@ public class AlertsStore extends AbstractComponent { } } else { logger.info("No previous .alert index, skip loading of alerts"); - templateHelper.checkAndUploadIndexTemplate(state, "alerts"); + templateUtils.checkAndUploadIndexTemplate(state, "alerts"); started.set(true); return true; } diff --git a/src/main/java/org/elasticsearch/alerts/State.java b/src/main/java/org/elasticsearch/alerts/State.java deleted file mode 100644 index a9d8b7f18bc..00000000000 --- a/src/main/java/org/elasticsearch/alerts/State.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * 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.alerts; - -import org.elasticsearch.ElasticsearchIllegalArgumentException; - -/** - * Encapsulates the state of the alerts plugin. - */ -public enum State { - - /** - * The alerts plugin is not running and not functional. - */ - STOPPED(0), - - /** - * The alerts plugin is performing the necessary operations to get into a started state. - */ - STARTING(1), - - /** - * The alerts plugin is running and completely functional. - */ - STARTED(2), - - /** - * The alerts plugin is shutting down and not functional. - */ - STOPPING(3); - - private final byte id; - - State(int id) { - this.id = (byte) id; - } - - public byte getId() { - return id; - } - - public static State fromId(byte id) { - switch (id) { - case 0: - return STOPPED; - case 1: - return STARTING; - case 2: - return STARTED; - case 3: - return STOPPING; - default: - throw new ElasticsearchIllegalArgumentException("Unknown id: " + id); - } - } -} diff --git a/src/main/java/org/elasticsearch/alerts/actions/AlertActionService.java b/src/main/java/org/elasticsearch/alerts/actions/AlertActionService.java index 19f48d2d10e..232c6598a11 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/AlertActionService.java +++ b/src/main/java/org/elasticsearch/alerts/actions/AlertActionService.java @@ -16,7 +16,9 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.alerts.*; -import org.elasticsearch.alerts.plugin.AlertsPlugin; +import org.elasticsearch.alerts.AlertsPlugin; +import org.elasticsearch.alerts.support.AlertUtils; +import org.elasticsearch.alerts.support.TemplateUtils; import org.elasticsearch.alerts.support.init.proxy.ClientProxy; import org.elasticsearch.alerts.triggers.TriggerResult; import org.elasticsearch.alerts.triggers.TriggerService; @@ -67,11 +69,11 @@ public class AlertActionService extends AbstractComponent { public static final String ALERT_HISTORY_TYPE = "alerthistory"; private final ClientProxy client; - private AlertService alertService; + private AlertsService alertsService; private final ThreadPool threadPool; private final AlertsStore alertsStore; private final TriggerService triggerService; - private final TemplateHelper templateHelper; + private final TemplateUtils templateUtils; private final AlertActionRegistry actionRegistry; private final int scrollSize; @@ -85,22 +87,22 @@ public class AlertActionService extends AbstractComponent { @Inject public AlertActionService(Settings settings, ClientProxy client, AlertActionRegistry actionRegistry, ThreadPool threadPool, AlertsStore alertsStore, TriggerService triggerService, - TemplateHelper templateHelper) { + TemplateUtils templateUtils) { super(settings); this.client = client; this.actionRegistry = actionRegistry; this.threadPool = threadPool; this.alertsStore = alertsStore; this.triggerService = triggerService; - this.templateHelper = templateHelper; + this.templateUtils = templateUtils; // Not using component settings, to let AlertsStore and AlertActionManager share the same settings this.scrollTimeout = settings.getAsTime("alerts.scroll.timeout", TimeValue.timeValueSeconds(30)); this.scrollSize = settings.getAsInt("alerts.scroll.size", 100); } - public void setAlertService(AlertService alertService){ - this.alertService = alertService; + public void setAlertsService(AlertsService alertsService){ + this.alertsService = alertsService; } public boolean start(ClusterState state) { @@ -111,7 +113,7 @@ public class AlertActionService extends AbstractComponent { String[] indices = state.metaData().concreteIndices(IndicesOptions.lenientExpandOpen(), ALERT_HISTORY_INDEX_PREFIX + "*"); if (indices.length == 0) { logger.info("No previous .alerthistory index, skip loading of alert actions"); - templateHelper.checkAndUploadIndexTemplate(state, "alerthistory"); + templateUtils.checkAndUploadIndexTemplate(state, "alerthistory"); doStart(); return true; } @@ -135,7 +137,7 @@ public class AlertActionService extends AbstractComponent { actionsToBeProcessed.clear(); return false; } - templateHelper.checkAndUploadIndexTemplate(state, "alerthistory"); + templateUtils.checkAndUploadIndexTemplate(state, "alerthistory"); doStart(); return true; } @@ -368,7 +370,7 @@ public class AlertActionService extends AbstractComponent { } updateHistoryEntry(entry, AlertActionState.SEARCH_UNDERWAY); logger.debug("Running an alert action entry for [{}]", entry.getAlertName()); - TriggerResult result = alertService.executeAlert(entry); + TriggerResult result = alertsService.executeAlert(entry); entry.setTriggerResponse(result.getTriggerResponse()); if (result.isTriggered()) { entry.setTriggered(true); @@ -410,7 +412,7 @@ public class AlertActionService extends AbstractComponent { while (started()) { AlertHistory entry = actionsToBeProcessed.take(); if (entry != null) { - threadPool.executor(AlertsPlugin.ALERT_THREAD_POOL_NAME).execute(new AlertHistoryRunnable(entry)); + threadPool.executor(AlertsPlugin.NAME).execute(new AlertHistoryRunnable(entry)); } } } catch (Exception e) { diff --git a/src/main/java/org/elasticsearch/alerts/actions/AlertHistory.java b/src/main/java/org/elasticsearch/alerts/actions/AlertHistory.java index 837ee675b03..b6932375308 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/AlertHistory.java +++ b/src/main/java/org/elasticsearch/alerts/actions/AlertHistory.java @@ -7,7 +7,7 @@ package org.elasticsearch.alerts.actions; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.alerts.Alert; -import org.elasticsearch.alerts.AlertUtils; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.triggers.AlertTrigger; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.xcontent.ToXContent; diff --git a/src/main/java/org/elasticsearch/alerts/rest/AlertsRestModule.java b/src/main/java/org/elasticsearch/alerts/rest/AlertsRestModule.java new file mode 100644 index 00000000000..445fd5908b1 --- /dev/null +++ b/src/main/java/org/elasticsearch/alerts/rest/AlertsRestModule.java @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * 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.alerts.rest; + +import org.elasticsearch.alerts.rest.action.*; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.PreProcessModule; +import org.elasticsearch.rest.RestModule; + +/** + * + */ +public class AlertsRestModule extends AbstractModule implements PreProcessModule { + + @Override + public void processModule(Module module) { + if (module instanceof RestModule) { + RestModule restModule = (RestModule) module; + restModule.addRestAction(RestPutAlertAction.class); + restModule.addRestAction(RestDeleteAlertAction.class); + restModule.addRestAction(RestAlertsStatsAction.class); + restModule.addRestAction(RestGetAlertAction.class); + restModule.addRestAction(RestAlertServiceAction.class); + restModule.addRestAction(RestConfigAlertAction.class); + restModule.addRestAction(RestAckAlertAction.class); + } + } + + @Override + protected void configure() { + } +} diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestAckAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestAckAlertAction.java similarity index 97% rename from src/main/java/org/elasticsearch/alerts/rest/RestAckAlertAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestAckAlertAction.java index f3a485e88a3..41569cb2f30 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestAckAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestAckAlertAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestAlertServiceAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestAlertServiceAction.java similarity index 98% rename from src/main/java/org/elasticsearch/alerts/rest/RestAlertServiceAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestAlertServiceAction.java index 5162c7fe343..0a60a9e5f01 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestAlertServiceAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestAlertServiceAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestAlertsStatsAction.java similarity index 98% rename from src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestAlertsStatsAction.java index b7a450c9f54..bdb4596fcf4 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestAlertsStatsAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestConfigAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestConfigAlertAction.java similarity index 98% rename from src/main/java/org/elasticsearch/alerts/rest/RestConfigAlertAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestConfigAlertAction.java index 02190232147..714e170970f 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestConfigAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestConfigAlertAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.alerts.AlertsStore; diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestDeleteAlertAction.java similarity index 98% rename from src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestDeleteAlertAction.java index 875438741bf..e4bd468b29f 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestDeleteAlertAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.alerts.AlertsStore; diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestGetAlertAction.java similarity index 98% rename from src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestGetAlertAction.java index d5f56222e78..2a543e3cf29 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestGetAlertAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.alerts.AlertsStore; diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestPutAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/action/RestPutAlertAction.java similarity index 98% rename from src/main/java/org/elasticsearch/alerts/rest/RestPutAlertAction.java rename to src/main/java/org/elasticsearch/alerts/rest/action/RestPutAlertAction.java index 5f083890bfd..ae52f7ddfee 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestPutAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/action/RestPutAlertAction.java @@ -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.alerts.rest; +package org.elasticsearch.alerts.rest.action; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.alerts.AlertsStore; diff --git a/src/main/java/org/elasticsearch/alerts/rest/package-info.java b/src/main/java/org/elasticsearch/alerts/rest/package-info.java deleted file mode 100644 index 603040d6744..00000000000 --- a/src/main/java/org/elasticsearch/alerts/rest/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * 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.alerts.rest; \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java b/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java index 5286dd1a312..3310c96d508 100644 --- a/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java +++ b/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java @@ -7,8 +7,8 @@ package org.elasticsearch.alerts.scheduler; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.alerts.Alert; -import org.elasticsearch.alerts.AlertService; -import org.elasticsearch.alerts.plugin.AlertsPlugin; +import org.elasticsearch.alerts.AlertsService; +import org.elasticsearch.alerts.AlertsPlugin; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.joda.time.DateTime; @@ -26,7 +26,7 @@ public class AlertScheduler extends AbstractComponent { // Not happy about it, but otherwise we're stuck with Quartz's SimpleThreadPool private volatile static ThreadPool threadPool; - private AlertService alertService; + private AlertsService alertsService; private volatile Scheduler scheduler; @Inject @@ -35,8 +35,8 @@ public class AlertScheduler extends AbstractComponent { AlertScheduler.threadPool = threadPool; } - public void setAlertService(AlertService alertService){ - this.alertService = alertService; + public void setAlertsService(AlertsService alertsService){ + this.alertsService = alertsService; } /** @@ -88,7 +88,7 @@ public class AlertScheduler extends AbstractComponent { public void executeAlert(String alertName, JobExecutionContext jobExecutionContext){ DateTime scheduledFireTime = new DateTime(jobExecutionContext.getScheduledFireTime()); DateTime fireTime = new DateTime(jobExecutionContext.getFireTime()); - alertService.scheduleAlert(alertName, scheduledFireTime, fireTime); + alertsService.scheduleAlert(alertName, scheduledFireTime, fireTime); } public boolean remove(String alertName) { diff --git a/src/main/java/org/elasticsearch/alerts/scheduler/AlertsSchedulerModule.java b/src/main/java/org/elasticsearch/alerts/scheduler/AlertsSchedulerModule.java new file mode 100644 index 00000000000..492c83f8bf3 --- /dev/null +++ b/src/main/java/org/elasticsearch/alerts/scheduler/AlertsSchedulerModule.java @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * 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.alerts.scheduler; + +import org.elasticsearch.common.inject.AbstractModule; + +/** + * + */ +public class AlertsSchedulerModule extends AbstractModule { + + @Override + protected void configure() { + bind(AlertScheduler.class).asEagerSingleton(); + } +} diff --git a/src/main/java/org/elasticsearch/alerts/scheduler/package-info.java b/src/main/java/org/elasticsearch/alerts/scheduler/package-info.java deleted file mode 100644 index 3d9acfc9f9a..00000000000 --- a/src/main/java/org/elasticsearch/alerts/scheduler/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * 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.alerts.scheduler; \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/alerts/AlertUtils.java b/src/main/java/org/elasticsearch/alerts/support/AlertUtils.java similarity index 99% rename from src/main/java/org/elasticsearch/alerts/AlertUtils.java rename to src/main/java/org/elasticsearch/alerts/support/AlertUtils.java index 87b7c970497..b6c8d5896f0 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertUtils.java +++ b/src/main/java/org/elasticsearch/alerts/support/AlertUtils.java @@ -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.alerts; +package org.elasticsearch.alerts.support; import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.ElasticsearchIllegalStateException; diff --git a/src/main/java/org/elasticsearch/alerts/TemplateHelper.java b/src/main/java/org/elasticsearch/alerts/support/TemplateUtils.java similarity index 94% rename from src/main/java/org/elasticsearch/alerts/TemplateHelper.java rename to src/main/java/org/elasticsearch/alerts/support/TemplateUtils.java index c9eb8903cc9..3c110fe9ca8 100644 --- a/src/main/java/org/elasticsearch/alerts/TemplateHelper.java +++ b/src/main/java/org/elasticsearch/alerts/support/TemplateUtils.java @@ -3,12 +3,13 @@ * 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.alerts; +package org.elasticsearch.alerts.support; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction; +import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.common.component.AbstractComponent; @@ -25,12 +26,12 @@ import java.util.regex.Pattern; /** */ -public class TemplateHelper extends AbstractComponent { +public class TemplateUtils extends AbstractComponent { private final TransportPutIndexTemplateAction transportPutIndexTemplateAction; @Inject - public TemplateHelper(Settings settings, TransportPutIndexTemplateAction transportPutIndexTemplateAction) { + public TemplateUtils(Settings settings, TransportPutIndexTemplateAction transportPutIndexTemplateAction) { super(settings); this.transportPutIndexTemplateAction = transportPutIndexTemplateAction; } diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/ack/TransportAckAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/ack/TransportAckAlertAction.java index ab9d83a6854..8b7df0e28a0 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/ack/TransportAckAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/ack/TransportAckAlertAction.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; -import org.elasticsearch.alerts.AlertService; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; @@ -25,13 +25,13 @@ import org.elasticsearch.transport.TransportService; */ public class TransportAckAlertAction extends TransportMasterNodeOperationAction { - private final AlertService alertService; + private final AlertsService alertsService; @Inject public TransportAckAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService) { + ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService) { super(settings, AckAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); - this.alertService = alertService; + this.alertsService = alertsService; } @Override @@ -52,7 +52,7 @@ public class TransportAckAlertAction extends TransportMasterNodeOperationAction< @Override protected void masterOperation(AckAlertRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { try { - AckAlertResponse response = new AckAlertResponse(alertService.ackAlert(request.getAlertName())); + AckAlertResponse response = new AckAlertResponse(alertsService.ackAlert(request.getAlertName())); listener.onResponse(response); } catch (Exception e) { listener.onFailure(e); diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/delete/TransportDeleteAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/delete/TransportDeleteAlertAction.java index 3c25254faa7..ed834044a8c 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/delete/TransportDeleteAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/delete/TransportDeleteAlertAction.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; -import org.elasticsearch.alerts.AlertService; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; @@ -25,13 +25,13 @@ import org.elasticsearch.transport.TransportService; */ public class TransportDeleteAlertAction extends TransportMasterNodeOperationAction { - private final AlertService alertService; + private final AlertsService alertsService; @Inject public TransportDeleteAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService) { + ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService) { super(settings, DeleteAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); - this.alertService = alertService; + this.alertsService = alertsService; } @Override @@ -52,7 +52,7 @@ public class TransportDeleteAlertAction extends TransportMasterNodeOperationActi @Override protected void masterOperation(DeleteAlertRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { try { - DeleteAlertResponse response = new DeleteAlertResponse(alertService.deleteAlert(request.getAlertName())); + DeleteAlertResponse response = new DeleteAlertResponse(alertsService.deleteAlert(request.getAlertName())); listener.onResponse(response); } catch (Exception e) { listener.onFailure(e); diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/get/TransportGetAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/get/TransportGetAlertAction.java index 5bc8dd11041..c0fe2d1bbfa 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/get/TransportGetAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/get/TransportGetAlertAction.java @@ -11,7 +11,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.alerts.Alert; -import org.elasticsearch.alerts.AlertService; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; @@ -32,13 +32,13 @@ import java.io.IOException; */ public class TransportGetAlertAction extends TransportMasterNodeOperationAction { - private final AlertService alertService; + private final AlertsService alertsService; @Inject public TransportGetAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService) { + ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService) { super(settings, GetAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); - this.alertService = alertService; + this.alertsService = alertsService; } @Override @@ -58,7 +58,7 @@ public class TransportGetAlertAction extends TransportMasterNodeOperationAction< @Override protected void masterOperation(GetAlertRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { - Alert alert = alertService.getAlert(request.alertName()); + Alert alert = alertsService.getAlert(request.alertName()); GetResult getResult; if (alert != null) { BytesReference alertSource = null; diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java index ad189bb3d12..513f0227a78 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java @@ -10,7 +10,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; -import org.elasticsearch.alerts.AlertService; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; @@ -25,13 +25,13 @@ import org.elasticsearch.transport.TransportService; */ public class TransportPutAlertAction extends TransportMasterNodeOperationAction { - private final AlertService alertService; + private final AlertsService alertsService; @Inject public TransportPutAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService) { + ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService) { super(settings, PutAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); - this.alertService = alertService; + this.alertsService = alertsService; } @Override @@ -52,7 +52,7 @@ public class TransportPutAlertAction extends TransportMasterNodeOperationAction< @Override protected void masterOperation(PutAlertRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { try { - IndexResponse indexResponse = alertService.putAlert(request.getAlertName(), request.getAlertSource()); + IndexResponse indexResponse = alertsService.putAlert(request.getAlertName(), request.getAlertSource()); listener.onResponse(new PutAlertResponse(indexResponse)); } catch (Exception e) { listener.onFailure(e); diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/service/TransportAlertsServiceAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/service/TransportAlertsServiceAction.java index 79b48839d1e..70e78bdcecb 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/service/TransportAlertsServiceAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/service/TransportAlertsServiceAction.java @@ -10,7 +10,7 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; -import org.elasticsearch.alerts.AlertService; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -24,12 +24,12 @@ import org.elasticsearch.transport.TransportService; */ public class TransportAlertsServiceAction extends TransportMasterNodeOperationAction { - private final AlertService alertService; + private final AlertsService alertsService; @Inject - public TransportAlertsServiceAction(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService) { + public TransportAlertsServiceAction(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService) { super(settings, actionName, transportService, clusterService, threadPool, actionFilters); - this.alertService = alertService; + this.alertsService = alertsService; } @Override @@ -51,14 +51,14 @@ public class TransportAlertsServiceAction extends TransportMasterNodeOperationAc protected void masterOperation(AlertsServiceRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { switch (request.getCommand()) { case "start": - alertService.start(); + alertsService.start(); break; case "stop": - alertService.stop(); + alertsService.stop(); break; case "restart": - alertService.start(); - alertService.stop(); + alertsService.start(); + alertsService.stop(); break; default: listener.onFailure(new ElasticsearchIllegalArgumentException("Command [" + request.getCommand() + "] is undefined")); diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/stats/AlertsStatsResponse.java b/src/main/java/org/elasticsearch/alerts/transport/actions/stats/AlertsStatsResponse.java index c0f83a5847c..b4e110cc2fc 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/stats/AlertsStatsResponse.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/stats/AlertsStatsResponse.java @@ -7,8 +7,8 @@ package org.elasticsearch.alerts.transport.actions.stats; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.alerts.AlertsBuild; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.alerts.AlertsVersion; -import org.elasticsearch.alerts.State; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -22,7 +22,7 @@ public class AlertsStatsResponse extends ActionResponse { private AlertsVersion version; private AlertsBuild build; private long numberOfRegisteredAlerts; - private State alertManagerState; + private AlertsService.State alertManagerState; private boolean alertActionManagerStarted; private long alertActionManagerQueueSize; private long alertActionManagerLargestQueueSize; @@ -55,11 +55,11 @@ public class AlertsStatsResponse extends ActionResponse { /** * Returns the state of the alert manager. */ - public State getAlertManagerStarted() { + public AlertsService.State getAlertManagerStarted() { return alertManagerState; } - void setAlertManagerState(State alertManagerState) { + void setAlertManagerState(AlertsService.State alertManagerState) { this.alertManagerState = alertManagerState; } @@ -113,7 +113,7 @@ public class AlertsStatsResponse extends ActionResponse { numberOfRegisteredAlerts = in.readLong(); alertActionManagerQueueSize = in.readLong(); alertActionManagerLargestQueueSize = in.readLong(); - alertManagerState = State.fromId(in.readByte()); + alertManagerState = AlertsService.State.fromId(in.readByte()); alertActionManagerStarted = in.readBoolean(); version = AlertsVersion.readVersion(in); build = AlertsBuild.readBuild(in); diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertsStatsAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertsStatsAction.java index f032aeb9588..8d0c4815fea 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertsStatsAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertsStatsAction.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; -import org.elasticsearch.alerts.AlertService; +import org.elasticsearch.alerts.AlertsService; import org.elasticsearch.alerts.AlertsBuild; import org.elasticsearch.alerts.AlertsVersion; import org.elasticsearch.alerts.actions.AlertActionService; @@ -27,15 +27,15 @@ import org.elasticsearch.transport.TransportService; */ public class TransportAlertsStatsAction extends TransportMasterNodeOperationAction { - private final AlertService alertService; + private final AlertsService alertsService; private final AlertActionService alertActionService; @Inject public TransportAlertsStatsAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService, + ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService, AlertActionService alertActionService) { super(settings, AlertsStatsAction.NAME, transportService, clusterService, threadPool, actionFilters); - this.alertService = alertService; + this.alertsService = alertsService; this.alertActionService = alertActionService; } @@ -57,10 +57,10 @@ public class TransportAlertsStatsAction extends TransportMasterNodeOperationActi @Override protected void masterOperation(AlertsStatsRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { AlertsStatsResponse statsResponse = new AlertsStatsResponse(); - statsResponse.setAlertManagerState(alertService.getState()); + statsResponse.setAlertManagerState(alertsService.getState()); statsResponse.setAlertActionManagerStarted(alertActionService.started()); statsResponse.setAlertActionManagerQueueSize(alertActionService.getQueueSize()); - statsResponse.setNumberOfRegisteredAlerts(alertService.getNumberOfAlerts()); + statsResponse.setNumberOfRegisteredAlerts(alertsService.getNumberOfAlerts()); statsResponse.setAlertActionManagerLargestQueueSize(alertActionService.getLargestQueueSize()); statsResponse.setVersion(AlertsVersion.CURRENT); statsResponse.setBuild(AlertsBuild.CURRENT); diff --git a/src/main/java/org/elasticsearch/alerts/triggers/AlertsTriggerModule.java b/src/main/java/org/elasticsearch/alerts/triggers/AlertsTriggerModule.java new file mode 100644 index 00000000000..e27df4cf497 --- /dev/null +++ b/src/main/java/org/elasticsearch/alerts/triggers/AlertsTriggerModule.java @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * 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.alerts.triggers; + +import org.elasticsearch.common.inject.AbstractModule; + +/** + * + */ +public class AlertsTriggerModule extends AbstractModule { + + @Override + protected void configure() { + bind(TriggerService.class).asEagerSingleton(); + } +} diff --git a/src/main/java/org/elasticsearch/alerts/triggers/TriggerService.java b/src/main/java/org/elasticsearch/alerts/triggers/TriggerService.java index bb3165a17ed..14aaa629860 100644 --- a/src/main/java/org/elasticsearch/alerts/triggers/TriggerService.java +++ b/src/main/java/org/elasticsearch/alerts/triggers/TriggerService.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.alerts.Alert; -import org.elasticsearch.alerts.AlertUtils; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.support.init.proxy.ClientProxy; import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.common.collect.ImmutableOpenMap; diff --git a/src/main/resources/es-plugin.properties b/src/main/resources/es-plugin.properties index d7b845cbc39..ffd992853f2 100644 --- a/src/main/resources/es-plugin.properties +++ b/src/main/resources/es-plugin.properties @@ -1,2 +1,2 @@ -plugin=org.elasticsearch.alerts.plugin.AlertsPlugin +plugin=org.elasticsearch.alerts.AlertsPlugin version=${project.version} \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java index a0eb115cfd7..f4287f5ec82 100644 --- a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java +++ b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.alerts.actions.AlertActionService; import org.elasticsearch.alerts.actions.AlertActionState; import org.elasticsearch.alerts.client.AlertsClient; -import org.elasticsearch.alerts.plugin.AlertsPlugin; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; @@ -71,7 +71,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest public void startAlertsIfNodesExist() throws Exception { if (internalTestCluster().size() > 0) { AlertsStatsResponse response = alertClient().prepareAlertsStats().get(); - if (response.getAlertManagerStarted() == State.STOPPED) { + if (response.getAlertManagerStarted() == AlertsService.State.STOPPED) { logger.info("[{}#{}]: starting alerts", getTestClass().getSimpleName(), getTestName()); startAlerting(); } else { @@ -223,7 +223,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest assertBusy(new Runnable() { @Override public void run() { - assertThat(alertClient().prepareAlertsStats().get().getAlertManagerStarted(), is(State.STARTED)); + assertThat(alertClient().prepareAlertsStats().get().getAlertManagerStarted(), is(AlertsService.State.STARTED)); } }); } @@ -232,7 +232,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest assertBusy(new Runnable() { @Override public void run() { - assertThat(alertClient().prepareAlertsStats().get().getAlertManagerStarted(), is(State.STOPPED)); + assertThat(alertClient().prepareAlertsStats().get().getAlertManagerStarted(), is(AlertsService.State.STOPPED)); } }); } @@ -330,29 +330,29 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest // First manually stop alerting on non elected master node, this will prevent that alerting becomes active // on these nodes for (String node : nodes) { - AlertService alertService = _testCluster.getInstance(AlertService.class, node); - assertThat(alertService.getState(), equalTo(State.STOPPED)); - alertService.stop(); // Prevents these nodes from starting alerting when new elected master node is picked. + AlertsService alertsService = _testCluster.getInstance(AlertsService.class, node); + assertThat(alertsService.getState(), equalTo(AlertsService.State.STOPPED)); + alertsService.stop(); // Prevents these nodes from starting alerting when new elected master node is picked. } // Then stop alerting on elected master node and wait until alerting has stopped on it. - final AlertService alertService = _testCluster.getInstance(AlertService.class, masterNode); + final AlertsService alertsService = _testCluster.getInstance(AlertsService.class, masterNode); try { assertBusy(new Runnable() { @Override public void run() { - assertThat(alertService.getState(), not(equalTo(State.STARTING))); + assertThat(alertsService.getState(), not(equalTo(AlertsService.State.STARTING))); } }); } catch (Exception e) { throw new RuntimeException(e); } - alertService.stop(); + alertsService.stop(); try { assertBusy(new Runnable() { @Override public void run() { - assertThat(alertService.getState(), equalTo(State.STOPPED)); + assertThat(alertsService.getState(), equalTo(AlertsService.State.STOPPED)); } }); } catch (Exception e) { diff --git a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java index 82e24215919..7099a9b678a 100644 --- a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java +++ b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java @@ -50,7 +50,7 @@ public class BootStrapTest extends AbstractAlertingTests { AlertsStatsResponse response = alertClient().prepareAlertsStats().get(); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L)); } @@ -61,7 +61,7 @@ public class BootStrapTest extends AbstractAlertingTests { AlertsStatsResponse response = alertClient().prepareAlertsStats().get(); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L)); SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value"))); @@ -94,7 +94,7 @@ public class BootStrapTest extends AbstractAlertingTests { response = alertClient().prepareAlertsStats().get(); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L)); assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(1L)); } @@ -140,7 +140,7 @@ public class BootStrapTest extends AbstractAlertingTests { AlertsStatsResponse response = alertClient().prepareAlertsStats().get(); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); long expectedMaximumQueueSize = numberOfAlertHistoryEntriesPerIndex * numberOfAlertHistoryIndices ; assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(expectedMaximumQueueSize)); diff --git a/src/test/java/org/elasticsearch/alerts/NoMasterNodeTests.java b/src/test/java/org/elasticsearch/alerts/NoMasterNodeTests.java index 143d0b932b9..2218a5e9111 100644 --- a/src/test/java/org/elasticsearch/alerts/NoMasterNodeTests.java +++ b/src/test/java/org/elasticsearch/alerts/NoMasterNodeTests.java @@ -141,8 +141,8 @@ public class NoMasterNodeTests extends AbstractAlertingTests { } }), equalTo(true)); // Ensure that the alert manager doesn't run elsewhere - for (AlertService alertService : internalTestCluster().getInstances(AlertService.class)) { - assertThat(alertService.getState(), is(State.STOPPED)); + for (AlertsService alertsService : internalTestCluster().getInstances(AlertsService.class)) { + assertThat(alertsService.getState(), is(AlertsService.State.STOPPED)); } } diff --git a/src/test/java/org/elasticsearch/alerts/PayloadSearchTest.java b/src/test/java/org/elasticsearch/alerts/PayloadSearchTest.java index 4610cb9f65f..1923091b495 100644 --- a/src/test/java/org/elasticsearch/alerts/PayloadSearchTest.java +++ b/src/test/java/org/elasticsearch/alerts/PayloadSearchTest.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.alerts.actions.AlertAction; import org.elasticsearch.alerts.actions.IndexAlertAction; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse; import org.elasticsearch.alerts.triggers.ScriptedTrigger; import org.elasticsearch.common.joda.time.DateTime; diff --git a/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java b/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java index 7cf1a23c5fb..8d865253494 100644 --- a/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java +++ b/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.alerts.*; import org.elasticsearch.alerts.client.AlertsClient; +import org.elasticsearch.alerts.support.AlertUtils; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse; import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest; @@ -110,11 +111,11 @@ public class AlertActionsTest extends AbstractAlertingTests { .setSource(jsonBuilder().startObject().startObject("template").startObject("match_all").endObject().endObject().endObject()) .get(); - final AlertService alertService = internalTestCluster().getInstance(AlertService.class, internalTestCluster().getMasterName()); + final AlertsService alertsService = internalTestCluster().getInstance(AlertsService.class, internalTestCluster().getMasterName()); assertBusy(new Runnable() { @Override public void run() { - assertThat(alertService.getState(), is(State.STARTED)); + assertThat(alertsService.getState(), is(AlertsService.State.STARTED)); } }); final AtomicBoolean alertActionInvoked = new AtomicBoolean(false); diff --git a/src/test/java/org/elasticsearch/alerts/actions/AlertStatsTests.java b/src/test/java/org/elasticsearch/alerts/actions/AlertStatsTests.java index a59dfd16df0..068fe232b7b 100644 --- a/src/test/java/org/elasticsearch/alerts/actions/AlertStatsTests.java +++ b/src/test/java/org/elasticsearch/alerts/actions/AlertStatsTests.java @@ -6,10 +6,7 @@ package org.elasticsearch.alerts.actions; import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.alerts.AbstractAlertingTests; -import org.elasticsearch.alerts.AlertsBuild; -import org.elasticsearch.alerts.AlertsVersion; -import org.elasticsearch.alerts.State; +import org.elasticsearch.alerts.*; import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse; @@ -36,7 +33,7 @@ public class AlertStatsTests extends AbstractAlertingTests { AlertsStatsResponse response = alertClient().alertsStats(alertsStatsRequest).actionGet(); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); assertThat(response.getAlertActionManagerQueueSize(), equalTo(0L)); assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L)); assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(0L)); @@ -52,7 +49,7 @@ public class AlertStatsTests extends AbstractAlertingTests { AlertsStatsResponse response = alertsClient.alertsStats(alertsStatsRequest).actionGet(); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value"))); BytesReference alertSource = createAlertSource("* * * * * ? *", searchRequest, "hits.total == 1"); @@ -67,7 +64,7 @@ public class AlertStatsTests extends AbstractAlertingTests { Thread.sleep(waitTime.getMillis()); assertTrue(response.isAlertActionManagerStarted()); - assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED)); + assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED)); assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L)); //assertThat(response.getAlertActionManagerLargestQueueSize(), greaterThan(0L)); }