Skip to content

Commit

Permalink
Zen2: Move all mixed-version REST tests to Zen2 (#36398)
Browse files Browse the repository at this point in the history
Moves all remaining (rolling-upgrade and mixed-version) REST tests to use Zen2. To avoid adding
extra configuration, it relies on Zen2 being set as the default discovery type. This required a few
smaller changes in other tests. I've removed AzureMinimumMasterNodesTests which tests Zen1
functionality and dates from a time where host providers were not configurable and each cloud
plugin had its own discovery.type, subclassing the ZenDiscovery class. I've also adapted a few tests
which were unnecessarily adding addTestZenDiscovery = false for the same legacy reasons. Finally,
this also moves the unconfigured-node-name REST test to Zen2, testing the auto-bootstrapping
functionality in development mode when no discovery configuration is provided.
  • Loading branch information
ywelsch authored Dec 10, 2018
1 parent 0b1e7e9 commit 6e6e63d
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ class ClusterConfiguration {
}
}

/**
* Whether the initial_master_nodes setting should be automatically derived from the nodes
* in the cluster. Only takes effect if all nodes in the cluster understand this setting
* and the discovery type is not explicitly set.
*/
@Input
boolean autoSetInitialMasterNodes = true

/**
* Whether the file-based discovery provider should be automatically setup based on
* the nodes in the cluster. Only takes effect if no other hosts provider is already
* configured.
*/
@Input
boolean autoSetHostsProvider = true

