17
17
import org .elasticsearch .action .support .ActionTestUtils ;
18
18
import org .elasticsearch .action .support .IndicesOptions ;
19
19
import org .elasticsearch .action .support .PlainActionFuture ;
20
+ import org .elasticsearch .action .support .RefCountingRunnable ;
20
21
import org .elasticsearch .cluster .metadata .ProjectId ;
21
22
import org .elasticsearch .cluster .node .DiscoveryNode ;
22
23
import org .elasticsearch .cluster .node .DiscoveryNodeRole ;
@@ -1625,9 +1626,12 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionWithCorrectProfi
1625
1626
{
1626
1627
final MockSecureSettings secureSettings = new MockSecureSettings ();
1627
1628
secureSettings .setString ("cluster.remote.cluster_1.credentials" , randomAlphaOfLength (10 ));
1628
- final PlainActionFuture <Void > listener = new PlainActionFuture <>();
1629
+ final PlainActionFuture <RemoteClusterService . RemoteClusterConnectionStatus > listener = new PlainActionFuture <>();
1629
1630
final Settings settings = Settings .builder ().put (clusterSettings ).setSecureSettings (secureSettings ).build ();
1630
- service .updateRemoteClusterCredentials (() -> settings , listener );
1631
+ final var result = service .getRemoteClusterCredentialsManager ().updateClusterCredentials (settings );
1632
+ assertThat (result .addedClusterAliases (), equalTo (Set .of ("cluster_1" )));
1633
+ final var config = buildLinkedProjectConfig ("cluster_1" , Settings .EMPTY , settings );
1634
+ service .updateRemoteCluster (config , true , listener );
1631
1635
listener .actionGet (10 , TimeUnit .SECONDS );
1632
1636
}
1633
1637
@@ -1637,12 +1641,13 @@ public void testUpdateRemoteClusterCredentialsRebuildsConnectionWithCorrectProfi
1637
1641
);
1638
1642
1639
1643
{
1640
- final PlainActionFuture <Void > listener = new PlainActionFuture <>();
1641
- service .updateRemoteClusterCredentials (
1642
- // Settings without credentials constitute credentials removal
1643
- () -> clusterSettings ,
1644
- listener
1645
- );
1644
+ final PlainActionFuture <RemoteClusterService .RemoteClusterConnectionStatus > listener = new PlainActionFuture <>();
1645
+ // Settings without credentials constitute credentials removal
1646
+ final var result = service .getRemoteClusterCredentialsManager ().updateClusterCredentials (clusterSettings );
1647
+ assertThat (result .addedClusterAliases ().size (), equalTo (0 ));
1648
+ assertThat (result .removedClusterAliases (), equalTo (Set .of ("cluster_1" )));
1649
+ final var config = buildLinkedProjectConfig ("cluster_1" , Settings .EMPTY , clusterSettings );
1650
+ service .updateRemoteCluster (config , true , listener );
1646
1651
listener .actionGet (10 , TimeUnit .SECONDS );
1647
1652
}
1648
1653
@@ -1718,6 +1723,8 @@ public void testUpdateRemoteClusterCredentialsRebuildsMultipleConnectionsDespite
1718
1723
assertConnectionHasProfile (service .getRemoteClusterConnection (goodCluster ), "default" );
1719
1724
assertConnectionHasProfile (service .getRemoteClusterConnection (badCluster ), "default" );
1720
1725
expectThrows (NoSuchRemoteClusterException .class , () -> service .getRemoteClusterConnection (missingCluster ));
1726
+ final Set <String > aliases = Set .of (badCluster , goodCluster , missingCluster );
1727
+ final ActionListener <RemoteClusterService .RemoteClusterConnectionStatus > noop = ActionListener .noop ();
1721
1728
1722
1729
{
1723
1730
final MockSecureSettings secureSettings = new MockSecureSettings ();
@@ -1730,7 +1737,14 @@ public void testUpdateRemoteClusterCredentialsRebuildsMultipleConnectionsDespite
1730
1737
.put (cluster2Settings )
1731
1738
.setSecureSettings (secureSettings )
1732
1739
.build ();
1733
- service .updateRemoteClusterCredentials (() -> settings , listener );
1740
+ final var result = service .getRemoteClusterCredentialsManager ().updateClusterCredentials (settings );
1741
+ assertThat (result .addedClusterAliases (), equalTo (aliases ));
1742
+ try (var connectionRefs = new RefCountingRunnable (() -> listener .onResponse (null ))) {
1743
+ for (String alias : aliases ) {
1744
+ final var config = buildLinkedProjectConfig (alias , Settings .EMPTY , settings );
1745
+ service .updateRemoteCluster (config , true , ActionListener .releaseAfter (noop , connectionRefs .acquire ()));
1746
+ }
1747
+ }
1734
1748
listener .actionGet (10 , TimeUnit .SECONDS );
1735
1749
}
1736
1750
@@ -1747,11 +1761,16 @@ public void testUpdateRemoteClusterCredentialsRebuildsMultipleConnectionsDespite
1747
1761
{
1748
1762
final PlainActionFuture <Void > listener = new PlainActionFuture <>();
1749
1763
final Settings settings = Settings .builder ().put (cluster1Settings ).put (cluster2Settings ).build ();
1750
- service .updateRemoteClusterCredentials (
1751
- // Settings without credentials constitute credentials removal
1752
- () -> settings ,
1753
- listener
1754
- );
1764
+ // Settings without credentials constitute credentials removal
1765
+ final var result = service .getRemoteClusterCredentialsManager ().updateClusterCredentials (settings );
1766
+ assertThat (result .addedClusterAliases ().size (), equalTo (0 ));
1767
+ assertThat (result .removedClusterAliases (), equalTo (aliases ));
1768
+ try (var connectionRefs = new RefCountingRunnable (() -> listener .onResponse (null ))) {
1769
+ for (String alias : aliases ) {
1770
+ final var config = buildLinkedProjectConfig (alias , Settings .EMPTY , settings );
1771
+ service .updateRemoteCluster (config , true , ActionListener .releaseAfter (noop , connectionRefs .acquire ()));
1772
+ }
1773
+ }
1755
1774
listener .actionGet (10 , TimeUnit .SECONDS );
1756
1775
}
1757
1776
@@ -1828,6 +1847,12 @@ public void testLogsConnectionResult() throws IOException {
1828
1847
}
1829
1848
}
1830
1849
1850
+ @ FixForMultiProject (description = "Refactor to add the linked project ID associated with the alias." )
1851
+ private LinkedProjectConfig buildLinkedProjectConfig (String alias , Settings staticSettings , Settings newSettings ) {
1852
+ final var mergedSettings = Settings .builder ().put (staticSettings , false ).put (newSettings , false ).build ();
1853
+ return RemoteClusterSettings .toConfig (projectResolver .getProjectId (), ProjectId .DEFAULT , alias , mergedSettings );
1854
+ }
1855
+
1831
1856
private void updateRemoteCluster (
1832
1857
RemoteClusterService service ,
1833
1858
String alias ,
@@ -1846,10 +1871,7 @@ private void updateRemoteCluster(
1846
1871
Settings newSettings ,
1847
1872
ActionListener <RemoteClusterService .RemoteClusterConnectionStatus > listener
1848
1873
) {
1849
- final var mergedSettings = Settings .builder ().put (settings , false ).put (newSettings , false ).build ();
1850
- @ FixForMultiProject (description = "Refactor to add the linked project ID associated with the alias." )
1851
- final var config = RemoteClusterSettings .toConfig (projectResolver .getProjectId (), ProjectId .DEFAULT , alias , mergedSettings );
1852
- service .updateRemoteCluster (config , false , listener );
1874
+ service .updateRemoteCluster (buildLinkedProjectConfig (alias , settings , newSettings ), false , listener );
1853
1875
}
1854
1876
1855
1877
private void initializeRemoteClusters (RemoteClusterService remoteClusterService ) {
0 commit comments