2020package org .elasticsearch .cluster ;
2121
2222import org .apache .lucene .search .join .ScoreMode ;
23+ import org .elasticsearch .action .admin .cluster .configuration .AddVotingConfigExclusionsAction ;
24+ import org .elasticsearch .action .admin .cluster .configuration .AddVotingConfigExclusionsRequest ;
25+ import org .elasticsearch .cluster .coordination .ClusterBootstrapService ;
2326import org .elasticsearch .common .settings .Settings ;
2427import org .elasticsearch .common .xcontent .XContentType ;
2528import org .elasticsearch .discovery .MasterNotDiscoveredException ;
2831import org .elasticsearch .test .ESIntegTestCase ;
2932import org .elasticsearch .test .ESIntegTestCase .ClusterScope ;
3033import org .elasticsearch .test .ESIntegTestCase .Scope ;
31- import org .elasticsearch .test .discovery .TestZenDiscovery ;
3234import org .elasticsearch .test .junit .annotations .TestLogging ;
3335
3436import java .io .IOException ;
37+ import java .util .Collections ;
38+ import java .util .List ;
39+ import java .util .concurrent .ExecutionException ;
3540
3641import static org .elasticsearch .discovery .zen .ElectMasterService .DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING ;
3742import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
@@ -45,10 +50,22 @@ public class SpecificMasterNodesIT extends ESIntegTestCase {
4550 @ Override
4651 protected Settings nodeSettings (int nodeOrdinal ) {
4752 return Settings .builder ().put (super .nodeSettings (nodeOrdinal ))
48- .put (TestZenDiscovery .USE_ZEN2 .getKey (), false ) // does unsafe things
4953 .put (DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING .getKey (), 1 ).build ();
5054 }
5155
56+ @ Override
57+ protected List <Settings > addExtraClusterBootstrapSettings (List <Settings > allNodesSettings ) {
58+ // if it's the first master in the cluster bootstrap the cluster with this node name
59+ Settings settings = allNodesSettings .get (0 );
60+ if (internalCluster ().numMasterNodes () == 0 && settings .getAsBoolean (Node .NODE_MASTER_SETTING .getKey (), false )) {
61+ return Collections .singletonList (Settings .builder ()
62+ .put (settings )
63+ .put (ClusterBootstrapService .INITIAL_MASTER_NODES_SETTING .getKey (), settings .get (Node .NODE_NAME_SETTING .getKey ()))
64+ .build ());
65+ }
66+ return allNodesSettings ;
67+ }
68+
5269 public void testSimpleOnlyMasterNodeElection () throws IOException {
5370 logger .info ("--> start data node / non master node" );
5471 internalCluster ().startNode (Settings .builder ().put (Node .NODE_DATA_SETTING .getKey (), true )
@@ -89,7 +106,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException {
89106 .execute ().actionGet ().getState ().nodes ().getMasterNode ().getName (), equalTo (nextMasterEligibleNodeName ));
90107 }
91108
92- public void testElectOnlyBetweenMasterNodes () throws IOException {
109+ public void testElectOnlyBetweenMasterNodes () throws IOException , ExecutionException , InterruptedException {
93110 logger .info ("--> start data node / non master node" );
94111 internalCluster ().startNode (Settings .builder ().put (Node .NODE_DATA_SETTING .getKey (), true )
95112 .put (Node .NODE_MASTER_SETTING .getKey (), false ).put ("discovery.initial_state_timeout" , "1s" ));
@@ -119,14 +136,16 @@ public void testElectOnlyBetweenMasterNodes() throws IOException {
119136 .execute ().actionGet ().getState ().nodes ().getMasterNode ().getName (), equalTo (masterNodeName ));
120137
121138 logger .info ("--> closing master node (1)" );
139+ client ().execute (AddVotingConfigExclusionsAction .INSTANCE ,
140+ new AddVotingConfigExclusionsRequest (new String []{masterNodeName })).get ();
122141 internalCluster ().stopCurrentMasterNode ();
123142 assertThat (internalCluster ().nonMasterClient ().admin ().cluster ().prepareState ()
124143 .execute ().actionGet ().getState ().nodes ().getMasterNode ().getName (), equalTo (nextMasterEligableNodeName ));
125144 assertThat (internalCluster ().masterClient ().admin ().cluster ().prepareState ()
126145 .execute ().actionGet ().getState ().nodes ().getMasterNode ().getName (), equalTo (nextMasterEligableNodeName ));
127146 }
128147
129- public void testAliasFilterValidation () throws Exception {
148+ public void testAliasFilterValidation () {
130149 logger .info ("--> start master node / non data" );
131150 internalCluster ().startNode (Settings .builder ()
132151 .put (Node .NODE_DATA_SETTING .getKey (), false ).put (Node .NODE_MASTER_SETTING .getKey (), true ));
0 commit comments