mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 05:15:04 +00:00
remove ProcessorFactoryProvider
This commit is contained in:
parent
e923545269
commit
da3f460bd1
@ -1,34 +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.ingest;
|
||||
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Functional interface that allows to create a {@link org.elasticsearch.ingest.Processor.Factory} once all the needed
|
||||
* components are available at a later stage, more specifically the {@link Environment} and the {@link TemplateService}
|
||||
* which some processors need.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ProcessorFactoryProvider extends BiFunction<Environment, TemplateService, Processor.Factory> {
|
||||
|
||||
}
|
@ -20,11 +20,13 @@
|
||||
package org.elasticsearch.ingest;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Registry for processor factories
|
||||
* @see org.elasticsearch.ingest.Processor.Factory
|
||||
* @see ProcessorFactoryProvider
|
||||
*/
|
||||
public class ProcessorsModule extends AbstractModule {
|
||||
|
||||
@ -42,7 +44,7 @@ public class ProcessorsModule extends AbstractModule {
|
||||
/**
|
||||
* Adds a processor factory under a specific type name.
|
||||
*/
|
||||
public void addProcessor(String type, ProcessorFactoryProvider processorFactoryProvider) {
|
||||
public void addProcessor(String type, BiFunction<Environment, TemplateService, Processor.Factory<?>> processorFactoryProvider) {
|
||||
processorsRegistry.addProcessor(type, processorFactoryProvider);
|
||||
}
|
||||
}
|
||||
|
@ -19,25 +19,28 @@
|
||||
|
||||
package org.elasticsearch.ingest;
|
||||
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ProcessorsRegistry {
|
||||
|
||||
private final Map<String, ProcessorFactoryProvider> processorFactoryProviders = new HashMap<>();
|
||||
private final Map<String, BiFunction<Environment, TemplateService, Processor.Factory<?>>> processorFactoryProviders = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Adds a processor factory under a specific name.
|
||||
*/
|
||||
public void addProcessor(String name, ProcessorFactoryProvider processorFactoryProvider) {
|
||||
ProcessorFactoryProvider provider = processorFactoryProviders.putIfAbsent(name, processorFactoryProvider);
|
||||
public void addProcessor(String name, BiFunction<Environment, TemplateService, Processor.Factory<?>> processorFactoryProvider) {
|
||||
BiFunction<Environment, TemplateService, Processor.Factory<?>> provider = processorFactoryProviders.putIfAbsent(name, processorFactoryProvider);
|
||||
if (provider != null) {
|
||||
throw new IllegalArgumentException("Processor factory already registered for name [" + name + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, ProcessorFactoryProvider>> entrySet() {
|
||||
public Set<Map.Entry<String, BiFunction<Environment, TemplateService, Processor.Factory<?>>>> entrySet() {
|
||||
return processorFactoryProviders.entrySet();
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,12 @@
|
||||
|
||||
package org.elasticsearch.ingest;
|
||||
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
@ -42,9 +44,9 @@ public class ProcessorsRegistryTests extends ESTestCase {
|
||||
assertThat(e.getMessage(), equalTo("Processor factory already registered for name [1]"));
|
||||
}
|
||||
|
||||
Set<Map.Entry<String, ProcessorFactoryProvider>> entrySet = processorsRegistry.entrySet();
|
||||
Set<Map.Entry<String, BiFunction<Environment, TemplateService, Processor.Factory<?>>>> entrySet = processorsRegistry.entrySet();
|
||||
assertThat(entrySet.size(), equalTo(2));
|
||||
for (Map.Entry<String, ProcessorFactoryProvider> entry : entrySet) {
|
||||
for (Map.Entry<String, BiFunction<Environment, TemplateService, Processor.Factory<?>>> entry : entrySet) {
|
||||
if (entry.getKey().equals("1")) {
|
||||
assertThat(entry.getValue().apply(null, null), equalTo(factory1));
|
||||
} else if (entry.getKey().equals("2")) {
|
||||
|
@ -36,7 +36,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||
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;
|
||||
@ -44,7 +43,6 @@ import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Instantiates and wires all the services that the ingest plugin will be needing.
|
||||
|
@ -41,10 +41,9 @@ import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.ingest.Pipeline;
|
||||
import org.elasticsearch.ingest.ProcessorFactoryProvider;
|
||||
import org.elasticsearch.ingest.Processor;
|
||||
import org.elasticsearch.ingest.ProcessorsRegistry;
|
||||
import org.elasticsearch.ingest.TemplateService;
|
||||
import org.elasticsearch.ingest.Processor;
|
||||
import org.elasticsearch.plugin.ingest.transport.delete.DeletePipelineRequest;
|
||||
import org.elasticsearch.plugin.ingest.transport.put.PutPipelineRequest;
|
||||
import org.elasticsearch.plugin.ingest.transport.reload.ReloadPipelinesAction;
|
||||
@ -61,6 +60,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class PipelineStore extends AbstractComponent implements Closeable {
|
||||
|
||||
@ -89,7 +89,7 @@ public class PipelineStore extends AbstractComponent implements Closeable {
|
||||
public void buildProcessorFactoryRegistry(ProcessorsRegistry processorsRegistry, Environment environment, ScriptService scriptService) {
|
||||
Map<String, Processor.Factory> processorFactories = new HashMap<>();
|
||||
TemplateService templateService = new InternalTemplateService(scriptService);
|
||||
for (Map.Entry<String, ProcessorFactoryProvider> entry : processorsRegistry.entrySet()) {
|
||||
for (Map.Entry<String, BiFunction<Environment, TemplateService, Processor.Factory<?>>> entry : processorsRegistry.entrySet()) {
|
||||
Processor.Factory processorFactory = entry.getValue().apply(environment, templateService);
|
||||
processorFactories.put(entry.getKey(), processorFactory);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user