Changed the alerts client to wrap es client
Instead of having another client interface, the alerts client should be a wrapper around the standard es client. This will make sure that whatever logic that is applied on these std clients will also be applied to any requests/actions that are executed in the alerts client. Using the es client introduces a cyclic dependency for all those services that use the es client and that are also injected into the transport actions. For this reason, instead of using the es client and script service directory, we're using proxies. The proxies are initialized lazily be a new `InitializationService`. Also introduced the `AlertsClientModule` and `AlertsTransportModule` Closes elastic/elasticsearch#56 Original commit: elastic/x-pack-elasticsearch@58990a7c85
This commit is contained in:
parent
8c6aad11ed
commit
4b38006f64
|
@ -12,13 +12,14 @@ import org.elasticsearch.action.delete.DeleteResponse;
|
|||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.alerts.actions.AlertHistory;
|
||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||
import org.elasticsearch.alerts.actions.AlertHistory;
|
||||
import org.elasticsearch.alerts.scheduler.AlertScheduler;
|
||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
|
@ -35,7 +36,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.gateway.GatewayService;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -47,6 +47,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
|
||||
public class AlertService extends AbstractComponent {
|
||||
|
||||
private final ClientProxy client;
|
||||
private final AlertScheduler scheduler;
|
||||
private final AlertsStore alertsStore;
|
||||
private final TriggerService triggerService;
|
||||
|
@ -54,18 +55,18 @@ public class AlertService extends AbstractComponent {
|
|||
private final AlertActionRegistry actionRegistry;
|
||||
private final ThreadPool threadPool;
|
||||
private final ClusterService clusterService;
|
||||
private final ScriptService scriptService;
|
||||
private final Client client;
|
||||
private final ScriptServiceProxy scriptService;
|
||||
private final KeyedLock<String> alertLock = new KeyedLock<>();
|
||||
private final AtomicReference<State> state = new AtomicReference<>(State.STOPPED);
|
||||
|
||||
private volatile boolean manuallyStopped;
|
||||
|
||||
@Inject
|
||||
public AlertService(Settings settings, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore,
|
||||
public AlertService(Settings settings, ClientProxy client, ClusterService clusterService, AlertScheduler scheduler, AlertsStore alertsStore,
|
||||
IndicesService indicesService, TriggerService triggerService, AlertActionService actionManager,
|
||||
AlertActionRegistry actionRegistry, ThreadPool threadPool, ScriptService scriptService, Client client) {
|
||||
AlertActionRegistry actionRegistry, ThreadPool threadPool, ScriptServiceProxy scriptService) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
this.scheduler = scheduler;
|
||||
this.threadPool = threadPool;
|
||||
this.scheduler.setAlertService(this);
|
||||
|
@ -75,9 +76,7 @@ public class AlertService extends AbstractComponent {
|
|||
this.actionManager.setAlertService(this);
|
||||
this.actionRegistry = actionRegistry;
|
||||
this.clusterService = clusterService;
|
||||
|
||||
this.scriptService = scriptService;
|
||||
this.client = client;
|
||||
|
||||
clusterService.add(new AlertsClusterStateListener());
|
||||
// Close if the indices service is being stopped, so we don't run into search failures (locally) that will
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.elasticsearch.ElasticsearchIllegalStateException;
|
|||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
|
@ -48,7 +48,7 @@ public final class AlertUtils {
|
|||
/**
|
||||
* Creates a new search request applying the scheduledFireTime and fireTime to the original request
|
||||
*/
|
||||
public static SearchRequest createSearchRequestWithTimes(SearchRequest request, DateTime scheduledFireTime, DateTime fireTime, ScriptService scriptService) throws IOException {
|
||||
public static SearchRequest createSearchRequestWithTimes(SearchRequest request, DateTime scheduledFireTime, DateTime fireTime, ScriptServiceProxy scriptService) throws IOException {
|
||||
SearchRequest triggerSearchRequest = new SearchRequest(request)
|
||||
.indicesOptions(request.indicesOptions())
|
||||
.indices(request.indices());
|
||||
|
|
|
@ -6,27 +6,33 @@
|
|||
package org.elasticsearch.alerts;
|
||||
|
||||
|
||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
||||
import org.elasticsearch.alerts.client.NodeAlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||
import org.elasticsearch.alerts.client.AlertsClientModule;
|
||||
import org.elasticsearch.alerts.rest.*;
|
||||
import org.elasticsearch.alerts.scheduler.AlertScheduler;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.TransportAckAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.config.TransportConfigAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.TransportDeleteAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.get.TransportGetAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.put.TransportPutAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.service.TransportAlertsServiceAction;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.TransportAlertStatsAction;
|
||||
import org.elasticsearch.alerts.support.init.InitializingModule;
|
||||
import org.elasticsearch.alerts.transport.AlertsTransportModule;
|
||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.SpawnModules;
|
||||
|
||||
|
||||
public class AlertingModule extends AbstractModule {
|
||||
public class AlertingModule extends AbstractModule implements SpawnModules {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Module> spawnModules() {
|
||||
return ImmutableList.of(
|
||||
new InitializingModule(),
|
||||
new AlertsTransportModule(),
|
||||
new AlertsClientModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
// Core components
|
||||
bind(TemplateHelper.class).asEagerSingleton();
|
||||
bind(AlertsStore.class).asEagerSingleton();
|
||||
|
@ -37,16 +43,6 @@ public class AlertingModule extends AbstractModule {
|
|||
bind(AlertActionRegistry.class).asEagerSingleton();
|
||||
bind(ConfigurationService.class).asEagerSingleton();
|
||||
|
||||
// Transport and client layer
|
||||
bind(TransportPutAlertAction.class).asEagerSingleton();
|
||||
bind(TransportDeleteAlertAction.class).asEagerSingleton();
|
||||
bind(TransportGetAlertAction.class).asEagerSingleton();
|
||||
bind(TransportAlertStatsAction.class).asEagerSingleton();
|
||||
bind(TransportAckAlertAction.class).asEagerSingleton();
|
||||
bind(TransportAlertsServiceAction.class).asEagerSingleton();
|
||||
bind(TransportConfigAlertAction.class).asEagerSingleton();
|
||||
bind(AlertsClient.class).to(NodeAlertsClient.class).asEagerSingleton();
|
||||
|
||||
// Rest layer
|
||||
bind(RestPutAlertAction.class).asEagerSingleton();
|
||||
bind(RestDeleteAlertAction.class).asEagerSingleton();
|
||||
|
|
|
@ -18,8 +18,8 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.alerts.actions.AlertAction;
|
||||
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
|
@ -59,7 +59,7 @@ public class AlertsStore extends AbstractComponent {
|
|||
public static final ParseField ACK_STATE_FIELD = new ParseField("ack_state");
|
||||
public static final ParseField META_FIELD = new ParseField("meta");
|
||||
|
||||
private final Client client;
|
||||
private final ClientProxy client;
|
||||
private final TriggerService triggerService;
|
||||
private final TemplateHelper templateHelper;
|
||||
private final ConcurrentMap<String, Alert> alertMap;
|
||||
|
@ -70,7 +70,7 @@ public class AlertsStore extends AbstractComponent {
|
|||
private final TimeValue scrollTimeout;
|
||||
|
||||
@Inject
|
||||
public AlertsStore(Settings settings, Client client, AlertActionRegistry alertActionRegistry,
|
||||
public AlertsStore(Settings settings, ClientProxy client, AlertActionRegistry alertActionRegistry,
|
||||
TriggerService triggerService, TemplateHelper templateHelper) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
|
@ -81,7 +81,6 @@ public class AlertsStore extends AbstractComponent {
|
|||
// Not using component settings, to let AlertsStore and AlertActionManager share the same settings
|
||||
this.scrollTimeout = settings.getAsTime("alerts.scroll.timeout", TimeValue.timeValueSeconds(30));
|
||||
this.scrollSize = settings.getAsInt("alerts.scroll.size", 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.alerts;
|
|||
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -29,11 +29,11 @@ public class ConfigurationService extends AbstractComponent {
|
|||
public static final String CONFIG_TYPE = "config";
|
||||
public static final String GLOBAL_CONFIG_NAME = "global";
|
||||
|
||||
private final Client client;
|
||||
private final ClientProxy client;
|
||||
private final CopyOnWriteArrayList<ConfigurableComponentListener> registeredComponents;
|
||||
|
||||
@Inject
|
||||
public ConfigurationService(Settings settings, Client client) {
|
||||
public ConfigurationService(Settings settings, ClientProxy client) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
registeredComponents = new CopyOnWriteArrayList<>();
|
||||
|
@ -60,8 +60,6 @@ public class ConfigurationService extends AbstractComponent {
|
|||
|
||||
/**
|
||||
* Notify the listeners of a new config
|
||||
*
|
||||
* @param settingsSource
|
||||
*/
|
||||
public IndexResponse updateConfig(BytesReference settingsSource) throws IOException {
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ package org.elasticsearch.alerts.actions;
|
|||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.ConfigurationService;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -26,8 +26,7 @@ public class AlertActionRegistry extends AbstractComponent {
|
|||
private volatile ImmutableOpenMap<String, AlertActionFactory> actionImplemented;
|
||||
|
||||
@Inject
|
||||
public AlertActionRegistry(Settings settings, Client client, ConfigurationService configurationService,
|
||||
ScriptService scriptService) {
|
||||
public AlertActionRegistry(Settings settings, ClientProxy client, ConfigurationService configurationService, ScriptServiceProxy scriptService) {
|
||||
super(settings);
|
||||
actionImplemented = ImmutableOpenMap.<String, AlertActionFactory>builder()
|
||||
.fPut("email", new SmtpAlertActionFactory(configurationService, scriptService))
|
||||
|
|
|
@ -17,9 +17,9 @@ import org.elasticsearch.action.search.SearchType;
|
|||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.alerts.*;
|
||||
import org.elasticsearch.alerts.plugin.AlertsPlugin;
|
||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.alerts.triggers.TriggerService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
@ -66,7 +66,7 @@ public class AlertActionService extends AbstractComponent {
|
|||
public static final DateTimeFormatter alertHistoryIndexTimeFormat = DateTimeFormat.forPattern("YYYY-MM-dd");
|
||||
public static final String ALERT_HISTORY_TYPE = "alerthistory";
|
||||
|
||||
private final Client client;
|
||||
private final ClientProxy client;
|
||||
private AlertService alertService;
|
||||
private final ThreadPool threadPool;
|
||||
private final AlertsStore alertsStore;
|
||||
|
@ -83,7 +83,7 @@ public class AlertActionService extends AbstractComponent {
|
|||
private volatile Thread queueReaderThread;
|
||||
|
||||
@Inject
|
||||
public AlertActionService(Settings settings, Client client, AlertActionRegistry actionRegistry,
|
||||
public AlertActionService(Settings settings, ClientProxy client, AlertActionRegistry actionRegistry,
|
||||
ThreadPool threadPool, AlertsStore alertsStore, TriggerService triggerService,
|
||||
TemplateHelper templateHelper) {
|
||||
super(settings);
|
||||
|
|
|
@ -11,8 +11,8 @@ import org.elasticsearch.ElasticsearchIllegalStateException;
|
|||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.ConfigurationService;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -23,10 +23,10 @@ import java.io.IOException;
|
|||
*/
|
||||
public class IndexAlertActionFactory implements AlertActionFactory {
|
||||
|
||||
private final Client client;
|
||||
private final ClientProxy client;
|
||||
private final ConfigurationService configurationService;
|
||||
|
||||
public IndexAlertActionFactory(Client client, ConfigurationService configurationService){
|
||||
public IndexAlertActionFactory(ClientProxy client, ConfigurationService configurationService){
|
||||
this.client = client;
|
||||
this.configurationService = configurationService;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.ElasticsearchIllegalStateException;
|
|||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.ConfigurableComponentListener;
|
||||
import org.elasticsearch.alerts.ConfigurationService;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -39,11 +40,11 @@ public class SmtpAlertActionFactory implements AlertActionFactory, ConfigurableC
|
|||
private static final String DEFAULT_MESSAGE = "{{alert_name}} triggered with {{response.hits.total}} results";
|
||||
|
||||
private final ConfigurationService configurationService;
|
||||
private final ScriptService scriptService;
|
||||
private final ScriptServiceProxy scriptService;
|
||||
|
||||
private volatile Settings settings;
|
||||
|
||||
public SmtpAlertActionFactory(ConfigurationService configurationService, ScriptService scriptService) {
|
||||
public SmtpAlertActionFactory(ConfigurationService configurationService, ScriptServiceProxy scriptService) {
|
||||
this.configurationService = configurationService;
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
@ -154,7 +155,7 @@ public class SmtpAlertActionFactory implements AlertActionFactory, ConfigurableC
|
|||
this.settings = settings;
|
||||
}
|
||||
|
||||
public static String renderTemplate(String template, Alert alert, TriggerResult result, ScriptService scriptService) {
|
||||
public static String renderTemplate(String template, Alert alert, TriggerResult result, ScriptServiceProxy scriptService) {
|
||||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put(ALERT_NAME_VARIABLE_NAME, alert.getAlertName());
|
||||
templateParams.put(RESPONSE_VARIABLE_NAME, result.getActionResponse());
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.netty.handler.codec.http.HttpMethod;
|
||||
|
@ -38,11 +39,11 @@ public class WebhookAlertActionFactory implements AlertActionFactory {
|
|||
private static String REQUEST = "request";
|
||||
static String DEFAULT_PARAMETER_STRING = "alertname={{alert_name}}&request=%{{request}}&response=%{{response}}";
|
||||
|
||||
private final ScriptService scriptService;
|
||||
private final ScriptServiceProxy scriptService;
|
||||
|
||||
private final Logger logger = Logger.getLogger(WebhookAlertActionFactory.class);
|
||||
|
||||
public WebhookAlertActionFactory(ScriptService scriptService) {
|
||||
public WebhookAlertActionFactory(ScriptServiceProxy scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
|
@ -129,7 +130,7 @@ public class WebhookAlertActionFactory implements AlertActionFactory {
|
|||
|
||||
}
|
||||
|
||||
static String encodeParameterString(String parameterString, Alert alert, TriggerResult result, ScriptService scriptService) throws IOException {
|
||||
static String encodeParameterString(String parameterString, Alert alert, TriggerResult result, ScriptServiceProxy scriptService) throws IOException {
|
||||
XContentBuilder responseBuilder = XContentFactory.jsonBuilder();
|
||||
|
||||
responseBuilder.startObject();
|
||||
|
@ -150,7 +151,7 @@ public class WebhookAlertActionFactory implements AlertActionFactory {
|
|||
}
|
||||
|
||||
|
||||
public String renderUrl(String url, Alert alert, TriggerResult result, ScriptService scriptService) {
|
||||
public String renderUrl(String url, Alert alert, TriggerResult result, ScriptServiceProxy scriptService) {
|
||||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put(ALERT_NAME, alert.getAlertName());
|
||||
templateParams.put(RESPONSE, result.getActionResponse());
|
||||
|
|
|
@ -5,17 +5,18 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.client;
|
||||
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.action.ClientAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* Base alert action class.
|
||||
*/
|
||||
public abstract class AlertsClientAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClient>> extends Action<Request, Response, RequestBuilder, AlertsClient> {
|
||||
public abstract class AlertsAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> extends ClientAction<Request, Response, RequestBuilder> {
|
||||
|
||||
protected AlertsClientAction(String name) {
|
||||
protected AlertsAction(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
|
@ -7,32 +7,47 @@ package org.elasticsearch.alerts.client;
|
|||
|
||||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.AckAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.AckAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.AckAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.AckAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.config.ConfigAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.config.ConfigAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.config.ConfigAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.config.ConfigAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.put.PutAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.put.PutAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.put.PutAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.service.AlertServiceRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.service.AlertsServiceAction;
|
||||
import org.elasticsearch.alerts.transport.actions.service.AlertsServiceRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.service.AlertsServiceRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.service.AlertsServiceResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsAction;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
||||
/**
|
||||
*/
|
||||
public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
||||
public class AlertsClient {
|
||||
|
||||
private final Client client;
|
||||
|
||||
@Inject
|
||||
public AlertsClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder that gets an alert by name (id)
|
||||
|
@ -40,14 +55,18 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
GetAlertRequestBuilder prepareGetAlert(String alertName);
|
||||
public GetAlertRequestBuilder prepareGetAlert(String alertName) {
|
||||
return new GetAlertRequestBuilder(client, alertName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder that gets an alert
|
||||
*
|
||||
* @return the request builder
|
||||
*/
|
||||
GetAlertRequestBuilder prepareGetAlert();
|
||||
public GetAlertRequestBuilder prepareGetAlert() {
|
||||
return new GetAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an alert from the alert index
|
||||
|
@ -55,7 +74,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The get alert request
|
||||
* @param listener The listener for the get alert response containing the GetResponse for this alert
|
||||
*/
|
||||
void getAlert(GetAlertRequest request, ActionListener<GetAlertResponse> listener);
|
||||
public void getAlert(GetAlertRequest request, ActionListener<GetAlertResponse> listener) {
|
||||
client.execute(GetAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an alert from the alert index
|
||||
|
@ -63,7 +84,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The get alert request with the alert name (id)
|
||||
* @return The response containing the GetResponse for this alert
|
||||
*/
|
||||
ActionFuture<GetAlertResponse> getAlert(GetAlertRequest request);
|
||||
public ActionFuture<GetAlertResponse> getAlert(GetAlertRequest request) {
|
||||
return client.execute(GetAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder to delete an alert by name (id)
|
||||
|
@ -71,14 +94,18 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
DeleteAlertRequestBuilder prepareDeleteAlert(String alertName);
|
||||
public DeleteAlertRequestBuilder prepareDeleteAlert(String alertName) {
|
||||
return new DeleteAlertRequestBuilder(client, alertName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder that deletes an alert
|
||||
*
|
||||
* @return The request builder
|
||||
*/
|
||||
DeleteAlertRequestBuilder prepareDeleteAlert();
|
||||
public DeleteAlertRequestBuilder prepareDeleteAlert() {
|
||||
return new DeleteAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an alert
|
||||
|
@ -86,7 +113,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The delete request with the alert name (id) to be deleted
|
||||
* @param listener The listener for the delete alert response containing the DeleteResponse for this action
|
||||
*/
|
||||
void deleteAlert(DeleteAlertRequest request, ActionListener<DeleteAlertResponse> listener);
|
||||
public void deleteAlert(DeleteAlertRequest request, ActionListener<DeleteAlertResponse> listener) {
|
||||
client.execute(DeleteAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an alert
|
||||
|
@ -94,7 +123,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The delete request with the alert name (id) to be deleted
|
||||
* @return The response containing the DeleteResponse for this action
|
||||
*/
|
||||
ActionFuture<DeleteAlertResponse> deleteAlert(DeleteAlertRequest request);
|
||||
public ActionFuture<DeleteAlertResponse> deleteAlert(DeleteAlertRequest request) {
|
||||
return client.execute(DeleteAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder to build a request to put an alert
|
||||
|
@ -102,14 +133,18 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param alertName The name of the alert to put
|
||||
* @return The builder to create the alert
|
||||
*/
|
||||
PutAlertRequestBuilder preparePutAlert(String alertName);
|
||||
public PutAlertRequestBuilder preparePutAlert(String alertName) {
|
||||
return new PutAlertRequestBuilder(client, alertName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder to build a request to put an alert
|
||||
*
|
||||
* @return The builder
|
||||
*/
|
||||
PutAlertRequestBuilder preparePutAlert();
|
||||
public PutAlertRequestBuilder preparePutAlert() {
|
||||
return new PutAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an alert and registers it with the scheduler
|
||||
|
@ -117,7 +152,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The request containing the alert to index and register
|
||||
* @param listener The listener for the response containing the IndexResponse for this alert
|
||||
*/
|
||||
void putAlert(PutAlertRequest request, ActionListener<PutAlertResponse> listener);
|
||||
public void putAlert(PutAlertRequest request, ActionListener<PutAlertResponse> listener) {
|
||||
client.execute(PutAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an alert and registers it with the scheduler
|
||||
|
@ -125,8 +162,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The request containing the alert to index and register
|
||||
* @return The response containing the IndexResponse for this alert
|
||||
*/
|
||||
ActionFuture<PutAlertResponse> putAlert(PutAlertRequest request);
|
||||
|
||||
public ActionFuture<PutAlertResponse> putAlert(PutAlertRequest request) {
|
||||
return client.execute(PutAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alert stats
|
||||
|
@ -134,14 +172,18 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The request for the alert stats
|
||||
* @return The response containing the StatsResponse for this action
|
||||
*/
|
||||
ActionFuture<AlertsStatsResponse> alertsStats(AlertsStatsRequest request);
|
||||
public ActionFuture<AlertsStatsResponse> alertsStats(AlertsStatsRequest request) {
|
||||
return client.execute(AlertsStatsAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder to build a request to get the alerts stats
|
||||
*
|
||||
* @return The builder get the alerts stats
|
||||
*/
|
||||
AlertsStatsRequestBuilder prepareAlertsStats();
|
||||
public AlertsStatsRequestBuilder prepareAlertsStats() {
|
||||
return new AlertsStatsRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alert stats
|
||||
|
@ -149,7 +191,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The request for the alert stats
|
||||
* @param listener The listener for the response containing the AlertsStatsResponse
|
||||
*/
|
||||
void alertsStats(AlertsStatsRequest request, ActionListener<AlertsStatsResponse> listener);
|
||||
public void alertsStats(AlertsStatsRequest request, ActionListener<AlertsStatsResponse> listener) {
|
||||
client.execute(AlertsStatsAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder to ack an alert by name (id)
|
||||
|
@ -157,14 +201,18 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
AckAlertRequestBuilder prepareAckAlert(String alertName);
|
||||
public AckAlertRequestBuilder prepareAckAlert(String alertName) {
|
||||
return new AckAlertRequestBuilder(client, alertName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request builder that acks an alert
|
||||
*
|
||||
* @return The request builder
|
||||
*/
|
||||
AckAlertRequestBuilder prepareAckAlert();
|
||||
public AckAlertRequestBuilder prepareAckAlert() {
|
||||
return new AckAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ack an alert
|
||||
|
@ -172,7 +220,9 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The ack request with the alert name (id) to be acked
|
||||
* @param listener The listener for the ack alert response
|
||||
*/
|
||||
void ackAlert(AckAlertRequest request, ActionListener<AckAlertResponse> listener);
|
||||
public void ackAlert(AckAlertRequest request, ActionListener<AckAlertResponse> listener) {
|
||||
client.execute(AckAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acks an alert
|
||||
|
@ -180,38 +230,49 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
|||
* @param request The ack request with the alert name (id) to be acked
|
||||
* @return The AckAlertResponse
|
||||
*/
|
||||
ActionFuture<AckAlertResponse> ackAlert(AckAlertRequest request);
|
||||
public ActionFuture<AckAlertResponse> ackAlert(AckAlertRequest request) {
|
||||
return client.execute(AckAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare make an alert service request.
|
||||
*/
|
||||
AlertServiceRequestBuilder prepareAlertService();
|
||||
public AlertsServiceRequestBuilder prepareAlertService() {
|
||||
return new AlertsServiceRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an alert service request to either start, stop or restart the alerting plugin.
|
||||
*/
|
||||
void alertService(AlertsServiceRequest request, ActionListener<AlertsServiceResponse> listener);
|
||||
public void alertService(AlertsServiceRequest request, ActionListener<AlertsServiceResponse> listener) {
|
||||
client.execute(AlertsServiceAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an alert service request to either start, stop or restart the alerting plugin.
|
||||
*/
|
||||
ActionFuture<AlertsServiceResponse> alertService(AlertsServiceRequest request);
|
||||
|
||||
public ActionFuture<AlertsServiceResponse> alertService(AlertsServiceRequest request) {
|
||||
return client.execute(AlertsServiceAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare make an alert config request.
|
||||
*/
|
||||
ConfigAlertRequestBuilder prepareAlertConfig();
|
||||
public ConfigAlertRequestBuilder prepareAlertConfig() {
|
||||
return new ConfigAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an config alert request
|
||||
*/
|
||||
void alertConfig(ConfigAlertRequest request, ActionListener<ConfigAlertResponse> listener);
|
||||
public void alertConfig(ConfigAlertRequest request, ActionListener<ConfigAlertResponse> listener) {
|
||||
client.execute(ConfigAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an config alert request
|
||||
*/
|
||||
ActionFuture<ConfigAlertResponse> alertConfig(ConfigAlertRequest request);
|
||||
|
||||
|
||||
public ActionFuture<ConfigAlertResponse> alertConfig(ConfigAlertRequest request) {
|
||||
return client.execute(ConfigAlertAction.INSTANCE, request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.client;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AlertsClientModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(AlertsClient.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -1,210 +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.client;
|
||||
|
||||
import org.elasticsearch.action.*;
|
||||
import org.elasticsearch.action.support.TransportAction;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.*;
|
||||
import org.elasticsearch.alerts.transport.actions.config.*;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.*;
|
||||
import org.elasticsearch.alerts.transport.actions.get.*;
|
||||
import org.elasticsearch.alerts.transport.actions.put.*;
|
||||
import org.elasticsearch.alerts.transport.actions.service.*;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.*;
|
||||
import org.elasticsearch.client.support.Headers;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
public class NodeAlertsClient implements AlertsClient {
|
||||
|
||||
private final Headers headers;
|
||||
private final ThreadPool threadPool;
|
||||
private final ImmutableMap<GenericAction, TransportAction> internalActions;
|
||||
|
||||
@Inject
|
||||
public NodeAlertsClient(ThreadPool threadPool, Headers headers, TransportPutAlertAction transportPutAlertAction,
|
||||
TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction,
|
||||
TransportAlertStatsAction transportAlertStatsAction, TransportAckAlertAction transportAckAlertAction,
|
||||
TransportAlertsServiceAction transportAlertsServiceAction, TransportConfigAlertAction transportConfigAlertAction) {
|
||||
this.headers = headers;
|
||||
this.threadPool = threadPool;
|
||||
internalActions = ImmutableMap.<GenericAction, TransportAction>builder()
|
||||
.put(PutAlertAction.INSTANCE, transportPutAlertAction)
|
||||
.put(GetAlertAction.INSTANCE, transportGetAlertAction)
|
||||
.put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction)
|
||||
.put(AlertsStatsAction.INSTANCE, transportAlertStatsAction)
|
||||
.put(AckAlertAction.INSTANCE, transportAckAlertAction)
|
||||
.put(AlertServiceAction.INSTANCE, transportAlertsServiceAction)
|
||||
.put(ConfigAlertAction.INSTANCE, transportConfigAlertAction)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAlertRequestBuilder prepareGetAlert(String alertName) {
|
||||
return new GetAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAlertRequestBuilder prepareGetAlert() {
|
||||
return new GetAlertRequestBuilder(this);
|
||||
}
|
||||
|
||||
public void getAlert(GetAlertRequest request, ActionListener<GetAlertResponse> response){
|
||||
execute(GetAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<GetAlertResponse> getAlert(GetAlertRequest request) {
|
||||
return execute(GetAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteAlertRequestBuilder prepareDeleteAlert(String alertName) {
|
||||
return new DeleteAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteAlertRequestBuilder prepareDeleteAlert() {
|
||||
return new DeleteAlertRequestBuilder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAlert(DeleteAlertRequest request, ActionListener<DeleteAlertResponse> response) {
|
||||
execute(DeleteAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<DeleteAlertResponse> deleteAlert(DeleteAlertRequest request) {
|
||||
return execute(DeleteAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutAlertRequestBuilder preparePutAlert(String alertName) {
|
||||
return new PutAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutAlertRequestBuilder preparePutAlert() {
|
||||
return new PutAlertRequestBuilder(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAlert(PutAlertRequest request, ActionListener<PutAlertResponse> response) {
|
||||
execute(PutAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<PutAlertResponse> putAlert(PutAlertRequest request) {
|
||||
return execute(PutAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<AlertsStatsResponse> alertsStats(AlertsStatsRequest request) {
|
||||
return execute(AlertsStatsAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertsStatsRequestBuilder prepareAlertsStats() {
|
||||
return new AlertsStatsRequestBuilder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alertsStats(AlertsStatsRequest request, ActionListener<AlertsStatsResponse> listener) {
|
||||
execute(AlertsStatsAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AckAlertRequestBuilder prepareAckAlert(String alertName) {
|
||||
return new AckAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AckAlertRequestBuilder prepareAckAlert() {
|
||||
return new AckAlertRequestBuilder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ackAlert(AckAlertRequest request, ActionListener<AckAlertResponse> listener) {
|
||||
execute(AckAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<AckAlertResponse> ackAlert(AckAlertRequest request) {
|
||||
return execute(AckAlertAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertServiceRequestBuilder prepareAlertService() {
|
||||
return new AlertServiceRequestBuilder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alertService(AlertsServiceRequest request, ActionListener<AlertsServiceResponse> listener) {
|
||||
execute(AlertServiceAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<AlertsServiceResponse> alertService(AlertsServiceRequest request) {
|
||||
return execute(AlertServiceAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare make an alert config request.
|
||||
*/
|
||||
@Override
|
||||
public ConfigAlertRequestBuilder prepareAlertConfig() {
|
||||
return new ConfigAlertRequestBuilder(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an config alert request
|
||||
*
|
||||
* @param request
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void alertConfig(ConfigAlertRequest request, ActionListener<ConfigAlertResponse> listener) {
|
||||
execute(ConfigAlertAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an config alert request
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@Override
|
||||
public ActionFuture<ConfigAlertResponse> alertConfig(ConfigAlertRequest request) {
|
||||
return execute(ConfigAlertAction.INSTANCE, request);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClient>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, AlertsClient> action, Request request) {
|
||||
headers.applyTo(request);
|
||||
TransportAction<Request, Response> transportAction = internalActions.get((AlertsClientAction)action);
|
||||
return transportAction.execute(request);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClient>> void execute(Action<Request, Response, RequestBuilder, AlertsClient> action, Request request, ActionListener<Response> listener) {
|
||||
headers.applyTo(request);
|
||||
TransportAction<Request, Response> transportAction = internalActions.get((AlertsClientAction)action);
|
||||
transportAction.execute(request, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClient>> RequestBuilder prepareExecute(Action<Request, Response, RequestBuilder, AlertsClient> action) {
|
||||
return action.newRequestBuilder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPool threadPool() {
|
||||
return threadPool;
|
||||
}
|
||||
}
|
|
@ -6,7 +6,10 @@
|
|||
package org.elasticsearch.alerts.plugin;
|
||||
|
||||
import org.elasticsearch.alerts.AlertingModule;
|
||||
import org.elasticsearch.alerts.support.init.InitializingService;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.collect.Lists;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.AbstractPlugin;
|
||||
|
@ -35,6 +38,15 @@ public class AlertsPlugin extends AbstractPlugin {
|
|||
return modules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> services() {
|
||||
return ImmutableList.<Class<? extends LifecycleComponent>>of(
|
||||
// the initialization service must be first in the list
|
||||
// as other services may depend on one of the initialized
|
||||
// constructs
|
||||
InitializingService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings additionalSettings() {
|
||||
return settingsBuilder()
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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.support.init;
|
||||
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class InitializingModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
bind(ClientProxy.class).asEagerSingleton();
|
||||
bind(ScriptServiceProxy.class).asEagerSingleton();
|
||||
|
||||
Multibinder<InitializingService.Initializable> mbinder = Multibinder.newSetBinder(binder(), InitializingService.Initializable.class);
|
||||
mbinder.addBinding().to(ClientProxy.class);
|
||||
mbinder.addBinding().to(ScriptServiceProxy.class);
|
||||
bind(InitializingService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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.support.init;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A service to lazy initialize {@link InitializingService.Initializable} constructs.
|
||||
*/
|
||||
public class InitializingService extends AbstractLifecycleComponent {
|
||||
|
||||
private final Injector injector;
|
||||
private final Set<Initializable> initializables;
|
||||
|
||||
@Inject
|
||||
public InitializingService(Settings settings, Injector injector, Set<Initializable> initializables) {
|
||||
super(settings);
|
||||
this.injector = injector;
|
||||
this.initializables = initializables;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ElasticsearchException {
|
||||
for (Initializable initializable : initializables) {
|
||||
initializable.init(injector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws ElasticsearchException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws ElasticsearchException {
|
||||
}
|
||||
|
||||
public static interface Initializable {
|
||||
|
||||
void init(Injector injector);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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.support.init.proxy;
|
||||
|
||||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.get.GetRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.*;
|
||||
import org.elasticsearch.alerts.support.init.InitializingService;
|
||||
import org.elasticsearch.client.AdminClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
|
||||
/**
|
||||
* A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client
|
||||
* needs to injected to be avoid circular dependencies issues.
|
||||
*/
|
||||
public class ClientProxy implements InitializingService.Initializable {
|
||||
|
||||
private Client client;
|
||||
|
||||
/**
|
||||
* Creates a proxy to the given client (can be used for testing)
|
||||
*/
|
||||
public static ClientProxy of(Client client) {
|
||||
ClientProxy proxy = new ClientProxy();
|
||||
proxy.client = client;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Injector injector) {
|
||||
client = injector.getInstance(Client.class);
|
||||
}
|
||||
|
||||
public AdminClient admin() {
|
||||
return client.admin();
|
||||
}
|
||||
|
||||
public ActionFuture<IndexResponse> index(IndexRequest request) {
|
||||
return client.index(request);
|
||||
}
|
||||
|
||||
public void index(IndexRequest request, ActionListener<IndexResponse> listener) {
|
||||
client.index(request, listener);
|
||||
}
|
||||
|
||||
public IndexRequestBuilder prepareIndex(String index, String type, String id) {
|
||||
return client.prepareIndex(index, type, id);
|
||||
}
|
||||
|
||||
public ActionFuture<DeleteResponse> delete(DeleteRequest request) {
|
||||
return client.delete(request);
|
||||
}
|
||||
|
||||
public GetRequestBuilder prepareGet(String index, String type, String id) {
|
||||
return client.prepareGet(index, type, id);
|
||||
}
|
||||
|
||||
public ActionFuture<SearchResponse> search(SearchRequest request) {
|
||||
return client.search(request);
|
||||
}
|
||||
|
||||
public SearchRequestBuilder prepareSearch(String... indices) {
|
||||
return client.prepareSearch(indices);
|
||||
}
|
||||
|
||||
public SearchScrollRequestBuilder prepareSearchScroll(String scrollId) {
|
||||
return client.prepareSearchScroll(scrollId);
|
||||
}
|
||||
|
||||
public ClearScrollRequestBuilder prepareClearScroll() {
|
||||
return client.prepareClearScroll();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.support.init.proxy;
|
||||
|
||||
import org.elasticsearch.alerts.support.init.InitializingService;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*A lazily initialized proxy to the elasticsearch {@link ScriptService}. Inject this proxy whenever the script
|
||||
* service needs to be injected to avoid circular dependencies issues.
|
||||
*/
|
||||
public class ScriptServiceProxy implements InitializingService.Initializable {
|
||||
|
||||
private ScriptService service;
|
||||
|
||||
/**
|
||||
* Creates a proxy to the given script service (can be used for testing)
|
||||
*/
|
||||
public static ScriptServiceProxy of(ScriptService service) {
|
||||
ScriptServiceProxy proxy = new ScriptServiceProxy();
|
||||
proxy.service = service;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Injector injector) {
|
||||
this.service = injector.getInstance(ScriptService.class);
|
||||
}
|
||||
|
||||
public ExecutableScript executable(String lang, String script, ScriptService.ScriptType scriptType, Map vars) {
|
||||
return service.executable(lang, script, scriptType, vars);
|
||||
}
|
||||
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
|
||||
return service.search(compiledScript, lookup, vars);
|
||||
}
|
||||
|
||||
public SearchScript search(SearchLookup lookup, String lang, String script, ScriptService.ScriptType scriptType, Map<String, Object> vars) {
|
||||
return service.search(lookup, lang, script, scriptType, vars);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.transport;
|
||||
|
||||
import org.elasticsearch.action.ActionModule;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.AckAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.ack.TransportAckAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.config.ConfigAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.config.TransportConfigAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.TransportDeleteAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.get.TransportGetAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.put.PutAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.put.TransportPutAlertAction;
|
||||
import org.elasticsearch.alerts.transport.actions.service.AlertsServiceAction;
|
||||
import org.elasticsearch.alerts.transport.actions.service.TransportAlertsServiceAction;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsAction;
|
||||
import org.elasticsearch.alerts.transport.actions.stats.TransportAlertsStatsAction;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.PreProcessModule;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AlertsTransportModule extends AbstractModule implements PreProcessModule {
|
||||
|
||||
@Override
|
||||
public void processModule(Module module) {
|
||||
if (module instanceof ActionModule) {
|
||||
ActionModule actionModule = (ActionModule) module;
|
||||
actionModule.registerAction(PutAlertAction.INSTANCE, TransportPutAlertAction.class);
|
||||
actionModule.registerAction(DeleteAlertAction.INSTANCE, TransportDeleteAlertAction.class);
|
||||
actionModule.registerAction(GetAlertAction.INSTANCE, TransportGetAlertAction.class);
|
||||
actionModule.registerAction(AlertsStatsAction.INSTANCE, TransportAlertsStatsAction.class);
|
||||
actionModule.registerAction(AckAlertAction.INSTANCE, TransportAckAlertAction.class);
|
||||
actionModule.registerAction(AlertsServiceAction.INSTANCE, TransportAlertsServiceAction.class);
|
||||
actionModule.registerAction(ConfigAlertAction.INSTANCE, TransportConfigAlertAction.class);
|
||||
actionModule.registerAction(ConfigAlertAction.INSTANCE, TransportConfigAlertAction.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
}
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.ack;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* This action acks an alert in memory, and the index
|
||||
*/
|
||||
public class AckAlertAction extends AlertsClientAction<AckAlertRequest, AckAlertResponse, AckAlertRequestBuilder> {
|
||||
public class AckAlertAction extends AlertsAction<AckAlertRequest, AckAlertResponse, AckAlertRequestBuilder> {
|
||||
|
||||
public static final AckAlertAction INSTANCE = new AckAlertAction();
|
||||
public static final String NAME = "indices:data/write/alert/ack";
|
||||
|
@ -26,7 +26,8 @@ public class AckAlertAction extends AlertsClientAction<AckAlertRequest, AckAlert
|
|||
}
|
||||
|
||||
@Override
|
||||
public AckAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
public AckAlertRequestBuilder newRequestBuilder(Client client) {
|
||||
return new AckAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,25 +24,19 @@ public class AckAlertRequest extends MasterNodeOperationRequest<AckAlertRequest>
|
|||
public AckAlertRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor for the requests that takes the name of the alert to ack
|
||||
* @param alertName
|
||||
*/
|
||||
public AckAlertRequest(String alertName) {
|
||||
this.alertName = alertName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the alert to be acked
|
||||
* @return
|
||||
* @return The name of the alert to be acked
|
||||
*/
|
||||
public String getAlertName() {
|
||||
return alertName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the alert to be acked
|
||||
* @param alertName
|
||||
* Sets the name of the alert to be acked
|
||||
*/
|
||||
public void setAlertName(String alertName) {
|
||||
this.alertName = alertName;
|
||||
|
|
|
@ -8,25 +8,23 @@ package org.elasticsearch.alerts.transport.actions.ack;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* A ack alert action request builder.
|
||||
*/
|
||||
public class AckAlertRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<AckAlertRequest, AckAlertResponse, AckAlertRequestBuilder, AlertsClient> {
|
||||
public class AckAlertRequestBuilder extends MasterNodeOperationRequestBuilder<AckAlertRequest, AckAlertResponse, AckAlertRequestBuilder, Client> {
|
||||
|
||||
public AckAlertRequestBuilder(AlertsClient client) {
|
||||
public AckAlertRequestBuilder(Client client) {
|
||||
super(client, new AckAlertRequest());
|
||||
}
|
||||
|
||||
public AckAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
public AckAlertRequestBuilder(Client client, String alertName) {
|
||||
super(client, new AckAlertRequest(alertName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the alert to be ack
|
||||
* @param alertName
|
||||
* @return
|
||||
*/
|
||||
public AckAlertRequestBuilder setAlertName(String alertName) {
|
||||
this.request().setAlertName(alertName);
|
||||
|
@ -35,7 +33,7 @@ public class AckAlertRequestBuilder
|
|||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<AckAlertResponse> listener) {
|
||||
client.ackAlert(request, listener);
|
||||
new AlertsClient(client).ackAlert(request, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,10 +23,6 @@ public class AckAlertResponse extends ActionResponse {
|
|||
public AckAlertResponse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Constructor that takes the ack state for the alert
|
||||
* @param alertAckState
|
||||
*/
|
||||
public AckAlertResponse(@Nullable AlertAckState alertAckState) {
|
||||
this.alertAckState = alertAckState;
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.config;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* This action deletes an alert from in memory, the scheduler and the index
|
||||
*/
|
||||
public class ConfigAlertAction extends AlertsClientAction<ConfigAlertRequest, ConfigAlertResponse, ConfigAlertRequestBuilder> {
|
||||
public class ConfigAlertAction extends AlertsAction<ConfigAlertRequest, ConfigAlertResponse, ConfigAlertRequestBuilder> {
|
||||
|
||||
public static final ConfigAlertAction INSTANCE = new ConfigAlertAction();
|
||||
public static final String NAME = "indices:data/write/alert/config";
|
||||
|
@ -26,7 +26,8 @@ public class ConfigAlertAction extends AlertsClientAction<ConfigAlertRequest, Co
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
public ConfigAlertRequestBuilder newRequestBuilder(Client client) {
|
||||
return new ConfigAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,23 +24,18 @@ public class ConfigAlertRequest extends MasterNodeOperationRequest<ConfigAlertRe
|
|||
private BytesReference configSource;
|
||||
private boolean configSourceUnsafe;
|
||||
|
||||
|
||||
public ConfigAlertRequest() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The source of the config
|
||||
* @return
|
||||
* @return The source of the config
|
||||
*/
|
||||
public BytesReference getConfigSource() {
|
||||
return configSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* The source of the config document
|
||||
* @param configSource
|
||||
* Sets the source of the config document
|
||||
*/
|
||||
public void setConfigSource(BytesReference configSource) {
|
||||
this.configSource = configSource;
|
||||
|
@ -48,8 +43,7 @@ public class ConfigAlertRequest extends MasterNodeOperationRequest<ConfigAlertRe
|
|||
}
|
||||
|
||||
/**
|
||||
* Is the ByteRef configSource safe
|
||||
* @return
|
||||
* @return Whether the ByteRef configSource safe
|
||||
*/
|
||||
public boolean isConfigSourceUnsafe() {
|
||||
return configSourceUnsafe;
|
||||
|
@ -62,8 +56,6 @@ public class ConfigAlertRequest extends MasterNodeOperationRequest<ConfigAlertRe
|
|||
|
||||
/**
|
||||
* Set the source of the config with boolean to control source safety
|
||||
* @param configSource
|
||||
* @param configSourceUnsafe
|
||||
*/
|
||||
public void setConfigSource(BytesReference configSource, boolean configSourceUnsafe) {
|
||||
this.configSource = configSource;
|
||||
|
|
|
@ -8,22 +8,20 @@ package org.elasticsearch.alerts.transport.actions.config;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
||||
/**
|
||||
* A alert config action request builder.
|
||||
*/
|
||||
public class ConfigAlertRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<ConfigAlertRequest, ConfigAlertResponse, ConfigAlertRequestBuilder, AlertsClient> {
|
||||
public class ConfigAlertRequestBuilder extends MasterNodeOperationRequestBuilder<ConfigAlertRequest, ConfigAlertResponse, ConfigAlertRequestBuilder, Client> {
|
||||
|
||||
public ConfigAlertRequestBuilder(AlertsClient client) {
|
||||
public ConfigAlertRequestBuilder(Client client) {
|
||||
super(client, new ConfigAlertRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the source of the config to be modified
|
||||
* @param configSource
|
||||
* @return
|
||||
*/
|
||||
public ConfigAlertRequestBuilder setConfigSource(BytesReference configSource) {
|
||||
this.request().setConfigSource(configSource);
|
||||
|
@ -32,8 +30,6 @@ public class ConfigAlertRequestBuilder
|
|||
|
||||
/**
|
||||
* Sets the source of the config to be modified with boolean to control safety
|
||||
* @param configSource
|
||||
* @return
|
||||
*/
|
||||
public ConfigAlertRequestBuilder setConfigSource(BytesReference configSource, boolean sourceUnsafe) {
|
||||
this.request().setConfigSource(configSource);
|
||||
|
@ -43,7 +39,7 @@ public class ConfigAlertRequestBuilder
|
|||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<ConfigAlertResponse> listener) {
|
||||
client.alertConfig(request, listener);
|
||||
new AlertsClient(client).alertConfig(request, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.delete;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* This action deletes an alert from in memory, the scheduler and the index
|
||||
*/
|
||||
public class DeleteAlertAction extends AlertsClientAction<DeleteAlertRequest, DeleteAlertResponse, DeleteAlertRequestBuilder> {
|
||||
public class DeleteAlertAction extends AlertsAction<DeleteAlertRequest, DeleteAlertResponse, DeleteAlertRequestBuilder> {
|
||||
|
||||
public static final DeleteAlertAction INSTANCE = new DeleteAlertAction();
|
||||
public static final String NAME = "indices:data/write/alert/delete";
|
||||
|
@ -26,7 +26,7 @@ public class DeleteAlertAction extends AlertsClientAction<DeleteAlertRequest, De
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeleteAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
public DeleteAlertRequestBuilder newRequestBuilder(Client client) {
|
||||
return new DeleteAlertRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,25 +26,19 @@ public class DeleteAlertRequest extends MasterNodeOperationRequest<DeleteAlertRe
|
|||
public DeleteAlertRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor for the requests that takes the name of the alert to delete
|
||||
* @param alertName
|
||||
*/
|
||||
public DeleteAlertRequest(String alertName) {
|
||||
this.alertName = alertName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the alert to be deleted
|
||||
* @return
|
||||
* @return The name of the alert to be deleted
|
||||
*/
|
||||
public String getAlertName() {
|
||||
return alertName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the alert to be deleted
|
||||
* @param alertName
|
||||
* Sets the name of the alert to be deleted
|
||||
*/
|
||||
public void setAlertName(String alertName) {
|
||||
this.alertName = alertName;
|
||||
|
|
|
@ -8,25 +8,23 @@ package org.elasticsearch.alerts.transport.actions.delete;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* A delete document action request builder.
|
||||
*/
|
||||
public class DeleteAlertRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<DeleteAlertRequest, DeleteAlertResponse, DeleteAlertRequestBuilder, AlertsClient> {
|
||||
public class DeleteAlertRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteAlertRequest, DeleteAlertResponse, DeleteAlertRequestBuilder, Client> {
|
||||
|
||||
public DeleteAlertRequestBuilder(AlertsClient client) {
|
||||
public DeleteAlertRequestBuilder(Client client) {
|
||||
super(client, new DeleteAlertRequest());
|
||||
}
|
||||
|
||||
public DeleteAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
public DeleteAlertRequestBuilder(Client client, String alertName) {
|
||||
super(client, new DeleteAlertRequest(alertName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the alert to be deleted
|
||||
* @param alertName
|
||||
* @return
|
||||
*/
|
||||
public DeleteAlertRequestBuilder setAlertName(String alertName) {
|
||||
this.request().setAlertName(alertName);
|
||||
|
@ -35,7 +33,7 @@ public class DeleteAlertRequestBuilder
|
|||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<DeleteAlertResponse> listener) {
|
||||
client.deleteAlert(request, listener);
|
||||
new AlertsClient(client).deleteAlert(request, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.get;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* This action gets an alert by name
|
||||
*/
|
||||
public class GetAlertAction extends AlertsClientAction<GetAlertRequest, GetAlertResponse, GetAlertRequestBuilder> {
|
||||
public class GetAlertAction extends AlertsAction<GetAlertRequest, GetAlertResponse, GetAlertRequestBuilder> {
|
||||
|
||||
public static final GetAlertAction INSTANCE = new GetAlertAction();
|
||||
public static final String NAME = "indices:data/read/alert/get";
|
||||
|
@ -26,7 +26,7 @@ public class GetAlertAction extends AlertsClientAction<GetAlertRequest, GetAlert
|
|||
}
|
||||
|
||||
@Override
|
||||
public GetAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
public GetAlertRequestBuilder newRequestBuilder(Client client) {
|
||||
return new GetAlertRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ public class GetAlertRequest extends MasterNodeOperationRequest<GetAlertRequest>
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructor taking name (id) of the alert to retrieve
|
||||
* @param alertName
|
||||
* @param alertName name (id) of the alert to retrieve
|
||||
*/
|
||||
public GetAlertRequest(String alertName) {
|
||||
this.alertName = alertName;
|
||||
|
@ -49,8 +48,7 @@ public class GetAlertRequest extends MasterNodeOperationRequest<GetAlertRequest>
|
|||
|
||||
|
||||
/**
|
||||
* The name of the alert to retrieve
|
||||
* @return
|
||||
* @return The name of the alert to retrieve
|
||||
*/
|
||||
public String alertName() {
|
||||
return alertName;
|
||||
|
|
|
@ -8,20 +8,20 @@ package org.elasticsearch.alerts.transport.actions.get;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
|
||||
/**
|
||||
* A delete document action request builder.
|
||||
*/
|
||||
public class GetAlertRequestBuilder extends ActionRequestBuilder<GetAlertRequest, GetAlertResponse, GetAlertRequestBuilder, AlertsClient> {
|
||||
public class GetAlertRequestBuilder extends ActionRequestBuilder<GetAlertRequest, GetAlertResponse, GetAlertRequestBuilder, Client> {
|
||||
|
||||
|
||||
public GetAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
public GetAlertRequestBuilder(Client client, String alertName) {
|
||||
super(client, new GetAlertRequest(alertName));
|
||||
}
|
||||
|
||||
|
||||
public GetAlertRequestBuilder(AlertsClient client) {
|
||||
public GetAlertRequestBuilder(Client client) {
|
||||
super(client, new GetAlertRequest());
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,6 @@ public class GetAlertRequestBuilder extends ActionRequestBuilder<GetAlertRequest
|
|||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<GetAlertResponse> listener) {
|
||||
client.getAlert(request, listener);
|
||||
new AlertsClient(client).getAlert(request, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ public class GetAlertResponse extends ActionResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* The GetResponse containing the alert source
|
||||
* @param getResponse
|
||||
* Sets the GetResponse containing the alert source
|
||||
*/
|
||||
public void getResponse(GetResponse getResponse) {
|
||||
this.getResponse = getResponse;
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.put;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* This action puts an alert into the alert index and adds it to the scheduler
|
||||
*/
|
||||
public class PutAlertAction extends AlertsClientAction<PutAlertRequest, PutAlertResponse, PutAlertRequestBuilder> {
|
||||
public class PutAlertAction extends AlertsAction<PutAlertRequest, PutAlertResponse, PutAlertRequestBuilder> {
|
||||
|
||||
public static final PutAlertAction INSTANCE = new PutAlertAction();
|
||||
public static final String NAME = "indices:data/write/alert/put";
|
||||
|
@ -20,13 +20,8 @@ public class PutAlertAction extends AlertsClientAction<PutAlertRequest, PutAlert
|
|||
super(NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Alerts Client
|
||||
* @param client
|
||||
* @return A PutAlertRequestBuilder
|
||||
*/
|
||||
@Override
|
||||
public PutAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
public PutAlertRequestBuilder newRequestBuilder(Client client) {
|
||||
return new PutAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,23 +25,18 @@ public class PutAlertRequest extends MasterNodeOperationRequest<PutAlertRequest>
|
|||
private BytesReference alertSource;
|
||||
private boolean alertSourceUnsafe;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public PutAlertRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that sets the alertSource
|
||||
* @param alertSource
|
||||
* @param alertSource The alertSource
|
||||
*/
|
||||
public PutAlertRequest(BytesReference alertSource) {
|
||||
this.alertSource = alertSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name that will be the ID of the indexed document
|
||||
* @return the alert name
|
||||
* @return The name that will be the ID of the indexed document
|
||||
*/
|
||||
public String getAlertName() {
|
||||
return alertName;
|
||||
|
@ -49,15 +44,13 @@ public class PutAlertRequest extends MasterNodeOperationRequest<PutAlertRequest>
|
|||
|
||||
/**
|
||||
* Set the alert name
|
||||
* @param alertName
|
||||
*/
|
||||
public void setAlertName(String alertName) {
|
||||
this.alertName = alertName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The source of the alert
|
||||
* @return
|
||||
* @return The source of the alert
|
||||
*/
|
||||
public BytesReference getAlertSource() {
|
||||
return alertSource;
|
||||
|
@ -65,7 +58,6 @@ public class PutAlertRequest extends MasterNodeOperationRequest<PutAlertRequest>
|
|||
|
||||
/**
|
||||
* Set the source of the alert
|
||||
* @param alertSource
|
||||
*/
|
||||
public void setAlertSource(BytesReference alertSource) {
|
||||
this.alertSource = alertSource;
|
||||
|
@ -74,8 +66,6 @@ public class PutAlertRequest extends MasterNodeOperationRequest<PutAlertRequest>
|
|||
|
||||
/**
|
||||
* Set the source of the alert with boolean to control source safety
|
||||
* @param alertSource
|
||||
* @param alertSourceUnsafe
|
||||
*/
|
||||
public void setAlertSource(BytesReference alertSource, boolean alertSourceUnsafe) {
|
||||
this.alertSource = alertSource;
|
||||
|
|
|
@ -8,37 +8,25 @@ package org.elasticsearch.alerts.transport.actions.put;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
||||
/**
|
||||
* A Builder to build a PutAlertRequest
|
||||
*/
|
||||
public class PutAlertRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<PutAlertRequest, PutAlertResponse,
|
||||
PutAlertRequestBuilder, AlertsClient> {
|
||||
public class PutAlertRequestBuilder extends MasterNodeOperationRequestBuilder<PutAlertRequest, PutAlertResponse, PutAlertRequestBuilder, Client> {
|
||||
|
||||
/**
|
||||
* The Constructor for the PutAlertRequestBuilder
|
||||
* @param client The client that will execute the action
|
||||
*/
|
||||
public PutAlertRequestBuilder(AlertsClient client) {
|
||||
public PutAlertRequestBuilder(Client client) {
|
||||
super(client, new PutAlertRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* The Constructor for the PutAlertRequestBuilder
|
||||
* @param client The client that will execute the action
|
||||
* @param alertName The name of the alert to be put
|
||||
*/
|
||||
public PutAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
public PutAlertRequestBuilder(Client client, String alertName) {
|
||||
super(client, new PutAlertRequest());
|
||||
request.setAlertName(alertName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the alert name to be created
|
||||
* @param alertName
|
||||
* @return
|
||||
* @param alertName The alert name to be created
|
||||
*/
|
||||
public PutAlertRequestBuilder setAlertName(String alertName){
|
||||
request.setAlertName(alertName);
|
||||
|
@ -46,9 +34,7 @@ public class PutAlertRequestBuilder
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the source of the alert to be created
|
||||
* @param alertSource
|
||||
* @return
|
||||
* @param alertSource the source of the alert to be created
|
||||
*/
|
||||
public PutAlertRequestBuilder setAlertSource(BytesReference alertSource) {
|
||||
request.setAlertSource(alertSource);
|
||||
|
@ -58,6 +44,6 @@ public class PutAlertRequestBuilder
|
|||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<PutAlertResponse> listener) {
|
||||
client.putAlert(request, listener);
|
||||
new AlertsClient(client).putAlert(request, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,9 @@ import java.io.IOException;
|
|||
* This response wraps the #IndexResponse returned from the persisting of the alert
|
||||
*/
|
||||
public class PutAlertResponse extends ActionResponse {
|
||||
|
||||
private IndexResponse indexResponse;
|
||||
|
||||
/**
|
||||
* Create the PutAlertResponse with the wrapped IndexResponse
|
||||
* @param indexResponse
|
||||
*/
|
||||
public PutAlertResponse(IndexResponse indexResponse) {
|
||||
this.indexResponse = indexResponse;
|
||||
}
|
||||
|
@ -32,8 +29,7 @@ public class PutAlertResponse extends ActionResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the IndexResponse for this PutAlertResponse
|
||||
* @return
|
||||
* @return The IndexResponse for this PutAlertResponse
|
||||
*/
|
||||
public IndexResponse indexResponse(){
|
||||
return indexResponse;
|
||||
|
@ -41,7 +37,6 @@ public class PutAlertResponse extends ActionResponse {
|
|||
|
||||
/**
|
||||
* Set the IndexResponse on this PutAlertResponse
|
||||
* @param indexResponse
|
||||
*/
|
||||
public void indexResponse(IndexResponse indexResponse){
|
||||
this.indexResponse = indexResponse;
|
||||
|
|
|
@ -5,17 +5,17 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.service;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AlertServiceAction extends AlertsClientAction<AlertsServiceRequest, AlertsServiceResponse, AlertServiceRequestBuilder> {
|
||||
public class AlertsServiceAction extends AlertsAction<AlertsServiceRequest, AlertsServiceResponse, AlertsServiceRequestBuilder> {
|
||||
|
||||
public static final AlertServiceAction INSTANCE = new AlertServiceAction();
|
||||
public static final AlertsServiceAction INSTANCE = new AlertsServiceAction();
|
||||
public static final String NAME = "cluster:admin/alerts/service";
|
||||
|
||||
private AlertServiceAction() {
|
||||
private AlertsServiceAction() {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@ public class AlertServiceAction extends AlertsClientAction<AlertsServiceRequest
|
|||
}
|
||||
|
||||
@Override
|
||||
public AlertServiceRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
return new AlertServiceRequestBuilder(client);
|
||||
public AlertsServiceRequestBuilder newRequestBuilder(Client client) {
|
||||
return new AlertsServiceRequestBuilder(client);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,19 +8,20 @@ package org.elasticsearch.alerts.transport.actions.service;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AlertServiceRequestBuilder extends MasterNodeOperationRequestBuilder<AlertsServiceRequest, AlertsServiceResponse, AlertServiceRequestBuilder, AlertsClient> {
|
||||
public class AlertsServiceRequestBuilder extends MasterNodeOperationRequestBuilder<AlertsServiceRequest, AlertsServiceResponse, AlertsServiceRequestBuilder, Client> {
|
||||
|
||||
public AlertServiceRequestBuilder(AlertsClient client) {
|
||||
public AlertsServiceRequestBuilder(Client client) {
|
||||
super(client, new AlertsServiceRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts alerting if not already started.
|
||||
*/
|
||||
public AlertServiceRequestBuilder start() {
|
||||
public AlertsServiceRequestBuilder start() {
|
||||
request.start();
|
||||
return this;
|
||||
}
|
||||
|
@ -28,7 +29,7 @@ public class AlertServiceRequestBuilder extends MasterNodeOperationRequestBuilde
|
|||
/**
|
||||
* Stops alerting if not already stopped.
|
||||
*/
|
||||
public AlertServiceRequestBuilder stop() {
|
||||
public AlertsServiceRequestBuilder stop() {
|
||||
request.stop();
|
||||
return this;
|
||||
}
|
||||
|
@ -36,13 +37,13 @@ public class AlertServiceRequestBuilder extends MasterNodeOperationRequestBuilde
|
|||
/**
|
||||
* Starts and stops alerting.
|
||||
*/
|
||||
public AlertServiceRequestBuilder restart() {
|
||||
public AlertsServiceRequestBuilder restart() {
|
||||
request.restart();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<AlertsServiceResponse> listener) {
|
||||
client.alertService(request, listener);
|
||||
new AlertsClient(client).alertService(request, listener);
|
||||
}
|
||||
}
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.transport.actions.stats;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* This Action gets the stats for the alert plugin
|
||||
*/
|
||||
public class AlertsStatsAction extends AlertsClientAction<AlertsStatsRequest, AlertsStatsResponse, AlertsStatsRequestBuilder> {
|
||||
public class AlertsStatsAction extends AlertsAction<AlertsStatsRequest, AlertsStatsResponse, AlertsStatsRequestBuilder> {
|
||||
|
||||
public static final AlertsStatsAction INSTANCE = new AlertsStatsAction();
|
||||
public static final String NAME = "cluster/alerts/stats";
|
||||
|
@ -26,7 +26,8 @@ public class AlertsStatsAction extends AlertsClientAction<AlertsStatsRequest, Al
|
|||
}
|
||||
|
||||
@Override
|
||||
public AlertsStatsRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
public AlertsStatsRequestBuilder newRequestBuilder(Client client) {
|
||||
return new AlertsStatsRequestBuilder(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,25 +8,24 @@ package org.elasticsearch.alerts.transport.actions.stats;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* An alert stats document action request builder.
|
||||
*/
|
||||
public class AlertsStatsRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<AlertsStatsRequest, AlertsStatsResponse, AlertsStatsRequestBuilder, AlertsClient> {
|
||||
public class AlertsStatsRequestBuilder extends MasterNodeOperationRequestBuilder<AlertsStatsRequest, AlertsStatsResponse, AlertsStatsRequestBuilder, Client> {
|
||||
|
||||
/**
|
||||
* The constructor for the AlertsStatsRequestBuilder
|
||||
* @param client
|
||||
*/
|
||||
public AlertsStatsRequestBuilder(AlertsClient client) {
|
||||
public AlertsStatsRequestBuilder(Client client) {
|
||||
super(client, new AlertsStatsRequest());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<AlertsStatsResponse> listener) {
|
||||
client.alertsStats(request, listener);
|
||||
new AlertsClient(client).alertsStats(request, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,8 +31,7 @@ public class AlertsStatsResponse extends ActionResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the current queue size in the alert action manager
|
||||
* @return
|
||||
* @return The current queue size in the alert action manager
|
||||
*/
|
||||
public long getAlertActionManagerQueueSize() {
|
||||
return alertActionManagerQueueSize;
|
||||
|
@ -43,8 +42,7 @@ public class AlertsStatsResponse extends ActionResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* The number of alerts currently registered in the system
|
||||
* @return
|
||||
* @return The number of alerts currently registered in the system
|
||||
*/
|
||||
public long getNumberOfRegisteredAlerts() {
|
||||
return numberOfRegisteredAlerts;
|
||||
|
@ -66,8 +64,7 @@ public class AlertsStatsResponse extends ActionResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns true if the alert action manager is started
|
||||
* @return
|
||||
* @return {@code true} if the alert action manager is started
|
||||
*/
|
||||
public boolean isAlertActionManagerStarted() {
|
||||
return alertActionManagerStarted;
|
||||
|
@ -78,8 +75,7 @@ public class AlertsStatsResponse extends ActionResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the largest queue size the alert action manager queue has grown to
|
||||
* @return
|
||||
* @return The largest queue size the alert action manager queue has grown to
|
||||
*/
|
||||
public long getAlertActionManagerLargestQueueSize() {
|
||||
return alertActionManagerLargestQueueSize;
|
||||
|
|
|
@ -10,9 +10,9 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||
import org.elasticsearch.alerts.AlertService;
|
||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||
import org.elasticsearch.alerts.AlertsBuild;
|
||||
import org.elasticsearch.alerts.AlertsVersion;
|
||||
import org.elasticsearch.alerts.actions.AlertActionService;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
|
@ -25,15 +25,15 @@ import org.elasticsearch.transport.TransportService;
|
|||
/**
|
||||
* Performs the stats operation.
|
||||
*/
|
||||
public class TransportAlertStatsAction extends TransportMasterNodeOperationAction<AlertsStatsRequest, AlertsStatsResponse> {
|
||||
public class TransportAlertsStatsAction extends TransportMasterNodeOperationAction<AlertsStatsRequest, AlertsStatsResponse> {
|
||||
|
||||
private final AlertService alertService;
|
||||
private final AlertActionService alertActionService;
|
||||
|
||||
@Inject
|
||||
public TransportAlertStatsAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService,
|
||||
AlertActionService alertActionService) {
|
||||
public TransportAlertsStatsAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, AlertService alertService,
|
||||
AlertActionService alertActionService) {
|
||||
super(settings, AlertsStatsAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||
this.alertService = alertService;
|
||||
this.alertActionService = alertActionService;
|
|
@ -10,7 +10,8 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
||||
|
@ -18,9 +19,10 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
public class ScriptedTriggerFactory implements TriggerFactory {
|
||||
private final ScriptService scriptService;
|
||||
|
||||
public ScriptedTriggerFactory(ScriptService service) {
|
||||
private final ScriptServiceProxy scriptService;
|
||||
|
||||
public ScriptedTriggerFactory(ScriptServiceProxy service) {
|
||||
scriptService = service;
|
||||
}
|
||||
|
||||
|
@ -76,9 +78,8 @@ public class ScriptedTriggerFactory implements TriggerFactory {
|
|||
}
|
||||
|
||||
ScriptedTrigger scriptedTrigger = (ScriptedTrigger)trigger;
|
||||
ExecutableScript executable = scriptService.executable(
|
||||
scriptedTrigger.getScriptLang(), scriptedTrigger.getScript(), scriptedTrigger.getScriptType(), response
|
||||
);
|
||||
ExecutableScript executable = scriptService.executable(scriptedTrigger.getScriptLang(),
|
||||
scriptedTrigger.getScript(), scriptedTrigger.getScriptType(), response);
|
||||
Object returnValue = executable.run();
|
||||
if (returnValue instanceof Boolean) {
|
||||
return (Boolean) returnValue;
|
||||
|
|
|
@ -10,7 +10,8 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.AlertUtils;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -19,7 +20,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,12 +29,12 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
|
||||
public class TriggerService extends AbstractComponent {
|
||||
|
||||
private final Client client;
|
||||
private final ScriptService scriptService;
|
||||
private final ClientProxy client;
|
||||
private final ScriptServiceProxy scriptService;
|
||||
private volatile ImmutableOpenMap<String, TriggerFactory> triggersImplemented;
|
||||
|
||||
@Inject
|
||||
public TriggerService(Settings settings, Client client, ScriptService scriptService) {
|
||||
public TriggerService(Settings settings, ClientProxy client, ScriptServiceProxy scriptService) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
this.scriptService = scriptService;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.alerts;
|
||||
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
@ -36,7 +37,7 @@ public class ConfigTest extends ElasticsearchIntegrationTest {
|
|||
.put("bar", 1)
|
||||
.put("baz", true)
|
||||
.build();
|
||||
ConfigurationService configurationService = new ConfigurationService(oldSettings, client());
|
||||
ConfigurationService configurationService = new ConfigurationService(oldSettings, ClientProxy.of(client()));
|
||||
|
||||
SettingsListener settingsListener = new SettingsListener();
|
||||
configurationService.registerListener(settingsListener);
|
||||
|
@ -79,10 +80,12 @@ public class ConfigTest extends ElasticsearchIntegrationTest {
|
|||
.get();
|
||||
assertTrue(indexResponse.isCreated());
|
||||
|
||||
ConfigurationService configurationService = new ConfigurationService(oldSettings, client());
|
||||
ConfigurationService configurationService = new ConfigurationService(oldSettings, ClientProxy.of(client()));
|
||||
Settings loadedSettings = configurationService.getConfig();
|
||||
assertThat(loadedSettings.get("foo"), equalTo(newSettings.get("foo")));
|
||||
assertThat(loadedSettings.get("bar"), equalTo(newSettings.get("bar")));
|
||||
assertThat(loadedSettings.get("baz"), equalTo(newSettings.get("baz")));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.AlertAckState;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
|
@ -70,7 +71,7 @@ public class EmailTemplateTest extends ElasticsearchTestCase {
|
|||
engineServiceSet.add(mustacheScriptEngineService);
|
||||
|
||||
ScriptService scriptService = new ScriptService(settings, new Environment(), engineServiceSet, new ResourceWatcherService(settings, tp));
|
||||
String parsedTemplate = SmtpAlertActionFactory.renderTemplate(template, alert, result, scriptService);
|
||||
String parsedTemplate = SmtpAlertActionFactory.renderTemplate(template, alert, result, ScriptServiceProxy.of(scriptService));
|
||||
tp.shutdownNow();
|
||||
assertEquals("test-email-template triggered with 0 hits", parsedTemplate);
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.actions;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.AlertAckState;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.alerts.triggers.AlertTrigger;
|
||||
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
|
||||
import org.elasticsearch.alerts.triggers.TriggerResult;
|
||||
|
@ -64,7 +64,7 @@ public class WebhookTest extends ElasticsearchTestCase {
|
|||
|
||||
|
||||
String encodedRequestParameters = WebhookAlertActionFactory.encodeParameterString(WebhookAlertActionFactory.DEFAULT_PARAMETER_STRING, alert,
|
||||
new TriggerResult(true, triggerRequest, responseMap, trigger), scriptService);
|
||||
new TriggerResult(true, triggerRequest, responseMap, trigger), ScriptServiceProxy.of(scriptService));
|
||||
assertEquals("alertname=test-email-template&request=%%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%7D&response=%%7B%22response%22%3A%7B%22hits%22%3A0%7D%7D", encodedRequestParameters);
|
||||
tp.shutdownNow();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -60,7 +61,7 @@ public class TriggerUnitTest extends ElasticsearchTestCase {
|
|||
engineServiceSet.add(groovyScriptEngineService);
|
||||
|
||||
ScriptService scriptService = new ScriptService(settings, new Environment(), engineServiceSet, new ResourceWatcherService(settings, tp));
|
||||
TriggerService triggerService = new TriggerService(settings, null, scriptService);
|
||||
TriggerService triggerService = new TriggerService(settings, null, ScriptServiceProxy.of(scriptService));
|
||||
|
||||
try {
|
||||
XContentBuilder builder = createTriggerContent("hits.total > 1", null, null);
|
||||
|
|
Loading…
Reference in New Issue