Skip to content

Commit

Permalink
Plugins: Remove IndexTemplateFilter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjernst committed Aug 19, 2016
1 parent 8281a3c commit 00c123b
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -105,10 +104,6 @@ public void registerShardsAllocator(String name, Class<? extends ShardsAllocator
shardsAllocators.registerExtension(name, clazz);
}

public void registerIndexTemplateFilter(Class<? extends IndexTemplateFilter> indexTemplateFilter) {
indexTemplateFilters.registerExtension(indexTemplateFilter);
}

public IndexNameExpressionResolver getIndexNameExpressionResolver() {
return indexNameExpressionResolver;
}
Expand Down Expand Up @@ -156,7 +151,6 @@ protected void configure() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@
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;
Expand All @@ -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);
Expand All @@ -129,18 +126,6 @@ public MetaDataCreateIndexService(Settings settings, ClusterService clusterServi
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);
}

Expand Down Expand Up @@ -242,7 +227,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {

// 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<>();

Expand Down Expand Up @@ -470,11 +455,11 @@ public void onFailure(String source, Exception e) {
});
}

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);
}
}
Expand Down Expand Up @@ -525,13 +510,6 @@ List<String> getIndexSettingsValidationErrors(Settings settings) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ private static List<Throwable> putTemplate(PutRequest request) {
null,
null,
null,
new HashSet<>(),
null,
null, null, null);
MetaDataIndexTemplateService service = new MetaDataIndexTemplateService(Settings.EMPTY, null, createIndexService, new AliasValidator(Settings.EMPTY), null, null);
Expand Down Expand Up @@ -188,7 +187,6 @@ private List<Throwable> putTemplateDetail(PutRequest request) throws Exception {
indicesService,
null,
null,
new HashSet<>(),
null,
nodeServicesProvider,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ public Map<DiscoveryNode, Float> weighShard(RoutingAllocation allocation, ShardR
}
}

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);
Expand Down Expand Up @@ -154,21 +147,4 @@ public void testEvenShardsAllocatorBackcompat() {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ private MetaDataCreateIndexService getCreateIndexService() {
null,
null,
null,
new HashSet<>(),
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) {
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,
Expand Down

This file was deleted.

0 comments on commit 00c123b

Please sign in to comment.