Commit e42e4a5 1 parent 00ae831 commit e42e4a5 Copy full SHA for e42e4a5
File tree 2 files changed +18
-12
lines changed
server/src/internalClusterTest/java/org/opensearch/cluster
test/framework/src/main/java/org/opensearch/test
2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 44
44
import org .opensearch .test .OpenSearchIntegTestCase .Scope ;
45
45
46
46
import java .io .IOException ;
47
+ import java .util .function .Supplier ;
47
48
48
49
import static org .opensearch .test .NodeRoles .clusterManagerNode ;
49
50
import static org .opensearch .test .NodeRoles .dataOnlyNode ;
@@ -254,9 +255,9 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
254
255
logger .info ("--> closing cluster-manager node (1)" );
255
256
client ().execute (AddVotingConfigExclusionsAction .INSTANCE , new AddVotingConfigExclusionsRequest (clusterManagerNodeName )).get ();
256
257
// removing the cluster-manager from the voting configuration immediately triggers the cluster-manager to step down
257
- assertBusy ( () -> {
258
- assertThat (
259
- internalCluster ().nonClusterManagerClient ()
258
+ Supplier < String > getClusterManagerIfElected = () -> {
259
+ try {
260
+ return internalCluster ().nonClusterManagerClient ()
260
261
.admin ()
261
262
.cluster ()
262
263
.prepareState ()
@@ -265,9 +266,14 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
265
266
.getState ()
266
267
.nodes ()
267
268
.getClusterManagerNode ()
268
- .getName (),
269
- equalTo (nextClusterManagerEligableNodeName )
270
- );
269
+ .getName ();
270
+ } catch (ClusterManagerNotDiscoveredException e ) {
271
+ logger .debug ("failed to get cluster-manager name" , e );
272
+ return null ;
273
+ }
274
+ };
275
+ assertBusy (() -> {
276
+ assertThat (getClusterManagerIfElected .get (), equalTo (nextClusterManagerEligableNodeName ));
271
277
assertThat (
272
278
internalCluster ().clusterManagerClient ()
273
279
.admin ()
Original file line number Diff line number Diff line change 89
89
import org .opensearch .core .index .shard .ShardId ;
90
90
import org .opensearch .core .indices .breaker .CircuitBreakerService ;
91
91
import org .opensearch .core .util .FileSystemUtils ;
92
+ import org .opensearch .discovery .ClusterManagerNotDiscoveredException ;
92
93
import org .opensearch .env .Environment ;
93
94
import org .opensearch .env .NodeEnvironment ;
94
95
import org .opensearch .env .ShardLockObtainFailedException ;
@@ -2155,13 +2156,12 @@ public String getClusterManagerName() {
2155
2156
* in the viaNode parameter. If viaNode isn't specified a random node will be picked to the send the request to.
2156
2157
*/
2157
2158
public String getClusterManagerName (@ Nullable String viaNode ) {
2158
- try {
2159
- Client client = viaNode != null ? client (viaNode ) : client ();
2160
- return client .admin ().cluster ().prepareState ().get ().getState ().nodes ().getClusterManagerNode ().getName ();
2161
- } catch (Exception e ) {
2162
- logger .warn ("Can't fetch cluster state" , e );
2163
- throw new RuntimeException ("Can't get cluster-manager node " + e .getMessage (), e );
2159
+ Client client = viaNode != null ? client (viaNode ) : client ();
2160
+ DiscoveryNode clusterManagerNode = client .admin ().cluster ().prepareState ().get ().getState ().nodes ().getClusterManagerNode ();
2161
+ if (clusterManagerNode == null ) {
2162
+ throw new ClusterManagerNotDiscoveredException ("Cluster manager node not discovered" );
2164
2163
}
2164
+ return clusterManagerNode .getName ();
2165
2165
}
2166
2166
2167
2167
/**
You can’t perform that action at this time.
0 commit comments