Core: Transport classes are now managed by Guide and are injected into the AlertsClient

Original commit: elastic/x-pack-elasticsearch@3cfdd3dc71
This commit is contained in:
Martijn van Groningen 2014-11-14 00:37:49 +01:00
parent ecdfdb11d9
commit e5293ba0c3
7 changed files with 45 additions and 57 deletions

View File

@ -9,11 +9,16 @@ package org.elasticsearch.alerts;
import org.elasticsearch.alerts.actions.AlertActionManager; import org.elasticsearch.alerts.actions.AlertActionManager;
import org.elasticsearch.alerts.actions.AlertActionRegistry; import org.elasticsearch.alerts.actions.AlertActionRegistry;
import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.client.AlertsClient;
import org.elasticsearch.alerts.client.AlertsClientInterface;
import org.elasticsearch.alerts.rest.RestAlertsStatsAction; import org.elasticsearch.alerts.rest.RestAlertsStatsAction;
import org.elasticsearch.alerts.rest.RestDeleteAlertAction; import org.elasticsearch.alerts.rest.RestDeleteAlertAction;
import org.elasticsearch.alerts.rest.RestGetAlertAction; import org.elasticsearch.alerts.rest.RestGetAlertAction;
import org.elasticsearch.alerts.rest.RestIndexAlertAction; import org.elasticsearch.alerts.rest.RestIndexAlertAction;
import org.elasticsearch.alerts.scheduler.AlertScheduler; import org.elasticsearch.alerts.scheduler.AlertScheduler;
import org.elasticsearch.alerts.transport.actions.delete.TransportDeleteAlertAction;
import org.elasticsearch.alerts.transport.actions.get.TransportGetAlertAction;
import org.elasticsearch.alerts.transport.actions.index.TransportIndexAlertAction;
import org.elasticsearch.alerts.transport.actions.stats.TransportAlertStatsAction;
import org.elasticsearch.alerts.triggers.TriggerManager; import org.elasticsearch.alerts.triggers.TriggerManager;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
@ -22,6 +27,7 @@ public class AlertingModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
// Core components
bind(TemplateHelper.class).asEagerSingleton(); bind(TemplateHelper.class).asEagerSingleton();
bind(AlertsStore.class).asEagerSingleton(); bind(AlertsStore.class).asEagerSingleton();
bind(AlertManager.class).asEagerSingleton(); bind(AlertManager.class).asEagerSingleton();
@ -29,12 +35,19 @@ public class AlertingModule extends AbstractModule {
bind(TriggerManager.class).asEagerSingleton(); bind(TriggerManager.class).asEagerSingleton();
bind(AlertScheduler.class).asEagerSingleton(); bind(AlertScheduler.class).asEagerSingleton();
bind(AlertActionRegistry.class).asEagerSingleton(); bind(AlertActionRegistry.class).asEagerSingleton();
// Transport and client layer
bind(TransportIndexAlertAction.class).asEagerSingleton();
bind(TransportDeleteAlertAction.class).asEagerSingleton();
bind(TransportGetAlertAction.class).asEagerSingleton();
bind(TransportAlertStatsAction.class).asEagerSingleton();
bind(AlertsClientInterface.class).to(AlertsClient.class).asEagerSingleton();
// Rest layer
bind(RestIndexAlertAction.class).asEagerSingleton(); bind(RestIndexAlertAction.class).asEagerSingleton();
bind(RestDeleteAlertAction.class).asEagerSingleton(); bind(RestDeleteAlertAction.class).asEagerSingleton();
bind(RestAlertsStatsAction.class).asEagerSingleton(); bind(RestAlertsStatsAction.class).asEagerSingleton();
bind(RestGetAlertAction.class).asEagerSingleton(); bind(RestGetAlertAction.class).asEagerSingleton();
//bind(AlertsClientInterface.class).to(AlertsClient.class).asEagerSingleton();
bind(AlertsClient.class).asEagerSingleton();
} }
} }

View File

