[cleanup] Refactoring of the code base
- Renamed `AlertingModule` to `AlertsModule` - Started modularizing the code base.. each module has its own guice module and `AlertsModule` spawn all the sub-modules - Renamed `*Helper` classes to `*Utils` for consistency sake and moved all utilities to `support` package - Moved `AlertsPlugin` to the base package (no need for `plugin` package... it just creates noise) - Moved `State` to be inner enum within `AlertsService` (that's where it belongs) - Moved all the rest actions to `rest.action` package Original commit: elastic/x-pack-elasticsearch@4ce9bf8dcd
This commit is contained in:
parent
4b38006f64
commit
79ee2ed62e
|
@ -7,6 +7,7 @@ package org.elasticsearch.alerts;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.alerts.actions.AlertAction;
|
import org.elasticsearch.alerts.actions.AlertAction;
|
||||||
|
import org.elasticsearch.alerts.support.AlertUtils;
|
||||||
import org.elasticsearch.alerts.triggers.AlertTrigger;
|
import org.elasticsearch.alerts.triggers.AlertTrigger;
|
||||||
import org.elasticsearch.common.joda.time.DateTime;
|
import org.elasticsearch.common.joda.time.DateTime;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
|
|
@ -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
|
* 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 {
|
public enum AlertAckState implements ToXContent {
|
||||||
|
|
||||||
NOT_ACKABLE, ///@TODO perhaps null
|
NOT_ACKABLE, ///@TODO perhaps null
|
||||||
NEEDS_ACK,
|
NEEDS_ACK,
|
||||||
ACKED,
|
ACKED,
|
||||||
|
|
|
@ -9,48 +9,40 @@ package org.elasticsearch.alerts;
|
||||||
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
||||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||||
import org.elasticsearch.alerts.client.AlertsClientModule;
|
import org.elasticsearch.alerts.client.AlertsClientModule;
|
||||||
import org.elasticsearch.alerts.rest.*;
|
import org.elasticsearch.alerts.rest.AlertsRestModule;
|
||||||
import org.elasticsearch.alerts.scheduler.AlertScheduler;
|
import org.elasticsearch.alerts.scheduler.AlertsSchedulerModule;
|
||||||
|
import org.elasticsearch.alerts.support.TemplateUtils;
|
||||||
import org.elasticsearch.alerts.support.init.InitializingModule;
|
import org.elasticsearch.alerts.support.init.InitializingModule;
|
||||||
import org.elasticsearch.alerts.transport.AlertsTransportModule;
|
import org.elasticsearch.alerts.transport.AlertsTransportModule;
|
||||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
|
||||||
import org.elasticsearch.common.collect.ImmutableList;
|
import org.elasticsearch.common.collect.ImmutableList;
|
||||||
import org.elasticsearch.common.inject.AbstractModule;
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Module;
|
import org.elasticsearch.common.inject.Module;
|
||||||
import org.elasticsearch.common.inject.SpawnModules;
|
import org.elasticsearch.common.inject.SpawnModules;
|
||||||
|
|
||||||
|
|
||||||
public class AlertingModule extends AbstractModule implements SpawnModules {
|
public class AlertsModule extends AbstractModule implements SpawnModules {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends Module> spawnModules() {
|
public Iterable<? extends Module> spawnModules() {
|
||||||
return ImmutableList.of(
|
return ImmutableList.of(
|
||||||
new InitializingModule(),
|
new InitializingModule(),
|
||||||
|
new AlertsSchedulerModule(),
|
||||||
new AlertsTransportModule(),
|
new AlertsTransportModule(),
|
||||||
new AlertsClientModule());
|
new AlertsClientModule(),
|
||||||
|
new AlertsRestModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
|
||||||
// Core components
|
// Core components
|
||||||
bind(TemplateHelper.class).asEagerSingleton();
|
bind(TemplateUtils.class).asEagerSingleton();
|
||||||
bind(AlertsStore.class).asEagerSingleton();
|
bind(AlertsStore.class).asEagerSingleton();
|
||||||
bind(AlertService.class).asEagerSingleton();
|
bind(AlertsService.class).asEagerSingleton();
|
||||||
bind(AlertActionService.class).asEagerSingleton();
|
bind(AlertActionService.class).asEagerSingleton();
|
||||||
bind(TriggerService.class).asEagerSingleton();
|
|
||||||
bind(AlertScheduler.class).asEagerSingleton();
|
|
||||||
bind(AlertActionRegistry.class).asEagerSingleton();
|
bind(AlertActionRegistry.class).asEagerSingleton();
|
||||||
bind(ConfigurationService.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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.alerts.support.init.InitializingService;
|
||||||
import org.elasticsearch.common.collect.ImmutableList;
|
import org.elasticsearch.common.collect.ImmutableList;
|
||||||
import org.elasticsearch.common.collect.Lists;
|
import org.elasticsearch.common.collect.Lists;
|
||||||
|
@ -20,11 +20,11 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
|
||||||
|
|
||||||
public class AlertsPlugin extends AbstractPlugin {
|
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";
|
public static final String SCHEDULER_THREAD_POOL_NAME = "alerts_scheduler";
|
||||||
|
|
||||||
@Override public String name() {
|
@Override public String name() {
|
||||||
return ALERT_THREAD_POOL_NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String description() {
|
@Override public String description() {
|
||||||
|
@ -33,9 +33,7 @@ public class AlertsPlugin extends AbstractPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends Module>> modules() {
|
public Collection<Class<? extends Module>> modules() {
|
||||||
Collection<Class<? extends Module>> modules = Lists.newArrayList();
|
return ImmutableList.<Class<? extends Module>>of(AlertsModule.class);
|
||||||
modules.add(AlertingModule.class);
|
|
||||||
return modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,8 +48,8 @@ public class AlertsPlugin extends AbstractPlugin {
|
||||||
@Override
|
@Override
|
||||||
public Settings additionalSettings() {
|
public Settings additionalSettings() {
|
||||||
return settingsBuilder()
|
return settingsBuilder()
|
||||||
.put("threadpool." + ALERT_THREAD_POOL_NAME + ".type", "fixed")
|
.put("threadpool." + 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 + ".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")
|
.put("threadpool." + SCHEDULER_THREAD_POOL_NAME + ".type", "cached")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.alerts;
|
||||||
|
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
|
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||||
import org.elasticsearch.action.delete.DeleteResponse;
|
import org.elasticsearch.action.delete.DeleteResponse;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
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.AlertActionService;
|
||||||
import org.elasticsearch.alerts.actions.AlertHistory;
|
import org.elasticsearch.alerts.actions.AlertHistory;
|
||||||
import org.elasticsearch.alerts.scheduler.AlertScheduler;
|
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.ClientProxy;
|
||||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||||
|
@ -45,7 +47,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
|
||||||
public class AlertService extends AbstractComponent {
|
public class AlertsService extends AbstractComponent {
|
||||||
|
|
||||||
private final ClientProxy client;
|
private final ClientProxy client;
|
||||||
private final AlertScheduler scheduler;
|
private final AlertScheduler scheduler;
|
||||||
|
@ -62,18 +64,18 @@ public class AlertService extends AbstractComponent {
|
||||||
private volatile boolean manuallyStopped;
|
private volatile boolean manuallyStopped;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AlertService(Settings settings, ClientProxy client, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore,
|
public AlertsService(Settings settings, ClientProxy client, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore,
|
||||||
IndicesService indicesService, TriggerService triggerService, AlertActionService actionManager,
|
IndicesService indicesService, TriggerService triggerService, AlertActionService actionManager,
|
||||||
AlertActionRegistry actionRegistry, ThreadPool threadPool, ScriptServiceProxy scriptService) {
|
AlertActionRegistry actionRegistry, ThreadPool threadPool, ScriptServiceProxy scriptService) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
this.scheduler.setAlertService(this);
|
this.scheduler.setAlertsService(this);
|
||||||
this.alertsStore = alertsStore;
|
this.alertsStore = alertsStore;
|
||||||
this.triggerService = triggerService;
|
this.triggerService = triggerService;
|
||||||
this.actionManager = actionManager;
|
this.actionManager = actionManager;
|
||||||
this.actionManager.setAlertService(this);
|
this.actionManager.setAlertsService(this);
|
||||||
this.actionRegistry = actionRegistry;
|
this.actionRegistry = actionRegistry;
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
this.scriptService = scriptService;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,6 +18,8 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.alerts.actions.AlertAction;
|
import org.elasticsearch.alerts.actions.AlertAction;
|
||||||
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
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.support.init.proxy.ClientProxy;
|
||||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
@ -61,7 +63,7 @@ public class AlertsStore extends AbstractComponent {
|
||||||
|
|
||||||
private final ClientProxy client;
|
private final ClientProxy client;
|
||||||
private final TriggerService triggerService;
|
private final TriggerService triggerService;
|
||||||
private final TemplateHelper templateHelper;
|
private final TemplateUtils templateUtils;
|
||||||
private final ConcurrentMap<String, Alert> alertMap;
|
private final ConcurrentMap<String, Alert> alertMap;
|
||||||
private final AlertActionRegistry alertActionRegistry;
|
private final AlertActionRegistry alertActionRegistry;
|
||||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||||
|
@ -71,11 +73,11 @@ public class AlertsStore extends AbstractComponent {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AlertsStore(Settings settings, ClientProxy client, AlertActionRegistry alertActionRegistry,
|
public AlertsStore(Settings settings, ClientProxy client, AlertActionRegistry alertActionRegistry,
|
||||||
TriggerService triggerService, TemplateHelper templateHelper) {
|
TriggerService triggerService, TemplateUtils templateUtils) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.alertActionRegistry = alertActionRegistry;
|
this.alertActionRegistry = alertActionRegistry;
|
||||||
this.templateHelper = templateHelper;
|
this.templateUtils = templateUtils;
|
||||||
this.alertMap = ConcurrentCollections.newConcurrentMap();
|
this.alertMap = ConcurrentCollections.newConcurrentMap();
|
||||||
this.triggerService = triggerService;
|
this.triggerService = triggerService;
|
||||||
// Not using component settings, to let AlertsStore and AlertActionManager share the same settings
|
// Not using component settings, to let AlertsStore and AlertActionManager share the same settings
|
||||||
|
@ -161,7 +163,7 @@ public class AlertsStore extends AbstractComponent {
|
||||||
alertMap.clear();
|
alertMap.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
templateHelper.checkAndUploadIndexTemplate(state, "alerts");
|
templateUtils.checkAndUploadIndexTemplate(state, "alerts");
|
||||||
started.set(true);
|
started.set(true);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -170,7 +172,7 @@ public class AlertsStore extends AbstractComponent {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.info("No previous .alert index, skip loading of alerts");
|
logger.info("No previous .alert index, skip loading of alerts");
|
||||||
templateHelper.checkAndUploadIndexTemplate(state, "alerts");
|
templateUtils.checkAndUploadIndexTemplate(state, "alerts");
|
||||||
started.set(true);
|
started.set(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,7 +16,9 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.alerts.*;
|
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.support.init.proxy.ClientProxy;
|
||||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||||
|
@ -67,11 +69,11 @@ public class AlertActionService extends AbstractComponent {
|
||||||
public static final String ALERT_HISTORY_TYPE = "alerthistory";
|
public static final String ALERT_HISTORY_TYPE = "alerthistory";
|
||||||
|
|
||||||
private final ClientProxy client;
|
private final ClientProxy client;
|
||||||
private AlertService alertService;
|
private AlertsService alertsService;
|
||||||
private final ThreadPool threadPool;
|
private final ThreadPool threadPool;
|
||||||
private final AlertsStore alertsStore;
|
private final AlertsStore alertsStore;
|
||||||
private final TriggerService triggerService;
|
private final TriggerService triggerService;
|
||||||
private final TemplateHelper templateHelper;
|
private final TemplateUtils templateUtils;
|
||||||
private final AlertActionRegistry actionRegistry;
|
private final AlertActionRegistry actionRegistry;
|
||||||
|
|
||||||
private final int scrollSize;
|
private final int scrollSize;
|
||||||
|
@ -85,22 +87,22 @@ public class AlertActionService extends AbstractComponent {
|
||||||
@Inject
|
@Inject
|
||||||
public AlertActionService(Settings settings, ClientProxy client, AlertActionRegistry actionRegistry,
|
public AlertActionService(Settings settings, ClientProxy client, AlertActionRegistry actionRegistry,
|
||||||
ThreadPool threadPool, AlertsStore alertsStore, TriggerService triggerService,
|
ThreadPool threadPool, AlertsStore alertsStore, TriggerService triggerService,
|
||||||
TemplateHelper templateHelper) {
|
TemplateUtils templateUtils) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.actionRegistry = actionRegistry;
|
this.actionRegistry = actionRegistry;
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
this.alertsStore = alertsStore;
|
this.alertsStore = alertsStore;
|
||||||
this.triggerService = triggerService;
|
this.triggerService = triggerService;
|
||||||
this.templateHelper = templateHelper;
|
this.templateUtils = templateUtils;
|
||||||
// Not using component settings, to let AlertsStore and AlertActionManager share the same settings
|
// Not using component settings, to let AlertsStore and AlertActionManager share the same settings
|
||||||
this.scrollTimeout = settings.getAsTime("alerts.scroll.timeout", TimeValue.timeValueSeconds(30));
|
this.scrollTimeout = settings.getAsTime("alerts.scroll.timeout", TimeValue.timeValueSeconds(30));
|
||||||
this.scrollSize = settings.getAsInt("alerts.scroll.size", 100);
|
this.scrollSize = settings.getAsInt("alerts.scroll.size", 100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlertService(AlertService alertService){
|
public void setAlertsService(AlertsService alertsService){
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(ClusterState state) {
|
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 + "*");
|
String[] indices = state.metaData().concreteIndices(IndicesOptions.lenientExpandOpen(), ALERT_HISTORY_INDEX_PREFIX + "*");
|
||||||
if (indices.length == 0) {
|
if (indices.length == 0) {
|
||||||
logger.info("No previous .alerthistory index, skip loading of alert actions");
|
logger.info("No previous .alerthistory index, skip loading of alert actions");
|
||||||
templateHelper.checkAndUploadIndexTemplate(state, "alerthistory");
|
templateUtils.checkAndUploadIndexTemplate(state, "alerthistory");
|
||||||
doStart();
|
doStart();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +137,7 @@ public class AlertActionService extends AbstractComponent {
|
||||||
actionsToBeProcessed.clear();
|
actionsToBeProcessed.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
templateHelper.checkAndUploadIndexTemplate(state, "alerthistory");
|
templateUtils.checkAndUploadIndexTemplate(state, "alerthistory");
|
||||||
doStart();
|
doStart();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -368,7 +370,7 @@ public class AlertActionService extends AbstractComponent {
|
||||||
}
|
}
|
||||||
updateHistoryEntry(entry, AlertActionState.SEARCH_UNDERWAY);
|
updateHistoryEntry(entry, AlertActionState.SEARCH_UNDERWAY);
|
||||||
logger.debug("Running an alert action entry for [{}]", entry.getAlertName());
|
logger.debug("Running an alert action entry for [{}]", entry.getAlertName());
|
||||||
TriggerResult result = alertService.executeAlert(entry);
|
TriggerResult result = alertsService.executeAlert(entry);
|
||||||
entry.setTriggerResponse(result.getTriggerResponse());
|
entry.setTriggerResponse(result.getTriggerResponse());
|
||||||
if (result.isTriggered()) {
|
if (result.isTriggered()) {
|
||||||
entry.setTriggered(true);
|
entry.setTriggered(true);
|
||||||
|
@ -410,7 +412,7 @@ public class AlertActionService extends AbstractComponent {
|
||||||
while (started()) {
|
while (started()) {
|
||||||
AlertHistory entry = actionsToBeProcessed.take();
|
AlertHistory entry = actionsToBeProcessed.take();
|
||||||
if (entry != null) {
|
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) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.alerts.actions;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.alerts.Alert;
|
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.alerts.triggers.AlertTrigger;
|
||||||
import org.elasticsearch.common.joda.time.DateTime;
|
import org.elasticsearch.common.joda.time.DateTime;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
|
|
|
@ -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() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.AlertsStore;
|
||||||
import org.elasticsearch.alerts.client.AlertsClient;
|
import org.elasticsearch.alerts.client.AlertsClient;
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.AlertsStore;
|
||||||
import org.elasticsearch.alerts.client.AlertsClient;
|
import org.elasticsearch.alerts.client.AlertsClient;
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.AlertsStore;
|
||||||
import org.elasticsearch.alerts.client.AlertsClient;
|
import org.elasticsearch.alerts.client.AlertsClient;
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.action.index.IndexResponse;
|
||||||
import org.elasticsearch.alerts.AlertsStore;
|
import org.elasticsearch.alerts.AlertsStore;
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.action.delete.DeleteResponse;
|
||||||
import org.elasticsearch.alerts.AlertsStore;
|
import org.elasticsearch.alerts.AlertsStore;
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.action.get.GetResponse;
|
||||||
import org.elasticsearch.alerts.AlertsStore;
|
import org.elasticsearch.alerts.AlertsStore;
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.action.index.IndexResponse;
|
||||||
import org.elasticsearch.alerts.AlertsStore;
|
import org.elasticsearch.alerts.AlertsStore;
|
|
@ -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;
|
|
|
@ -7,8 +7,8 @@ package org.elasticsearch.alerts.scheduler;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.alerts.Alert;
|
import org.elasticsearch.alerts.Alert;
|
||||||
import org.elasticsearch.alerts.AlertService;
|
import org.elasticsearch.alerts.AlertsService;
|
||||||
import org.elasticsearch.alerts.plugin.AlertsPlugin;
|
import org.elasticsearch.alerts.AlertsPlugin;
|
||||||
import org.elasticsearch.common.component.AbstractComponent;
|
import org.elasticsearch.common.component.AbstractComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.joda.time.DateTime;
|
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
|
// Not happy about it, but otherwise we're stuck with Quartz's SimpleThreadPool
|
||||||
private volatile static ThreadPool threadPool;
|
private volatile static ThreadPool threadPool;
|
||||||
|
|
||||||
private AlertService alertService;
|
private AlertsService alertsService;
|
||||||
private volatile Scheduler scheduler;
|
private volatile Scheduler scheduler;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -35,8 +35,8 @@ public class AlertScheduler extends AbstractComponent {
|
||||||
AlertScheduler.threadPool = threadPool;
|
AlertScheduler.threadPool = threadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlertService(AlertService alertService){
|
public void setAlertsService(AlertsService alertsService){
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +88,7 @@ public class AlertScheduler extends AbstractComponent {
|
||||||
public void executeAlert(String alertName, JobExecutionContext jobExecutionContext){
|
public void executeAlert(String alertName, JobExecutionContext jobExecutionContext){
|
||||||
DateTime scheduledFireTime = new DateTime(jobExecutionContext.getScheduledFireTime());
|
DateTime scheduledFireTime = new DateTime(jobExecutionContext.getScheduledFireTime());
|
||||||
DateTime fireTime = new DateTime(jobExecutionContext.getFireTime());
|
DateTime fireTime = new DateTime(jobExecutionContext.getFireTime());
|
||||||
alertService.scheduleAlert(alertName, scheduledFireTime, fireTime);
|
alertsService.scheduleAlert(alertName, scheduledFireTime, fireTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean remove(String alertName) {
|
public boolean remove(String alertName) {
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
|
@ -3,7 +3,7 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.ElasticsearchIllegalArgumentException;
|
||||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
import org.elasticsearch.ElasticsearchIllegalStateException;
|
|
@ -3,12 +3,13 @@
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
* you may not use this file except in compliance with 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.ActionFuture;
|
||||||
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
|
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.PutIndexTemplateResponse;
|
||||||
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
|
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
|
||||||
|
import org.elasticsearch.alerts.AlertsStore;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||||
import org.elasticsearch.common.component.AbstractComponent;
|
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;
|
private final TransportPutIndexTemplateAction transportPutIndexTemplateAction;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TemplateHelper(Settings settings, TransportPutIndexTemplateAction transportPutIndexTemplateAction) {
|
public TemplateUtils(Settings settings, TransportPutIndexTemplateAction transportPutIndexTemplateAction) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.transportPutIndexTemplateAction = transportPutIndexTemplateAction;
|
this.transportPutIndexTemplateAction = transportPutIndexTemplateAction;
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
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.alerts.AlertsStore;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
@ -25,13 +25,13 @@ import org.elasticsearch.transport.TransportService;
|
||||||
*/
|
*/
|
||||||
public class TransportAckAlertAction extends TransportMasterNodeOperationAction<AckAlertRequest, AckAlertResponse> {
|
public class TransportAckAlertAction extends TransportMasterNodeOperationAction<AckAlertRequest, AckAlertResponse> {
|
||||||
|
|
||||||
private final AlertService alertService;
|
private final AlertsService alertsService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportAckAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
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);
|
super(settings, AckAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,7 @@ public class TransportAckAlertAction extends TransportMasterNodeOperationAction<
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(AckAlertRequest request, ClusterState state, ActionListener<AckAlertResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(AckAlertRequest request, ClusterState state, ActionListener<AckAlertResponse> listener) throws ElasticsearchException {
|
||||||
try {
|
try {
|
||||||
AckAlertResponse response = new AckAlertResponse(alertService.ackAlert(request.getAlertName()));
|
AckAlertResponse response = new AckAlertResponse(alertsService.ackAlert(request.getAlertName()));
|
||||||
listener.onResponse(response);
|
listener.onResponse(response);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
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.alerts.AlertsStore;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
@ -25,13 +25,13 @@ import org.elasticsearch.transport.TransportService;
|
||||||
*/
|
*/
|
||||||
public class TransportDeleteAlertAction extends TransportMasterNodeOperationAction<DeleteAlertRequest, DeleteAlertResponse> {
|
public class TransportDeleteAlertAction extends TransportMasterNodeOperationAction<DeleteAlertRequest, DeleteAlertResponse> {
|
||||||
|
|
||||||
private final AlertService alertService;
|
private final AlertsService alertsService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportDeleteAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
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);
|
super(settings, DeleteAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,7 @@ public class TransportDeleteAlertAction extends TransportMasterNodeOperationActi
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(DeleteAlertRequest request, ClusterState state, ActionListener<DeleteAlertResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(DeleteAlertRequest request, ClusterState state, ActionListener<DeleteAlertResponse> listener) throws ElasticsearchException {
|
||||||
try {
|
try {
|
||||||
DeleteAlertResponse response = new DeleteAlertResponse(alertService.deleteAlert(request.getAlertName()));
|
DeleteAlertResponse response = new DeleteAlertResponse(alertsService.deleteAlert(request.getAlertName()));
|
||||||
listener.onResponse(response);
|
listener.onResponse(response);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||||
import org.elasticsearch.alerts.Alert;
|
import org.elasticsearch.alerts.Alert;
|
||||||
import org.elasticsearch.alerts.AlertService;
|
import org.elasticsearch.alerts.AlertsService;
|
||||||
import org.elasticsearch.alerts.AlertsStore;
|
import org.elasticsearch.alerts.AlertsStore;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
@ -32,13 +32,13 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class TransportGetAlertAction extends TransportMasterNodeOperationAction<GetAlertRequest, GetAlertResponse> {
|
public class TransportGetAlertAction extends TransportMasterNodeOperationAction<GetAlertRequest, GetAlertResponse> {
|
||||||
|
|
||||||
private final AlertService alertService;
|
private final AlertsService alertsService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportGetAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
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);
|
super(settings, GetAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,7 +58,7 @@ public class TransportGetAlertAction extends TransportMasterNodeOperationAction<
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(GetAlertRequest request, ClusterState state, ActionListener<GetAlertResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(GetAlertRequest request, ClusterState state, ActionListener<GetAlertResponse> listener) throws ElasticsearchException {
|
||||||
Alert alert = alertService.getAlert(request.alertName());
|
Alert alert = alertsService.getAlert(request.alertName());
|
||||||
GetResult getResult;
|
GetResult getResult;
|
||||||
if (alert != null) {
|
if (alert != null) {
|
||||||
BytesReference alertSource = null;
|
BytesReference alertSource = null;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
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.alerts.AlertsStore;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
@ -25,13 +25,13 @@ import org.elasticsearch.transport.TransportService;
|
||||||
*/
|
*/
|
||||||
public class TransportPutAlertAction extends TransportMasterNodeOperationAction<PutAlertRequest, PutAlertResponse> {
|
public class TransportPutAlertAction extends TransportMasterNodeOperationAction<PutAlertRequest, PutAlertResponse> {
|
||||||
|
|
||||||
private final AlertService alertService;
|
private final AlertsService alertsService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportPutAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
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);
|
super(settings, PutAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,7 @@ public class TransportPutAlertAction extends TransportMasterNodeOperationAction<
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(PutAlertRequest request, ClusterState state, ActionListener<PutAlertResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(PutAlertRequest request, ClusterState state, ActionListener<PutAlertResponse> listener) throws ElasticsearchException {
|
||||||
try {
|
try {
|
||||||
IndexResponse indexResponse = alertService.putAlert(request.getAlertName(), request.getAlertSource());
|
IndexResponse indexResponse = alertsService.putAlert(request.getAlertName(), request.getAlertSource());
|
||||||
listener.onResponse(new PutAlertResponse(indexResponse));
|
listener.onResponse(new PutAlertResponse(indexResponse));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
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.ClusterService;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||||
|
@ -24,12 +24,12 @@ import org.elasticsearch.transport.TransportService;
|
||||||
*/
|
*/
|
||||||
public class TransportAlertsServiceAction extends TransportMasterNodeOperationAction<AlertsServiceRequest, AlertsServiceResponse> {
|
public class TransportAlertsServiceAction extends TransportMasterNodeOperationAction<AlertsServiceRequest, AlertsServiceResponse> {
|
||||||
|
|
||||||
private final AlertService alertService;
|
private final AlertsService alertsService;
|
||||||
|
|
||||||
@Inject
|
@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);
|
super(settings, actionName, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,14 +51,14 @@ public class TransportAlertsServiceAction extends TransportMasterNodeOperationAc
|
||||||
protected void masterOperation(AlertsServiceRequest request, ClusterState state, ActionListener<AlertsServiceResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(AlertsServiceRequest request, ClusterState state, ActionListener<AlertsServiceResponse> listener) throws ElasticsearchException {
|
||||||
switch (request.getCommand()) {
|
switch (request.getCommand()) {
|
||||||
case "start":
|
case "start":
|
||||||
alertService.start();
|
alertsService.start();
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
alertService.stop();
|
alertsService.stop();
|
||||||
break;
|
break;
|
||||||
case "restart":
|
case "restart":
|
||||||
alertService.start();
|
alertsService.start();
|
||||||
alertService.stop();
|
alertsService.stop();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
listener.onFailure(new ElasticsearchIllegalArgumentException("Command [" + request.getCommand() + "] is undefined"));
|
listener.onFailure(new ElasticsearchIllegalArgumentException("Command [" + request.getCommand() + "] is undefined"));
|
||||||
|
|
|
@ -7,8 +7,8 @@ package org.elasticsearch.alerts.transport.actions.stats;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionResponse;
|
import org.elasticsearch.action.ActionResponse;
|
||||||
import org.elasticsearch.alerts.AlertsBuild;
|
import org.elasticsearch.alerts.AlertsBuild;
|
||||||
|
import org.elasticsearch.alerts.AlertsService;
|
||||||
import org.elasticsearch.alerts.AlertsVersion;
|
import org.elasticsearch.alerts.AlertsVersion;
|
||||||
import org.elasticsearch.alerts.State;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class AlertsStatsResponse extends ActionResponse {
|
||||||
private AlertsVersion version;
|
private AlertsVersion version;
|
||||||
private AlertsBuild build;
|
private AlertsBuild build;
|
||||||
private long numberOfRegisteredAlerts;
|
private long numberOfRegisteredAlerts;
|
||||||
private State alertManagerState;
|
private AlertsService.State alertManagerState;
|
||||||
private boolean alertActionManagerStarted;
|
private boolean alertActionManagerStarted;
|
||||||
private long alertActionManagerQueueSize;
|
private long alertActionManagerQueueSize;
|
||||||
private long alertActionManagerLargestQueueSize;
|
private long alertActionManagerLargestQueueSize;
|
||||||
|
@ -55,11 +55,11 @@ public class AlertsStatsResponse extends ActionResponse {
|
||||||
/**
|
/**
|
||||||
* Returns the state of the alert manager.
|
* Returns the state of the alert manager.
|
||||||
*/
|
*/
|
||||||
public State getAlertManagerStarted() {
|
public AlertsService.State getAlertManagerStarted() {
|
||||||
return alertManagerState;
|
return alertManagerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAlertManagerState(State alertManagerState) {
|
void setAlertManagerState(AlertsService.State alertManagerState) {
|
||||||
this.alertManagerState = alertManagerState;
|
this.alertManagerState = alertManagerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class AlertsStatsResponse extends ActionResponse {
|
||||||
numberOfRegisteredAlerts = in.readLong();
|
numberOfRegisteredAlerts = in.readLong();
|
||||||
alertActionManagerQueueSize = in.readLong();
|
alertActionManagerQueueSize = in.readLong();
|
||||||
alertActionManagerLargestQueueSize = in.readLong();
|
alertActionManagerLargestQueueSize = in.readLong();
|
||||||
alertManagerState = State.fromId(in.readByte());
|
alertManagerState = AlertsService.State.fromId(in.readByte());
|
||||||
alertActionManagerStarted = in.readBoolean();
|
alertActionManagerStarted = in.readBoolean();
|
||||||
version = AlertsVersion.readVersion(in);
|
version = AlertsVersion.readVersion(in);
|
||||||
build = AlertsBuild.readBuild(in);
|
build = AlertsBuild.readBuild(in);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
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.AlertsBuild;
|
||||||
import org.elasticsearch.alerts.AlertsVersion;
|
import org.elasticsearch.alerts.AlertsVersion;
|
||||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||||
|
@ -27,15 +27,15 @@ import org.elasticsearch.transport.TransportService;
|
||||||
*/
|
*/
|
||||||
public class TransportAlertsStatsAction extends TransportMasterNodeOperationAction<AlertsStatsRequest, AlertsStatsResponse> {
|
public class TransportAlertsStatsAction extends TransportMasterNodeOperationAction<AlertsStatsRequest, AlertsStatsResponse> {
|
||||||
|
|
||||||
private final AlertService alertService;
|
private final AlertsService alertsService;
|
||||||
private final AlertActionService alertActionService;
|
private final AlertActionService alertActionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportAlertsStatsAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
public TransportAlertsStatsAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||||
ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService,
|
ThreadPool threadPool, ActionFilters actionFilters, AlertsService alertsService,
|
||||||
AlertActionService alertActionService) {
|
AlertActionService alertActionService) {
|
||||||
super(settings, AlertsStatsAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
super(settings, AlertsStatsAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.alertService = alertService;
|
this.alertsService = alertsService;
|
||||||
this.alertActionService = alertActionService;
|
this.alertActionService = alertActionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +57,10 @@ public class TransportAlertsStatsAction extends TransportMasterNodeOperationActi
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(AlertsStatsRequest request, ClusterState state, ActionListener<AlertsStatsResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(AlertsStatsRequest request, ClusterState state, ActionListener<AlertsStatsResponse> listener) throws ElasticsearchException {
|
||||||
AlertsStatsResponse statsResponse = new AlertsStatsResponse();
|
AlertsStatsResponse statsResponse = new AlertsStatsResponse();
|
||||||
statsResponse.setAlertManagerState(alertService.getState());
|
statsResponse.setAlertManagerState(alertsService.getState());
|
||||||
statsResponse.setAlertActionManagerStarted(alertActionService.started());
|
statsResponse.setAlertActionManagerStarted(alertActionService.started());
|
||||||
statsResponse.setAlertActionManagerQueueSize(alertActionService.getQueueSize());
|
statsResponse.setAlertActionManagerQueueSize(alertActionService.getQueueSize());
|
||||||
statsResponse.setNumberOfRegisteredAlerts(alertService.getNumberOfAlerts());
|
statsResponse.setNumberOfRegisteredAlerts(alertsService.getNumberOfAlerts());
|
||||||
statsResponse.setAlertActionManagerLargestQueueSize(alertActionService.getLargestQueueSize());
|
statsResponse.setAlertActionManagerLargestQueueSize(alertActionService.getLargestQueueSize());
|
||||||
statsResponse.setVersion(AlertsVersion.CURRENT);
|
statsResponse.setVersion(AlertsVersion.CURRENT);
|
||||||
statsResponse.setBuild(AlertsBuild.CURRENT);
|
statsResponse.setBuild(AlertsBuild.CURRENT);
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.alerts.Alert;
|
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.ClientProxy;
|
||||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
plugin=org.elasticsearch.alerts.plugin.AlertsPlugin
|
plugin=org.elasticsearch.alerts.AlertsPlugin
|
||||||
version=${project.version}
|
version=${project.version}
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||||
import org.elasticsearch.alerts.actions.AlertActionState;
|
import org.elasticsearch.alerts.actions.AlertActionState;
|
||||||
import org.elasticsearch.alerts.client.AlertsClient;
|
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.alerts.transport.actions.stats.AlertsStatsResponse;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
@ -71,7 +71,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest
|
||||||
public void startAlertsIfNodesExist() throws Exception {
|
public void startAlertsIfNodesExist() throws Exception {
|
||||||
if (internalTestCluster().size() > 0) {
|
if (internalTestCluster().size() > 0) {
|
||||||
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
||||||
if (response.getAlertManagerStarted() == State.STOPPED) {
|
if (response.getAlertManagerStarted() == AlertsService.State.STOPPED) {
|
||||||
logger.info("[{}#{}]: starting alerts", getTestClass().getSimpleName(), getTestName());
|
logger.info("[{}#{}]: starting alerts", getTestClass().getSimpleName(), getTestName());
|
||||||
startAlerting();
|
startAlerting();
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,7 +223,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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
|
// First manually stop alerting on non elected master node, this will prevent that alerting becomes active
|
||||||
// on these nodes
|
// on these nodes
|
||||||
for (String node : nodes) {
|
for (String node : nodes) {
|
||||||
AlertService alertService = _testCluster.getInstance(AlertService.class, node);
|
AlertsService alertsService = _testCluster.getInstance(AlertsService.class, node);
|
||||||
assertThat(alertService.getState(), equalTo(State.STOPPED));
|
assertThat(alertsService.getState(), equalTo(AlertsService.State.STOPPED));
|
||||||
alertService.stop(); // Prevents these nodes from starting alerting when new elected master node is picked.
|
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.
|
// 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 {
|
try {
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
assertThat(alertService.getState(), not(equalTo(State.STARTING)));
|
assertThat(alertsService.getState(), not(equalTo(AlertsService.State.STARTING)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
alertService.stop();
|
alertsService.stop();
|
||||||
try {
|
try {
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
assertThat(alertService.getState(), equalTo(State.STOPPED));
|
assertThat(alertsService.getState(), equalTo(AlertsService.State.STOPPED));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||||
|
|
||||||
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
assertTrue(response.isAlertActionManagerStarted());
|
||||||
assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED));
|
assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED));
|
||||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L));
|
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||||
|
|
||||||
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
assertTrue(response.isAlertActionManagerStarted());
|
||||||
assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED));
|
assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED));
|
||||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
||||||
|
|
||||||
SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
|
SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
|
||||||
|
@ -94,7 +94,7 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||||
|
|
||||||
response = alertClient().prepareAlertsStats().get();
|
response = alertClient().prepareAlertsStats().get();
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
assertTrue(response.isAlertActionManagerStarted());
|
||||||
assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED));
|
assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED));
|
||||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
||||||
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(1L));
|
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(1L));
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class BootStrapTest extends AbstractAlertingTests {
|
||||||
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
AlertsStatsResponse response = alertClient().prepareAlertsStats().get();
|
||||||
|
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
assertTrue(response.isAlertActionManagerStarted());
|
||||||
assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED));
|
assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED));
|
||||||
long expectedMaximumQueueSize = numberOfAlertHistoryEntriesPerIndex * numberOfAlertHistoryIndices ;
|
long expectedMaximumQueueSize = numberOfAlertHistoryEntriesPerIndex * numberOfAlertHistoryIndices ;
|
||||||
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(expectedMaximumQueueSize));
|
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(expectedMaximumQueueSize));
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,8 @@ public class NoMasterNodeTests extends AbstractAlertingTests {
|
||||||
}
|
}
|
||||||
}), equalTo(true));
|
}), equalTo(true));
|
||||||
// Ensure that the alert manager doesn't run elsewhere
|
// Ensure that the alert manager doesn't run elsewhere
|
||||||
for (AlertService alertService : internalTestCluster().getInstances(AlertService.class)) {
|
for (AlertsService alertsService : internalTestCluster().getInstances(AlertsService.class)) {
|
||||||
assertThat(alertService.getState(), is(State.STOPPED));
|
assertThat(alertsService.getState(), is(AlertsService.State.STOPPED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.alerts.actions.AlertAction;
|
import org.elasticsearch.alerts.actions.AlertAction;
|
||||||
import org.elasticsearch.alerts.actions.IndexAlertAction;
|
import org.elasticsearch.alerts.actions.IndexAlertAction;
|
||||||
|
import org.elasticsearch.alerts.support.AlertUtils;
|
||||||
import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
|
import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
|
||||||
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
|
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
|
||||||
import org.elasticsearch.common.joda.time.DateTime;
|
import org.elasticsearch.common.joda.time.DateTime;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||||
import org.elasticsearch.alerts.*;
|
import org.elasticsearch.alerts.*;
|
||||||
import org.elasticsearch.alerts.client.AlertsClient;
|
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.DeleteAlertRequest;
|
||||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
||||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest;
|
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())
|
.setSource(jsonBuilder().startObject().startObject("template").startObject("match_all").endObject().endObject().endObject())
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
final AlertService alertService = internalTestCluster().getInstance(AlertService.class, internalTestCluster().getMasterName());
|
final AlertsService alertsService = internalTestCluster().getInstance(AlertsService.class, internalTestCluster().getMasterName());
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
assertThat(alertService.getState(), is(State.STARTED));
|
assertThat(alertsService.getState(), is(AlertsService.State.STARTED));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final AtomicBoolean alertActionInvoked = new AtomicBoolean(false);
|
final AtomicBoolean alertActionInvoked = new AtomicBoolean(false);
|
||||||
|
|
|
@ -6,10 +6,7 @@
|
||||||
package org.elasticsearch.alerts.actions;
|
package org.elasticsearch.alerts.actions;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.alerts.AbstractAlertingTests;
|
import org.elasticsearch.alerts.*;
|
||||||
import org.elasticsearch.alerts.AlertsBuild;
|
|
||||||
import org.elasticsearch.alerts.AlertsVersion;
|
|
||||||
import org.elasticsearch.alerts.State;
|
|
||||||
import org.elasticsearch.alerts.client.AlertsClient;
|
import org.elasticsearch.alerts.client.AlertsClient;
|
||||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest;
|
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest;
|
||||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse;
|
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse;
|
||||||
|
@ -36,7 +33,7 @@ public class AlertStatsTests extends AbstractAlertingTests {
|
||||||
AlertsStatsResponse response = alertClient().alertsStats(alertsStatsRequest).actionGet();
|
AlertsStatsResponse response = alertClient().alertsStats(alertsStatsRequest).actionGet();
|
||||||
|
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
assertTrue(response.isAlertActionManagerStarted());
|
||||||
assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED));
|
assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED));
|
||||||
assertThat(response.getAlertActionManagerQueueSize(), equalTo(0L));
|
assertThat(response.getAlertActionManagerQueueSize(), equalTo(0L));
|
||||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(0L));
|
||||||
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(0L));
|
assertThat(response.getAlertActionManagerLargestQueueSize(), equalTo(0L));
|
||||||
|
@ -52,7 +49,7 @@ public class AlertStatsTests extends AbstractAlertingTests {
|
||||||
AlertsStatsResponse response = alertsClient.alertsStats(alertsStatsRequest).actionGet();
|
AlertsStatsResponse response = alertsClient.alertsStats(alertsStatsRequest).actionGet();
|
||||||
|
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
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")));
|
SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
|
||||||
BytesReference alertSource = createAlertSource("* * * * * ? *", searchRequest, "hits.total == 1");
|
BytesReference alertSource = createAlertSource("* * * * * ? *", searchRequest, "hits.total == 1");
|
||||||
|
@ -67,7 +64,7 @@ public class AlertStatsTests extends AbstractAlertingTests {
|
||||||
Thread.sleep(waitTime.getMillis());
|
Thread.sleep(waitTime.getMillis());
|
||||||
|
|
||||||
assertTrue(response.isAlertActionManagerStarted());
|
assertTrue(response.isAlertActionManagerStarted());
|
||||||
assertThat(response.getAlertManagerStarted(), equalTo(State.STARTED));
|
assertThat(response.getAlertManagerStarted(), equalTo(AlertsService.State.STARTED));
|
||||||
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L));
|
assertThat(response.getNumberOfRegisteredAlerts(), equalTo(1L));
|
||||||
//assertThat(response.getAlertActionManagerLargestQueueSize(), greaterThan(0L));
|
//assertThat(response.getAlertActionManagerLargestQueueSize(), greaterThan(0L));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue