Alerts : Alert Transport Layer
This commit fixes the test and tests to make sure the alert we get back from the alertsstore isn't null in execute alert since it may have been deleted. Original commit: elastic/x-pack-elasticsearch@7a57dd090a
This commit is contained in:
parent
a05fc88f0d
commit
85655ac16d
|
@ -118,6 +118,10 @@ public class AlertManager extends AbstractComponent {
|
|||
public void executeAlert(String alertName, DateTime scheduledFireTime, DateTime fireTime){
|
||||
ensureStarted();
|
||||
Alert alert = alertsStore.getAlert(alertName);
|
||||
if (alert == null) {
|
||||
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;
|
||||
|
|
|
@ -106,10 +106,6 @@ public class AlertsStore extends AbstractComponent {
|
|||
* Creates an alert with the specified and fails if an alert with the name already exists.
|
||||
*/
|
||||
public Alert createAlert(Alert alert) throws IOException {
|
||||
if (!client.admin().indices().prepareExists(ALERT_INDEX).execute().actionGet().isExists()) {
|
||||
createAlertsIndex();
|
||||
}
|
||||
|
||||
if (alertMap.putIfAbsent(alert.alertName(), alert) == null) {
|
||||
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
||||
alert.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.alerts.actions;
|
||||
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
|
@ -18,6 +19,8 @@ import org.elasticsearch.alerts.client.AlertsClientInterface;
|
|||
import org.elasticsearch.alerts.plugin.AlertsPlugin;
|
||||
import org.elasticsearch.alerts.transport.actions.create.CreateAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.create.CreateAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.update.UpdateAlertRequest;
|
||||
|
@ -129,10 +132,11 @@ public class AlertActionsTest extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAlert() throws Exception {
|
||||
public void testAlertActions() throws Exception {
|
||||
createIndex("my-index");
|
||||
createIndex(AlertsStore.ALERT_INDEX);
|
||||
createIndex(AlertActionManager.ALERT_HISTORY_INDEX);
|
||||
|
||||
ensureGreen("my-index", AlertsStore.ALERT_INDEX, AlertActionManager.ALERT_HISTORY_INDEX);
|
||||
|
||||
client().preparePutIndexedScript()
|
||||
|
@ -224,6 +228,15 @@ public class AlertActionsTest extends ElasticsearchIntegrationTest {
|
|||
UpdateAlertResponse updateAlertResponse = alertsClient.updateAlert(updateAlertRequest).actionGet();
|
||||
assertTrue(updateAlertResponse.success());
|
||||
|
||||
DeleteAlertRequest deleteAlertRequest = new DeleteAlertRequest(alert.alertName());
|
||||
DeleteAlertResponse deleteAlertResponse = alertsClient.deleteAlert(deleteAlertRequest).actionGet();
|
||||
assertTrue(deleteAlertResponse.success());
|
||||
|
||||
getAlertResponse = alertsClient.getAlert(getAlertRequest).actionGet();
|
||||
assertFalse(getAlertResponse.found());
|
||||
|
||||
updateAlertResponse = alertsClient.updateAlert(updateAlertRequest).actionGet();
|
||||
assertFalse(updateAlertResponse.success());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue