use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.
the class RestClusterStatsAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterStatsRequest clusterStatsRequest = new ClusterStatsRequest().nodesIds(request.paramAsStringArray("nodeId", null));
clusterStatsRequest.timeout(request.param("timeout"));
return channel -> client.admin().cluster().clusterStats(clusterStatsRequest, new NodesResponseRestListener<>(channel));
}
use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.
the class RestFieldStatsAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
if (request.hasContentOrSourceParam() && request.hasParam("fields")) {
throw new IllegalArgumentException("can't specify a request body and [fields] request parameter, " + "either specify a request body or the [fields] request parameter");
}
final FieldStatsRequest fieldStatsRequest = new FieldStatsRequest();
fieldStatsRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
fieldStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, fieldStatsRequest.indicesOptions()));
fieldStatsRequest.level(request.param("level", FieldStatsRequest.DEFAULT_LEVEL));
if (request.hasContentOrSourceParam()) {
try (XContentParser parser = request.contentOrSourceParamParser()) {
fieldStatsRequest.source(parser);
}
} else {
fieldStatsRequest.setFields(Strings.splitStringByCommaToArray(request.param("fields")));
}
return channel -> client.fieldStats(fieldStatsRequest, new RestBuilderListener<FieldStatsResponse>(channel) {
@Override
public RestResponse buildResponse(FieldStatsResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
buildBroadcastShardsHeader(builder, request, response);
builder.startObject("indices");
for (Map.Entry<String, Map<String, FieldStats>> entry1 : response.getIndicesMergedFieldStats().entrySet()) {
builder.startObject(entry1.getKey());
builder.startObject("fields");
for (Map.Entry<String, FieldStats> entry2 : entry1.getValue().entrySet()) {
builder.field(entry2.getKey());
entry2.getValue().toXContent(builder, request);
}
builder.endObject();
builder.endObject();
}
builder.endObject();
if (response.getConflicts().size() > 0) {
builder.startObject("conflicts");
for (Map.Entry<String, String> entry : response.getConflicts().entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
builder.endObject();
}
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
});
}
use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.
the class RestIndicesStatsActionTests method testUnrecognizedMetric.
public void testUnrecognizedMetric() throws IOException {
final HashMap<String, String> params = new HashMap<>();
final String metric = randomAsciiOfLength(64);
params.put("metric", metric);
final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_stats").withParams(params).build();
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, mock(NodeClient.class)));
assertThat(e, hasToString(containsString("request [/_stats] contains unrecognized metric: [" + metric + "]")));
}
use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.
the class RestNodesStatsActionTests method testAllRequestWithOtherMetrics.
public void testAllRequestWithOtherMetrics() throws IOException {
final HashMap<String, String> params = new HashMap<>();
final String metric = randomSubsetOf(1, RestNodesStatsAction.METRICS.keySet()).get(0);
params.put("metric", "_all," + metric);
final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_nodes/stats").withParams(params).build();
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, mock(NodeClient.class)));
assertThat(e, hasToString(containsString("request [/_nodes/stats] contains _all and individual metrics [_all," + metric + "]")));
}
use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.
the class RestNodesStatsActionTests method testUnrecognizedIndexMetric.
public void testUnrecognizedIndexMetric() {
final HashMap<String, String> params = new HashMap<>();
params.put("metric", "indices");
final String indexMetric = randomAsciiOfLength(64);
params.put("index_metric", indexMetric);
final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_nodes/stats").withParams(params).build();
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, mock(NodeClient.class)));
assertThat(e, hasToString(containsString("request [/_nodes/stats] contains unrecognized index metric: [" + indexMetric + "]")));
}
Aggregations