@ -6,56 +6,34 @@
package org.elasticsearch.alerts.client; package org.elasticsearch.alerts.client;
import org.elasticsearch.action.*; import org.elasticsearch.action.*;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.alerts.AlertManager;
import org.elasticsearch.alerts.actions.AlertActionManager;
import org.elasticsearch.alerts.transport.actions.index.*;
import org.elasticsearch.alerts.transport.actions.delete.*; import org.elasticsearch.alerts.transport.actions.delete.*;
import org.elasticsearch.alerts.transport.actions.get.*; import org.elasticsearch.alerts.transport.actions.get.*;
import org.elasticsearch.alerts.transport.actions.index.*;
import org.elasticsearch.alerts.transport.actions.stats.*; import org.elasticsearch.alerts.transport.actions.stats.*;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.support.Headers; import org.elasticsearch.client.support.Headers;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.HashMap;
import java.util.Map;
public class AlertsClient implements AlertsClientInterface { public class AlertsClient implements AlertsClientInterface {
private final Headers headers; private final Headers headers;
private final Map<GenericAction, TransportAction> internalActions;
private final ThreadPool threadPool; private final ThreadPool threadPool;
private final ImmutableMap<GenericAction, TransportAction> internalActions;
@Inject @Inject
public AlertsClient(ThreadPool threadPool, public AlertsClient(ThreadPool threadPool, Headers headers, TransportIndexAlertAction transportIndexAlertAction,
Settings settings, TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction,
Headers headers, TransportAlertStatsAction transportAlertStatsAction) {
ActionFilters filters,
TransportService transportService, ClusterService clusterService, AlertManager alertManager,
Client client, AlertActionManager alertActionManager) {
this.headers = headers; this.headers = headers;
internalActions = new HashMap<>();
this.threadPool = threadPool; this.threadPool = threadPool;
internalActions = ImmutableMap.<GenericAction, TransportAction>builder()
internalActions.put(IndexAlertAction.INSTANCE, new TransportIndexAlertAction(settings, .put(IndexAlertAction.INSTANCE, transportIndexAlertAction)
IndexAlertAction.NAME, transportService, clusterService, threadPool, filters, alertManager)); .put(GetAlertAction.INSTANCE, transportGetAlertAction)
.put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction)
internalActions.put(GetAlertAction.INSTANCE, new TransportGetAlertAction(settings, .put(AlertsStatsAction.INSTANCE, transportAlertStatsAction)
GetAlertAction.NAME, threadPool, filters, client)); .build();
internalActions.put(DeleteAlertAction.INSTANCE, new TransportDeleteAlertAction(settings,
DeleteAlertAction.NAME, transportService, clusterService, threadPool, filters, alertManager));
internalActions.put(AlertsStatsAction.INSTANCE, new TransportAlertStatsAction(settings,
AlertsStatsAction.NAME, transportService, clusterService, threadPool, filters, alertManager,
alertActionManager));
} }
@Override @Override

View File

@ -5,15 +5,15 @@
*/ */
package org.elasticsearch.alerts.client; package org.elasticsearch.alerts.client;
import org.elasticsearch.action.*; import org.elasticsearch.action.Action;
import org.elasticsearch.alerts.Alert; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionResponse;
/** /**
* Created by brian on 10/29/14. * Base alert action class.
*/ */
public abstract class AlertsClientAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClientInterface>> extends Action<Request, Response, RequestBuilder, AlertsClientInterface> {
public abstract class AlertsClientAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClientInterface>>
extends Action<Request, Response, RequestBuilder, AlertsClientInterface> {
protected AlertsClientAction(String name) { protected AlertsClientAction(String name) {
super(name); super(name);

View File

@ -29,10 +29,9 @@ public class TransportDeleteAlertAction extends TransportMasterNodeOperationActi
private final AlertManager alertManager; private final AlertManager alertManager;
@Inject @Inject
public TransportDeleteAlertAction(Settings settings, String actionName, TransportService transportService, public TransportDeleteAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager) {
AlertManager alertManager) { super(settings, DeleteAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
super(settings, actionName, transportService, clusterService, threadPool, actionFilters);
this.alertManager = alertManager; this.alertManager = alertManager;
} }

View File

@ -23,9 +23,8 @@ public class TransportGetAlertAction extends TransportAction<GetAlertRequest, G
private final Client client; private final Client client;
@Inject @Inject
public TransportGetAlertAction(Settings settings, String actionName, ThreadPool threadPool, public TransportGetAlertAction(Settings settings, ThreadPool threadPool, ActionFilters actionFilters, Client client) {
ActionFilters actionFilters, Client client) { super(settings, GetAlertAction.NAME, threadPool, actionFilters);
super(settings, actionName, threadPool, actionFilters);
this.client = client; this.client = client;
} }

View File

@ -29,10 +29,9 @@ public class TransportIndexAlertAction extends TransportMasterNodeOperationActio
private final AlertManager alertManager; private final AlertManager alertManager;
@Inject @Inject
public TransportIndexAlertAction(Settings settings, String actionName, TransportService transportService, public TransportIndexAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager) {
AlertManager alertManager) { super(settings, IndexAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
super(settings, actionName, transportService, clusterService, threadPool, actionFilters);
this.alertManager = alertManager; this.alertManager = alertManager;
} }

View File

@ -28,10 +28,10 @@ public class TransportAlertStatsAction extends TransportMasterNodeOperationActio
private final AlertActionManager alertActionManager; private final AlertActionManager alertActionManager;
@Inject @Inject
public TransportAlertStatsAction(Settings settings, String actionName, TransportService transportService, public TransportAlertStatsAction(Settings settings, TransportService transportService, ClusterService clusterService,
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager,
AlertManager alertManager, AlertActionManager alertActionManager) { AlertActionManager alertActionManager) {
super(settings, actionName, transportService, clusterService, threadPool, actionFilters); super(settings, AlertsStatsAction.NAME, transportService, clusterService, threadPool, actionFilters);
this.alertManager = alertManager; this.alertManager = alertManager;
this.alertActionManager = alertActionManager; this.alertActionManager = alertActionManager;
} }