@@ -374,18 +374,58 @@ public void run() {
374
374
}
375
375
376
376
public void testGetConnectionInfo () throws Exception {
377
+ doTestGetConnectionInfo (false );
378
+ doTestGetConnectionInfo (true );
379
+ }
380
+
381
+ private void doTestGetConnectionInfo (boolean hasClusterCredentials ) throws Exception {
377
382
List <DiscoveryNode > knownNodes = new CopyOnWriteArrayList <>();
383
+ final Settings seedTransportSettings ;
384
+ if (hasClusterCredentials ) {
385
+ seedTransportSettings = Settings .builder ()
386
+ .put (RemoteClusterPortSettings .REMOTE_CLUSTER_SERVER_ENABLED .getKey (), "true" )
387
+ .put (RemoteClusterPortSettings .PORT .getKey (), "0" )
388
+ .build ();
389
+ } else {
390
+ seedTransportSettings = Settings .EMPTY ;
391
+ }
378
392
try (
379
- MockTransportService transport1 = startTransport ("seed_node" , knownNodes , Version .CURRENT , TransportVersion .CURRENT );
380
- MockTransportService transport2 = startTransport ("seed_node_1" , knownNodes , Version .CURRENT , TransportVersion .CURRENT );
381
- MockTransportService transport3 = startTransport ("discoverable_node" , knownNodes , Version .CURRENT , TransportVersion .CURRENT )
393
+ MockTransportService transport1 = startTransport (
394
+ "seed_node" ,
395
+ knownNodes ,
396
+ Version .CURRENT ,
397
+ TransportVersion .CURRENT ,
398
+ threadPool ,
399
+ seedTransportSettings
400
+ );
401
+ MockTransportService transport2 = startTransport (
402
+ "seed_node_1" ,
403
+ knownNodes ,
404
+ Version .CURRENT ,
405
+ TransportVersion .CURRENT ,
406
+ threadPool ,
407
+ seedTransportSettings
408
+ );
409
+ MockTransportService transport3 = startTransport (
410
+ "discoverable_node" ,
411
+ knownNodes ,
412
+ Version .CURRENT ,
413
+ TransportVersion .CURRENT ,
414
+ threadPool ,
415
+ seedTransportSettings
416
+ )
382
417
) {
383
418
DiscoveryNode node1 = transport1 .getLocalDiscoNode ();
384
419
DiscoveryNode node2 = transport3 .getLocalDiscoNode ();
385
420
DiscoveryNode node3 = transport2 .getLocalDiscoNode ();
386
- knownNodes .add (transport1 .getLocalDiscoNode ());
387
- knownNodes .add (transport3 .getLocalDiscoNode ());
388
- knownNodes .add (transport2 .getLocalDiscoNode ());
421
+ if (hasClusterCredentials ) {
422
+ node1 = node1 .withTransportAddress (transport1 .boundRemoteAccessAddress ().publishAddress ());
423
+ node2 = node2 .withTransportAddress (transport3 .boundRemoteAccessAddress ().publishAddress ());
424
+ node3 = node3 .withTransportAddress (transport2 .boundRemoteAccessAddress ().publishAddress ());
425
+ }
426
+ knownNodes .add (node1 );
427
+ knownNodes .add (node2 );
428
+ knownNodes .add (node3 );
389
429
Collections .shuffle (knownNodes , random ());
390
430
List <String > seedNodes = addresses (node3 , node1 , node2 );
391
431
Collections .shuffle (seedNodes , random ());
@@ -407,6 +447,15 @@ public void testGetConnectionInfo() throws Exception {
407
447
.put (buildSniffSettings (clusterAlias , seedNodes ))
408
448
.put (SniffConnectionStrategy .REMOTE_CONNECTIONS_PER_CLUSTER .getKey (), maxNumConnections )
409
449
.build ();
450
+ if (hasClusterCredentials ) {
451
+ settings = Settings .builder ()
452
+ .put (settings )
453
+ .put (
454
+ RemoteClusterService .REMOTE_CLUSTER_AUTHORIZATION .getConcreteSettingForNamespace (clusterAlias ).getKey (),
455
+ randomAlphaOfLength (20 )
456
+ )
457
+ .build ();
458
+ }
410
459
try (RemoteClusterConnection connection = new RemoteClusterConnection (settings , clusterAlias , service )) {
411
460
// test no nodes connected
412
461
RemoteConnectionInfo remoteConnectionInfo = assertSerialization (connection .getConnectionInfo ());
@@ -416,6 +465,7 @@ public void testGetConnectionInfo() throws Exception {
416
465
assertEquals (3 , sniffInfo .seedNodes .size ());
417
466
assertEquals (maxNumConnections , sniffInfo .maxConnectionsPerCluster );
418
467
assertEquals (clusterAlias , remoteConnectionInfo .clusterAlias );
468
+ assertEquals (hasClusterCredentials , remoteConnectionInfo .hasClusterCredentials );
419
469
}
420
470
}
421
471
}
@@ -436,22 +486,26 @@ public void testRemoteConnectionInfo() throws IOException {
436
486
modeInfo2 = new ProxyConnectionStrategy .ProxyModeInfo (remoteAddresses .get (0 ), serverName , 18 , 17 );
437
487
}
438
488
439
- RemoteConnectionInfo stats = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (30 ), false );
489
+ RemoteConnectionInfo stats = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (30 ), false , false );
440
490
assertSerialization (stats );
441
491
442
- RemoteConnectionInfo stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (30 ), true );
492
+ RemoteConnectionInfo stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (30 ), true , false );
443
493
assertSerialization (stats1 );
444
494
assertNotEquals (stats , stats1 );
445
495
446
- stats1 = new RemoteConnectionInfo ("test_cluster_1" , modeInfo1 , TimeValue .timeValueMinutes (30 ), false );
496
+ stats1 = new RemoteConnectionInfo ("test_cluster_1" , modeInfo1 , TimeValue .timeValueMinutes (30 ), false , false );
447
497
assertSerialization (stats1 );
448
498
assertNotEquals (stats , stats1 );
449
499
450
- stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (325 ), false );
500
+ stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (325 ), false , false );
451
501
assertSerialization (stats1 );
452
502
assertNotEquals (stats , stats1 );
453
503
454
- stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo2 , TimeValue .timeValueMinutes (30 ), false );
504
+ stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo2 , TimeValue .timeValueMinutes (30 ), false , false );
505
+ assertSerialization (stats1 );
506
+ assertNotEquals (stats , stats1 );
507
+
508
+ stats1 = new RemoteConnectionInfo ("test_cluster" , modeInfo1 , TimeValue .timeValueMinutes (30 ), false , true );
455
509
assertSerialization (stats1 );
456
510
assertNotEquals (stats , stats1 );
457
511
}
@@ -481,16 +535,23 @@ public void testRenderConnectionInfoXContent() throws IOException {
481
535
} else {
482
536
modeInfo = new ProxyConnectionStrategy .ProxyModeInfo (remoteAddresses .get (0 ), serverName , 18 , 16 );
483
537
}
484
-
485
- RemoteConnectionInfo stats = new RemoteConnectionInfo ("test_cluster" , modeInfo , TimeValue .timeValueMinutes (30 ), true );
538
+ final boolean hasClusterCredentials = randomBoolean ();
539
+
540
+ RemoteConnectionInfo stats = new RemoteConnectionInfo (
541
+ "test_cluster" ,
542
+ modeInfo ,
543
+ TimeValue .timeValueMinutes (30 ),
544
+ true ,
545
+ hasClusterCredentials
546
+ );
486
547
stats = assertSerialization (stats );
487
548
XContentBuilder builder = XContentFactory .jsonBuilder ();
488
549
builder .startObject ();
489
550
stats .toXContent (builder , null );
490
551
builder .endObject ();
491
552
492
553
if (sniff ) {
493
- assertEquals (XContentHelper .stripWhitespace ("""
554
+ assertEquals (XContentHelper .stripWhitespace (Strings . format ( """
494
555
{
495
556
"test_cluster": {
496
557
"connected": true,
@@ -499,11 +560,11 @@ public void testRenderConnectionInfoXContent() throws IOException {
499
560
"num_nodes_connected": 2,
500
561
"max_connections_per_cluster": 3,
501
562
"initial_connect_timeout": "30m",
502
- "skip_unavailable": true
563
+ "skip_unavailable": true%s
503
564
}
504
- }""" ), Strings .toString (builder ));
565
+ }""" , hasClusterCredentials ? ", \" cluster_credentials \" : \" ::es_redacted:: \" " : "" ) ), Strings .toString (builder ));
505
566
} else {
506
- assertEquals (XContentHelper .stripWhitespace ("""
567
+ assertEquals (XContentHelper .stripWhitespace (Strings . format ( """
507
568
{
508
569
"test_cluster": {
509
570
"connected": true,
@@ -513,9 +574,9 @@ public void testRenderConnectionInfoXContent() throws IOException {
513
574
"num_proxy_sockets_connected": 16,
514
575
"max_proxy_socket_connections": 18,
515
576
"initial_connect_timeout": "30m",
516
- "skip_unavailable": true
577
+ "skip_unavailable": true%s
517
578
}
518
- }""" ), Strings .toString (builder ));
579
+ }""" , hasClusterCredentials ? ", \" cluster_credentials \" : \" ::es_redacted:: \" " : "" ) ), Strings .toString (builder ));
519
580
}
520
581
}
521
582
0 commit comments