use of org.sonar.server.es.newindex.NewIndex 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;
}
use of org.sonar.server.es.newindex.NewIndex in project sonarqube by SonarSource.
the class ViewIndexDefinitionTest method define.
@Test
public void define() {
ViewIndexDefinition def = new ViewIndexDefinition(new MapSettings().asConfig());
def.define(underTest);
assertThat(underTest.getIndices()).hasSize(1);
NewIndex index = underTest.getIndices().get("views");
assertThat(index.getMainType()).isEqualTo(IndexType.main(Index.simple("views"), "view"));
assertThat(index.getRelationsStream()).isEmpty();
assertThat(index.getSetting("index.number_of_shards")).isEqualTo("5");
assertThat(index.getSetting("index.number_of_replicas")).isEqualTo("0");
}
use of org.sonar.server.es.newindex.NewIndex in project sonarqube by SonarSource.
the class UserIndexDefinitionTest method define.
@Test
public void define() {
UserIndexDefinition def = new UserIndexDefinition(new MapSettings().asConfig());
def.define(underTest);
assertThat(underTest.getIndices()).hasSize(1);
NewIndex index = underTest.getIndices().get("users");
assertThat(index.getMainType()).isEqualTo(IndexType.main(Index.simple("users"), "user"));
assertThat(index.getRelationsStream()).isEmpty();
// no cluster by default
assertThat(index.getSetting("index.number_of_shards")).isEqualTo("1");
assertThat(index.getSetting("index.number_of_replicas")).isEqualTo("0");
}
use of org.sonar.server.es.newindex.NewIndex 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());
}
});
}
use of org.sonar.server.es.newindex.NewIndex in project sonarqube by SonarSource.
the class RuleIndexDefinitionTest method enable_replica_if_clustering_is_enabled.
@Test
public void enable_replica_if_clustering_is_enabled() {
settings.setProperty(CLUSTER_ENABLED.getKey(), true);
IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
underTest.define(context);
NewIndex ruleIndex = context.getIndices().get("rules");
assertThat(ruleIndex.getSetting("index.number_of_replicas")).isEqualTo("1");
}
Aggregations