diff --git a/core/src/main/java/org/elasticsearch/ingest/ProcessorsModule.java b/core/src/main/java/org/elasticsearch/ingest/ProcessorsModule.java index c8dd515c81f..22d5ba92bbc 100644 --- a/core/src/main/java/org/elasticsearch/ingest/ProcessorsModule.java +++ b/core/src/main/java/org/elasticsearch/ingest/ProcessorsModule.java @@ -20,10 +20,6 @@ package org.elasticsearch.ingest; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.MapBinder; - -import java.util.HashMap; -import java.util.Map; /** * Registry for processor factories @@ -32,20 +28,21 @@ import java.util.Map; */ public class ProcessorsModule extends AbstractModule { - private final Map processorFactoryProviders = new HashMap<>(); + private final ProcessorsRegistry processorsRegistry; + + public ProcessorsModule() { + this.processorsRegistry = new ProcessorsRegistry(); + } @Override protected void configure() { - MapBinder mapBinder = MapBinder.newMapBinder(binder(), String.class, ProcessorFactoryProvider.class); - for (Map.Entry entry : processorFactoryProviders.entrySet()) { - mapBinder.addBinding(entry.getKey()).toInstance(entry.getValue()); - } + bind(ProcessorsRegistry.class).toInstance(processorsRegistry); } /** * Adds a processor factory under a specific type name. */ public void addProcessor(String type, ProcessorFactoryProvider processorFactoryProvider) { - processorFactoryProviders.put(type, processorFactoryProvider); + processorsRegistry.addProcessor(type, processorFactoryProvider); } } diff --git a/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java b/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java new file mode 100644 index 00000000000..f747414e891 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java @@ -0,0 +1,44 @@ +/* + * 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.ingest; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class ProcessorsRegistry { + + private final Map processorFactoryProviders = new HashMap<>(); + + /** + * Adds a processor factory under a specific type name. + */ + public void addProcessor(String type, ProcessorFactoryProvider processorFactoryProvider) { + processorFactoryProviders.put(type, processorFactoryProvider); + } + + public ProcessorFactoryProvider getProcessor(String type) { + return processorFactoryProviders.get(type); + } + + public Set> entrySet() { + return processorFactoryProviders.entrySet(); + } +} diff --git a/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/IngestBootstrapper.java b/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/IngestBootstrapper.java index 4f114fc61fe..b13c95a3681 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/IngestBootstrapper.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/IngestBootstrapper.java @@ -37,6 +37,7 @@ import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.env.Environment; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.ingest.ProcessorFactoryProvider; +import org.elasticsearch.ingest.ProcessorsRegistry; import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -58,16 +59,16 @@ public class IngestBootstrapper extends AbstractLifecycleComponent implements Cl private final Environment environment; private final PipelineStore pipelineStore; private final PipelineExecutionService pipelineExecutionService; - private final Map processorFactoryProvider; + private final ProcessorsRegistry processorsRegistry; @Inject public IngestBootstrapper(Settings settings, ThreadPool threadPool, Environment environment, ClusterService clusterService, TransportService transportService, - Map processorFactoryProvider) { + ProcessorsRegistry processorsRegistry) { super(settings); this.threadPool = threadPool; this.environment = environment; - this.processorFactoryProvider = processorFactoryProvider; + this.processorsRegistry = processorsRegistry; this.pipelineStore = new PipelineStore(settings, clusterService, transportService); this.pipelineExecutionService = new PipelineExecutionService(pipelineStore, threadPool); @@ -83,7 +84,7 @@ public class IngestBootstrapper extends AbstractLifecycleComponent implements Cl clusterService.add(this); this.pipelineStore = pipelineStore; this.pipelineExecutionService = pipelineExecutionService; - this.processorFactoryProvider = null; + this.processorsRegistry = null; } public PipelineStore getPipelineStore() { @@ -102,7 +103,7 @@ public class IngestBootstrapper extends AbstractLifecycleComponent implements Cl @Inject public void setScriptService(ScriptService scriptService) { - pipelineStore.buildProcessorFactoryRegistry(processorFactoryProvider, environment, scriptService); + pipelineStore.buildProcessorFactoryRegistry(processorsRegistry, environment, scriptService); } @Override diff --git a/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/PipelineStore.java b/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/PipelineStore.java index a0daf06deff..1f52bd6b41e 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/PipelineStore.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/PipelineStore.java @@ -42,6 +42,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.ingest.Pipeline; import org.elasticsearch.ingest.ProcessorFactoryProvider; +import org.elasticsearch.ingest.ProcessorsRegistry; import org.elasticsearch.ingest.TemplateService; import org.elasticsearch.ingest.Processor; import org.elasticsearch.plugin.ingest.transport.delete.DeletePipelineRequest; @@ -85,10 +86,10 @@ public class PipelineStore extends AbstractComponent implements Closeable { this.client = client; } - public void buildProcessorFactoryRegistry(Map processorFactoryProviders, Environment environment, ScriptService scriptService) { + public void buildProcessorFactoryRegistry(ProcessorsRegistry processorsRegistry, Environment environment, ScriptService scriptService) { Map processorFactories = new HashMap<>(); TemplateService templateService = new InternalTemplateService(scriptService); - for (Map.Entry entry : processorFactoryProviders.entrySet()) { + for (Map.Entry entry : processorsRegistry.entrySet()) { Processor.Factory processorFactory = entry.getValue().apply(environment, templateService); processorFactories.put(entry.getKey(), processorFactory); } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/plugin/ingest/IngestTemplateTests.java b/plugins/ingest/src/test/java/org/elasticsearch/plugin/ingest/IngestTemplateTests.java index d7456cd9152..49ef9d8a50d 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/plugin/ingest/IngestTemplateTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/plugin/ingest/IngestTemplateTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; +import org.elasticsearch.ingest.ProcessorsRegistry; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -32,8 +33,6 @@ import org.hamcrest.Matchers; import org.junit.Before; import org.mockito.Mockito; -import java.util.Collections; - public class IngestTemplateTests extends ESSingleNodeTestCase { private IngestBootstrapper bootstrapper; @@ -51,7 +50,7 @@ public class IngestTemplateTests extends ESSingleNodeTestCase { ClusterService clusterService = Mockito.mock(ClusterService.class); TransportService transportService = Mockito.mock(TransportService.class); bootstrapper = new IngestBootstrapper( - Settings.EMPTY, threadPool, environment, clusterService, transportService, Collections.emptyMap() + Settings.EMPTY, threadPool, environment, clusterService, transportService, new ProcessorsRegistry() ); bootstrapper.setClient(client()); }