Search in sources :

Example 1 with IndexDefinitionContext

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;
}
Also used : BuiltIndex(org.sonar.server.es.newindex.BuiltIndex) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NewIndex(org.sonar.server.es.newindex.NewIndex) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) IndexDefinitionContext(org.sonar.server.es.IndexDefinition.IndexDefinitionContext) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) Settings(org.elasticsearch.common.settings.Settings) HttpTransportSettings(org.elasticsearch.http.HttpTransportSettings) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 CreateIndexResponse (org.elasticsearch.client.indices.CreateIndexResponse)1 DiskThresholdSettings (org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)1 Settings (org.elasticsearch.common.settings.Settings)1 HttpTransportSettings (org.elasticsearch.http.HttpTransportSettings)1 RecoverySettings (org.elasticsearch.indices.recovery.RecoverySettings)1 IndexDefinitionContext (org.sonar.server.es.IndexDefinition.IndexDefinitionContext)1 BuiltIndex (org.sonar.server.es.newindex.BuiltIndex)1 NewIndex (org.sonar.server.es.newindex.NewIndex)1