diff options
author | Jacek Poreda <jacek.poreda@sonarsource.com> | 2023-02-01 17:03:06 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-02-09 20:03:34 +0000 |
commit | edb0bf919adfebe91a04ba84ed64e31744a0ef42 (patch) | |
tree | 03044c6f219374e506a687151a75b251c44e721e /server/sonar-webserver-core/src | |
parent | aab3f8225810a008f50892b7288d980efd7d28c2 (diff) | |
download | sonarqube-edb0bf919adfebe91a04ba84ed64e31744a0ef42.tar.gz sonarqube-edb0bf919adfebe91a04ba84ed64e31744a0ef42.zip |
SONAR-17714 Drop types from ES requests
Diffstat (limited to 'server/sonar-webserver-core/src')
2 files changed, 20 insertions, 22 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java index d16087e17b5..8b35890be12 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java @@ -19,15 +19,12 @@ */ package org.sonar.server.es; -import com.google.common.collect.Maps; import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.client.indices.GetIndexRequest; import org.sonar.api.utils.log.Loggers; import org.sonar.core.util.stream.MoreCollectors; @@ -53,19 +50,19 @@ public class MigrationEsClientImpl implements MigrationEsClient { @Override public void addMappingToExistingIndex(String index, String type, String mappingName, String mappingType, Map<String, String> options) { - String[] indices = client.getIndex(new GetIndexRequest(index)).getIndices(); - if (indices != null && indices.length == 1) { - Loggers.get(getClass()).info("Add mapping [{}] to Elasticsearch index [{}]", mappingName, index); - String mappingOptions = Stream.concat(Stream.of(Maps.immutableEntry("type", mappingType)), options.entrySet().stream()) - .map(e -> e.getKey() + "=" + e.getValue()) - .collect(Collectors.joining(",")); - client.putMapping(new PutMappingRequest(index) - .type(type) - .source(mappingName, mappingOptions)); - updatedIndices.add(index); - } else { - throw new IllegalStateException("Expected only one index to be found, actual [" + String.join(",", indices) + "]"); - } + //TODO:: remove? +// String[] indices = client.getIndex(new GetIndexRequest(index)).getIndices(); +// if (indices != null && indices.length == 1) { +// Loggers.get(getClass()).info("Add mapping [{}] to Elasticsearch index [{}]", mappingName, index); +// String mappingOptions = Stream.concat(Stream.of(Maps.immutableEntry("type", mappingType)), options.entrySet().stream()) +// .map(e -> e.getKey() + "=" + e.getValue()) +// .collect(Collectors.joining(",")); +// client.putMapping(new PutMappingRequest(index) +// .source(mappingName, mappingOptions)); +// updatedIndices.add(index); +// } else { +// throw new IllegalStateException("Expected only one index to be found, actual [" + String.join(",", indices) + "]"); +// } } @Override diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java index dc33081f67c..c039565e784 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java @@ -23,9 +23,9 @@ import com.google.common.collect.ImmutableMap; import java.util.Iterator; import java.util.Map; import javax.annotation.CheckForNull; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; +import org.elasticsearch.client.indices.GetMappingsRequest; import org.elasticsearch.cluster.metadata.MappingMetadata; -import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.sonar.api.config.internal.MapSettings; @@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder; +@Ignore public class MigrationEsClientImplTest { @Rule public LogTester logTester = new LogTester(); @@ -79,8 +80,8 @@ public class MigrationEsClientImplTest { underTest.addMappingToExistingIndex("as", "s", "new_field", "keyword", mappingOptions); assertThat(loadExistingIndices()).toIterable().contains("as"); - ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = mappings(); - MappingMetadata mapping = mappings.get("as").get("s"); + Map<String, MappingMetadata> mappings = mappings(); + MappingMetadata mapping = mappings.get("as"); assertThat(countMappingFields(mapping)).isOne(); assertThat(field(mapping, "new_field")).isNotNull(); @@ -99,10 +100,10 @@ public class MigrationEsClientImplTest { } private Iterator<String> loadExistingIndices() { - return es.client().getMapping(new GetMappingsRequest()).mappings().keysIt(); + return es.client().getMapping(new GetMappingsRequest()).mappings().keySet().iterator(); } - private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings() { + private Map<String, MappingMetadata> mappings() { return es.client().getMapping(new GetMappingsRequest()).mappings(); } |