REST : Fix rendering on GetAlerts
Original commit: elastic/x-pack-elasticsearch@81fc5d86df
This commit is contained in:
parent
6a5a1710d0
commit
e79a98c568
|
@ -29,7 +29,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, "/_alert/_stats", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.elasticsearch.alerts.transport.actions.get.GetAlertResponse;
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
@ -37,13 +36,21 @@ public class RestGetAlertAction extends BaseRestHandler {
|
|||
|
||||
@Override
|
||||
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
|
||||
GetAlertRequest getAlertRequest = new GetAlertRequest();
|
||||
final GetAlertRequest getAlertRequest = new GetAlertRequest();
|
||||
getAlertRequest.alertName(request.param("name"));
|
||||
alertsClient.getAlert(getAlertRequest, new RestBuilderListener<GetAlertResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(GetAlertResponse result, XContentBuilder builder) throws Exception {
|
||||
GetResponse getResponse = result.getResponse();
|
||||
getResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.startObject()
|
||||
.field("found", getResponse.isExists())
|
||||
.field("_index", getResponse.getIndex())
|
||||
.field("_type", getResponse.getType())
|
||||
.field("_id", getResponse.getId())
|
||||
.field("_version", getResponse.getVersion())
|
||||
.field("alert", getResponse.getSource())
|
||||
.endObject();
|
||||
|
||||
RestStatus status = OK;
|
||||
if (!getResponse.isExists()) {
|
||||
status = NOT_FOUND;
|
||||
|
|
|
@ -10,12 +10,10 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||
import org.elasticsearch.alerts.AlertManager;
|
||||
import org.elasticsearch.alerts.AlertsStore;
|
||||
import org.elasticsearch.alerts.actions.AlertActionManager;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -64,7 +62,7 @@ public class TransportAlertStatsAction extends TransportMasterNodeOperationActio
|
|||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(AlertsStatsRequest request, ClusterState state) {
|
||||
return state.blocks().indicesBlockedException(ClusterBlockLevel.WRITE, new String[]{AlertsStore.ALERT_INDEX, AlertActionManager.ALERT_HISTORY_INDEX});
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.alerts;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.alerts.actions.AlertAction;
|
||||
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
|
||||
|
@ -12,6 +13,7 @@ import org.elasticsearch.common.joda.time.DateTime;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -37,6 +39,13 @@ public class TestAlertSerialization extends ElasticsearchIntegrationTest {
|
|||
|
||||
Alert parsedAlert = alertsStore.parseAlert("test-serialization", jsonBuilder.bytes());
|
||||
assertEquals(parsedAlert, alert);
|
||||
|
||||
logger.error(XContentHelper.convertToJson(jsonBuilder.bytes(),false,true));
|
||||
|
||||
if (true) {
|
||||
throw new ElasticsearchException("foobarbaz");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue