Remove `node.mode` and `node.local` settings (#19428)
Today `node.mode` and `node.local` serve almost the same purpose, they are a shortcut for `discovery.type` and `transport.type`. If `node.local: true` or `node.mode: local` is set elasticsearch will start in _local_ mode which means only nodes within the same JVM are discovered and a non-network based transport is used. The _local_ mode it only really used in tests or if nodes are embedded. For both, embedding and tests explicit configuration via `discovery.type` and `transport.type` should be preferred. This change removes all the usage of these settings and by-default doesn't configure a default transport implemenation since netty is now a module. Yet, to make the user expericence flawless, plugins or modules can set a `http.type.default` and `transport.type.default`. Plugins set this via `PluginService#additionalSettings()` which enforces _set-once_ which prevents node startup if set multiple times. This means that our distributions will just startup with netty transport since it's packaged as a module unless `transport.type` or `http.transport.type` is explicitly set. This change also found a bunch of bugs since several NamedWriteables were not registered if a transport client is used. Now that we don't rely on the `node.mode` leniency which is inherited instead of using explicit settings, `TransportClient` uses `AssertingLocalTransport` which detects these problems since it serializes all messages. Closes #16234
This commit is contained in:
parent
4156a4bebb
commit
5616251f22
|
@ -128,6 +128,7 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
|||
* {@code group_by=nodes}.
|
||||
*/
|
||||
public void setDiscoveryNodes(DiscoveryNodes discoveryNodes) {
|
||||
//WTF is this? Why isn't this set by default;
|
||||
this.discoveryNodes = discoveryNodes;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,23 +48,6 @@ import static org.elasticsearch.common.transport.TransportAddressSerializers.add
|
|||
*/
|
||||
public class DiscoveryNode implements Writeable, ToXContent {
|
||||
|
||||
public static boolean isLocalNode(Settings settings) {
|
||||
if (Node.NODE_LOCAL_SETTING.exists(settings)) {
|
||||
return Node.NODE_LOCAL_SETTING.get(settings);
|
||||
}
|
||||
if (Node.NODE_MODE_SETTING.exists(settings)) {
|
||||
String nodeMode = Node.NODE_MODE_SETTING.get(settings);
|
||||
if ("local".equals(nodeMode)) {
|
||||
return true;
|
||||
} else if ("network".equals(nodeMode)) {
|
||||
return false;
|
||||
} else {
|
||||
throw new IllegalArgumentException("unsupported node.mode [" + nodeMode + "]. Should be one of [local, network].");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean nodeRequiresLocalStorage(Settings settings) {
|
||||
boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings);
|
||||
if (localStorageEnable == false &&
|
||||
|
|
|
@ -54,8 +54,9 @@ public class NetworkModule extends AbstractModule {
|
|||
public static final String TRANSPORT_SERVICE_TYPE_KEY = "transport.service.type";
|
||||
public static final String HTTP_TYPE_KEY = "http.type";
|
||||
public static final String LOCAL_TRANSPORT = "local";
|
||||
public static final String NETTY_TRANSPORT = "netty";
|
||||
|
||||
public static final Setting<String> TRANSPORT_DEFAULT_TYPE_SETTING = Setting.simpleString("transport.type.default", Property.NodeScope);
|
||||
public static final Setting<String> HTTP_DEFAULT_TYPE_SETTING = Setting.simpleString("http.type.default", Property.NodeScope);
|
||||
public static final Setting<String> HTTP_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_KEY, Property.NodeScope);
|
||||
public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true, Property.NodeScope);
|
||||
public static final Setting<String> TRANSPORT_SERVICE_TYPE_SETTING =
|
||||
|
@ -85,7 +86,7 @@ public class NetworkModule extends AbstractModule {
|
|||
this.settings = settings;
|
||||
this.transportClient = transportClient;
|
||||
this.namedWriteableRegistry = namedWriteableRegistry;
|
||||
registerTransportService(NETTY_TRANSPORT, TransportService.class);
|
||||
registerTransportService("default", TransportService.class);
|
||||
registerTransport(LOCAL_TRANSPORT, LocalTransport.class);
|
||||
registerTaskStatus(ReplicationTask.Status.NAME, ReplicationTask.Status::new);
|
||||
registerTaskStatus(RawTaskStatus.NAME, RawTaskStatus::new);
|
||||
|
@ -146,16 +147,13 @@ public class NetworkModule extends AbstractModule {
|
|||
protected void configure() {
|
||||
bind(NetworkService.class).toInstance(networkService);
|
||||
bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);
|
||||
|
||||
boolean nettyRegistered = transportTypes.getExtension(NETTY_TRANSPORT) != null;
|
||||
transportServiceTypes.bindType(binder(), settings, TRANSPORT_SERVICE_TYPE_KEY, NETTY_TRANSPORT);
|
||||
String defaultTransport = DiscoveryNode.isLocalNode(settings) || nettyRegistered == false ? LOCAL_TRANSPORT : NETTY_TRANSPORT;
|
||||
transportTypes.bindType(binder(), settings, TRANSPORT_TYPE_KEY, defaultTransport);
|
||||
transportServiceTypes.bindType(binder(), settings, TRANSPORT_SERVICE_TYPE_KEY, "default");
|
||||
transportTypes.bindType(binder(), settings, TRANSPORT_TYPE_KEY, TRANSPORT_DEFAULT_TYPE_SETTING.get(settings));
|
||||
|
||||
if (transportClient == false) {
|
||||
if (HTTP_ENABLED.get(settings)) {
|
||||
bind(HttpServer.class).asEagerSingleton();
|
||||
httpTransportTypes.bindType(binder(), settings, HTTP_TYPE_SETTING.getKey(), NETTY_TRANSPORT);
|
||||
httpTransportTypes.bindType(binder(), settings, HTTP_TYPE_SETTING.getKey(), HTTP_DEFAULT_TYPE_SETTING.get(settings));
|
||||
} else {
|
||||
bind(HttpServer.class).toProvider(Providers.of(null));
|
||||
}
|
||||
|
|
|
@ -214,6 +214,8 @@ public final class ClusterSettings extends AbstractScopedSettings {
|
|||
GatewayService.RECOVER_AFTER_NODES_SETTING,
|
||||
GatewayService.RECOVER_AFTER_TIME_SETTING,
|
||||
NetworkModule.HTTP_ENABLED,
|
||||
NetworkModule.HTTP_DEFAULT_TYPE_SETTING,
|
||||
NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING,
|
||||
NetworkModule.HTTP_TYPE_SETTING,
|
||||
NetworkModule.TRANSPORT_SERVICE_TYPE_SETTING,
|
||||
NetworkModule.TRANSPORT_TYPE_SETTING,
|
||||
|
@ -339,8 +341,6 @@ public final class ClusterSettings extends AbstractScopedSettings {
|
|||
Node.NODE_NAME_SETTING,
|
||||
Node.NODE_DATA_SETTING,
|
||||
Node.NODE_MASTER_SETTING,
|
||||
Node.NODE_LOCAL_SETTING,
|
||||
Node.NODE_MODE_SETTING,
|
||||
Node.NODE_INGEST_SETTING,
|
||||
Node.NODE_ATTRIBUTES,
|
||||
Node.NODE_LOCAL_STORAGE_SETTING,
|
||||
|
|
|
@ -72,7 +72,7 @@ public abstract class ExtensionPoint {
|
|||
*/
|
||||
public static class ClassMap<T> extends ExtensionPoint {
|
||||
protected final Class<T> extensionClass;
|
||||
private final Map<String, Class<? extends T>> extensions = new HashMap<>();
|
||||
protected final Map<String, Class<? extends T>> extensions = new HashMap<>();
|
||||
private final Set<String> reservedKeys;
|
||||
|
||||
/**
|
||||
|
@ -147,7 +147,8 @@ public abstract class ExtensionPoint {
|
|||
}
|
||||
final Class<? extends T> instance = getExtension(type);
|
||||
if (instance == null) {
|
||||
throw new IllegalArgumentException("Unknown [" + this.name + "] type [" + type + "]");
|
||||
throw new IllegalArgumentException("Unknown [" + this.name + "] type [" + type + "] possible values: "
|
||||
+ extensions.keySet());
|
||||
}
|
||||
if (extensionClass == instance) {
|
||||
binder.bind(extensionClass).asEagerSingleton();
|
||||
|
|
|
@ -47,7 +47,7 @@ import java.util.function.Function;
|
|||
public class DiscoveryModule extends AbstractModule {
|
||||
|
||||
public static final Setting<String> DISCOVERY_TYPE_SETTING =
|
||||
new Setting<>("discovery.type", settings -> DiscoveryNode.isLocalNode(settings) ? "local" : "zen", Function.identity(),
|
||||
new Setting<>("discovery.type", "zen", Function.identity(),
|
||||
Property.NodeScope);
|
||||
public static final Setting<String> ZEN_MASTER_SERVICE_TYPE_SETTING =
|
||||
new Setting<>("discovery.zen.masterservice.type", "zen", Function.identity(), Property.NodeScope);
|
||||
|
|
|
@ -147,10 +147,6 @@ public class Node implements Closeable {
|
|||
public static final Setting<Boolean> NODE_DATA_SETTING = Setting.boolSetting("node.data", true, Property.NodeScope);
|
||||
public static final Setting<Boolean> NODE_MASTER_SETTING =
|
||||
Setting.boolSetting("node.master", true, Property.NodeScope);
|
||||
public static final Setting<Boolean> NODE_LOCAL_SETTING =
|
||||
Setting.boolSetting("node.local", false, Property.NodeScope);
|
||||
public static final Setting<String> NODE_MODE_SETTING =
|
||||
new Setting<>("node.mode", "network", Function.identity(), Property.NodeScope);
|
||||
public static final Setting<Boolean> NODE_INGEST_SETTING =
|
||||
Setting.boolSetting("node.ingest", true, Property.NodeScope);
|
||||
|
||||
|
|
|
@ -382,10 +382,8 @@ public class SearchModule extends AbstractModule {
|
|||
* Register an aggregation.
|
||||
*/
|
||||
public void registerAggregation(AggregationSpec spec) {
|
||||
if (false == transportClient) {
|
||||
namedWriteableRegistry.register(AggregationBuilder.class, spec.aggregationName.getPreferredName(), spec.builderReader);
|
||||
aggregationParserRegistry.register(spec.aggregationParser, spec.aggregationName);
|
||||
}
|
||||
namedWriteableRegistry.register(AggregationBuilder.class, spec.aggregationName.getPreferredName(), spec.builderReader);
|
||||
aggregationParserRegistry.register(spec.aggregationParser, spec.aggregationName);
|
||||
for (Map.Entry<String, Writeable.Reader<? extends InternalAggregation>> t : spec.resultReaders.entrySet()) {
|
||||
String writeableName = t.getKey();
|
||||
Writeable.Reader<? extends InternalAggregation> internalReader = t.getValue();
|
||||
|
@ -414,7 +412,7 @@ public class SearchModule extends AbstractModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a reader for the shard level results of the aggregation with {@linkplain aggregationName}'s
|
||||
* Add a reader for the shard level results of the aggregation with {@linkplain #aggregationName}'s
|
||||
* {@link ParseField#getPreferredName()} as the {@link NamedWriteable#getWriteableName()}.
|
||||
*/
|
||||
public AggregationSpec addResultReader(Writeable.Reader<? extends InternalAggregation> resultReader) {
|
||||
|
@ -444,9 +442,9 @@ public class SearchModule extends AbstractModule {
|
|||
Writeable.Reader<? extends PipelineAggregator> internalReader, Writeable.Reader<? extends InternalAggregation> bucketReader,
|
||||
PipelineAggregator.Parser aggregationParser, ParseField aggregationName) {
|
||||
if (false == transportClient) {
|
||||
namedWriteableRegistry.register(PipelineAggregationBuilder.class, aggregationName.getPreferredName(), reader);
|
||||
pipelineAggregationParserRegistry.register(aggregationParser, aggregationName);
|
||||
}
|
||||
namedWriteableRegistry.register(PipelineAggregationBuilder.class, aggregationName.getPreferredName(), reader);
|
||||
namedWriteableRegistry.register(PipelineAggregator.class, aggregationName.getPreferredName(), internalReader);
|
||||
namedWriteableRegistry.register(InternalAggregation.class, aggregationName.getPreferredName(), bucketReader);
|
||||
}
|
||||
|
@ -469,9 +467,9 @@ public class SearchModule extends AbstractModule {
|
|||
bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry);
|
||||
bind(Suggesters.class).toInstance(getSuggesters());
|
||||
configureSearch();
|
||||
configureShapes();
|
||||
bind(AggregatorParsers.class).toInstance(aggregatorParsers);
|
||||
}
|
||||
configureShapes();
|
||||
}
|
||||
|
||||
private void registerBuiltinAggregations() {
|
||||
|
|
|
@ -199,7 +199,7 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
|
|||
@SuppressWarnings("unchecked")
|
||||
public R create(String name, List<B> ranges, DocValueFormat formatter, boolean keyed, List<PipelineAggregator> pipelineAggregators,
|
||||
Map<String, Object> metaData) {
|
||||
return (R) new InternalRange<>(name, ranges, formatter, keyed, pipelineAggregators, metaData);
|
||||
return (R) new InternalRange<B, R>(name, ranges, formatter, keyed, pipelineAggregators, metaData);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -210,7 +210,7 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public R create(List<B> ranges, R prototype) {
|
||||
return (R) new InternalRange<>(prototype.name, ranges, prototype.format, prototype.keyed, prototype.pipelineAggregators(),
|
||||
return (R) new InternalRange<B, R>(prototype.name, ranges, prototype.format, prototype.keyed, prototype.pipelineAggregators(),
|
||||
prototype.metaData);
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
|
|||
public InternalAggregation doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
|
||||
List<Bucket>[] rangeList = new List[ranges.size()];
|
||||
for (int i = 0; i < rangeList.length; ++i) {
|
||||
rangeList[i] = new ArrayList<Bucket>();
|
||||
rangeList[i] = new ArrayList<>();
|
||||
}
|
||||
for (InternalAggregation aggregation : aggregations) {
|
||||
InternalRange<B, R> ranges = (InternalRange<B, R>) aggregation;
|
||||
|
|
|
@ -98,6 +98,11 @@ public class TasksIT extends ESIntegTestCase {
|
|||
|
||||
private Map<Tuple<String, String>, RecordingTaskManagerListener> listeners = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected boolean addMockTransportService() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return pluginList(MockTransportService.TestPlugin.class, TestTaskPlugin.class);
|
||||
|
|
|
@ -158,6 +158,7 @@ public class BulkProcessorIT extends ESIntegTestCase {
|
|||
//we create a transport client with no nodes to make sure it throws NoNodeAvailableException
|
||||
Settings settings = Settings.builder()
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put("transport.type", "local")
|
||||
.build();
|
||||
Client transportClient = TransportClient.builder().settings(settings).build();
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.action.search;
|
|||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
|
@ -40,6 +41,7 @@ public class SearchRequestBuilderTests extends ESTestCase {
|
|||
//that is why we create it but we don't add any transport address to it
|
||||
Settings settings = Settings.builder()
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.build();
|
||||
client = TransportClient.builder().settings(settings).build();
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTestCase {
|
|||
.settings(Settings.builder()
|
||||
.put("client.transport.sniff", false)
|
||||
.put("cluster.name", "cluster1")
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.put("node.name", "transport_client_" + this.getTestName())
|
||||
.put(headersSettings)
|
||||
.build())
|
||||
|
@ -82,6 +83,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTestCase {
|
|||
.settings(Settings.builder()
|
||||
.put("client.transport.sniff", true)
|
||||
.put("cluster.name", "cluster1")
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.put("node.name", "transport_client_" + this.getTestName() + "_1")
|
||||
.put("client.transport.nodes_sampler_interval", "1s")
|
||||
.put(HEADER_SETTINGS)
|
||||
|
|
|
@ -56,6 +56,7 @@ public class TransportClientIT extends ESIntegTestCase {
|
|||
.put(internalCluster().getDefaultSettings())
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.put("node.name", "testNodeVersionIsUpdated")
|
||||
.put("transport.type", "local")
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(Node.NODE_DATA_SETTING.getKey(), false)
|
||||
.put("cluster.name", "foobar")
|
||||
|
@ -90,7 +91,8 @@ public class TransportClientIT extends ESIntegTestCase {
|
|||
public void testThatTransportClientSettingCannotBeChanged() {
|
||||
Settings baseSettings = Settings.builder()
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.build();
|
||||
.put("transport.type", "local")
|
||||
.build();
|
||||
try (TransportClient client = TransportClient.builder().settings(baseSettings).build()) {
|
||||
Settings settings = client.injector.getInstance(Settings.class);
|
||||
assertThat(Client.CLIENT_TYPE_SETTING_S.get(settings), is("transport"));
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.support.PlainListenableActionFuture;
|
|||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
@ -52,13 +53,13 @@ public class TransportClientRetryIT extends ESIntegTestCase {
|
|||
|
||||
Settings.Builder builder = Settings.builder().put("client.transport.nodes_sampler_interval", "1s")
|
||||
.put("node.name", "transport_client_retry_test")
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), internalCluster().getNodeMode())
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), internalCluster().getClusterName())
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir());
|
||||
|
||||
try (TransportClient client = TransportClient.builder().settings(builder.build()).build()) {
|
||||
client.addTransportAddresses(addresses);
|
||||
assertThat(client.connectedNodes().size(), equalTo(internalCluster().size()));
|
||||
assertEquals(client.connectedNodes().size(), internalCluster().size());
|
||||
|
||||
int size = cluster().size();
|
||||
//kill all nodes one by one, leaving a single master/data node at the end of the loop
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.client.transport;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -31,7 +32,8 @@ import static org.hamcrest.object.HasToString.hasToString;
|
|||
public class TransportClientTests extends ESTestCase {
|
||||
|
||||
public void testThatUsingAClosedClientThrowsAnException() throws ExecutionException, InterruptedException {
|
||||
final TransportClient client = TransportClient.builder().settings(Settings.EMPTY).build();
|
||||
final TransportClient client = TransportClient.builder().settings(Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "local"))
|
||||
.build();
|
||||
client.close();
|
||||
final IllegalStateException e =
|
||||
expectThrows(IllegalStateException.class, () -> client.admin().cluster().health(new ClusterHealthRequest()).get());
|
||||
|
|
|
@ -110,6 +110,7 @@ public class NetworkModuleTests extends ModuleTestCase {
|
|||
public void testRegisterTransportService() {
|
||||
Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, "custom")
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.build();
|
||||
NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry());
|
||||
module.registerTransportService("custom", FakeTransportService.class);
|
||||
|
@ -140,7 +141,9 @@ public class NetworkModuleTests extends ModuleTestCase {
|
|||
}
|
||||
|
||||
public void testRegisterHttpTransport() {
|
||||
Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").build();
|
||||
Settings settings = Settings.builder()
|
||||
.put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom")
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
|
||||
NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry());
|
||||
module.registerHttpTransport("custom", FakeHttpTransport.class);
|
||||
assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class);
|
||||
|
@ -158,7 +161,8 @@ public class NetworkModuleTests extends ModuleTestCase {
|
|||
}
|
||||
|
||||
// not added if http is disabled
|
||||
settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
|
||||
settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
|
||||
module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry());
|
||||
assertNotBound(module, HttpServerTransport.class);
|
||||
assertFalse(module.isTransportClient());
|
||||
|
|
|
@ -38,10 +38,8 @@ public class DiscoveryModuleTests extends ModuleTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void testRegisterMasterElectionService() {
|
||||
Settings settings = Settings.builder().put(Node.NODE_LOCAL_SETTING.getKey(), false).
|
||||
put(DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING.getKey(), "custom").build();
|
||||
Settings settings = Settings.builder().put(DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING.getKey(), "custom").build();
|
||||
DiscoveryModule module = new DiscoveryModule(settings);
|
||||
module.addElectMasterService("custom", DummyMasterElectionService.class);
|
||||
assertBinding(module, ElectMasterService.class, DummyMasterElectionService.class);
|
||||
|
@ -49,24 +47,20 @@ public class DiscoveryModuleTests extends ModuleTestCase {
|
|||
}
|
||||
|
||||
public void testLoadUnregisteredMasterElectionService() {
|
||||
Settings settings = Settings.builder().put(Node.NODE_LOCAL_SETTING.getKey(), false).
|
||||
put(DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING.getKey(), "foobar").build();
|
||||
Settings settings = Settings.builder().put(DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING.getKey(), "foobar").build();
|
||||
DiscoveryModule module = new DiscoveryModule(settings);
|
||||
module.addElectMasterService("custom", DummyMasterElectionService.class);
|
||||
assertBindingFailure(module, "Unknown master service type [foobar]");
|
||||
}
|
||||
|
||||
public void testRegisterDefaults() {
|
||||
boolean local = randomBoolean();
|
||||
Settings settings = Settings.builder().put(Node.NODE_LOCAL_SETTING.getKey(), local).build();
|
||||
Settings settings = Settings.EMPTY;
|
||||
DiscoveryModule module = new DiscoveryModule(settings);
|
||||
assertBinding(module, Discovery.class, local ? LocalDiscovery.class : ZenDiscovery.class);
|
||||
assertBinding(module, Discovery.class, ZenDiscovery.class);
|
||||
}
|
||||
|
||||
public void testRegisterDiscovery() {
|
||||
boolean local = randomBoolean();
|
||||
Settings settings = Settings.builder().put(Node.NODE_LOCAL_SETTING.getKey(), local).
|
||||
put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "custom").build();
|
||||
Settings settings = Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "custom").build();
|
||||
DiscoveryModule module = new DiscoveryModule(settings);
|
||||
module.addDiscoveryType("custom", NoopDiscovery.class);
|
||||
assertBinding(module, Discovery.class, NoopDiscovery.class);
|
||||
|
|
|
@ -43,6 +43,11 @@ public class CustomQueryParserIT extends ESIntegTestCase {
|
|||
return pluginList(DummyQueryParserPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
|
||||
return pluginList(DummyQueryParserPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
|
|
@ -61,6 +61,11 @@ public class FunctionScorePluginIT extends ESIntegTestCase {
|
|||
return pluginList(CustomDistanceScorePlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
|
||||
return pluginList(CustomDistanceScorePlugin.class);
|
||||
}
|
||||
|
||||
public void testPlugin() throws Exception {
|
||||
client().admin()
|
||||
.indices()
|
||||
|
|
|
@ -60,6 +60,11 @@ public class CustomSuggesterSearchIT extends ESIntegTestCase {
|
|||
return pluginList(CustomSuggesterPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
|
||||
return pluginList(CustomSuggesterPlugin.class);
|
||||
}
|
||||
|
||||
public void testThatCustomSuggestersCanBeRegisteredAndWork() throws Exception {
|
||||
createIndex("test");
|
||||
client().prepareIndex("test", "test", "1").setSource(jsonBuilder()
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.elasticsearch.common.collect.Tuple;
|
|||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.discovery.MasterNotDiscoveredException;
|
||||
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing;
|
||||
import org.elasticsearch.node.Node;
|
||||
|
@ -76,11 +77,9 @@ public class TribeIT extends ESIntegTestCase {
|
|||
@Before
|
||||
public void setupSecondCluster() throws Exception {
|
||||
if (cluster2 == null) {
|
||||
final Tuple<String, NodeConfigurationSource> configSource = getNodeConfigSource();
|
||||
final String nodeMode = configSource.v1();
|
||||
final NodeConfigurationSource nodeConfigurationSource = configSource.v2();
|
||||
cluster2 = new InternalTestCluster(nodeMode, randomLong(), createTempDir(), true, 2, 2,
|
||||
UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins(),
|
||||
final NodeConfigurationSource configSource = getNodeConfigSource();
|
||||
cluster2 = new InternalTestCluster(randomLong(), createTempDir(), true, 2, 2,
|
||||
UUIDs.randomBase64UUID(random()), configSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins(),
|
||||
Function.identity());
|
||||
cluster2.beforeTest(random(), 0.1);
|
||||
cluster2.ensureAtLeastNumDataNodes(2);
|
||||
|
@ -131,9 +130,16 @@ public class TribeIT extends ESIntegTestCase {
|
|||
Settings merged = Settings.builder()
|
||||
.put("tribe.t1.cluster.name", internalCluster().getClusterName())
|
||||
.put("tribe.t2.cluster.name", cluster2.getClusterName())
|
||||
.put("tribe.t1.transport.type", "local")
|
||||
.put("tribe.t2.transport.type", "local")
|
||||
.put("tribe.t1.discovery.type", "local")
|
||||
.put("tribe.t2.discovery.type", "local")
|
||||
.put("transport.type", "local")
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
|
||||
.put("tribe.blocks.write", false)
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(settings)
|
||||
|
||||
.put(tribe1Defaults.build())
|
||||
.put(tribe2Defaults.build())
|
||||
.put(internalCluster().getDefaultSettings())
|
||||
|
|
|
@ -28,6 +28,9 @@ The `name` setting has been removed and is replaced by `node.name`. Usage of
|
|||
|
||||
The `node.add_id_to_custom_path` was renamed to `add_lock_id_to_custom_path`.
|
||||
|
||||
The settings `node.mode` and `node.local` are removed. Local mode should be configured via
|
||||
`discovery.type: local` and `transport.type:local`. In order to disable _http_ please use `http.enabled: false`
|
||||
|
||||
==== Node attribute settings
|
||||
|
||||
Node level attributes used for allocation filtering, forced awareness or other node identification / grouping
|
||||
|
|
|
@ -33,8 +33,6 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class NettyPlugin extends Plugin {
|
||||
|
||||
|
||||
public static final String NETTY_TRANSPORT_NAME = "netty";
|
||||
public static final String NETTY_HTTP_TRANSPORT_NAME = "netty";
|
||||
|
||||
|
@ -85,6 +83,16 @@ public class NettyPlugin extends Plugin {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings additionalSettings() {
|
||||
return Settings.builder()
|
||||
// here we set the netty transport and http transport as the default. This is a set once setting
|
||||
// ie. if another plugin does that as well the server will fail - only one default network can exist!
|
||||
.put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), NETTY_HTTP_TRANSPORT_NAME)
|
||||
.put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), NETTY_TRANSPORT_NAME)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void onModule(NetworkModule networkModule) {
|
||||
if (networkModule.canRegisterHttpExtensions()) {
|
||||
networkModule.registerHttpTransport(NETTY_HTTP_TRANSPORT_NAME, NettyHttpServerTransport.class);
|
||||
|
|
|
@ -43,9 +43,7 @@ public abstract class AbstractAzureComputeServiceTestCase extends ESIntegTestCas
|
|||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings.Builder builder = Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put("discovery.type", "azure")
|
||||
// We need the network to make the mock working
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), "network");
|
||||
.put("discovery.type", "azure");
|
||||
|
||||
// We add a fake subscription_id to start mock compute service
|
||||
builder.put(Management.SUBSCRIPTION_ID_SETTING.getKey(), "fake")
|
||||
|
|
|
@ -29,10 +29,7 @@ import org.elasticsearch.test.ESIntegTestCase;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST,
|
||||
numDataNodes = 0,
|
||||
transportClientRatio = 0.0,
|
||||
numClientNodes = 0)
|
||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, transportClientRatio = 0.0, numClientNodes = 0)
|
||||
public class AzureSimpleTests extends AbstractAzureComputeServiceTestCase {
|
||||
public AzureSimpleTests() {
|
||||
super(AzureComputeServiceSimpleMock.TestPlugin.class);
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
|||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.node.Node;
|
||||
|
@ -52,13 +53,13 @@ public class TribeUnitTests extends ESTestCase {
|
|||
private static Node tribe1;
|
||||
private static Node tribe2;
|
||||
|
||||
private static final String NODE_MODE = InternalTestCluster.configuredNodeMode();
|
||||
|
||||
@BeforeClass
|
||||
public static void createTribes() {
|
||||
Settings baseSettings = Settings.builder()
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), NODE_MODE)
|
||||
.put("transport.type", "local")
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
|
||||
|
||||
tribe1 = new TribeClientNode(
|
||||
|
@ -94,26 +95,23 @@ public class TribeUnitTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private static void assertTribeNodeSuccessfullyCreated(Settings extraSettings) throws Exception {
|
||||
//tribe node doesn't need the node.mode setting, as it's forced local internally anyways. The tribe clients do need it to make sure
|
||||
//they can find their corresponding tribes using the proper transport
|
||||
//The tribe clients do need it to make sure they can find their corresponding tribes using the proper transport
|
||||
Settings settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put("node.name", "tribe_node")
|
||||
.put("tribe.t1.node.mode", NODE_MODE).put("tribe.t2.node.mode", NODE_MODE)
|
||||
.put("transport.type", "local").put("discovery.type", "local")
|
||||
.put("tribe.t1.transport.type", "local").put("tribe.t2.transport.type", "local")
|
||||
.put("tribe.t1.discovery.type", "local").put("tribe.t2.discovery.type", "local")
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), NODE_MODE)
|
||||
.put(extraSettings).build();
|
||||
|
||||
try (Node node = new Node(settings).start()) {
|
||||
try (Client client = node.client()) {
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClusterState state = client.admin().cluster().prepareState().clear().setNodes(true).get().getState();
|
||||
assertThat(state.getClusterName().value(), equalTo("tribe_node_cluster"));
|
||||
assertThat(state.getNodes().getSize(), equalTo(5));
|
||||
for (DiscoveryNode discoveryNode : state.getNodes()) {
|
||||
assertThat(discoveryNode.getName(), either(equalTo("tribe1_node")).or(equalTo("tribe2_node"))
|
||||
.or(equalTo("tribe_node")).or(equalTo("tribe_node/t1")).or(equalTo("tribe_node/t2")));
|
||||
}
|
||||
assertBusy(() -> {
|
||||
ClusterState state = client.admin().cluster().prepareState().clear().setNodes(true).get().getState();
|
||||
assertThat(state.getClusterName().value(), equalTo("tribe_node_cluster"));
|
||||
assertThat(state.getNodes().getSize(), equalTo(5));
|
||||
for (DiscoveryNode discoveryNode : state.getNodes()) {
|
||||
assertThat(discoveryNode.getName(), either(equalTo("tribe1_node")).or(equalTo("tribe2_node"))
|
||||
.or(equalTo("tribe_node")).or(equalTo("tribe_node/t1")).or(equalTo("tribe_node/t2")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -96,8 +96,7 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase {
|
|||
Settings.Builder builder = Settings.builder()
|
||||
.put("node.name", "qa_smoke_client_" + counter.getAndIncrement())
|
||||
.put("client.transport.ignore_cluster_name", true)
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), "network");// we require network here!
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
|
||||
if (random().nextBoolean()) {
|
||||
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, NettyPlugin.NETTY_TRANSPORT_NAME);
|
||||
transportClientBuilder.addPlugin(NettyPlugin.class);
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.common.io.PathUtils;
|
|||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
|
@ -242,7 +243,7 @@ public abstract class ESBackcompatTestCase extends ESIntegTestCase {
|
|||
protected Settings commonNodeSettings(int nodeOrdinal) {
|
||||
Settings.Builder builder = Settings.builder().put(requiredSettings());
|
||||
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, "netty"); // run same transport / disco as external
|
||||
builder.put(Node.NODE_MODE_SETTING.getKey(), "network");
|
||||
builder.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "zen");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
import org.apache.lucene.util.TestUtil;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.transport.MockTcpTransportPlugin;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
|
@ -1724,37 +1725,53 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
maxNumDataNodes = getMaxNumDataNodes();
|
||||
}
|
||||
Collection<Class<? extends Plugin>> mockPlugins = getMockPlugins();
|
||||
Tuple<String, NodeConfigurationSource> configSource = getNodeConfigSource();
|
||||
final String nodeMode = configSource.v1();
|
||||
final NodeConfigurationSource nodeConfigurationSource = configSource.v2();
|
||||
return new InternalTestCluster(nodeMode, seed, createTempDir(), supportsDedicatedMasters, minNumDataNodes, maxNumDataNodes,
|
||||
final NodeConfigurationSource nodeConfigurationSource = getNodeConfigSource();
|
||||
if (addMockTransportService()) {
|
||||
ArrayList<Class<? extends Plugin>> mocks = new ArrayList<>(mockPlugins);
|
||||
// add both mock plugins - local and tcp if they are not there
|
||||
// we do this in case somebody overrides getMockPlugins and misses to call super
|
||||
if (mockPlugins.contains(AssertingLocalTransport.TestPlugin.class) == false) {
|
||||
mocks.add(AssertingLocalTransport.TestPlugin.class);
|
||||
}
|
||||
if (mockPlugins.contains(MockTcpTransportPlugin.class) == false) {
|
||||
mocks.add(MockTcpTransportPlugin.class);
|
||||
}
|
||||
mockPlugins = mocks;
|
||||
}
|
||||
return new InternalTestCluster(seed, createTempDir(), supportsDedicatedMasters, minNumDataNodes, maxNumDataNodes,
|
||||
InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", nodeConfigurationSource, getNumClientNodes(),
|
||||
InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix, mockPlugins, getClientWrapper());
|
||||
}
|
||||
|
||||
protected Tuple<String, NodeConfigurationSource> getNodeConfigSource() {
|
||||
protected NodeConfigurationSource getNodeConfigSource() {
|
||||
SuppressLocalMode noLocal = getAnnotation(this.getClass(), SuppressLocalMode.class);
|
||||
SuppressNetworkMode noNetwork = getAnnotation(this.getClass(), SuppressNetworkMode.class);
|
||||
String nodeMode = InternalTestCluster.configuredNodeMode();
|
||||
Settings.Builder networkSettings = Settings.builder();
|
||||
final boolean isNetwork;
|
||||
if (noLocal != null && noNetwork != null) {
|
||||
throw new IllegalStateException("Can't suppress both network and local mode");
|
||||
} else if (noLocal != null) {
|
||||
nodeMode = "network";
|
||||
if (addMockTransportService()) {
|
||||
networkSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
|
||||
}
|
||||
} else if (noNetwork != null) {
|
||||
nodeMode = "local";
|
||||
isNetwork = true;
|
||||
} else {
|
||||
if (addMockTransportService()) {
|
||||
networkSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, AssertingLocalTransport.ASSERTING_TRANSPORT_NAME);
|
||||
} else {
|
||||
networkSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, "local");
|
||||
}
|
||||
isNetwork = false;
|
||||
}
|
||||
final boolean isNetwork = "network".equals(nodeMode);
|
||||
|
||||
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {
|
||||
@Override
|
||||
public Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put(networkSettings.build()).
|
||||
return Settings.builder()
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(),
|
||||
isNetwork ? DiscoveryModule.DISCOVERY_TYPE_SETTING.getDefault(Settings.EMPTY) : "local")
|
||||
.put(networkSettings.build()).
|
||||
put(ESIntegTestCase.this.nodeSettings(nodeOrdinal)).build();
|
||||
}
|
||||
|
||||
|
@ -1775,11 +1792,14 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
if (isNetwork && plugins.contains(MockTcpTransportPlugin.class) == false) {
|
||||
plugins = new ArrayList<>(plugins);
|
||||
plugins.add(MockTcpTransportPlugin.class);
|
||||
} else if (isNetwork == false && plugins.contains(AssertingLocalTransport.class) == false) {
|
||||
plugins = new ArrayList<>(plugins);
|
||||
plugins.add(AssertingLocalTransport.TestPlugin.class);
|
||||
}
|
||||
return Collections.unmodifiableCollection(plugins);
|
||||
}
|
||||
};
|
||||
return new Tuple<>(nodeMode, nodeConfigurationSource);
|
||||
return nodeConfigurationSource;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1819,12 +1839,12 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
mocks.add(MockSearchService.TestPlugin.class);
|
||||
}
|
||||
}
|
||||
mocks.add(TestSeedPlugin.class);
|
||||
|
||||
if (addMockTransportService()) {
|
||||
// add both mock plugins - local and tcp
|
||||
mocks.add(AssertingLocalTransport.TestPlugin.class);
|
||||
mocks.add(MockTcpTransportPlugin.class);
|
||||
}
|
||||
mocks.add(TestSeedPlugin.class);
|
||||
return Collections.unmodifiableList(mocks);
|
||||
}
|
||||
|
||||
|
|
|
@ -179,13 +179,13 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
|
|||
.put("script.stored", "true")
|
||||
.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1) // limit the number of threads created
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(Node.NODE_LOCAL_SETTING.getKey(), true)
|
||||
.put("discovery.type", "local")
|
||||
.put("transport.type", "local")
|
||||
.put(Node.NODE_DATA_SETTING.getKey(), true)
|
||||
.put(nodeSettings()) // allow test cases to provide their own settings or override these
|
||||
.build();
|
||||
Node build = new MockNode(settings, getPlugins());
|
||||
build.start();
|
||||
assertThat(DiscoveryNode.isLocalNode(build.settings()), is(true));
|
||||
return build;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ final class ExternalNode implements Closeable {
|
|||
|
||||
public static final Settings REQUIRED_SETTINGS = Settings.builder()
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "zen")
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), "network").build(); // we need network mode for this
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "netty").build(); // we need network mode for this
|
||||
|
||||
private final Path path;
|
||||
private final Random random;
|
||||
|
@ -106,8 +106,6 @@ final class ExternalNode implements Closeable {
|
|||
case "cluster.name":
|
||||
case "node.name":
|
||||
case "path.home":
|
||||
case "node.mode":
|
||||
case "node.local":
|
||||
case NetworkModule.TRANSPORT_TYPE_KEY:
|
||||
case "discovery.type":
|
||||
case NetworkModule.TRANSPORT_SERVICE_TYPE_KEY:
|
||||
|
|
|
@ -77,8 +77,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||
.put(additionalSettings)
|
||||
.put("node.name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement())
|
||||
.put("client.transport.ignore_cluster_name", true)
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), "network");// we require network here!
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
|
||||
TransportClient.Builder transportClientBuilder = TransportClient.builder();
|
||||
boolean addMockTcpTransport = additionalSettings.get(NetworkModule.TRANSPORT_TYPE_KEY) == null;
|
||||
if (addMockTcpTransport) {
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.elasticsearch.common.io.FileSystemUtils;
|
|||
import org.elasticsearch.common.lease.Releasables;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.Settings.Builder;
|
||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
||||
|
@ -224,19 +225,14 @@ public final class InternalTestCluster extends TestCluster {
|
|||
private final Path baseDir;
|
||||
|
||||
private ServiceDisruptionScheme activeDisruptionScheme;
|
||||
private String nodeMode;
|
||||
private Function<Client, Client> clientWrapper;
|
||||
|
||||
public InternalTestCluster(String nodeMode, long clusterSeed, Path baseDir,
|
||||
public InternalTestCluster(long clusterSeed, Path baseDir,
|
||||
boolean randomlyAddDedicatedMasters,
|
||||
int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes,
|
||||
boolean enableHttpPipelining, String nodePrefix, Collection<Class<? extends Plugin>> mockPlugins, Function<Client, Client> clientWrapper) {
|
||||
super(clusterSeed);
|
||||
if ("network".equals(nodeMode) == false && "local".equals(nodeMode) == false) {
|
||||
throw new IllegalArgumentException("Unknown nodeMode: " + nodeMode);
|
||||
}
|
||||
this.clientWrapper = clientWrapper;
|
||||
this.nodeMode = nodeMode;
|
||||
this.baseDir = baseDir;
|
||||
this.clusterName = clusterName;
|
||||
if (minNumDataNodes < 0 || maxNumDataNodes < 0) {
|
||||
|
@ -308,7 +304,6 @@ public final class InternalTestCluster extends TestCluster {
|
|||
builder.put(Environment.PATH_REPO_SETTING.getKey(), baseDir.resolve("repos"));
|
||||
builder.put(TransportSettings.PORT.getKey(), TRANSPORT_BASE_PORT + "-" + (TRANSPORT_BASE_PORT + PORTS_PER_CLUSTER));
|
||||
builder.put("http.port", HTTP_BASE_PORT + "-" + (HTTP_BASE_PORT + PORTS_PER_CLUSTER));
|
||||
builder.put(Node.NODE_MODE_SETTING.getKey(), nodeMode);
|
||||
builder.put("http.pipelining", enableHttpPipelining);
|
||||
if (Strings.hasLength(System.getProperty("tests.es.logger.level"))) {
|
||||
builder.put("logger.level", System.getProperty("tests.es.logger.level"));
|
||||
|
@ -333,24 +328,6 @@ public final class InternalTestCluster extends TestCluster {
|
|||
executor = EsExecutors.newScaling("test runner", 0, Integer.MAX_VALUE, 0, TimeUnit.SECONDS, EsExecutors.daemonThreadFactory("test_" + clusterName), new ThreadContext(Settings.EMPTY));
|
||||
}
|
||||
|
||||
public static String configuredNodeMode() {
|
||||
Builder builder = Settings.builder();
|
||||
if (Strings.isEmpty(System.getProperty("tests.es.node.mode")) && Strings.isEmpty(System.getProperty("tests.node.local"))) {
|
||||
return "local"; // default if nothing is specified
|
||||
}
|
||||
if (Strings.hasLength(System.getProperty("tests.es.node.mode"))) {
|
||||
builder.put(Node.NODE_MODE_SETTING.getKey(), System.getProperty("tests.es.node.mode"));
|
||||
}
|
||||
if (Strings.hasLength(System.getProperty("tests.es.node.local"))) {
|
||||
builder.put(Node.NODE_LOCAL_SETTING.getKey(), System.getProperty("tests.es.node.local"));
|
||||
}
|
||||
if (DiscoveryNode.isLocalNode(builder.build())) {
|
||||
return "local";
|
||||
} else {
|
||||
return "network";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
|
@ -360,10 +337,6 @@ public final class InternalTestCluster extends TestCluster {
|
|||
return nodes.keySet().toArray(Strings.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private boolean isLocalTransportConfigured() {
|
||||
return "local".equals(nodeMode);
|
||||
}
|
||||
|
||||
private Settings getSettings(int nodeOrdinal, long nodeSeed, Settings others) {
|
||||
Builder builder = Settings.builder().put(defaultSettings)
|
||||
.put(getRandomNodeSettings(nodeSeed));
|
||||
|
@ -390,9 +363,7 @@ public final class InternalTestCluster extends TestCluster {
|
|||
private Settings getRandomNodeSettings(long seed) {
|
||||
Random random = new Random(seed);
|
||||
Builder builder = Settings.builder();
|
||||
if (isLocalTransportConfigured() == false) {
|
||||
builder.put(Transport.TRANSPORT_TCP_COMPRESS.getKey(), rarely(random));
|
||||
}
|
||||
builder.put(Transport.TRANSPORT_TCP_COMPRESS.getKey(), rarely(random));
|
||||
if (random.nextBoolean()) {
|
||||
builder.put("cache.recycler.page.type", RandomPicks.randomFrom(random, PageCacheRecycler.Type.values()));
|
||||
}
|
||||
|
@ -768,10 +739,6 @@ public final class InternalTestCluster extends TestCluster {
|
|||
}
|
||||
}
|
||||
|
||||
public String getNodeMode() {
|
||||
return nodeMode;
|
||||
}
|
||||
|
||||
private final class NodeAndClient implements Closeable {
|
||||
private MockNode node;
|
||||
private Client nodeClient;
|
||||
|
@ -839,7 +806,7 @@ public final class InternalTestCluster extends TestCluster {
|
|||
/* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down.
|
||||
* we first need support of transportClientRatio as annotations or so
|
||||
*/
|
||||
transportClient = new TransportClientFactory(false, nodeConfigurationSource.transportClientSettings(), baseDir, nodeMode, nodeConfigurationSource.transportClientPlugins()).client(node, clusterName);
|
||||
transportClient = new TransportClientFactory(false, nodeConfigurationSource.transportClientSettings(), baseDir, nodeConfigurationSource.transportClientPlugins()).client(node, clusterName);
|
||||
}
|
||||
return clientWrapper.apply(transportClient);
|
||||
}
|
||||
|
@ -914,14 +881,12 @@ public final class InternalTestCluster extends TestCluster {
|
|||
private final boolean sniff;
|
||||
private final Settings settings;
|
||||
private final Path baseDir;
|
||||
private final String nodeMode;
|
||||
private final Collection<Class<? extends Plugin>> plugins;
|
||||
|
||||
TransportClientFactory(boolean sniff, Settings settings, Path baseDir, String nodeMode, Collection<Class<? extends Plugin>> plugins) {
|
||||
TransportClientFactory(boolean sniff, Settings settings, Path baseDir, Collection<Class<? extends Plugin>> plugins) {
|
||||
this.sniff = sniff;
|
||||
this.settings = settings != null ? settings : Settings.EMPTY;
|
||||
this.baseDir = baseDir;
|
||||
this.nodeMode = nodeMode;
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
|
@ -933,15 +898,12 @@ public final class InternalTestCluster extends TestCluster {
|
|||
.put(Environment.PATH_HOME_SETTING.getKey(), baseDir)
|
||||
.put("node.name", TRANSPORT_CLIENT_PREFIX + node.settings().get("node.name"))
|
||||
.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName).put("client.transport.sniff", sniff)
|
||||
.put(Node.NODE_MODE_SETTING.getKey(), Node.NODE_MODE_SETTING.exists(nodeSettings) ? Node.NODE_MODE_SETTING.get(nodeSettings) : nodeMode)
|
||||
.put("logger.prefix", nodeSettings.get("logger.prefix", ""))
|
||||
.put("logger.level", nodeSettings.get("logger.level", "INFO"))
|
||||
.put(settings);
|
||||
|
||||
if (Node.NODE_LOCAL_SETTING.exists(nodeSettings)) {
|
||||
builder.put(Node.NODE_LOCAL_SETTING.getKey(), Node.NODE_LOCAL_SETTING.get(nodeSettings));
|
||||
if ( NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings)) {
|
||||
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, NetworkModule.TRANSPORT_TYPE_SETTING.get(settings));
|
||||
}
|
||||
|
||||
TransportClient.Builder clientBuilder = TransportClient.builder().settings(builder.build());
|
||||
for (Class<? extends Plugin> plugin : plugins) {
|
||||
clientBuilder.addPlugin(plugin);
|
||||
|
|
|
@ -140,8 +140,7 @@ public class ReproduceInfoPrinter extends RunListener {
|
|||
appendProperties("tests.es.logger.level");
|
||||
if (inVerifyPhase()) {
|
||||
// these properties only make sense for integration tests
|
||||
appendProperties("tests.es.node.mode", "tests.es.node.local", TESTS_CLUSTER,
|
||||
ESIntegTestCase.TESTS_ENABLE_MOCK_MODULES);
|
||||
appendProperties(TESTS_CLUSTER, ESIntegTestCase.TESTS_ENABLE_MOCK_MODULES);
|
||||
}
|
||||
appendProperties("tests.assertion.disabled", "tests.security.manager", "tests.nightly", "tests.jvms",
|
||||
"tests.client.ratio", "tests.heap.size", "tests.bwc", "tests.bwc.version");
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
|||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.discovery.DiscoverySettings;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -76,10 +77,10 @@ public class InternalTestClusterTests extends ESTestCase {
|
|||
String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10);
|
||||
|
||||
Path baseDir = createTempDir();
|
||||
InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, masterNodes,
|
||||
InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
|
||||
minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes,
|
||||
enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
|
||||
InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, masterNodes,
|
||||
InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
|
||||
minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes,
|
||||
enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
|
||||
// TODO: this is not ideal - we should have a way to make sure ports are initialized in the same way
|
||||
|
@ -131,7 +132,16 @@ public class InternalTestClusterTests extends ESTestCase {
|
|||
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {
|
||||
@Override
|
||||
public Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
|
||||
return Settings.builder()
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings transportClientSettings() {
|
||||
return Settings.builder()
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
|
||||
}
|
||||
};
|
||||
int numClientNodes = randomIntBetween(0, 2);
|
||||
|
@ -139,10 +149,10 @@ public class InternalTestClusterTests extends ESTestCase {
|
|||
String nodePrefix = "foobar";
|
||||
|
||||
Path baseDir = createTempDir();
|
||||
InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, masterNodes,
|
||||
InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
|
||||
minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes,
|
||||
enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
|
||||
InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, masterNodes,
|
||||
InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
|
||||
minNumDataNodes, maxNumDataNodes, clusterName2, nodeConfigurationSource, numClientNodes,
|
||||
enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
|
||||
|
||||
|
@ -182,13 +192,21 @@ public class InternalTestClusterTests extends ESTestCase {
|
|||
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {
|
||||
@Override
|
||||
public Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
|
||||
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
|
||||
.build();
|
||||
}
|
||||
@Override
|
||||
public Settings transportClientSettings() {
|
||||
return Settings.builder()
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
|
||||
}
|
||||
}; int numClientNodes = randomIntBetween(0, 2);
|
||||
boolean enableHttpPipelining = randomBoolean();
|
||||
String nodePrefix = "test";
|
||||
Path baseDir = createTempDir();
|
||||
InternalTestCluster cluster = new InternalTestCluster("local", clusterSeed, baseDir, masterNodes,
|
||||
InternalTestCluster cluster = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
|
||||
minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes,
|
||||
enableHttpPipelining, nodePrefix, Collections.emptyList(), Function.identity());
|
||||
try {
|
||||
|
@ -250,18 +268,21 @@ public class InternalTestClusterTests extends ESTestCase {
|
|||
|
||||
public void testDifferentRolesMaintainPathOnRestart() throws Exception {
|
||||
final Path baseDir = createTempDir();
|
||||
InternalTestCluster cluster = new InternalTestCluster("local", randomLong(), baseDir, true, 0, 0, "test",
|
||||
InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, true, 0, 0, "test",
|
||||
new NodeConfigurationSource() {
|
||||
@Override
|
||||
public Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder()
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
|
||||
.put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings transportClientSettings() {
|
||||
return Settings.EMPTY;
|
||||
return Settings.builder()
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
|
||||
}
|
||||
}, 0, randomBoolean(), "", Collections.emptyList(), Function.identity());
|
||||
cluster.beforeTest(random(), 0.0);
|
||||
|
|
Loading…
Reference in New Issue