diff --git a/src/main/java/org/elasticsearch/alerts/AlertManager.java b/src/main/java/org/elasticsearch/alerts/AlertManager.java index 817529137a6..43b3bd9eac5 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertManager.java +++ b/src/main/java/org/elasticsearch/alerts/AlertManager.java @@ -38,7 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean; // The KeyedLock make sure that we only lock on the same alert, but not on different alerts. public class AlertManager extends AbstractComponent { - private AlertScheduler scheduler; + private final AlertScheduler scheduler; private final AlertsStore alertsStore; private final TriggerManager triggerManager; private final ClusterService clusterService; @@ -48,9 +48,12 @@ public class AlertManager extends AbstractComponent { @Inject - public AlertManager(Settings settings, ClusterService clusterService, AlertsStore alertsStore, - IndicesService indicesService, TriggerManager triggerManager, AlertActionManager actionManager, AlertActionRegistry actionRegistry) { + public AlertManager(Settings settings, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore, + IndicesService indicesService, TriggerManager triggerManager, AlertActionManager actionManager, + AlertActionRegistry actionRegistry) { super(settings); + this.scheduler = scheduler; + this.scheduler.setAlertManager(this); this.alertsStore = alertsStore; this.clusterService = clusterService; this.triggerManager = triggerManager; @@ -68,10 +71,6 @@ public class AlertManager extends AbstractComponent { }); } - public void setAlertScheduler(AlertScheduler scheduler){ - this.scheduler = scheduler; - } - public DeleteResponse deleteAlert(String name) throws InterruptedException, ExecutionException { ensureStarted(); if (alertsStore.hasAlert(name)) { diff --git a/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java b/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java index f275e573587..882b862e669 100644 --- a/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java +++ b/src/main/java/org/elasticsearch/alerts/scheduler/AlertScheduler.java @@ -19,13 +19,15 @@ import org.quartz.simpl.SimpleJobFactory; public class AlertScheduler extends AbstractComponent { private volatile Scheduler scheduler; - private final AlertManager alertManager; + private AlertManager alertManager; @Inject - public AlertScheduler(Settings settings, AlertManager alertManager) { + public AlertScheduler(Settings settings) { super(settings); + } + + public void setAlertManager(AlertManager alertManager){ this.alertManager = alertManager; - alertManager.setAlertScheduler(this); } public void start() { diff --git a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java index e57555324d6..037eac23968 100644 --- a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java +++ b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java @@ -42,11 +42,8 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest return ImmutableSettings.builder() .put(super.nodeSettings(nodeOrdinal)) .put("scroll.size", randomIntBetween(1, 100)) - .put("plugin.mandatory", "alerts") .put("plugin.types", AlertsPlugin.class.getName()) .put("node.mode", "network") - .put("http.enabled", true) - .put("plugins.load_classpath_plugins", false) .build(); } diff --git a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java index 0bb560332b3..a0793912e87 100644 --- a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java +++ b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java @@ -6,26 +6,19 @@ package org.elasticsearch.alerts; import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.alerts.actions.AlertAction; import org.elasticsearch.alerts.client.AlertsClientInterface; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse; -import org.elasticsearch.alerts.triggers.ScriptedTrigger; +import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.joda.time.DateTime; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; -import java.util.ArrayList; - import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; +import static org.hamcrest.Matchers.is; /** */ @@ -54,9 +47,10 @@ public class BasicAlertingTest extends AbstractAlertingTests { client().prepareIndex("my-index", "my-type").setSource("field", "value").get(); SearchRequest searchRequest = new SearchRequest("my-index").source(searchSource().query(matchAllQuery())); BytesReference alertSource = createAlertSource("0/5 * * * * ? *", searchRequest, "hits.total == 1"); - alertsClient.prepareIndexAlert("my-first-alert") + IndexAlertResponse indexResponse = alertsClient.prepareIndexAlert("my-first-alert") .setAlertSource(alertSource) .get(); + assertThat(indexResponse.indexResponse().isCreated(), is(true)); DeleteAlertRequest deleteAlertRequest = new DeleteAlertRequest("my-first-alert"); DeleteAlertResponse deleteAlertResponse = alertsClient.deleteAlert(deleteAlertRequest).actionGet();