diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java index ff94af47dfa..2b00c575374 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -83,7 +83,6 @@ public class ClusterModule extends AbstractModule { new Setting<>("cluster.routing.allocation.type", BALANCED_ALLOCATOR, Function.identity(), Property.NodeScope); private final Settings settings; - private final ExtensionPoint.ClassSet indexTemplateFilters = new ExtensionPoint.ClassSet<>("index_template_filter", IndexTemplateFilter.class); private final ClusterService clusterService; private final IndexNameExpressionResolver indexNameExpressionResolver; // pkg private for tests @@ -101,10 +100,6 @@ public class ClusterModule extends AbstractModule { indexNameExpressionResolver = new IndexNameExpressionResolver(settings); } - public void registerIndexTemplateFilter(Class indexTemplateFilter) { - indexTemplateFilters.registerExtension(indexTemplateFilter); - } - public IndexNameExpressionResolver getIndexNameExpressionResolver() { return indexNameExpressionResolver; } @@ -167,8 +162,6 @@ public class ClusterModule extends AbstractModule { @Override protected void configure() { - indexTemplateFilters.bind(binder()); - bind(ClusterInfoService.class).to(clusterInfoServiceImpl).asEagerSingleton(); bind(GatewayAllocator.class).asEagerSingleton(); bind(AllocationService.class).asEagerSingleton(); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateFilter.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateFilter.java index 0ec3c5f863b..6ed9664c92b 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateFilter.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateFilter.java @@ -31,23 +31,4 @@ public interface IndexTemplateFilter { * {@code false} otherwise. */ boolean apply(CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template); - - class Compound implements IndexTemplateFilter { - - private IndexTemplateFilter[] filters; - - Compound(IndexTemplateFilter... filters) { - this.filters = filters; - } - - @Override - public boolean apply(CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) { - for (IndexTemplateFilter filter : filters) { - if (!filter.apply(request, template)) { - return false; - } - } - return true; - } - } } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index dfb5474ca59..041850a0b27 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -102,13 +102,11 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_C public class MetaDataCreateIndexService extends AbstractComponent { public static final int MAX_INDEX_NAME_BYTES = 255; - private static final DefaultIndexTemplateFilter DEFAULT_INDEX_TEMPLATE_FILTER = new DefaultIndexTemplateFilter(); private final ClusterService clusterService; private final IndicesService indicesService; private final AllocationService allocationService; private final AliasValidator aliasValidator; - private final IndexTemplateFilter indexTemplateFilter; private final Environment env; private final NodeServicesProvider nodeServicesProvider; private final IndexScopedSettings indexScopedSettings; @@ -117,8 +115,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { @Inject public MetaDataCreateIndexService(Settings settings, ClusterService clusterService, IndicesService indicesService, AllocationService allocationService, - AliasValidator aliasValidator, - Set indexTemplateFilters, Environment env, + AliasValidator aliasValidator, Environment env, NodeServicesProvider nodeServicesProvider, IndexScopedSettings indexScopedSettings, ThreadPool threadPool) { super(settings); @@ -129,18 +126,6 @@ public class MetaDataCreateIndexService extends AbstractComponent { this.env = env; this.nodeServicesProvider = nodeServicesProvider; this.indexScopedSettings = indexScopedSettings; - - if (indexTemplateFilters.isEmpty()) { - this.indexTemplateFilter = DEFAULT_INDEX_TEMPLATE_FILTER; - } else { - IndexTemplateFilter[] templateFilters = new IndexTemplateFilter[indexTemplateFilters.size() + 1]; - templateFilters[0] = DEFAULT_INDEX_TEMPLATE_FILTER; - int i = 1; - for (IndexTemplateFilter indexTemplateFilter : indexTemplateFilters) { - templateFilters[i++] = indexTemplateFilter; - } - this.indexTemplateFilter = new IndexTemplateFilter.Compound(templateFilters); - } this.activeShardsObserver = new ActiveShardsObserver(settings, clusterService, threadPool); } @@ -242,7 +227,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { // we only find a template when its an API call (a new index) // find templates, highest order are better matching - List templates = findTemplates(request, currentState, indexTemplateFilter); + List templates = findTemplates(request, currentState); Map customs = new HashMap<>(); @@ -470,11 +455,11 @@ public class MetaDataCreateIndexService extends AbstractComponent { }); } - private List findTemplates(CreateIndexClusterStateUpdateRequest request, ClusterState state, IndexTemplateFilter indexTemplateFilter) throws IOException { + private List findTemplates(CreateIndexClusterStateUpdateRequest request, ClusterState state) throws IOException { List templates = new ArrayList<>(); for (ObjectCursor cursor : state.metaData().templates().values()) { IndexTemplateMetaData template = cursor.value; - if (indexTemplateFilter.apply(request, template)) { + if (Regex.simpleMatch(template.template(), request.index())) { templates.add(template); } } @@ -525,13 +510,6 @@ public class MetaDataCreateIndexService extends AbstractComponent { return validationErrors; } - private static class DefaultIndexTemplateFilter implements IndexTemplateFilter { - @Override - public boolean apply(CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) { - return Regex.simpleMatch(template.template(), request.index()); - } - } - /** * Validates the settings and mappings for shrinking an index. * @return the list of nodes at least one instance of the source index shards are allocated diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java index 8493c58729d..d895ef9cbf5 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java @@ -158,7 +158,6 @@ public class MetaDataIndexTemplateServiceTests extends ESSingleNodeTestCase { null, null, null, - new HashSet<>(), null, null, null, null); MetaDataIndexTemplateService service = new MetaDataIndexTemplateService(Settings.EMPTY, null, createIndexService, new AliasValidator(Settings.EMPTY), null, null); @@ -188,7 +187,6 @@ public class MetaDataIndexTemplateServiceTests extends ESSingleNodeTestCase { indicesService, null, null, - new HashSet<>(), null, nodeServicesProvider, null, diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 00a84485942..5c710ec92da 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -67,13 +67,6 @@ public class ClusterModuleTests extends ModuleTestCase { } } - static class FakeIndexTemplateFilter implements IndexTemplateFilter { - @Override - public boolean apply(CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) { - return false; - } - } - public void testRegisterClusterDynamicSettingDuplicate() { try { new SettingsModule(Settings.EMPTY, EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING); @@ -163,21 +156,4 @@ public class ClusterModuleTests extends ModuleTestCase { NullPointerException e = expectThrows(NullPointerException.class, () -> newClusterModuleWithShardsAllocator(settings, "bad", () -> null)); } - - public void testRegisterIndexTemplateFilterDuplicate() { - ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService, Collections.emptyList()); - try { - module.registerIndexTemplateFilter(FakeIndexTemplateFilter.class); - module.registerIndexTemplateFilter(FakeIndexTemplateFilter.class); - } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), - "Can't register the same [index_template_filter] more than once for [" + FakeIndexTemplateFilter.class.getName() + "]"); - } - } - - public void testRegisterIndexTemplateFilter() { - ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService, Collections.emptyList()); - module.registerIndexTemplateFilter(FakeIndexTemplateFilter.class); - assertSetMultiBinding(module, IndexTemplateFilter.class, FakeIndexTemplateFilter.class); - } } diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java index adf34859d4e..de82ce8d073 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java @@ -215,7 +215,6 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase { null, null, null, - new HashSet<>(), null, null, null, diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java index c3429edc39b..a5e4b2ab7e1 100644 --- a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java +++ b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java @@ -165,7 +165,7 @@ public class ClusterStateChanges extends AbstractComponent { MetaDataUpdateSettingsService metaDataUpdateSettingsService = new MetaDataUpdateSettingsService(settings, clusterService, allocationService, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, indicesService, nodeServicesProvider); MetaDataCreateIndexService createIndexService = new MetaDataCreateIndexService(settings, clusterService, indicesService, - allocationService, new AliasValidator(settings), Collections.emptySet(), environment, + allocationService, new AliasValidator(settings), environment, nodeServicesProvider, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, threadPool); transportCloseIndexAction = new TransportCloseIndexAction(settings, transportService, clusterService, threadPool, diff --git a/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java b/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java deleted file mode 100644 index 356538d62cb..00000000000 --- a/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.indices.template; - -import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; -import org.elasticsearch.cluster.ClusterModule; -import org.elasticsearch.cluster.metadata.IndexTemplateFilter; -import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; -import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.test.ESIntegTestCase; -import org.elasticsearch.test.ESIntegTestCase.ClusterScope; -import org.elasticsearch.test.ESIntegTestCase.Scope; - -import java.util.Arrays; -import java.util.Collection; - -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.notNullValue; - -@ClusterScope(scope = Scope.SUITE) -public class IndexTemplateFilteringIT extends ESIntegTestCase { - @Override - protected Collection> nodePlugins() { - return Arrays.asList(TestPlugin.class); - } - - public void testTemplateFiltering() throws Exception { - client().admin().indices().preparePutTemplate("template1") - .setTemplate("test*") - .addMapping("type1", "field1", "type=text").get(); - - client().admin().indices().preparePutTemplate("template2") - .setTemplate("test*") - .addMapping("type2", "field2", "type=text").get(); - - client().admin().indices().preparePutTemplate("template3") - .setTemplate("no_match") - .addMapping("type3", "field3", "type=text").get(); - - assertAcked(prepareCreate("test")); - - GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - assertThat(response, notNullValue()); - ImmutableOpenMap metadata = response.getMappings().get("test"); - assertThat(metadata.size(), is(1)); - assertThat(metadata.get("type2"), notNullValue()); - } - - public static class TestFilter implements IndexTemplateFilter { - @Override - public boolean apply(CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) { - //make sure that no_match template is filtered out before the custom filters as it doesn't match the index name - return (template.name().equals("template2") || template.name().equals("no_match")); - } - } - - public static class TestPlugin extends Plugin { - public void onModule(ClusterModule module) { - module.registerIndexTemplateFilter(TestFilter.class); - } - } -}