use of org.sonar.server.es.IndexDefinition.IndexDefinitionContext in project sonarqube by SonarSource.
the class EsTester method createIndices.
private static List<BuiltIndex> createIndices(IndexDefinition... definitions) {
IndexDefinitionContext context = new IndexDefinitionContext();
Stream.of(definitions).forEach(d -> d.define(context));
List<BuiltIndex> result = new ArrayList<>();
for (NewIndex newIndex : context.getIndices().values()) {
BuiltIndex index = newIndex.build();
String indexName = index.getMainType().getIndex().getName();
deleteIndexIfExists(indexName);
// create index
Settings.Builder settings = Settings.builder();
settings.put(index.getSettings());
CreateIndexResponse indexResponse = createIndex(indexName, settings);
if (!indexResponse.isAcknowledged()) {
throw new IllegalStateException("Failed to create index " + indexName);
}
waitForClusterYellowStatus(indexName);
// create types
String typeName = index.getMainType().getType();
putIndexMapping(index, indexName, typeName);
waitForClusterYellowStatus(indexName);
result.add(index);
}
return result;
}
Aggregations