Move generateCustomNameResolvers to DiscoveryPlugin interface

This commit is contained in:
David Pilato 2016-07-27 11:36:06 +02:00
parent e9339a1960
commit e949101cc7
3 changed files with 20 additions and 16 deletions

View File

@ -64,7 +64,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.node.Node.generateCustomNameResolvers; import static org.elasticsearch.plugins.DiscoveryPlugin.generateCustomNameResolvers;
/** /**
* The transport client allows to create a client that is not part of the cluster, but simply connects to one * The transport client allows to create a client that is not part of the cluster, but simply connects to one

View File

@ -135,6 +135,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.plugins.DiscoveryPlugin.generateCustomNameResolvers;
/** /**
* A node represent a node within a cluster (<tt>cluster.name</tt>). The {@link #client()} can be used * A node represent a node within a cluster (<tt>cluster.name</tt>). The {@link #client()} can be used
* in order to use a {@link Client} to perform actions/operations against the cluster. * in order to use a {@link Client} to perform actions/operations against the cluster.
@ -723,19 +725,4 @@ public class Node implements Closeable {
BigArrays createBigArrays(Settings settings, CircuitBreakerService circuitBreakerService) { BigArrays createBigArrays(Settings settings, CircuitBreakerService circuitBreakerService) {
return new BigArrays(settings, circuitBreakerService); return new BigArrays(settings, circuitBreakerService);
} }
/**
* Generate Custom Name Resolvers list based on a Discovery Plugins list
* @param discoveryPlugins Discovery plugins list
*/
public static List<NetworkService.CustomNameResolver> generateCustomNameResolvers(Settings settings, List<DiscoveryPlugin> discoveryPlugins) {
List<NetworkService.CustomNameResolver> customNameResolvers = new ArrayList<>();
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
if (customNameResolver != null) {
customNameResolvers.add(customNameResolver);
}
}
return customNameResolvers;
}
} }

View File

@ -31,6 +31,8 @@ import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.index.analysis.TokenizerFactory; import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider; import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
@ -55,4 +57,19 @@ public interface DiscoveryPlugin {
default NetworkService.CustomNameResolver getCustomNameResolver(Settings settings) { default NetworkService.CustomNameResolver getCustomNameResolver(Settings settings) {
return null; return null;
} }
/**
* Generate Custom Name Resolvers list based on a Discovery Plugins list
* @param discoveryPlugins Discovery plugins list
*/
static List<NetworkService.CustomNameResolver> generateCustomNameResolvers(Settings settings, List<DiscoveryPlugin> discoveryPlugins) {
List<NetworkService.CustomNameResolver> customNameResolvers = new ArrayList<>();
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
if (customNameResolver != null) {
customNameResolvers.add(customNameResolver);
}
}
return customNameResolvers;
}
} }