Plugins: Remove IndexTemplateFilter
How index templates match is currently controlled by the IndexTemplateFilter interface. It is pluggable, to add additional filter implementations to the default glob matcher. This change removes the IndexTemplateFilter interface completely. This is a very esoteric extension point, and not worth maintaining. Instead, any improvements should be made to all of our glob matching.
This commit is contained in:
parent
8281a3ce79
commit
00c123b59f
|
@ -83,7 +83,6 @@ public class ClusterModule extends AbstractModule {
|
|||
|
||||
private final Settings settings;
|
||||
private final ExtensionPoint.SelectedType<ShardsAllocator> shardsAllocators = new ExtensionPoint.SelectedType<>("shards_allocator", ShardsAllocator.class);
|
||||
private final ExtensionPoint.ClassSet<IndexTemplateFilter> indexTemplateFilters = new ExtensionPoint.ClassSet<>("index_template_filter", IndexTemplateFilter.class);
|
||||
private final ClusterService clusterService;
|
||||
private final IndexNameExpressionResolver indexNameExpressionResolver;
|
||||
// pkg private for tests
|
||||
|
@ -105,10 +104,6 @@ public class ClusterModule extends AbstractModule {
|
|||
shardsAllocators.registerExtension(name, clazz);
|
||||
}
|
||||
|
||||
public void registerIndexTemplateFilter(Class<? extends IndexTemplateFilter> indexTemplateFilter) {
|
||||
indexTemplateFilters.registerExtension(indexTemplateFilter);
|
||||
}
|
||||
|
||||
public IndexNameExpressionResolver getIndexNameExpressionResolver() {
|
||||
return indexNameExpressionResolver;
|
||||
}
|
||||
|
@ -156,7 +151,6 @@ public class ClusterModule extends AbstractModule {
|
|||
final ESLogger logger = Loggers.getLogger(getClass(), settings);
|
||||
logger.warn("{} allocator has been removed in 2.0 using {} instead", ClusterModule.EVEN_SHARD_COUNT_ALLOCATOR, ClusterModule.BALANCED_ALLOCATOR);
|
||||
}
|
||||
indexTemplateFilters.bind(binder());
|
||||
|
||||
bind(ClusterInfoService.class).to(clusterInfoServiceImpl).asEagerSingleton();
|
||||
bind(GatewayAllocator.class).asEagerSingleton();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IndexTemplateFilter> 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<IndexTemplateMetaData> templates = findTemplates(request, currentState, indexTemplateFilter);
|
||||
List<IndexTemplateMetaData> templates = findTemplates(request, currentState);
|
||||
|
||||
Map<String, Custom> customs = new HashMap<>();
|
||||
|
||||
|
@ -470,11 +455,11 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
});
|
||||
}
|
||||
|
||||
private List<IndexTemplateMetaData> findTemplates(CreateIndexClusterStateUpdateRequest request, ClusterState state, IndexTemplateFilter indexTemplateFilter) throws IOException {
|
||||
private List<IndexTemplateMetaData> findTemplates(CreateIndexClusterStateUpdateRequest request, ClusterState state) throws IOException {
|
||||
List<IndexTemplateMetaData> templates = new ArrayList<>();
|
||||
for (ObjectCursor<IndexTemplateMetaData> 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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -65,13 +65,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);
|
||||
|
@ -154,21 +147,4 @@ public class ClusterModuleTests extends ModuleTestCase {
|
|||
ClusterModule module = new ClusterModule(settings, clusterService, Collections.emptyList());
|
||||
assertBinding(module, ShardsAllocator.class, BalancedShardsAllocator.class);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,7 +215,6 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase {
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
new HashSet<>(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Class<? extends Plugin>> 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<String, MappingMetaData> 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue