Skip to content

Commit

Permalink
Fix updating Index Templates V2
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 21, 2020
1 parent 4ed0dc8 commit d0779a8
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 @@ -356,6 +356,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 d0779a8

Please sign in to comment.