use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class StatsApi method stats.
private JsonNode stats(Collection<String> indices, Collection<String> metrics, Consumer<Request> prepareRequest) {
final StringBuilder endpoint = new StringBuilder();
if (!indices.isEmpty()) {
final String joinedIndices = String.join(",", indices);
endpoint.append("/");
endpoint.append(joinedIndices);
}
endpoint.append("/_stats");
if (!metrics.isEmpty()) {
final String joinedMetrics = String.join(",", metrics);
endpoint.append("/");
endpoint.append(joinedMetrics);
}
final Request request = new Request("GET", endpoint.toString());
prepareRequest.accept(request);
return client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(response.getEntity().getContent());
}, "Unable to retrieve index stats for " + String.join(",", indices));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class CatApi method perform.
private <R> R perform(Request request, TypeReference<R> responseClass, String errorMessage) {
return client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return returnType(response, responseClass);
}, errorMessage);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ClusterStateApi method fields.
public Map<String, Set<String>> fields(Collection<String> indices) {
final Request request = request(indices);
final JsonNode jsonResponse = client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(response.getEntity().getContent());
}, "Unable to retrieve fields from indices: " + String.join(",", indices));
// noinspection UnstableApiUsage
return Streams.stream(jsonResponse.path("metadata").path("indices").fields()).flatMap(index -> allFieldsFromIndex(index.getKey(), index.getValue())).collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, Collectors.toSet())));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorSingleHeader.
@Test
public void testInterceptorSingleHeader() throws IOException, HttpException {
ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
response.addHeader("Test", "This header should not trigger the interceptor.");
interceptor.process(response, null);
assertThat(response.getAllHeaders()).as("Number of Headers should be unchanged.").hasSize(1);
assertThat(response.getAllHeaders()[0].getName()).as("Remaining Header should be same as the given.").isEqualTo("Test");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers.
@Test
public void testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers() throws IOException, HttpException {
ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
response.addHeader("Test", "This header should not trigger the interceptor.");
response.addHeader("Warning", "This warning should not trigger the interceptor.");
response.addHeader("Warning", "This text contains the trigger: but in a future major version, direct access to system indices and their aliases will not be allowed - and should be filtered out");
response.addHeader("Warning", "This text contains the trigger: setting was deprecated in Elasticsearch - and should be filtered out");
assertThat(response.getAllHeaders()).as("Number of Headers should be 4 before start.").hasSize(4);
interceptor.process(response, null);
assertThat(response.getAllHeaders()).as("Number of Headers should be 2 less after running the interceptor.").hasSize(2);
}
Aggregations