From 532e5d7b355c6dccea3f51d61f96df22c1ec1b04 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 17 Nov 2014 12:09:22 +0100 Subject: [PATCH] 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@0f1a9e23b16c1ac52be679689ed3be8c172c2659 --- README.md | 6 ++-- .../elasticsearch/alerts/AlertingModule.java | 8 ++--- .../alerts/client/AlertsClient.java | 14 ++++---- .../alerts/client/NodeAlertsClient.java | 22 ++++++------- .../alerts/rest/RestAlertsStatsAction.java | 3 +- .../alerts/rest/RestDeleteAlertAction.java | 3 +- .../alerts/rest/RestGetAlertAction.java | 3 +- ...ertAction.java => RestPutAlertAction.java} | 23 ++++++------- .../actions/index/IndexAlertAction.java | 32 ------------------- .../transport/actions/put/PutAlertAction.java | 32 +++++++++++++++++++ .../PutAlertRequest.java} | 8 ++--- .../PutAlertRequestBuilder.java} | 22 ++++++------- .../PutAlertResponse.java} | 8 ++--- .../TransportPutAlertAction.java} | 24 +++++++------- .../actions/{index => put}/package-info.java | 2 +- .../stats/TransportAlertStatsAction.java | 1 + .../alerts/BasicAlertingTest.java | 4 +-- .../alerts/actions/AlertActionsTest.java | 8 ++--- 18 files changed, 114 insertions(+), 109 deletions(-) rename src/main/java/org/elasticsearch/alerts/rest/{RestIndexAlertAction.java => RestPutAlertAction.java} (66%) delete mode 100644 src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertAction.java create mode 100644 src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertAction.java rename src/main/java/org/elasticsearch/alerts/transport/actions/{index/IndexAlertRequest.java => put/PutAlertRequest.java} (91%) rename src/main/java/org/elasticsearch/alerts/transport/actions/{index/IndexAlertRequestBuilder.java => put/PutAlertRequestBuilder.java} (52%) rename src/main/java/org/elasticsearch/alerts/transport/actions/{index/IndexAlertResponse.java => put/PutAlertResponse.java} (86%) rename src/main/java/org/elasticsearch/alerts/transport/actions/{index/TransportIndexAlertAction.java => put/TransportPutAlertAction.java} (64%) rename src/main/java/org/elasticsearch/alerts/transport/actions/{index => put}/package-info.java (80%) diff --git a/README.md b/README.md index 5dfe994c9e3..285a1addb38 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is the elasticsearch alerting plugin repo. Creating an alert : ```` -PUT _alert/testalert +PUT /.alerts/alert/testalert { "request" : { "indices" : [ @@ -63,7 +63,7 @@ Expected response : Viewing an existing alert : ```` -GET _alert/testalert +GET /.alerts/alert/testalert ```` ```` @@ -119,7 +119,7 @@ GET _alert/testalert Deleting an alert : ```` -DELETE _alert/testalert +DELETE /.alerts/alert/testalert ```` Expected output : diff --git a/src/main/java/org/elasticsearch/alerts/AlertingModule.java b/src/main/java/org/elasticsearch/alerts/AlertingModule.java index 49c816ce718..4b4eb3205e2 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertingModule.java +++ b/src/main/java/org/elasticsearch/alerts/AlertingModule.java @@ -13,11 +13,11 @@ import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.rest.RestAlertsStatsAction; import org.elasticsearch.alerts.rest.RestDeleteAlertAction; 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.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.put.TransportPutAlertAction; import org.elasticsearch.alerts.transport.actions.stats.TransportAlertStatsAction; import org.elasticsearch.alerts.triggers.TriggerManager; import org.elasticsearch.common.inject.AbstractModule; @@ -37,14 +37,14 @@ public class AlertingModule extends AbstractModule { bind(AlertActionRegistry.class).asEagerSingleton(); // Transport and client layer - bind(TransportIndexAlertAction.class).asEagerSingleton(); + bind(TransportPutAlertAction.class).asEagerSingleton(); bind(TransportDeleteAlertAction.class).asEagerSingleton(); bind(TransportGetAlertAction.class).asEagerSingleton(); bind(TransportAlertStatsAction.class).asEagerSingleton(); bind(AlertsClient.class).to(NodeAlertsClient.class).asEagerSingleton(); // Rest layer - bind(RestIndexAlertAction.class).asEagerSingleton(); + bind(RestPutAlertAction.class).asEagerSingleton(); bind(RestDeleteAlertAction.class).asEagerSingleton(); bind(RestAlertsStatsAction.class).asEagerSingleton(); bind(RestGetAlertAction.class).asEagerSingleton(); diff --git a/src/main/java/org/elasticsearch/alerts/client/AlertsClient.java b/src/main/java/org/elasticsearch/alerts/client/AlertsClient.java index a347a70c358..f5f2e4a381b 100644 --- a/src/main/java/org/elasticsearch/alerts/client/AlertsClient.java +++ b/src/main/java/org/elasticsearch/alerts/client/AlertsClient.java @@ -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.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.put.PutAlertRequest; +import org.elasticsearch.alerts.transport.actions.put.PutAlertRequestBuilder; +import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequestBuilder; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse; @@ -93,14 +93,14 @@ public interface AlertsClient extends ElasticsearchClient { * @param alertName The name of the alert to index * @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 * * @return The builder */ - IndexAlertRequestBuilder prepareIndexAlert(); + PutAlertRequestBuilder prepareIndexAlert(); /** * Indexes an alert and registers it with the scheduler @@ -108,7 +108,7 @@ public interface AlertsClient extends ElasticsearchClient { * @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 listener); + void indexAlert(PutAlertRequest request, ActionListener listener); /** * Indexes an alert and registers it with the scheduler @@ -116,7 +116,7 @@ public interface AlertsClient extends ElasticsearchClient { * @param request The request containing the alert to index and register * @return The response containing the IndexResponse for this alert */ - ActionFuture indexAlert(IndexAlertRequest request); + ActionFuture indexAlert(PutAlertRequest request); /** diff --git a/src/main/java/org/elasticsearch/alerts/client/NodeAlertsClient.java b/src/main/java/org/elasticsearch/alerts/client/NodeAlertsClient.java index b330b46013e..47778a91f29 100644 --- a/src/main/java/org/elasticsearch/alerts/client/NodeAlertsClient.java +++ b/src/main/java/org/elasticsearch/alerts/client/NodeAlertsClient.java @@ -9,7 +9,7 @@ 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.put.*; import org.elasticsearch.alerts.transport.actions.stats.*; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.ImmutableMap; @@ -23,13 +23,13 @@ public class NodeAlertsClient implements AlertsClient { private final ImmutableMap internalActions; @Inject - public NodeAlertsClient(ThreadPool threadPool, Headers headers, TransportIndexAlertAction transportIndexAlertAction, + public NodeAlertsClient(ThreadPool threadPool, Headers headers, TransportPutAlertAction transportPutAlertAction, TransportGetAlertAction transportGetAlertAction, TransportDeleteAlertAction transportDeleteAlertAction, TransportAlertStatsAction transportAlertStatsAction) { this.headers = headers; this.threadPool = threadPool; internalActions = ImmutableMap.builder() - .put(IndexAlertAction.INSTANCE, transportIndexAlertAction) + .put(PutAlertAction.INSTANCE, transportPutAlertAction) .put(GetAlertAction.INSTANCE, transportGetAlertAction) .put(DeleteAlertAction.INSTANCE, transportDeleteAlertAction) .put(AlertsStatsAction.INSTANCE, transportAlertStatsAction) @@ -76,23 +76,23 @@ public class NodeAlertsClient implements AlertsClient { } @Override - public IndexAlertRequestBuilder prepareIndexAlert(String alertName) { - return new IndexAlertRequestBuilder(this, alertName); + public PutAlertRequestBuilder prepareIndexAlert(String alertName) { + return new PutAlertRequestBuilder(this, alertName); } @Override - public IndexAlertRequestBuilder prepareIndexAlert() { - return new IndexAlertRequestBuilder(this, null); + public PutAlertRequestBuilder prepareIndexAlert() { + return new PutAlertRequestBuilder(this, null); } @Override - public void indexAlert(IndexAlertRequest request, ActionListener response) { - execute(IndexAlertAction.INSTANCE, request, response); + public void indexAlert(PutAlertRequest request, ActionListener response) { + execute(PutAlertAction.INSTANCE, request, response); } @Override - public ActionFuture indexAlert(IndexAlertRequest request) { - return execute(IndexAlertAction.INSTANCE, request); + public ActionFuture indexAlert(PutAlertRequest request) { + return execute(PutAlertAction.INSTANCE, request); } @Override diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java b/src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java index b6a5c3806d5..021a06072f0 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/RestAlertsStatsAction.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.alerts.rest; +import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsRequest; 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) { super(settings, controller, client); this.alertsClient = alertsClient; - controller.registerHandler(GET, "/_alert/_stats", this); + controller.registerHandler(GET, AlertsStore.ALERT_INDEX + "/alert/_stats", this); } @Override diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java index 521eabbf4e6..875438741bf 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/RestDeleteAlertAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.alerts.rest; import org.elasticsearch.action.delete.DeleteResponse; +import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.transport.actions.delete.DeleteAlertRequest; 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) { super(settings, controller, client); this.alertsClient = alertsClient; - controller.registerHandler(DELETE, "/_alert/{name}", this); + controller.registerHandler(DELETE, AlertsStore.ALERT_INDEX + "/alert/{name}", this); } @Override diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java index 8d84c09cdf1..d5f56222e78 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/RestGetAlertAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.alerts.rest; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; import org.elasticsearch.alerts.transport.actions.get.GetAlertRequest; 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) { super(settings, controller, client); this.alertsClient = alertsClient; - controller.registerHandler(GET, "/_alert/{name}", this); + controller.registerHandler(GET, AlertsStore.ALERT_INDEX + "/alert/{name}", this); } @Override diff --git a/src/main/java/org/elasticsearch/alerts/rest/RestIndexAlertAction.java b/src/main/java/org/elasticsearch/alerts/rest/RestPutAlertAction.java similarity index 66% rename from src/main/java/org/elasticsearch/alerts/rest/RestIndexAlertAction.java rename to src/main/java/org/elasticsearch/alerts/rest/RestPutAlertAction.java index 164c51cad8d..6d7c3a88c7d 100644 --- a/src/main/java/org/elasticsearch/alerts/rest/RestIndexAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/rest/RestPutAlertAction.java @@ -6,9 +6,10 @@ package org.elasticsearch.alerts.rest; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.alerts.AlertsStore; import org.elasticsearch.alerts.client.AlertsClient; -import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest; -import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; +import org.elasticsearch.alerts.transport.actions.put.PutAlertRequest; +import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; 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; @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); this.alertsClient = alertsClient; - controller.registerHandler(POST, "/_alert/{name}", this); - controller.registerHandler(PUT, "/_alert/{name}", this); + controller.registerHandler(POST, AlertsStore.ALERT_INDEX + "/alert/{name}", this); + controller.registerHandler(PUT, AlertsStore.ALERT_INDEX + "/alert/{name}", this); } @Override protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception { - IndexAlertRequest indexAlertRequest = new IndexAlertRequest(); - indexAlertRequest.setAlertName(request.param("name")); - indexAlertRequest.setAlertSource(request.content(), request.contentUnsafe()); - alertsClient.indexAlert(indexAlertRequest, new RestBuilderListener(channel) { + PutAlertRequest putAlertRequest = new PutAlertRequest(); + putAlertRequest.setAlertName(request.param("name")); + putAlertRequest.setAlertSource(request.content(), request.contentUnsafe()); + alertsClient.indexAlert(putAlertRequest, new RestBuilderListener(channel) { @Override - public RestResponse buildResponse(IndexAlertResponse response, XContentBuilder builder) throws Exception { + public RestResponse buildResponse(PutAlertResponse response, XContentBuilder builder) throws Exception { IndexResponse indexResponse = response.indexResponse(); builder.startObject() .field("_index", indexResponse.getIndex()) diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertAction.java deleted file mode 100644 index 894407e5fa8..00000000000 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertAction.java +++ /dev/null @@ -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 { - - 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(); - } -} diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertAction.java new file mode 100644 index 00000000000..68900c072c2 --- /dev/null +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertAction.java @@ -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 { + + 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(); + } +} diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertRequest.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertRequest.java similarity index 91% rename from src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertRequest.java rename to src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertRequest.java index 0cdd4d1d232..ebfd3ff2712 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertRequest.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertRequest.java @@ -3,7 +3,7 @@ * 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; +package org.elasticsearch.alerts.transport.actions.put; import org.elasticsearch.action.ActionRequestValidationException; @@ -17,16 +17,16 @@ import java.io.IOException; /** */ -public class IndexAlertRequest extends MasterNodeOperationRequest { +public class PutAlertRequest extends MasterNodeOperationRequest { private String alertName; private BytesReference alertSource; private boolean alertSourceUnsafe; - public IndexAlertRequest() { + public PutAlertRequest() { } - public IndexAlertRequest(BytesReference alertSource) { + public PutAlertRequest(BytesReference alertSource) { this.alertSource = alertSource; } diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertRequestBuilder.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertRequestBuilder.java similarity index 52% rename from src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertRequestBuilder.java rename to src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertRequestBuilder.java index 23751233ccd..3519a6a62eb 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertRequestBuilder.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertRequestBuilder.java @@ -3,7 +3,7 @@ * 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; +package org.elasticsearch.alerts.transport.actions.put; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; @@ -12,34 +12,34 @@ import org.elasticsearch.common.bytes.BytesReference; /** */ -public class IndexAlertRequestBuilder - extends MasterNodeOperationRequestBuilder { +public class PutAlertRequestBuilder + extends MasterNodeOperationRequestBuilder { - public IndexAlertRequestBuilder(AlertsClient client) { - super(client, new IndexAlertRequest()); + public PutAlertRequestBuilder(AlertsClient client) { + super(client, new PutAlertRequest()); } - public IndexAlertRequestBuilder(AlertsClient client, String alertName) { - super(client, new IndexAlertRequest()); + public PutAlertRequestBuilder(AlertsClient client, String alertName) { + super(client, new PutAlertRequest()); request.setAlertName(alertName); } - public IndexAlertRequestBuilder setAlertName(String alertName){ + public PutAlertRequestBuilder setAlertName(String alertName){ request.setAlertName(alertName); return this; } - public IndexAlertRequestBuilder setAlertSource(BytesReference alertSource) { + public PutAlertRequestBuilder setAlertSource(BytesReference alertSource) { request.setAlertSource(alertSource); return this; } @Override - protected void doExecute(ActionListener listener) { + protected void doExecute(ActionListener listener) { client.indexAlert(request, listener); } } diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertResponse.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertResponse.java similarity index 86% rename from src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertResponse.java rename to src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertResponse.java index dfe632021d3..04b5f49477d 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/index/IndexAlertResponse.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/PutAlertResponse.java @@ -3,7 +3,7 @@ * 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; +package org.elasticsearch.alerts.transport.actions.put; import org.elasticsearch.action.ActionResponse; 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; - public IndexAlertResponse(IndexResponse indexResponse) { + public PutAlertResponse(IndexResponse indexResponse) { this.indexResponse = indexResponse; } - public IndexAlertResponse() { + public PutAlertResponse() { indexResponse = null; } diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/index/TransportIndexAlertAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java similarity index 64% rename from src/main/java/org/elasticsearch/alerts/transport/actions/index/TransportIndexAlertAction.java rename to src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java index c06724f4b29..ef020299d9a 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/index/TransportIndexAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/TransportPutAlertAction.java @@ -3,7 +3,7 @@ * 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; +package org.elasticsearch.alerts.transport.actions.put; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; @@ -24,14 +24,14 @@ import org.elasticsearch.transport.TransportService; /** */ -public class TransportIndexAlertAction extends TransportMasterNodeOperationAction { +public class TransportPutAlertAction extends TransportMasterNodeOperationAction { private final AlertManager alertManager; @Inject - public TransportIndexAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager) { - super(settings, IndexAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); + public TransportPutAlertAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, ActionFilters actionFilters, AlertManager alertManager) { + super(settings, PutAlertAction.NAME, transportService, clusterService, threadPool, actionFilters); this.alertManager = alertManager; } @@ -41,27 +41,27 @@ public class TransportIndexAlertAction extends TransportMasterNodeOperationActio } @Override - protected IndexAlertRequest newRequest() { - return new IndexAlertRequest(); + protected PutAlertRequest newRequest() { + return new PutAlertRequest(); } @Override - protected IndexAlertResponse newResponse() { - return new IndexAlertResponse(); + protected PutAlertResponse newResponse() { + return new PutAlertResponse(); } @Override - protected void masterOperation(IndexAlertRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { + protected void masterOperation(PutAlertRequest request, ClusterState state, ActionListener listener) throws ElasticsearchException { try { IndexResponse indexResponse = alertManager.addAlert(request.getAlertName(), request.getAlertSource()); - listener.onResponse(new IndexAlertResponse(indexResponse)); + listener.onResponse(new PutAlertResponse(indexResponse)); } catch (Exception e) { listener.onFailure(e); } } @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 return state.blocks().indicesBlockedException(ClusterBlockLevel.WRITE, new String[]{AlertsStore.ALERT_INDEX, AlertActionManager.ALERT_HISTORY_INDEX}); diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/index/package-info.java b/src/main/java/org/elasticsearch/alerts/transport/actions/put/package-info.java similarity index 80% rename from src/main/java/org/elasticsearch/alerts/transport/actions/index/package-info.java rename to src/main/java/org/elasticsearch/alerts/transport/actions/put/package-info.java index 434eb2a71a5..a667749964a 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/index/package-info.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/put/package-info.java @@ -3,4 +3,4 @@ * 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; \ No newline at end of file +package org.elasticsearch.alerts.transport.actions.put; \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertStatsAction.java b/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertStatsAction.java index 382bd9bd7d3..3f701bfba0c 100644 --- a/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertStatsAction.java +++ b/src/main/java/org/elasticsearch/alerts/transport/actions/stats/TransportAlertStatsAction.java @@ -58,6 +58,7 @@ public class TransportAlertStatsAction extends TransportMasterNodeOperationActio statsResponse.setAlertActionManagerStarted(alertActionManager.started()); statsResponse.setAlertActionManagerQueueSize(alertActionManager.getQueueSize()); statsResponse.setNumberOfRegisteredAlerts(alertManager.getNumberOfAlerts()); + listener.onResponse(statsResponse); } @Override diff --git a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java index f73ec5b5eac..fb8f25ec036 100644 --- a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java +++ b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java @@ -10,7 +10,7 @@ import org.elasticsearch.action.search.SearchRequest; 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; +import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.script.ScriptService; 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(); SearchRequest searchRequest = new SearchRequest("my-index").source(searchSource().query(matchAllQuery())); 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) .get(); assertThat(indexResponse.indexResponse().isCreated(), is(true)); diff --git a/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java b/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java index f9f33468ffe..63b25b4856d 100644 --- a/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java +++ b/src/test/java/org/elasticsearch/alerts/actions/AlertActionsTest.java @@ -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.get.GetAlertRequest; import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse; -import org.elasticsearch.alerts.transport.actions.index.IndexAlertRequest; -import org.elasticsearch.alerts.transport.actions.index.IndexAlertResponse; +import org.elasticsearch.alerts.transport.actions.put.PutAlertRequest; +import org.elasticsearch.alerts.transport.actions.put.PutAlertResponse; import org.elasticsearch.alerts.triggers.AlertTrigger; import org.elasticsearch.alerts.triggers.ScriptedTrigger; import org.elasticsearch.alerts.triggers.TriggerResult; @@ -198,8 +198,8 @@ public class AlertActionsTest extends ElasticsearchIntegrationTest { 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(); + PutAlertRequest alertRequest = alertsClient.prepareIndexAlert().setAlertName("my-first-alert").setAlertSource(jsonBuilder.bytes()).request(); + PutAlertResponse alertsResponse = alertsClient.indexAlert(alertRequest).actionGet(); assertNotNull(alertsResponse.indexResponse()); assertTrue(alertsResponse.indexResponse().isCreated());