Core: Change the rest api url structure as if all operations are targetted for the `.alerts` index.

Closes elastic/elasticsearch#44

Original commit: elastic/x-pack-elasticsearch@0f1a9e23b1
This commit is contained in:
Martijn van Groningen 2014-11-17 12:09:22 +01:00
parent 6891702397
commit 532e5d7b35
18 changed files with 114 additions and 109 deletions

View File

@ -6,7 +6,7 @@ This is the elasticsearch alerting plugin repo.
Creating an alert : Creating an alert :
```` ````
PUT _alert/testalert PUT /.alerts/alert/testalert
{ {
"request" : { "request" : {
"indices" : [ "indices" : [
@ -63,7 +63,7 @@ Expected response :
Viewing an existing alert : Viewing an existing alert :
```` ````
GET _alert/testalert GET /.alerts/alert/testalert
```` ````
```` ````
@ -119,7 +119,7 @@ GET _alert/testalert
Deleting an alert : Deleting an alert :
```` ````
DELETE _alert/testalert DELETE /.alerts/alert/testalert
```` ````
Expected output : Expected output :

View File

@ -13,11 +13,11 @@ import org.elasticsearch.alerts.client.AlertsClient;
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.RestPutAlertAction;
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.delete.TransportDeleteAlertAction;
import org.elasticsearch.alerts.transport.actions.get.TransportGetAlertAction; import org.elasticsearch.alerts.transport.actions.get.TransportGetAlertAction;
import org.elasticsearch.alerts.transport.actions.index.TransportIndexAlertAction; import org.elasticsearch.alerts.transport.actions.put.TransportPutAlertAction;
import org.elasticsearch.alerts.transport.actions.stats.TransportAlertStatsAction; 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;
@ -37,14 +37,14 @@ public class AlertingModule extends AbstractModule {
bind(AlertActionRegistry.class).asEagerSingleton(); bind(AlertActionRegistry.class).asEagerSingleton();
// Transport and client layer // Transport and client layer
bind(TransportIndexAlertAction.class).asEagerSingleton(); bind(TransportPutAlertAction.class).asEagerSingleton();
bind(TransportDeleteAlertAction.class).asEagerSingleton(); bind(TransportDeleteAlertAction.class).asEagerSingleton();
bind(TransportGetAlertAction.class).asEagerSingleton(); bind(TransportGetAlertAction.class).asEagerSingleton();
bind(TransportAlertStatsAction.class).asEagerSingleton(); bind(TransportAlertStatsAction.class).asEagerSingleton();
bind(AlertsClient.class).to(NodeAlertsClient.class).asEagerSingleton(); bind(AlertsClient.class).to(NodeAlertsClient.class).asEagerSingleton();
// Rest layer // Rest layer
bind(RestIndexAlertAction.class).asEagerSingleton(); bind(RestPutAlertAction.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();

View File

@ -13,9 +13,9 @@ import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest; import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest;
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequestBuilder; import org.elasticsearch.alerts.transport.actions.get.GetAlertRequestBuilder;
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse; import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest; import org.elasticsearch.alerts.transport.actions.put.PutAlertRequest;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequestBuilder; import org.elasticsearch.alerts.transport.actions.put.PutAlertRequestBuilder;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest;
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequestBuilder; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequestBuilder;
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse;
@ -93,14 +93,14 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
* @param alertName The name of the alert to index * @param alertName The name of the alert to index
* @return The builder to create the alert * @return The builder to create the alert
*/ */
IndexAlertRequestBuilder prepareIndexAlert(String alertName); PutAlertRequestBuilder prepareIndexAlert(String alertName);
/** /**
* Creates a request builder to build a request to index an alert * Creates a request builder to build a request to index an alert
* *
* @return The builder * @return The builder
*/ */
IndexAlertRequestBuilder prepareIndexAlert(); PutAlertRequestBuilder prepareIndexAlert();
/** /**
* Indexes an alert and registers it with the scheduler * Indexes an alert and registers it with the scheduler
@ -108,7 +108,7 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
* @param request The request containing the alert to index and register * @param request The request containing the alert to index and register
* @param listener The listener for the response containing the IndexResponse for this alert * @param listener The listener for the response containing the IndexResponse for this alert
*/ */
void indexAlert(IndexAlertRequest request, ActionListener<IndexAlertResponse> listener); void indexAlert(PutAlertRequest request, ActionListener<PutAlertResponse> listener);
/** /**
* Indexes an alert and registers it with the scheduler * Indexes an alert and registers it with the scheduler
@ -116,7 +116,7 @@ public interface AlertsClient extends ElasticsearchClient<AlertsClient> {
* @param request The request containing the alert to index and register * @param request The request containing the alert to index and register
* @return The response containing the IndexResponse for this alert * @return The response containing the IndexResponse for this alert
*/ */
ActionFuture<IndexAlertResponse> indexAlert(IndexAlertRequest request); ActionFuture<PutAlertResponse> indexAlert(PutAlertRequest request);
/** /**

View File

@ -9,7 +9,7 @@ import org.elasticsearch.action.*;
import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.action.support.TransportAction;
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.put.*;
import org.elasticsearch.alerts.transport.actions.stats.*; import org.elasticsearch.alerts.transport.actions.stats.*;
import org.elasticsearch.client.support.Headers; import org.elasticsearch.client.support.Headers;
import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.collect.ImmutableMap;
@ -23,13 +23,13 @@ public class NodeAlertsClient implements AlertsClient {
private final ImmutableMap<GenericAction, TransportAction> internalActions; private final ImmutableMap<GenericAction, TransportAction> internalActions;
@Inject @Inject
public NodeAlertsClient(ThreadPool threadPool, Headers headers, TransportIndexAlertAction transportIndexAlertAction, public NodeAlertsClient(ThreadPool threadPool, Headers headers, TransportPutAlertAction transportPutAlertAction,
TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction, TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction,
TransportAlertStatsAction transportAlertStatsAction) { TransportAlertStatsAction transportAlertStatsAction) {
this.headers = headers; this.headers = headers;
this.threadPool = threadPool; this.threadPool = threadPool;
internalActions = ImmutableMap.<GenericAction, TransportAction>builder() internalActions = ImmutableMap.<GenericAction, TransportAction>builder()
.put(IndexAlertAction.INSTANCE, transportIndexAlertAction) .put(PutAlertAction.INSTANCE, transportPutAlertAction)
.put(GetAlertAction.INSTANCE, transportGetAlertAction) .put(GetAlertAction.INSTANCE, transportGetAlertAction)
.put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction) .put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction)
.put(AlertsStatsAction.INSTANCE, transportAlertStatsAction) .put(AlertsStatsAction.INSTANCE, transportAlertStatsAction)
@ -76,23 +76,23 @@ public class NodeAlertsClient implements AlertsClient {
} }
@Override @Override
public IndexAlertRequestBuilder prepareIndexAlert(String alertName) { public PutAlertRequestBuilder prepareIndexAlert(String alertName) {
return new IndexAlertRequestBuilder(this, alertName); return new PutAlertRequestBuilder(this, alertName);
} }
@Override @Override
public IndexAlertRequestBuilder prepareIndexAlert() { public PutAlertRequestBuilder prepareIndexAlert() {
return new IndexAlertRequestBuilder(this, null); return new PutAlertRequestBuilder(this, null);
} }
@Override @Override
public void indexAlert(IndexAlertRequest request, ActionListener<IndexAlertResponse> response) { public void indexAlert(PutAlertRequest request, ActionListener<PutAlertResponse> response) {
execute(IndexAlertAction.INSTANCE, request, response); execute(PutAlertAction.INSTANCE, request, response);
} }
@Override @Override
public ActionFuture<IndexAlertResponse> indexAlert(IndexAlertRequest request) { public ActionFuture<PutAlertResponse> indexAlert(PutAlertRequest request) {
return execute(IndexAlertAction.INSTANCE, request); return execute(PutAlertAction.INSTANCE, request);
} }
@Override @Override

View File

@ -5,6 +5,7 @@
*/ */
package org.elasticsearch.alerts.rest; package org.elasticsearch.alerts.rest;
import org.elasticsearch.alerts.AlertsStore;
import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.client.AlertsClient;
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest;
import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse;
@ -29,7 +30,7 @@ public class RestAlertsStatsAction extends BaseRestHandler {
protected RestAlertsStatsAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) { protected RestAlertsStatsAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) {
super(settings, controller, client); super(settings, controller, client);
this.alertsClient = alertsClient; this.alertsClient = alertsClient;
controller.registerHandler(GET, "/_alert/_stats", this); controller.registerHandler(GET, AlertsStore.ALERT_INDEX + "/alert/_stats", this);
} }
@Override @Override

View File

@ -6,6 +6,7 @@
package org.elasticsearch.alerts.rest; package org.elasticsearch.alerts.rest;
import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.alerts.AlertsStore;
import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.client.AlertsClient;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
@ -30,7 +31,7 @@ public class RestDeleteAlertAction extends BaseRestHandler {
public RestDeleteAlertAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) { public RestDeleteAlertAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) {
super(settings, controller, client); super(settings, controller, client);
this.alertsClient = alertsClient; this.alertsClient = alertsClient;
controller.registerHandler(DELETE, "/_alert/{name}", this); controller.registerHandler(DELETE, AlertsStore.ALERT_INDEX + "/alert/{name}", this);
} }
@Override @Override

View File

@ -6,6 +6,7 @@
package org.elasticsearch.alerts.rest; package org.elasticsearch.alerts.rest;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.alerts.AlertsStore;
import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.client.AlertsClient;
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest; import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest;
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse; import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
@ -31,7 +32,7 @@ public class RestGetAlertAction extends BaseRestHandler {
public RestGetAlertAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) { public RestGetAlertAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) {
super(settings, controller, client); super(settings, controller, client);
this.alertsClient = alertsClient; this.alertsClient = alertsClient;
controller.registerHandler(GET, "/_alert/{name}", this); controller.registerHandler(GET, AlertsStore.ALERT_INDEX + "/alert/{name}", this);
} }
@Override @Override

View File

@ -6,9 +6,10 @@
package org.elasticsearch.alerts.rest; package org.elasticsearch.alerts.rest;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.alerts.AlertsStore;
import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.client.AlertsClient;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest; import org.elasticsearch.alerts.transport.actions.put.PutAlertRequest;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -23,26 +24,26 @@ import static org.elasticsearch.rest.RestStatus.OK;
/** /**
*/ */
public class RestIndexAlertAction extends BaseRestHandler { public class RestPutAlertAction extends BaseRestHandler {
private final AlertsClient alertsClient; private final AlertsClient alertsClient;
@Inject @Inject
public RestIndexAlertAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) { public RestPutAlertAction(Settings settings, RestController controller, Client client, AlertsClient alertsClient) {
super(settings, controller, client); super(settings, controller, client);
this.alertsClient = alertsClient; this.alertsClient = alertsClient;
controller.registerHandler(POST, "/_alert/{name}", this); controller.registerHandler(POST, AlertsStore.ALERT_INDEX + "/alert/{name}", this);
controller.registerHandler(PUT, "/_alert/{name}", this); controller.registerHandler(PUT, AlertsStore.ALERT_INDEX + "/alert/{name}", this);
} }
@Override @Override
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception { protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
IndexAlertRequest indexAlertRequest = new IndexAlertRequest(); PutAlertRequest putAlertRequest = new PutAlertRequest();
indexAlertRequest.setAlertName(request.param("name")); putAlertRequest.setAlertName(request.param("name"));
indexAlertRequest.setAlertSource(request.content(), request.contentUnsafe()); putAlertRequest.setAlertSource(request.content(), request.contentUnsafe());
alertsClient.indexAlert(indexAlertRequest, new RestBuilderListener<IndexAlertResponse>(channel) { alertsClient.indexAlert(putAlertRequest, new RestBuilderListener<PutAlertResponse>(channel) {
@Override @Override
public RestResponse buildResponse(IndexAlertResponse response, XContentBuilder builder) throws Exception { public RestResponse buildResponse(PutAlertResponse response, XContentBuilder builder) throws Exception {
IndexResponse indexResponse = response.indexResponse(); IndexResponse indexResponse = response.indexResponse();
builder.startObject() builder.startObject()
.field("_index", indexResponse.getIndex()) .field("_index", indexResponse.getIndex())

View File

@ -1,32 +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.transport.actions.index;
import org.elasticsearch.alerts.client.AlertsClientAction;
import org.elasticsearch.alerts.client.AlertsClient;
/**
*/
public class IndexAlertAction extends AlertsClientAction<IndexAlertRequest, IndexAlertResponse, IndexAlertRequestBuilder> {
public static final IndexAlertAction INSTANCE = new IndexAlertAction();
public static final String NAME = "indices:data/write/alert/index";
private IndexAlertAction() {
super(NAME);
}
@Override
public IndexAlertRequestBuilder newRequestBuilder(AlertsClient client) {
return new IndexAlertRequestBuilder(client);
}
@Override
public IndexAlertResponse newResponse() {
return new IndexAlertResponse();
}
}

View File

@ -0,0 +1,32 @@
/*
* 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.actions.put;
import org.elasticsearch.alerts.client.AlertsClientAction;
import org.elasticsearch.alerts.client.AlertsClient;
/**
*/
public class PutAlertAction extends AlertsClientAction<PutAlertRequest, PutAlertResponse, PutAlertRequestBuilder> {
public static final PutAlertAction INSTANCE = new PutAlertAction();
public static final String NAME = "indices:data/write/alert/put";
private PutAlertAction() {
super(NAME);
}
@Override
public PutAlertRequestBuilder newRequestBuilder(AlertsClient client) {
return new PutAlertRequestBuilder(client);
}
@Override
public PutAlertResponse newResponse() {
return new PutAlertResponse();
}
}

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.alerts.transport.actions.index; package org.elasticsearch.alerts.transport.actions.put;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
@ -17,16 +17,16 @@ import java.io.IOException;
/** /**
*/ */
public class IndexAlertRequest extends MasterNodeOperationRequest<IndexAlertRequest> { public class PutAlertRequest extends MasterNodeOperationRequest<PutAlertRequest> {
private String alertName; private String alertName;
private BytesReference alertSource; private BytesReference alertSource;
private boolean alertSourceUnsafe; private boolean alertSourceUnsafe;
public IndexAlertRequest() { public PutAlertRequest() {
} }
public IndexAlertRequest(BytesReference alertSource) { public PutAlertRequest(BytesReference alertSource) {
this.alertSource = alertSource; this.alertSource = alertSource;
} }

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.alerts.transport.actions.index; package org.elasticsearch.alerts.transport.actions.put;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
@ -12,34 +12,34 @@ import org.elasticsearch.common.bytes.BytesReference;
/** /**
*/ */
public class IndexAlertRequestBuilder public class PutAlertRequestBuilder
extends MasterNodeOperationRequestBuilder<IndexAlertRequest, IndexAlertResponse, extends MasterNodeOperationRequestBuilder<PutAlertRequest, PutAlertResponse,
IndexAlertRequestBuilder, AlertsClient> { PutAlertRequestBuilder, AlertsClient> {
public IndexAlertRequestBuilder(AlertsClient client) { public PutAlertRequestBuilder(AlertsClient client) {
super(client, new IndexAlertRequest()); super(client, new PutAlertRequest());
} }
public IndexAlertRequestBuilder(AlertsClient client, String alertName) { public PutAlertRequestBuilder(AlertsClient client, String alertName) {
super(client, new IndexAlertRequest()); super(client, new PutAlertRequest());
request.setAlertName(alertName); request.setAlertName(alertName);
} }
public IndexAlertRequestBuilder setAlertName(String alertName){ public PutAlertRequestBuilder setAlertName(String alertName){
request.setAlertName(alertName); request.setAlertName(alertName);
return this; return this;
} }
public IndexAlertRequestBuilder setAlertSource(BytesReference alertSource) { public PutAlertRequestBuilder setAlertSource(BytesReference alertSource) {
request.setAlertSource(alertSource); request.setAlertSource(alertSource);
return this; return this;
} }
@Override @Override
protected void doExecute(ActionListener<IndexAlertResponse> listener) { protected void doExecute(ActionListener<PutAlertResponse> listener) {
client.indexAlert(request, listener); client.indexAlert(request, listener);
} }
} }

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.alerts.transport.actions.index; package org.elasticsearch.alerts.transport.actions.put;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
@ -14,14 +14,14 @@ import java.io.IOException;
/** /**
*/ */
public class IndexAlertResponse extends ActionResponse { public class PutAlertResponse extends ActionResponse {
private IndexResponse indexResponse; private IndexResponse indexResponse;
public IndexAlertResponse(IndexResponse indexResponse) { public PutAlertResponse(IndexResponse indexResponse) {
this.indexResponse = indexResponse; this.indexResponse = indexResponse;
} }
public IndexAlertResponse() { public PutAlertResponse() {
indexResponse = null; indexResponse = null;
} }

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.alerts.transport.actions.index; package org.elasticsearch.alerts.transport.actions.put;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
@ -24,14 +24,14 @@ import org.elasticsearch.transport.TransportService;
/** /**
*/ */
public class TransportIndexAlertAction extends TransportMasterNodeOperationAction<IndexAlertRequest, IndexAlertResponse> { public class TransportPutAlertAction extends TransportMasterNodeOperationAction<PutAlertRequest, PutAlertResponse> {
private final AlertManager alertManager; private final AlertManager alertManager;
@Inject @Inject
public TransportIndexAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportPutAlertAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager) { ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager) {
super(settings, IndexAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); super(settings, PutAlertAction.NAME, transportService, clusterService, threadPool, actionFilters);
this.alertManager = alertManager; this.alertManager = alertManager;
} }
@ -41,27 +41,27 @@ public class TransportIndexAlertAction extends TransportMasterNodeOperationActio
} }
@Override @Override
protected IndexAlertRequest newRequest() { protected PutAlertRequest newRequest() {
return new IndexAlertRequest(); return new PutAlertRequest();
} }
@Override @Override
protected IndexAlertResponse newResponse() { protected PutAlertResponse newResponse() {
return new IndexAlertResponse(); return new PutAlertResponse();
} }
@Override @Override
protected void masterOperation(IndexAlertRequest request, ClusterState state, ActionListener<IndexAlertResponse> listener) throws ElasticsearchException { protected void masterOperation(PutAlertRequest request, ClusterState state, ActionListener<PutAlertResponse> listener) throws ElasticsearchException {
try { try {
IndexResponse indexResponse = alertManager.addAlert(request.getAlertName(), request.getAlertSource()); IndexResponse indexResponse = alertManager.addAlert(request.getAlertName(), request.getAlertSource());
listener.onResponse(new IndexAlertResponse(indexResponse)); listener.onResponse(new PutAlertResponse(indexResponse));
} catch (Exception e) { } catch (Exception e) {
listener.onFailure(e); listener.onFailure(e);
} }
} }
@Override @Override
protected ClusterBlockException checkBlock(IndexAlertRequest request, ClusterState state) { protected ClusterBlockException checkBlock(PutAlertRequest request, ClusterState state) {
request.beforeLocalFork(); // This is the best place to make the alert source safe request.beforeLocalFork(); // This is the best place to make the alert source safe
return state.blocks().indicesBlockedException(ClusterBlockLevel.WRITE, new String[]{AlertsStore.ALERT_INDEX, AlertActionManager.ALERT_HISTORY_INDEX}); return state.blocks().indicesBlockedException(ClusterBlockLevel.WRITE, new String[]{AlertsStore.ALERT_INDEX, AlertActionManager.ALERT_HISTORY_INDEX});

View File

@ -3,4 +3,4 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.alerts.transport.actions.index; package org.elasticsearch.alerts.transport.actions.put;

View File

@ -58,6 +58,7 @@ public class TransportAlertStatsAction extends TransportMasterNodeOperationActio
statsResponse.setAlertActionManagerStarted(alertActionManager.started()); statsResponse.setAlertActionManagerStarted(alertActionManager.started());
statsResponse.setAlertActionManagerQueueSize(alertActionManager.getQueueSize()); statsResponse.setAlertActionManagerQueueSize(alertActionManager.getQueueSize());
statsResponse.setNumberOfRegisteredAlerts(alertManager.getNumberOfAlerts()); statsResponse.setNumberOfRegisteredAlerts(alertManager.getNumberOfAlerts());
listener.onResponse(statsResponse);
} }
@Override @Override

View File

@ -10,7 +10,7 @@ import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.client.AlertsClient;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
@ -69,7 +69,7 @@ public class BasicAlertingTest extends AbstractAlertingTests {
client().prepareIndex("my-index", "my-type").setSource("field", "value").get(); client().prepareIndex("my-index", "my-type").setSource("field", "value").get();
SearchRequest searchRequest = new SearchRequest("my-index").source(searchSource().query(matchAllQuery())); SearchRequest searchRequest = new SearchRequest("my-index").source(searchSource().query(matchAllQuery()));
BytesReference alertSource = createAlertSource("0/5 * * * * ? *", searchRequest, "hits.total == 1"); BytesReference alertSource = createAlertSource("0/5 * * * * ? *", searchRequest, "hits.total == 1");
IndexAlertResponse indexResponse = alertsClient.prepareIndexAlert("my-first-alert") PutAlertResponse indexResponse = alertsClient.prepareIndexAlert("my-first-alert")
.setAlertSource(alertSource) .setAlertSource(alertSource)
.get(); .get();
assertThat(indexResponse.indexResponse().isCreated(), is(true)); assertThat(indexResponse.indexResponse().isCreated(), is(true));

View File

@ -19,8 +19,8 @@ import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest;
import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertResponse;
import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest; import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest;
import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse; import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest; import org.elasticsearch.alerts.transport.actions.put.PutAlertRequest;
import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse;
import org.elasticsearch.alerts.triggers.AlertTrigger; import org.elasticsearch.alerts.triggers.AlertTrigger;
import org.elasticsearch.alerts.triggers.ScriptedTrigger; import org.elasticsearch.alerts.triggers.ScriptedTrigger;
import org.elasticsearch.alerts.triggers.TriggerResult; import org.elasticsearch.alerts.triggers.TriggerResult;
@ -198,8 +198,8 @@ public class AlertActionsTest extends ElasticsearchIntegrationTest {
AlertsClient 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(); PutAlertRequest alertRequest = alertsClient.prepareIndexAlert().setAlertName("my-first-alert").setAlertSource(jsonBuilder.bytes()).request();
IndexAlertResponse alertsResponse = alertsClient.indexAlert(alertRequest).actionGet(); PutAlertResponse alertsResponse = alertsClient.indexAlert(alertRequest).actionGet();
assertNotNull(alertsResponse.indexResponse()); assertNotNull(alertsResponse.indexResponse());
assertTrue(alertsResponse.indexResponse().isCreated()); assertTrue(alertsResponse.indexResponse().isCreated());