use of org.sonar.server.es.IndexType.IndexMainType in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method hash_changes_if_textFieldBuilder_options_change.
@Test
public void hash_changes_if_textFieldBuilder_options_change() {
Index index = Index.withRelations("foo");
IndexMainType mainType = IndexMainType.main(index, "bar");
String fieldName = "field1";
computeAndVerifyAllDifferentHashesOnMapping(mainType, (mapping) -> mapping.textFieldBuilder(fieldName).build(), (mapping) -> mapping.textFieldBuilder(fieldName).disableSearch().build(), (mapping) -> mapping.textFieldBuilder(fieldName).disableNorms().build(), (mapping) -> mapping.textFieldBuilder(fieldName).disableNorms().disableSearch().build());
}
use of org.sonar.server.es.IndexType.IndexMainType in project sonarqube by SonarSource.
the class NewIndex method createTypeMapping.
protected TypeMapping createTypeMapping(IndexRelationType relationType) {
checkAcceptsRelations();
IndexMainType mainType = getMainType();
checkArgument(relationType.getMainType().equals(mainType), "mainType of relation must be %s", mainType);
String relationName = relationType.getName();
checkArgument(!relations.containsKey(relationName), "relation %s already exists", relationName);
relations.put(relationName, relationType);
return new TypeMapping(this);
}
use of org.sonar.server.es.IndexType.IndexMainType in project sonarqube by SonarSource.
the class MetadataIndexImpl method initializedId.
private static String initializedId(IndexType indexType) {
if (indexType instanceof IndexMainType) {
IndexMainType mainType = (IndexMainType) indexType;
return mainType.getIndex().getName() + "." + mainType.getType() + ".initialized";
}
if (indexType instanceof IndexRelationType) {
IndexRelationType relationType = (IndexRelationType) indexType;
IndexMainType mainType = relationType.getMainType();
return mainType.getIndex().getName() + "." + mainType.getType() + "." + relationType.getName() + ".initialized";
}
throw new IllegalArgumentException("Unsupported IndexType " + indexType.getClass());
}
use of org.sonar.server.es.IndexType.IndexMainType in project sonarqube by SonarSource.
the class NewIndexTest method createTypeMapping_with_IndexRelationType_fails_with_ISE_if_index_does_not_allow_relations.
@Test
public void createTypeMapping_with_IndexRelationType_fails_with_ISE_if_index_does_not_allow_relations() {
IndexType.IndexRelationType indexRelationType = IndexType.relation(IndexType.main(Index.withRelations(someIndexName), "bar"), "bar");
Index index = Index.simple(someIndexName);
IndexMainType mainType = IndexType.main(index, "foo");
NewIndex underTest = new NewIndex(index, defaultSettingsConfiguration) {
@Override
public IndexMainType getMainType() {
return mainType;
}
@Override
public BuiltIndex build() {
throw new UnsupportedOperationException("build not implemented");
}
};
assertThatThrownBy(() -> underTest.createTypeMapping(indexRelationType)).isInstanceOf(IllegalStateException.class).hasMessage("Index is not configured to accept relations. Update IndexDefinition.Descriptor instance for this index");
}
use of org.sonar.server.es.IndexType.IndexMainType in project sonarqube by SonarSource.
the class NewIndexTest method indexAndTypeMappings.
@DataProvider
public static Object[][] indexAndTypeMappings() {
String indexName = randomAlphabetic(5).toLowerCase();
MapSettings settings = new MapSettings();
SettingsConfiguration defaultSettingsConfiguration = newBuilder(settings.asConfig()).build();
Index index = Index.withRelations(indexName);
IndexMainType mainType = IndexType.main(index, "foo");
SimplestNewIndex newIndex = new SimplestNewIndex(mainType, defaultSettingsConfiguration);
TypeMapping mainMapping = newIndex.createTypeMapping(mainType);
TypeMapping relationMapping = newIndex.createTypeMapping(IndexType.relation(mainType, "bar"));
return new Object[][] { { newIndex, mainMapping }, { newIndex, relationMapping } };
}
Aggregations