Search in sources :

Example 1 with State

use of io.searchbox.cluster.State in project graylog2-server by Graylog2.

the class V20170607164210_MigrateReopenedIndicesToAliasesClusterStateES6 method getForIndices.

@Override
public JsonNode getForIndices(Collection<String> indices) {
    final String indexList = String.join(",", indices);
    final State request = new State.Builder().withMetadata().indices(indexList).build();
    final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for reopened indices " + indices);
    return jestResult.getJsonObject();
}
Also used : State(io.searchbox.cluster.State) JestResult(io.searchbox.client.JestResult)

Example 2 with State

use of io.searchbox.cluster.State in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method fieldsInIndices.

@Override
public Map<String, Set<String>> fieldsInIndices(String[] writeIndexWildcards) {
    final String indices = String.join(",", writeIndexWildcards);
    final State request = new State.Builder().indices(indices).withMetadata().build();
    final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for indices " + indices);
    final JsonNode indicesJson = getClusterStateIndicesMetadata(jestResult.getJsonObject());
    final ImmutableMap.Builder<String, Set<String>> fields = ImmutableMap.builder();
    final Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields();
    while (it.hasNext()) {
        final Map.Entry<String, JsonNode> entry = it.next();
        final String indexName = entry.getKey();
        final Set<String> fieldNames = ImmutableSet.copyOf(entry.getValue().path("mappings").path(IndexMapping.TYPE_MESSAGE).path("properties").fieldNames());
        if (!fieldNames.isEmpty()) {
            fields.put(indexName, fieldNames);
        }
    }
    return fields.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) JsonNode(com.fasterxml.jackson.databind.JsonNode) ImmutableMap(com.google.common.collect.ImmutableMap) State(io.searchbox.cluster.State) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) JestResult(io.searchbox.client.JestResult)

Example 3 with State

use of io.searchbox.cluster.State in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method getIndexState.

private String getIndexState(String index) {
    final State request = new State.Builder().indices(index).withMetadata().build();
    final JestResult response = JestUtils.execute(jestClient, request, () -> "Failed to get index metadata");
    return response.getJsonObject().path("metadata").path("indices").path(index).path("state").asText();
}
Also used : State(io.searchbox.cluster.State) JestResult(io.searchbox.client.JestResult)

Example 4 with State

use of io.searchbox.cluster.State in project graylog2-server by Graylog2.

the class ClientES6 method cleanUp.

@Override
public void cleanUp() {
    final State request = new State.Builder().withMetadata().build();
    final JsonNode result = JestUtils.execute(client, request, () -> "failed to read state").getJsonObject();
    deleteTemplates(metadataFieldNamesFor(result, "templates"));
    deleteIndices(metadataFieldNamesFor(result, "indices"));
}
Also used : State(io.searchbox.cluster.State) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

State (io.searchbox.cluster.State)4 JestResult (io.searchbox.client.JestResult)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1