Core: Renamed AlertsClient to NodeAlertsClient and renamed AlertsClientInterface to AlertsClient
Original commit: elastic/x-pack-elasticsearch@7aff2cbdd8
This commit is contained in:
parent
e5293ba0c3
commit
5c34d8b59a
|
@ -8,8 +8,8 @@ package org.elasticsearch.alerts;
|
|||
|
||||
import org.elasticsearch.alerts.actions.AlertActionManager;
|
||||
import org.elasticsearch.alerts.actions.AlertActionRegistry;
|
||||
import org.elasticsearch.alerts.client.NodeAlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.rest.RestAlertsStatsAction;
|
||||
import org.elasticsearch.alerts.rest.RestDeleteAlertAction;
|
||||
import org.elasticsearch.alerts.rest.RestGetAlertAction;
|
||||
|
@ -41,7 +41,7 @@ public class AlertingModule extends AbstractModule {
|
|||
bind(TransportDeleteAlertAction.class).asEagerSingleton();
|
||||
bind(TransportGetAlertAction.class).asEagerSingleton();
|
||||
bind(TransportAlertStatsAction.class).asEagerSingleton();
|
||||
bind(AlertsClientInterface.class).to(AlertsClient.class).asEagerSingleton();
|
||||
bind(AlertsClient.class).to(NodeAlertsClient.class).asEagerSingleton();
|
||||
|
||||
// Rest layer
|
||||
bind(RestIndexAlertAction.class).asEagerSingleton();
|
||||
|
|
|
@ -5,134 +5,141 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts.client;
|
||||
|
||||
import org.elasticsearch.action.*;
|
||||
import org.elasticsearch.action.support.TransportAction;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.*;
|
||||
import org.elasticsearch.alerts.transport.actions.get.*;
|
||||
import org.elasticsearch.alerts.transport.actions.index.*;
|
||||
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;
|
||||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
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.GetAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse;
|
||||
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;
|
||||
|
||||
public class AlertsClient implements AlertsClientInterface {
|
||||
/**
|
||||
*/
|
||||
public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
|
||||
|
||||
private final Headers headers;
|
||||
private final ThreadPool threadPool;
|
||||
private final ImmutableMap<GenericAction, TransportAction> internalActions;
|
||||
/**
|
||||
* Creates a request builder that gets an alert by name (id)
|
||||
*
|
||||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
GetAlertRequestBuilder prepareGetAlert(String alertName);
|
||||
|
||||
@Inject
|
||||
public AlertsClient(ThreadPool threadPool, Headers headers, TransportIndexAlertAction transportIndexAlertAction,
|
||||
TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction,
|
||||
TransportAlertStatsAction transportAlertStatsAction) {
|
||||
this.headers = headers;
|
||||
this.threadPool = threadPool;
|
||||
internalActions = ImmutableMap.<GenericAction, TransportAction>builder()
|
||||
.put(IndexAlertAction.INSTANCE, transportIndexAlertAction)
|
||||
.put(GetAlertAction.INSTANCE, transportGetAlertAction)
|
||||
.put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction)
|
||||
.put(AlertsStatsAction.INSTANCE, transportAlertStatsAction)
|
||||
.build();
|
||||
}
|
||||
/**
|
||||
* Creates a request builder that gets an alert
|
||||
*
|
||||
* @return the request builder
|
||||
*/
|
||||
GetAlertRequestBuilder prepareGetAlert();
|
||||
|
||||
@Override
|
||||
public GetAlertRequestBuilder prepareGetAlert(String alertName) {
|
||||
return new GetAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
/**
|
||||
* Gets an alert from the alert index
|
||||
*
|
||||
* @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);
|
||||
|
||||
@Override
|
||||
public GetAlertRequestBuilder prepareGetAlert() {
|
||||
return new GetAlertRequestBuilder(this);
|
||||
}
|
||||
/**
|
||||
* Gets an alert from the alert index
|
||||
*
|
||||
* @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 void getAlert(GetAlertRequest request, ActionListener<GetAlertResponse> response){
|
||||
execute(GetAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
/**
|
||||
* Creates a request builder to delete an alert by name (id)
|
||||
*
|
||||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
DeleteAlertRequestBuilder prepareDeleteAlert(String alertName);
|
||||
|
||||
@Override
|
||||
public ActionFuture<GetAlertResponse> getAlert(GetAlertRequest request) {
|
||||
return execute(GetAlertAction.INSTANCE, request);
|
||||
}
|
||||
/**
|
||||
* Creates a request builder that deletes an alert
|
||||
*
|
||||
* @return The request builder
|
||||
*/
|
||||
DeleteAlertRequestBuilder prepareDeleteAlert();
|
||||
|
||||
@Override
|
||||
public DeleteAlertRequestBuilder prepareDeleteAlert(String alertName) {
|
||||
return new DeleteAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
/**
|
||||
* Deletes an alert
|
||||
*
|
||||
* @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);
|
||||
|
||||
@Override
|
||||
public DeleteAlertRequestBuilder prepareDeleteAlert() {
|
||||
return new DeleteAlertRequestBuilder(this);
|
||||
}
|
||||
/**
|
||||
* Deletes an alert
|
||||
*
|
||||
* @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);
|
||||
|
||||
@Override
|
||||
public void deleteAlert(DeleteAlertRequest request, ActionListener<DeleteAlertResponse> response) {
|
||||
execute(DeleteAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
/**
|
||||
* Creates a request builder to build a request to index an alert
|
||||
*
|
||||
* @param alertName The name of the alert to index
|
||||
* @return The builder to create the alert
|
||||
*/
|
||||
IndexAlertRequestBuilder prepareIndexAlert(String alertName);
|
||||
|
||||
@Override
|
||||
public ActionFuture<DeleteAlertResponse> deleteAlert(DeleteAlertRequest request) {
|
||||
return execute(DeleteAlertAction.INSTANCE, request);
|
||||
}
|
||||
/**
|
||||
* Creates a request builder to build a request to index an alert
|
||||
*
|
||||
* @return The builder
|
||||
*/
|
||||
IndexAlertRequestBuilder prepareIndexAlert();
|
||||
|
||||
@Override
|
||||
public IndexAlertRequestBuilder prepareIndexAlert(String alertName) {
|
||||
return new IndexAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
/**
|
||||
* Indexes an alert and registers it with the scheduler
|
||||
*
|
||||
* @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 indexAlert(IndexAlertRequest request, ActionListener<IndexAlertResponse> listener);
|
||||
|
||||
@Override
|
||||
public IndexAlertRequestBuilder prepareIndexAlert() {
|
||||
return new IndexAlertRequestBuilder(this, null);
|
||||
}
|
||||
/**
|
||||
* Indexes an alert and registers it with the scheduler
|
||||
*
|
||||
* @param request The request containing the alert to index and register
|
||||
* @return The response containing the IndexResponse for this alert
|
||||
*/
|
||||
ActionFuture<IndexAlertResponse> indexAlert(IndexAlertRequest request);
|
||||
|
||||
@Override
|
||||
public void indexAlert(IndexAlertRequest request, ActionListener<IndexAlertResponse> response) {
|
||||
execute(IndexAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<IndexAlertResponse> indexAlert(IndexAlertRequest request) {
|
||||
return execute(IndexAlertAction.INSTANCE, request);
|
||||
}
|
||||
/**
|
||||
* Gets the alert stats
|
||||
*
|
||||
* @param request The request for the alert stats
|
||||
* @return The response containing the StatsResponse for this action
|
||||
*/
|
||||
ActionFuture<AlertsStatsResponse> alertsStats(AlertsStatsRequest request);
|
||||
|
||||
@Override
|
||||
public ActionFuture<AlertsStatsResponse> alertsStats(AlertsStatsRequest request) {
|
||||
return 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();
|
||||
|
||||
@Override
|
||||
public AlertsStatsRequestBuilder prepareAlertsStats() {
|
||||
return new AlertsStatsRequestBuilder(this);
|
||||
}
|
||||
/**
|
||||
* Gets the alert stats
|
||||
*
|
||||
* @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);
|
||||
|
||||
@Override
|
||||
public void alertsStats(AlertsStatsRequest request, ActionListener<AlertsStatsResponse> listener) {
|
||||
execute(AlertsStatsAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, AlertsClientInterface>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, AlertsClientInterface> 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, AlertsClientInterface>> void execute(Action<Request, Response, RequestBuilder, AlertsClientInterface> 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, AlertsClientInterface>> RequestBuilder prepareExecute(Action<Request, Response, RequestBuilder, AlertsClientInterface> action) {
|
||||
return action.newRequestBuilder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPool threadPool() {
|
||||
return threadPool;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.action.ActionResponse;
|
|||
/**
|
||||
* 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, AlertsClient>> extends Action<Request, Response, RequestBuilder, AlertsClient> {
|
||||
|
||||
protected AlertsClientAction(String name) {
|
||||
super(name);
|
||||
|
|
|
@ -1,146 +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.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
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.GetAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequestBuilder;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse;
|
||||
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;
|
||||
|
||||
/**
|
||||
*/
|
||||
public interface AlertsClientInterface extends ElasticsearchClient<AlertsClientInterface> {
|
||||
|
||||
/**
|
||||
* Creates a request builder that gets an alert by name (id)
|
||||
*
|
||||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
GetAlertRequestBuilder prepareGetAlert(String alertName);
|
||||
|
||||
/**
|
||||
* Creates a request builder that gets an alert
|
||||
*
|
||||
* @return the request builder
|
||||
*/
|
||||
GetAlertRequestBuilder prepareGetAlert();
|
||||
|
||||
/**
|
||||
* Gets an alert from the alert index
|
||||
*
|
||||
* @param request The get alert request
|
||||
* @param listener The listener for the get alert response containing the GetResponse for this alert
|
||||
*/
|
||||
public void getAlert(GetAlertRequest request, ActionListener<GetAlertResponse> listener);
|
||||
|
||||
/**
|
||||
* Gets an alert from the alert index
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Creates a request builder to delete an alert by name (id)
|
||||
*
|
||||
* @param alertName the name (id) of the alert
|
||||
* @return The request builder
|
||||
*/
|
||||
DeleteAlertRequestBuilder prepareDeleteAlert(String alertName);
|
||||
|
||||
/**
|
||||
* Creates a request builder that deletes an alert
|
||||
*
|
||||
* @return The request builder
|
||||
*/
|
||||
DeleteAlertRequestBuilder prepareDeleteAlert();
|
||||
|
||||
/**
|
||||
* Deletes an alert
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public void deleteAlert(DeleteAlertRequest request, ActionListener<DeleteAlertResponse> listener);
|
||||
|
||||
/**
|
||||
* Deletes an alert
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Creates a request builder to build a request to index an alert
|
||||
*
|
||||
* @param alertName The name of the alert to index
|
||||
* @return The builder to create the alert
|
||||
*/
|
||||
IndexAlertRequestBuilder prepareIndexAlert(String alertName);
|
||||
|
||||
/**
|
||||
* Creates a request builder to build a request to index an alert
|
||||
*
|
||||
* @return The builder
|
||||
*/
|
||||
IndexAlertRequestBuilder prepareIndexAlert();
|
||||
|
||||
/**
|
||||
* Indexes an alert and registers it with the scheduler
|
||||
*
|
||||
* @param request The request containing the alert to index and register
|
||||
* @param listener The listener for the response containing the IndexResponse for this alert
|
||||
*/
|
||||
public void indexAlert(IndexAlertRequest request, ActionListener<IndexAlertResponse> listener);
|
||||
|
||||
/**
|
||||
* Indexes an alert and registers it with the scheduler
|
||||
*
|
||||
* @param request The request containing the alert to index and register
|
||||
* @return The response containing the IndexResponse for this alert
|
||||
*/
|
||||
ActionFuture<IndexAlertResponse> indexAlert(IndexAlertRequest request);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the alert stats
|
||||
*
|
||||
* @param request The request for the alert stats
|
||||
* @return The response containing the StatsResponse for this action
|
||||
*/
|
||||
ActionFuture<AlertsStatsResponse> alertsStats(AlertsStatsRequest request);
|
||||
|
||||
/**
|
||||
* Creates a request builder to build a request to get the alerts stats
|
||||
*
|
||||
* @return The builder get the alerts stats
|
||||
*/
|
||||
AlertsStatsRequestBuilder prepareAlertsStats();
|
||||
|
||||
/**
|
||||
* Gets the alert stats
|
||||
*
|
||||
* @param request The request for the alert stats
|
||||
* @param listener The listener for the response containing the AlertsStatsResponse
|
||||
*/
|
||||
public void alertsStats(AlertsStatsRequest request, ActionListener<AlertsStatsResponse> listener);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* 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.delete.*;
|
||||
import org.elasticsearch.alerts.transport.actions.get.*;
|
||||
import org.elasticsearch.alerts.transport.actions.index.*;
|
||||
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, TransportIndexAlertAction transportIndexAlertAction,
|
||||
TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction,
|
||||
TransportAlertStatsAction transportAlertStatsAction) {
|
||||
this.headers = headers;
|
||||
this.threadPool = threadPool;
|
||||
internalActions = ImmutableMap.<GenericAction, TransportAction>builder()
|
||||
.put(IndexAlertAction.INSTANCE, transportIndexAlertAction)
|
||||
.put(GetAlertAction.INSTANCE, transportGetAlertAction)
|
||||
.put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction)
|
||||
.put(AlertsStatsAction.INSTANCE, transportAlertStatsAction)
|
||||
.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 IndexAlertRequestBuilder prepareIndexAlert(String alertName) {
|
||||
return new IndexAlertRequestBuilder(this, alertName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexAlertRequestBuilder prepareIndexAlert() {
|
||||
return new IndexAlertRequestBuilder(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexAlert(IndexAlertRequest request, ActionListener<IndexAlertResponse> response) {
|
||||
execute(IndexAlertAction.INSTANCE, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<IndexAlertResponse> indexAlert(IndexAlertRequest request) {
|
||||
return execute(IndexAlertAction.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);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,8 @@ import org.elasticsearch.rest.action.support.RestBuilderListener;
|
|||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||
import static org.elasticsearch.rest.RestStatus.*;
|
||||
import static org.elasticsearch.rest.RestStatus.CREATED;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.alerts.transport.actions.delete;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -25,7 +25,7 @@ public class DeleteAlertAction extends AlertsClientAction<DeleteAlertRequest, De
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeleteAlertRequestBuilder newRequestBuilder(AlertsClientInterface client) {
|
||||
public DeleteAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
return new DeleteAlertRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,19 @@ package org.elasticsearch.alerts.transport.actions.delete;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
|
||||
/**
|
||||
* A delete document action request builder.
|
||||
*/
|
||||
public class DeleteAlertRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<DeleteAlertRequest, DeleteAlertResponse, DeleteAlertRequestBuilder, AlertsClientInterface> {
|
||||
extends MasterNodeOperationRequestBuilder<DeleteAlertRequest, DeleteAlertResponse, DeleteAlertRequestBuilder, AlertsClient> {
|
||||
|
||||
public DeleteAlertRequestBuilder(AlertsClientInterface client) {
|
||||
public DeleteAlertRequestBuilder(AlertsClient client) {
|
||||
super(client, new DeleteAlertRequest());
|
||||
}
|
||||
|
||||
public DeleteAlertRequestBuilder(AlertsClientInterface client, String alertName) {
|
||||
public DeleteAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
super(client, new DeleteAlertRequest(alertName));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.alerts.transport.actions.get;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -25,7 +25,7 @@ public class GetAlertAction extends AlertsClientAction<GetAlertRequest, GetAlert
|
|||
}
|
||||
|
||||
@Override
|
||||
public GetAlertRequestBuilder newRequestBuilder(AlertsClientInterface client) {
|
||||
public GetAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
return new GetAlertRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,25 +7,21 @@ package org.elasticsearch.alerts.transport.actions.get;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
|
||||
/**
|
||||
* A delete document action request builder.
|
||||
*/
|
||||
public class GetAlertRequestBuilder
|
||||
extends ActionRequestBuilder<GetAlertRequest, GetAlertResponse, GetAlertRequestBuilder, AlertsClientInterface> {
|
||||
public class GetAlertRequestBuilder extends ActionRequestBuilder<GetAlertRequest, GetAlertResponse, GetAlertRequestBuilder, AlertsClient> {
|
||||
|
||||
|
||||
public GetAlertRequestBuilder(AlertsClientInterface client, String alertName) {
|
||||
public GetAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
super(client, new GetAlertRequest(alertName));
|
||||
}
|
||||
|
||||
|
||||
public GetAlertRequestBuilder(AlertsClientInterface client) {
|
||||
public GetAlertRequestBuilder(AlertsClient client) {
|
||||
super(client, new GetAlertRequest());
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.alerts.transport.actions.index;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@ public class IndexAlertAction extends AlertsClientAction<IndexAlertRequest, Inde
|
|||
|
||||
|
||||
@Override
|
||||
public IndexAlertRequestBuilder newRequestBuilder(AlertsClientInterface client) {
|
||||
public IndexAlertRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
return new IndexAlertRequestBuilder(client);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,22 +7,22 @@ package org.elasticsearch.alerts.transport.actions.index;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class IndexAlertRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<IndexAlertRequest, IndexAlertResponse,
|
||||
IndexAlertRequestBuilder, AlertsClientInterface> {
|
||||
IndexAlertRequestBuilder, AlertsClient> {
|
||||
|
||||
|
||||
public IndexAlertRequestBuilder(AlertsClientInterface client) {
|
||||
public IndexAlertRequestBuilder(AlertsClient client) {
|
||||
super(client, new IndexAlertRequest());
|
||||
}
|
||||
|
||||
|
||||
public IndexAlertRequestBuilder(AlertsClientInterface client, String alertName) {
|
||||
public IndexAlertRequestBuilder(AlertsClient client, String alertName) {
|
||||
super(client, new IndexAlertRequest());
|
||||
request.setAlertName(alertName);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.alerts.transport.actions.stats;
|
||||
|
||||
import org.elasticsearch.alerts.client.AlertsClientAction;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -25,7 +25,7 @@ public class AlertsStatsAction extends AlertsClientAction<AlertsStatsRequest, Al
|
|||
}
|
||||
|
||||
@Override
|
||||
public AlertsStatsRequestBuilder newRequestBuilder(AlertsClientInterface client) {
|
||||
public AlertsStatsRequestBuilder newRequestBuilder(AlertsClient client) {
|
||||
return new AlertsStatsRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,15 @@ package org.elasticsearch.alerts.transport.actions.stats;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
|
||||
/**
|
||||
* An alert stats document action request builder.
|
||||
*/
|
||||
public class AlertsStatsRequestBuilder
|
||||
extends MasterNodeOperationRequestBuilder<AlertsStatsRequest, AlertsStatsResponse, AlertsStatsRequestBuilder, AlertsClientInterface> {
|
||||
extends MasterNodeOperationRequestBuilder<AlertsStatsRequest, AlertsStatsResponse, AlertsStatsRequestBuilder, AlertsClient> {
|
||||
|
||||
public AlertsStatsRequestBuilder(AlertsClientInterface client) {
|
||||
public AlertsStatsRequestBuilder(AlertsClient client) {
|
||||
super(client, new AlertsStatsRequest());
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.alerts;
|
|||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
||||
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse;
|
||||
|
@ -32,7 +32,7 @@ public class BasicAlertingTest extends AbstractAlertingTests {
|
|||
|
||||
@Test
|
||||
public void testIndexAlert() throws Exception {
|
||||
AlertsClientInterface alertsClient = alertClient();
|
||||
AlertsClient alertsClient = alertClient();
|
||||
createIndex("my-index");
|
||||
// Have a sample document in the index, the alert is going to evaluate
|
||||
client().prepareIndex("my-index", "my-type").setSource("field", "value").get();
|
||||
|
@ -46,7 +46,7 @@ public class BasicAlertingTest extends AbstractAlertingTests {
|
|||
|
||||
@Test
|
||||
public void testIndexAlert_registerAlertBeforeTargetIndex() throws Exception {
|
||||
AlertsClientInterface alertsClient = alertClient();
|
||||
AlertsClient alertsClient = alertClient();
|
||||
SearchRequest searchRequest = new SearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
|
||||
BytesReference alertSource = createAlertSource("0/5 * * * * ? *", searchRequest, "hits.total == 1");
|
||||
alertsClient.prepareIndexAlert("my-first-alert")
|
||||
|
@ -63,7 +63,7 @@ public class BasicAlertingTest extends AbstractAlertingTests {
|
|||
|
||||
@Test
|
||||
public void testDeleteAlert() throws Exception {
|
||||
AlertsClientInterface alertsClient = alertClient();
|
||||
AlertsClient alertsClient = alertClient();
|
||||
createIndex("my-index");
|
||||
// Have a sample document in the index, the alert is going to evaluate
|
||||
client().prepareIndex("my-index", "my-type").setSource("field", "value").get();
|
||||
|
@ -91,7 +91,7 @@ public class BasicAlertingTest extends AbstractAlertingTests {
|
|||
|
||||
@Test
|
||||
public void testMalformedAlert() throws Exception {
|
||||
AlertsClientInterface alertsClient = alertClient();
|
||||
AlertsClient alertsClient = alertClient();
|
||||
createIndex("my-index");
|
||||
// Have a sample document in the index, the alert is going to evaluate
|
||||
client().prepareIndex("my-index", "my-type").setSource("field", "value").get();
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.alerts;
|
|||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.base.Predicate;
|
||||
|
@ -51,7 +51,7 @@ public class NoMasterNodeTests extends AbstractAlertingTests {
|
|||
public void testSimpleFailure() throws Exception {
|
||||
config = new ClusterDiscoveryConfiguration.UnicastZen(2);
|
||||
internalTestCluster().startNodesAsync(2).get();
|
||||
AlertsClientInterface alertsClient = alertClient();
|
||||
AlertsClient alertsClient = alertClient();
|
||||
createIndex("my-index");
|
||||
// Have a sample document in the index, the alert is going to evaluate
|
||||
client().prepareIndex("my-index", "my-type").setSource("field", "value").get();
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.elasticsearch.alerts.AlertManager;
|
|||
import org.elasticsearch.alerts.AlertUtils;
|
||||
import org.elasticsearch.alerts.AlertsStore;
|
||||
import org.elasticsearch.alerts.client.AlertsClient;
|
||||
import org.elasticsearch.alerts.client.AlertsClientInterface;
|
||||
import org.elasticsearch.alerts.plugin.AlertsPlugin;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
|
||||
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
|
||||
|
@ -197,7 +196,7 @@ public class AlertActionsTest extends ElasticsearchIntegrationTest {
|
|||
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
||||
alert.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
|
||||
|
||||
AlertsClientInterface alertsClient = internalCluster().getInstance(AlertsClient.class, internalCluster().getMasterName());
|
||||
AlertsClient alertsClient = internalCluster().getInstance(AlertsClient.class, internalCluster().getMasterName());
|
||||
|
||||
IndexAlertRequest alertRequest = alertsClient.prepareIndexAlert().setAlertName("my-first-alert").setAlertSource(jsonBuilder.bytes()).request();
|
||||
IndexAlertResponse alertsResponse = alertsClient.indexAlert(alertRequest).actionGet();
|
||||
|
|
|
@ -9,7 +9,6 @@ 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.client.AlertsClient;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
|
Loading…
Reference in New Issue