From 8512dfcb36efb60441d17c9b8f9472c5bf4b6970 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 26 Nov 2014 15:30:11 +0100 Subject: [PATCH] Removed enable from Alert. Original commit: elastic/x-pack-elasticsearch@d65a883f7041d4929063c856ce14ac456a3841f7 --- README.md | 7 ++----- .../java/org/elasticsearch/alerts/Alert.java | 16 +--------------- .../org/elasticsearch/alerts/AlertManager.java | 4 ---- .../org/elasticsearch/alerts/AlertsStore.java | 3 --- .../alerts/actions/AlertActionManager.java | 3 --- src/main/resources/alerts.json | 3 --- .../alerts/AbstractAlertingTests.java | 2 -- .../alerts/AlertSerializationTest.java | 2 -- .../elasticsearch/alerts/AlertThrottleTests.java | 2 -- .../elasticsearch/alerts/BasicAlertingTest.java | 1 - .../org/elasticsearch/alerts/BootStrapTest.java | 1 - .../alerts/actions/AlertActionsTest.java | 1 - 12 files changed, 3 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 285a1addb38..06d2d7b93ec 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,7 @@ PUT /.alerts/alert/testalert } }, - "schedule" : "0 0/1 * * * ?", - "enable" : true + "schedule" : "0 0/1 * * * ?" } ```` @@ -105,7 +104,6 @@ GET /.alerts/alert/testalert "logstash*" ] }, - "enable": true, "actions": { "email": { "addresses": [ @@ -178,8 +176,7 @@ PUT _alert/404alert "addresses" : ["brian.murphy@elasticsearch.com"] } }, - "schedule" : "0 0/1 * * * ?", - "enable" : true + "schedule" : "0 0/1 * * * ?" } ```` diff --git a/src/main/java/org/elasticsearch/alerts/Alert.java b/src/main/java/org/elasticsearch/alerts/Alert.java index 679ba350d0a..4f4d14b88cd 100644 --- a/src/main/java/org/elasticsearch/alerts/Alert.java +++ b/src/main/java/org/elasticsearch/alerts/Alert.java @@ -26,7 +26,6 @@ public class Alert implements ToXContent { private String schedule; private DateTime lastActionFire; private long version; - private boolean enabled; private TimeValue throttlePeriod = new TimeValue(0); private DateTime timeLastActionExecuted = null; private AlertAckState ackState = AlertAckState.NOT_ACKABLE; @@ -35,7 +34,7 @@ public class Alert implements ToXContent { actions = new ArrayList<>(); } - public Alert(String alertName, SearchRequest searchRequest, AlertTrigger trigger, List actions, String schedule, DateTime lastActionFire, long version, boolean enabled, TimeValue throttlePeriod, AlertAckState ackState) { + public Alert(String alertName, SearchRequest searchRequest, AlertTrigger trigger, List actions, String schedule, DateTime lastActionFire, long version, TimeValue throttlePeriod, AlertAckState ackState) { this.alertName = alertName; this.searchRequest = searchRequest; this.trigger = trigger; @@ -43,7 +42,6 @@ public class Alert implements ToXContent { this.schedule = schedule; this.lastActionFire = lastActionFire; this.version = version; - this.enabled = enabled; this.throttlePeriod = throttlePeriod; this.ackState = ackState; } @@ -52,7 +50,6 @@ public class Alert implements ToXContent { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(AlertsStore.SCHEDULE_FIELD.getPreferredName(), schedule); - builder.field(AlertsStore.ENABLE.getPreferredName(), enabled); builder.field(AlertsStore.REQUEST_FIELD.getPreferredName()); AlertUtils.writeSearchRequest(searchRequest, builder, params); builder.field(AlertsStore.THROTTLE_PERIOD_FIELD.getPreferredName(), throttlePeriod.millis()); @@ -96,17 +93,6 @@ public class Alert implements ToXContent { this.lastActionFire = lastActionFire; } - /** - * @return Whether this alert has been enabled. - */ - public boolean enabled() { - return enabled; - } - - public void enabled(boolean enabled) { - this.enabled = enabled; - } - /** * @return The current version of the alert. (es document version) */ diff --git a/src/main/java/org/elasticsearch/alerts/AlertManager.java b/src/main/java/org/elasticsearch/alerts/AlertManager.java index f74ae575a20..088cc849f78 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertManager.java +++ b/src/main/java/org/elasticsearch/alerts/AlertManager.java @@ -121,10 +121,6 @@ public class AlertManager extends AbstractComponent { logger.warn("Unable to find [{}] in the alert store, perhaps it has been deleted", alertName); return; } - if (!alert.enabled()) { - logger.debug("Alert [{}] is not enabled", alert.alertName()); - return; - } try { actionManager.addAlertAction(alert, scheduledFireTime, fireTime); diff --git a/src/main/java/org/elasticsearch/alerts/AlertsStore.java b/src/main/java/org/elasticsearch/alerts/AlertsStore.java index da6dd9deb6e..a204adb09f5 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertsStore.java +++ b/src/main/java/org/elasticsearch/alerts/AlertsStore.java @@ -52,7 +52,6 @@ public class AlertsStore extends AbstractComponent { public static final ParseField TRIGGER_FIELD = new ParseField("trigger"); public static final ParseField ACTION_FIELD = new ParseField("actions"); public static final ParseField LAST_ACTION_FIRE = new ParseField("last_action_fire"); - public static final ParseField ENABLE = new ParseField("enable"); public static final ParseField REQUEST_FIELD = new ParseField("request"); public static final ParseField THROTTLE_PERIOD_FIELD = new ParseField("throttle_period"); public static final ParseField LAST_ACTION_EXECUTED_FIELD = new ParseField("last_action_executed"); @@ -250,8 +249,6 @@ public class AlertsStore extends AbstractComponent { } else if (token.isValue()) { if (SCHEDULE_FIELD.match(currentFieldName)) { alert.schedule(parser.textOrNull()); - } else if (ENABLE.match(currentFieldName)) { - alert.enabled(parser.booleanValue()); } else if (LAST_ACTION_FIRE.match(currentFieldName)) { alert.lastActionFire(DateTime.parse(parser.textOrNull())); } else if (LAST_ACTION_EXECUTED_FIELD.match(currentFieldName)) { diff --git a/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java b/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java index c126aca75ca..9d7f9ecaa5b 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java +++ b/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java @@ -306,9 +306,6 @@ public class AlertActionManager extends AbstractComponent { entry.setErrorMsg("Alert was not found in the alerts store"); updateHistoryEntry(entry, AlertActionState.ERROR); return; - } else if (!alert.enabled()) { - updateHistoryEntry(entry, AlertActionState.NO_ACTION_NEEDED); ///@TODO DISABLED - return; } updateHistoryEntry(entry, AlertActionState.SEARCH_UNDERWAY); logger.debug("Running an alert action entry for [{}]", entry.getAlertName()); diff --git a/src/main/resources/alerts.json b/src/main/resources/alerts.json index 2195d4cb071..0c6f157bbb8 100644 --- a/src/main/resources/alerts.json +++ b/src/main/resources/alerts.json @@ -10,9 +10,6 @@ "alert": { "dynamic" : "strict", "properties": { - "enable": { - "type": "boolean" - }, "schedule": { "type": "string" }, diff --git a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java index b2264a5b0de..d8eb1c491d0 100644 --- a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java +++ b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java @@ -88,8 +88,6 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest protected BytesReference createAlertSource(String cron, SearchRequest request, String scriptTrigger) throws IOException { XContentBuilder builder = jsonBuilder().startObject(); builder.field("schedule", cron); - builder.field("enable", true); - builder.field("request"); AlertUtils.writeSearchRequest(request, builder, ToXContent.EMPTY_PARAMS); diff --git a/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java b/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java index 1d58f968c84..460bb15d633 100644 --- a/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java +++ b/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java @@ -37,7 +37,6 @@ public class AlertSerializationTest extends ElasticsearchIntegrationTest { "0/5 * * * * ? *", new DateTime(), 0, - false, new TimeValue(0), AlertAckState.NOT_TRIGGERED); @@ -49,7 +48,6 @@ public class AlertSerializationTest extends ElasticsearchIntegrationTest { internalCluster().getInstance(AlertsStore.class, internalCluster().getMasterName()); Alert parsedAlert = alertsStore.parseAlert("test-serialization", jsonBuilder.bytes()); - assertEquals(parsedAlert.enabled(), alert.enabled()); assertEquals(parsedAlert.version(), alert.version()); assertEquals(parsedAlert.actions(), alert.actions()); assertEquals(parsedAlert.lastActionFire().getMillis(), alert.lastActionFire().getMillis()); diff --git a/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java b/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java index 1bb5b830e24..8507c016d2c 100644 --- a/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java +++ b/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java @@ -57,7 +57,6 @@ public class AlertThrottleTests extends AbstractAlertingTests { alert.actions().add(new IndexAlertAction("action-index", "action-type")); alert.schedule( "0/5 * * * * ? *"); alert.lastActionFire(new DateTime()); - alert.enabled(true); XContentBuilder jsonBuilder = XContentFactory.jsonBuilder(); alert.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS); @@ -130,7 +129,6 @@ public class AlertThrottleTests extends AbstractAlertingTests { alert.actions().add(new IndexAlertAction("action-index", "action-type")); alert.schedule("0/5 * * * * ? *"); alert.lastActionFire(new DateTime()); - alert.enabled(true); alert.setThrottlePeriod(new TimeValue(10, TimeUnit.SECONDS)); XContentBuilder jsonBuilder = XContentFactory.jsonBuilder(); diff --git a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java index 6451b499dbf..7865b9276d0 100644 --- a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java +++ b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java @@ -98,7 +98,6 @@ public class BasicAlertingTest extends AbstractAlertingTests { BytesReference alertSource = jsonBuilder().startObject() .field("schedule", "0/5 * * * * ? *") .startObject("trigger").startObject("script").field("script", "return true").endObject().endObject() - .field("enable", true) .field("malformed_field", "x") .endObject().bytes(); try { diff --git a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java index 3d3389cd152..b209a76efaf 100644 --- a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java +++ b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java @@ -70,7 +70,6 @@ public class BootStrapTest extends AbstractAlertingTests { "0 0/5 * * * ? *", new DateTime(), 0, - true, new TimeValue(0), AlertAckState.NOT_ACKABLE); diff --git a/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java b/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java index 85203b3b1f7..5501fe20cbd 100644 --- a/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java +++ b/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java @@ -163,7 +163,6 @@ public class AlertActionsTest extends AbstractAlertingTests { "0/5 * * * * ? *", null, 1, - true, new TimeValue(0), AlertAckState.NOT_ACKABLE );