use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method clusterHealthRequest.
@Override
public void clusterHealthRequest(String timeout) throws IOException {
Request clusterHealthRequest = new Request(REQUEST_TYPE_GET, REQUEST_SEPARATOR + "_cluster" + REQUEST_SEPARATOR + "health");
clusterHealthRequest.addParameter("wait_for_status", "yellow");
clusterHealthRequest.addParameter("timeout", timeout);
final Response response = delegate.performRequest(clusterHealthRequest);
try (final InputStream inputStream = response.getEntity().getContent()) {
final Map<String, Object> values = mapReader.readValue(inputStream);
if (!values.containsKey("timed_out")) {
throw new IOException("Unexpected response for Elasticsearch cluster health request");
} else if (!Objects.equals(values.get("timed_out"), false)) {
throw new IOException("Elasticsearch timeout waiting for yellow status");
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method createMapping.
@Override
public void createMapping(String indexName, String typeName, Map<String, Object> mapping) throws IOException {
Request request;
if (useMappingTypes) {
request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping" + REQUEST_SEPARATOR + typeName);
if (esVersion7) {
request.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
} else {
request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping");
}
performRequest(request, mapWriter.writeValueAsBytes(mapping));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method pendingTasks.
@Override
public PendingTasksStats pendingTasks() {
final Request request = new Request("GET", "/_cluster/pending_tasks");
final JsonNode response = jsonApi.perform(request, "Couldn't read Elasticsearch pending cluster tasks");
final JsonNode pendingClusterTasks = response.path("tasks");
final int pendingTasksSize = pendingClusterTasks.size();
final List<Long> pendingTasksTimeInQueue = Lists.newArrayListWithCapacity(pendingTasksSize);
for (JsonNode jsonElement : pendingClusterTasks) {
if (jsonElement.has("time_in_queue_millis")) {
pendingTasksTimeInQueue.add(jsonElement.get("time_in_queue_millis").asLong());
}
}
return PendingTasksStats.create(pendingTasksSize, pendingTasksTimeInQueue);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method clusterHealth.
private Optional<ClusterHealthResponse> clusterHealth(Collection<String> indices) {
final String[] indicesAry = indices.toArray(new String[0]);
if (!indices.isEmpty() && !indicesExist(indicesAry)) {
return Optional.empty();
}
final ClusterHealthRequest request = new ClusterHealthRequest(indicesAry).timeout(TimeValue.timeValueSeconds(Ints.saturatedCast(requestTimeout.toSeconds()))).indicesOptions(IndicesOptions.lenientExpand());
try {
return Optional.of(client.execute((c, requestOptions) -> c.cluster().health(request, requestOptions)));
} catch (ElasticsearchException e) {
if (LOG.isDebugEnabled()) {
LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"), e);
} else {
LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"));
}
return Optional.empty();
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method clusterAllocationDiskSettings.
@Override
public ClusterAllocationDiskSettings clusterAllocationDiskSettings() {
final ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
request.includeDefaults(true);
final ClusterGetSettingsResponse response = client.execute((c, requestOptions) -> c.cluster().getSettings(request, requestOptions));
return ClusterAllocationDiskSettingsFactory.create(Boolean.parseBoolean(response.getSetting("cluster.routing.allocation.disk.threshold_enabled")), response.getSetting("cluster.routing.allocation.disk.watermark.low"), response.getSetting("cluster.routing.allocation.disk.watermark.high"), response.getSetting("cluster.routing.allocation.disk.watermark.flood_stage"));
}
Aggregations