@Input
String jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') +
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ class ClusterFormationTasks {
Object dependsOn
if (node.nodeVersion.onOrAfter("6.5.0")) {
writeConfigSetup = { Map esConfig ->
// Don't force discovery provider if one is set by the test cluster specs already
if (esConfig.containsKey('discovery.zen.hosts_provider') == false) {
esConfig['discovery.zen.hosts_provider'] = 'file'
if (config.getAutoSetHostsProvider()) {
// Don't force discovery provider if one is set by the test cluster specs already
if (esConfig.containsKey('discovery.zen.hosts_provider') == false) {
esConfig['discovery.zen.hosts_provider'] = 'file'
}
esConfig['discovery.zen.ping.unicast.hosts'] = []
}
esConfig['discovery.zen.ping.unicast.hosts'] = []
if (hasBwcNodes == false && esConfig['discovery.type'] == null) {
esConfig['discovery.type'] = 'zen2'
boolean supportsInitialMasterNodes = hasBwcNodes == false || config.bwcVersion.onOrAfter("7.0.0")
if (esConfig['discovery.type'] == null && config.getAutoSetInitialMasterNodes() && supportsInitialMasterNodes) {
esConfig['cluster.initial_master_nodes'] = nodes.stream().map({ n ->
if (n.config.settings['node.name'] == null) {
return "node-" + n.nodeNum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singletonList(TestPlugin.class);
}

@Override
protected boolean addTestZenDiscovery() {
return false;
}

/**
* Register an existing node as a Azure node, exposing its address and details htrough
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,4 @@ protected Settings nodeSettings(int nodeOrdinal) {
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(Ec2DiscoveryPlugin.class);
}

@Override
protected boolean addTestZenDiscovery() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* starting.
* This test requires AWS to run.
*/
@ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0, autoMinMasterNodes = false)
@ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
public class Ec2DiscoveryUpdateSettingsTests extends AbstractAwsTestCase {
public void testMinimumMasterNodesStart() {
Settings nodeSettings = Settings.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ protected Settings nodeSettings(int nodeOrdinal) {
.build();
}

@Override
protected boolean addTestZenDiscovery() {
return false;
}

public void testJoin() {
// start master node
final String masterNode = internalCluster().startMasterOnlyNode();
Expand Down
3 changes: 1 addition & 2 deletions qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ for (Version version : bwcVersions.wireCompatible) {
clusterName = 'rolling-upgrade'
otherUnicastHostAddresses = { getOtherUnicastHostAddresses() }
minimumMasterNodes = { 2 }
autoSetInitialMasterNodes = false
/* Override the data directory so the new node always gets the node we
* just stopped's data directory. */
dataDir = { nodeNumber -> oldClusterTest.nodes[stopNode].dataDir }
setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
setting 'node.name', "upgraded-node-${stopNode}"
// TODO: Move to Zen2 once we support rolling upgrade with Zen2
setting 'discovery.type', 'zen'
}
}

Expand Down
6 changes: 4 additions & 2 deletions qa/unconfigured-node-name/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ apply plugin: 'elasticsearch.rest-test'

integTestCluster {
setting 'node.name', null
// TODO: Run this using zen2, with no discovery configuration at all, demonstrating that the node forms a cluster on its own without help
setting 'discovery.type', 'zen'
// Run with no discovery configuration at all, demonstrating that a node in its
// "out-of-the-box" configuration can automatically bootstrap a cluster
autoSetInitialMasterNodes = false
autoSetHostsProvider = false
}

integTestRunner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void start() {
transportService.getThreadPool().scheduleUnlessShuttingDown(unconfiguredBootstrapTimeout, Names.SAME, new Runnable() {
@Override
public void run() {
// TODO: remove the following line once schedule method properly preserves thread context
threadContext.markAsSystemContext();
final GetDiscoveredNodesRequest request = new GetDiscoveredNodesRequest();
logger.trace("sending {}", request);
transportService.sendRequest(transportService.getLocalNode(), GetDiscoveredNodesAction.NAME, request,
Expand Down Expand Up @@ -212,6 +214,8 @@ public void handleException(TransportException exp) {
transportService.getThreadPool().scheduleUnlessShuttingDown(TimeValue.timeValueSeconds(10), Names.SAME, new Runnable() {
@Override
public void run() {
// TODO: remove the following line once schedule method properly preserves thread context
transportService.getThreadPool().getThreadContext().markAsSystemContext();
awaitBootstrap(bootstrapConfiguration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class DiscoveryModule {
public static final String ZEN2_DISCOVERY_TYPE = "zen2";

public static final Setting<String> DISCOVERY_TYPE_SETTING =
new Setting<>("discovery.type", ZEN_DISCOVERY_TYPE, Function.identity(), Property.NodeScope);
new Setting<>("discovery.type", ZEN2_DISCOVERY_TYPE, Function.identity(), Property.NodeScope);
public static final Setting<List<String>> DISCOVERY_HOSTS_PROVIDER_SETTING =
Setting.listSetting("discovery.zen.hosts_provider", Collections.emptyList(), Function.identity(), Property.NodeScope);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.transport.MockTransport;
import org.elasticsearch.threadpool.TestThreadPool;
Expand Down Expand Up @@ -102,7 +103,10 @@ public void testHandlesNonstandardDiscoveryImplementation() throws InterruptedEx
final Discovery discovery = mock(Discovery.class);
verifyZeroInteractions(discovery);

new TransportBootstrapClusterAction(Settings.EMPTY, EMPTY_FILTERS, transportService, discovery); // registers action
final String nonstandardDiscoveryType = randomFrom(DiscoveryModule.ZEN_DISCOVERY_TYPE, "single-node", "unknown");
new TransportBootstrapClusterAction(
Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), nonstandardDiscoveryType).build(),
EMPTY_FILTERS, transportService, discovery); // registers action
transportService.start();
transportService.acceptIncomingRequests();

Expand All @@ -117,7 +121,8 @@ public void handleResponse(BootstrapClusterResponse response) {
public void handleException(TransportException exp) {
final Throwable rootCause = exp.getRootCause();
assertThat(rootCause, instanceOf(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), equalTo("cluster bootstrapping is not supported by discovery type [zen]"));
assertThat(rootCause.getMessage(), equalTo("cluster bootstrapping is not supported by discovery type [" +
nonstandardDiscoveryType + "]"));
countDownLatch.countDown();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.discovery.PeersRequest;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.transport.MockTransport;
Expand Down Expand Up @@ -124,7 +125,10 @@ public void testHandlesNonstandardDiscoveryImplementation() throws InterruptedEx
final Discovery discovery = mock(Discovery.class);
verifyZeroInteractions(discovery);

new TransportGetDiscoveredNodesAction(Settings.EMPTY, EMPTY_FILTERS, transportService, discovery); // registers action
final String nonstandardDiscoveryType = randomFrom(DiscoveryModule.ZEN_DISCOVERY_TYPE, "single-node", "unknown");
new TransportGetDiscoveredNodesAction(
Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), nonstandardDiscoveryType).build(),
EMPTY_FILTERS, transportService, discovery); // registers action
transportService.start();
transportService.acceptIncomingRequests();

Expand All @@ -139,7 +143,8 @@ public void handleResponse(GetDiscoveredNodesResponse response) {
public void handleException(TransportException exp) {
final Throwable rootCause = exp.getRootCause();
assertThat(rootCause, instanceOf(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), equalTo("discovered nodes are not exposed by discovery type [zen]"));
assertThat(rootCause.getMessage(), equalTo("discovered nodes are not exposed by discovery type [" +
nonstandardDiscoveryType + "]"));
countDownLatch.countDown();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.coordination.Coordinator;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.service.ClusterApplier;
Expand Down Expand Up @@ -107,7 +108,7 @@ private DiscoveryModule newModule(Settings settings, List<DiscoveryPlugin> plugi

public void testDefaults() {
DiscoveryModule module = newModule(Settings.EMPTY, Collections.emptyList());
assertTrue(module.getDiscovery() instanceof ZenDiscovery);
assertTrue(module.getDiscovery() instanceof Coordinator);
}

public void testLazyConstructionDiscovery() {
Expand Down Expand Up @@ -205,7 +206,9 @@ public void testLazyConstructionHostsProvider() {

public void testJoinValidator() {
BiConsumer<DiscoveryNode, ClusterState> consumer = (a, b) -> {};
DiscoveryModule module = newModule(Settings.EMPTY, Collections.singletonList(new DiscoveryPlugin() {
// TODO: move to zen2 once join validators are implemented
DiscoveryModule module = newModule(Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(),
DiscoveryModule.ZEN_DISCOVERY_TYPE).build(), Collections.singletonList(new DiscoveryPlugin() {
@Override
public BiConsumer<DiscoveryNode, ClusterState> getJoinValidator() {
return consumer;
Expand Down
3 changes: 1 addition & 2 deletions x-pack/qa/rolling-upgrade-basic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ for (Version version : bwcVersions.wireCompatible) {
clusterName = 'rolling-upgrade-basic'
otherUnicastHostAddresses = { getOtherUnicastHostAddresses() }
minimumMasterNodes = { 2 }
autoSetInitialMasterNodes = false
/* Override the data directory so the new node always gets the node we
* just stopped's data directory. */
dataDir = { nodeNumber -> oldClusterTest.nodes[stopNode].dataDir }
Expand All @@ -66,8 +67,6 @@ for (Version version : bwcVersions.wireCompatible) {
setting 'xpack.watcher.enabled', 'false'
setting 'xpack.license.self_generated.type', 'basic'
setting 'node.name', "upgraded-node-${stopNode}"
// TODO: Move to Zen2 once we support rolling upgrade with Zen2
setting 'discovery.type', 'zen'
}
}

Expand Down
3 changes: 1 addition & 2 deletions x-pack/qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ subprojects {
clusterName = 'rolling-upgrade'
otherUnicastHostAddresses = { getOtherUnicastHostAddresses() }
minimumMasterNodes = { 2 }
autoSetInitialMasterNodes = false
/* Override the data directory so the new node always gets the node we
* just stopped's data directory. */
dataDir = { nodeNumber -> oldClusterTest.nodes[stopNode].dataDir }
Expand Down Expand Up @@ -215,8 +216,6 @@ subprojects {
if (version.before('6.0.0')) {
keystoreSetting 'xpack.security.authc.token.passphrase', 'token passphrase'
}
// TODO: Move to Zen2 once we support rolling upgrade with Zen2
setting 'discovery.type', 'zen'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ node.name: "node-master"
node.master: true
node.data: false
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]
cluster.initial_master_nodes: ["node-master"]
xpack.ssl.key: $ESCONFIG/certs/node-master/node-master.key
xpack.ssl.certificate: $ESCONFIG/certs/node-master/node-master.crt
Expand Down

0 comments on commit 6e6e63d

Please sign in to comment.