Skip to content

Commit

Permalink
Fix updating Index Templates V2 (elastic#55556)
Browse files Browse the repository at this point in the history
This change fixes problem with updating Index Templates V2.
Validatation added in elastic#54933 didn't filter list of conflicting templates correctly so
new template was always clashing with itself unless patterns were not changed completely.
  • Loading branch information
probakowski committed Apr 22, 2020
1 parent 3504755 commit a5f230e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ ClusterState addIndexTemplateV2(final ClusterState currentState, final boolean c

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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,25 @@ public void testAddIndexTemplateV2() throws Exception {
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();
Expand Down

0 comments on commit a5f230e

Please sign in to comment.