use of org.graylog2.indexer.indices.IndexSettings in project graylog2-server by Graylog2.
the class V20170607164210_MigrateReopenedIndicesToAliases method getReopenedIndices.
private Set<String> getReopenedIndices(final Collection<String> indices) {
final SearchVersion elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version."));
final JsonNode clusterStateJson = clusterState.getForIndices(indices);
final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices");
final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder();
if (indicesJson.isMissingNode()) {
LOG.error("Retrieved cluster state is invalid (no metadata.indices key).");
LOG.debug("Received cluster state was: {}", clusterStateJson.toString());
return Collections.emptySet();
}
for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) {
final Map.Entry<String, JsonNode> entry = it.next();
final String indexName = entry.getKey();
final JsonNode value = entry.getValue();
final JsonNode indexSettings = value.path("settings");
if (indexSettings.isMissingNode()) {
LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName);
LOG.debug("Index metadata was: {}", value.toString());
continue;
}
if (checkForReopened(indexSettings, elasticsearchVersion)) {
LOG.debug("Adding {} to list of indices to be migrated.", indexName);
reopenedIndices.add(indexName);
}
}
return reopenedIndices.build();
}
use of org.graylog2.indexer.indices.IndexSettings in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method create.
@Override
public void create(String indexName, IndexSettings indexSettings) {
final Map<String, Object> settings = new HashMap<>();
settings.put("number_of_shards", indexSettings.shards());
settings.put("number_of_replicas", indexSettings.replicas());
final CreateIndex request = new CreateIndex.Builder(indexName).settings(settings).build();
final JestResult jestResult;
try {
jestResult = jestClient.execute(request);
} catch (IOException e) {
throw new ElasticsearchException("Couldn't create index " + indexName, e);
}
if (!jestResult.isSucceeded()) {
throw new ElasticsearchException(jestResult.getErrorMessage());
}
}
Aggregations