Fix updating Index Templates V2 (#55556) (#55610)

This change fixes problem with updating Index Templates V2.
Validatation added in #54933 didn't filter list of conflicting templates correctly so
new template was always clashing with itself unless patterns were not changed completely.
This commit is contained in:
Przemko Robakowski 2020-04-22 19:42:32 +02:00 committed by GitHub
parent 41748f02a5
commit 6e1b958069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -341,6 +341,7 @@ public class MetadataIndexTemplateService {
Map<String, List<String>> overlaps = findConflictingV2Templates(currentState, name, template.indexPatterns(), true,
template.priority());
overlaps.remove(name);
if (overlaps.size() > 0) {
String error = String.format(Locale.ROOT, "index template [%s] has index patterns %s matching patterns from " +
"existing templates [%s] with patterns (%s) that have the same priority [%d], multiple index templates may not " +

View File

@ -358,6 +358,25 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
assertNotNull(state.metadata().templatesV2().get("bar"));
}
public void testUpdateIndexTemplateV2() throws Exception {
ClusterState state = ClusterState.EMPTY_STATE;
final MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
IndexTemplateV2 template = IndexTemplateV2Tests.randomInstance();
state = metadataIndexTemplateService.addIndexTemplateV2(state, false, "foo", template);
assertNotNull(state.metadata().templatesV2().get("foo"));
assertTemplatesEqual(state.metadata().templatesV2().get("foo"), template);
List<String> patterns = new ArrayList<>(template.indexPatterns());
patterns.add("new-pattern");
template = new IndexTemplateV2(patterns, template.template(), template.composedOf(), template.priority(), template.version(),
template.metadata());
state = metadataIndexTemplateService.addIndexTemplateV2(state, false, "foo", template);
assertNotNull(state.metadata().templatesV2().get("foo"));
assertTemplatesEqual(state.metadata().templatesV2().get("foo"), template);
}
public void testRemoveIndexTemplateV2() throws Exception {
IndexTemplateV2 template = IndexTemplateV2Tests.randomInstance();
final MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();