Search in sources :

Example 1 with TYPE_METADATA

use of org.sonar.server.es.metadata.MetadataIndexDefinition.TYPE_METADATA in project sonarqube by SonarSource.

the class IndexCreator method start.

@Override
public void start() {
    // create the "metadata" index first
    IndexType.IndexMainType metadataMainType = TYPE_METADATA;
    if (!client.indexExists(new GetIndexRequest(metadataMainType.getIndex().getName()))) {
        IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
        metadataIndexDefinition.define(context);
        NewIndex index = context.getIndices().values().iterator().next();
        createIndex(index.build(), false);
    } else {
        ensureWritable(metadataMainType);
    }
    checkDbCompatibility(definitions.getIndices().values());
    // create indices that do not exist or that have a new definition (different mapping, cluster enabled, ...)
    definitions.getIndices().values().stream().filter(i -> !i.getMainType().equals(metadataMainType)).forEach(index -> {
        boolean exists = client.indexExists(new GetIndexRequest(index.getMainType().getIndex().getName()));
        if (!exists) {
            createIndex(index, true);
        } else if (hasDefinitionChange(index)) {
            updateIndex(index);
        } else {
            ensureWritable(index.getMainType());
        }
    });
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) BuiltIndex(org.sonar.server.es.newindex.BuiltIndex) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) Loggers(org.sonar.api.utils.log.Loggers) Settings(org.elasticsearch.common.settings.Settings) Configuration(org.sonar.api.config.Configuration) MetadataIndex(org.sonar.server.es.metadata.MetadataIndex) MetadataIndexDefinition(org.sonar.server.es.metadata.MetadataIndexDefinition) DESCRIPTOR(org.sonar.server.es.metadata.MetadataIndexDefinition.DESCRIPTOR) Logger(org.sonar.api.utils.log.Logger) TYPE_METADATA(org.sonar.server.es.metadata.MetadataIndexDefinition.TYPE_METADATA) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Startable(org.sonar.api.Startable) Collection(java.util.Collection) EsDbCompatibility(org.sonar.server.es.metadata.EsDbCompatibility) Set(java.util.Set) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) List(java.util.List) ProcessProperties(org.sonar.process.ProcessProperties) NewIndex(org.sonar.server.es.newindex.NewIndex) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) ServerSide(org.sonar.api.server.ServerSide) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) MigrationEsClient(org.sonar.server.platform.db.migration.es.MigrationEsClient) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) MetadataIndexDefinition(org.sonar.server.es.metadata.MetadataIndexDefinition) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) NewIndex(org.sonar.server.es.newindex.NewIndex)

Aggregations

Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 PutMappingRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest)1 GetSettingsRequest (org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)1 UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)1 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)1 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)1 CreateIndexResponse (org.elasticsearch.client.indices.CreateIndexResponse)1 GetIndexRequest (org.elasticsearch.client.indices.GetIndexRequest)1 ClusterHealthStatus (org.elasticsearch.cluster.health.ClusterHealthStatus)1 Settings (org.elasticsearch.common.settings.Settings)1 Startable (org.sonar.api.Startable)1 Configuration (org.sonar.api.config.Configuration)1 ServerSide (org.sonar.api.server.ServerSide)1 Logger (org.sonar.api.utils.log.Logger)1