25
25
import org .elasticsearch .action .support .ContextPreservingActionListener ;
26
26
import org .elasticsearch .cluster .node .DiscoveryNode ;
27
27
import org .elasticsearch .cluster .node .DiscoveryNodes ;
28
- import org .elasticsearch .common .collect .Tuple ;
29
28
import org .elasticsearch .common .io .stream .StreamInput ;
30
29
import org .elasticsearch .common .settings .Settings ;
31
30
import org .elasticsearch .common .unit .TimeValue ;
36
35
import java .io .Closeable ;
37
36
import java .io .IOException ;
38
37
import java .util .Collections ;
39
- import java .util .List ;
40
38
import java .util .function .Function ;
41
- import java .util .function .Predicate ;
42
- import java .util .function .Supplier ;
43
- import java .util .stream .Collectors ;
44
39
45
40
/**
46
41
* Represents a connection to a single remote cluster. In contrast to a local cluster a remote cluster is not joined such that the
@@ -61,46 +56,29 @@ final class RemoteClusterConnection implements Closeable {
61
56
private final RemoteConnectionManager remoteConnectionManager ;
62
57
private final RemoteConnectionStrategy connectionStrategy ;
63
58
private final String clusterAlias ;
64
- private final int maxNumRemoteConnections ;
65
59
private final ThreadPool threadPool ;
66
- private final List <Tuple <String , Supplier <DiscoveryNode >>> seedNodes ;
67
- private final String proxyAddress ;
68
60
private volatile boolean skipUnavailable ;
69
61
private final TimeValue initialConnectionTimeout ;
70
62
71
63
/**
72
64
* Creates a new {@link RemoteClusterConnection}
73
65
* @param settings the nodes settings object
74
66
* @param clusterAlias the configured alias of the cluster to connect to
75
- * @param seedNodes a list of seed nodes to discover eligible nodes from
76
67
* @param transportService the local nodes transport service
77
- * @param maxNumRemoteConnections the maximum number of connections to the remote cluster
78
- * @param nodePredicate a predicate to filter eligible remote nodes to connect to
79
- * @param proxyAddress the proxy address
80
- * @param connectionProfile the connection profile to use
81
68
*/
82
- RemoteClusterConnection (Settings settings , String clusterAlias , List <Tuple <String , Supplier <DiscoveryNode >>> seedNodes ,
83
- TransportService transportService , int maxNumRemoteConnections , Predicate <DiscoveryNode > nodePredicate ,
84
- String proxyAddress , ConnectionProfile connectionProfile ) {
85
- this (settings , clusterAlias , seedNodes , transportService , maxNumRemoteConnections , nodePredicate , proxyAddress ,
86
- createConnectionManager (connectionProfile , transportService ));
69
+ RemoteClusterConnection (Settings settings , String clusterAlias , TransportService transportService ) {
70
+ this (settings , clusterAlias , transportService ,
71
+ createConnectionManager (buildConnectionProfileFromSettings (settings , clusterAlias ), transportService ));
87
72
}
88
73
89
- // Public for tests to pass a StubbableConnectionManager
90
- RemoteClusterConnection (Settings settings , String clusterAlias , List <Tuple <String , Supplier <DiscoveryNode >>> seedNodes ,
91
- TransportService transportService , int maxNumRemoteConnections , Predicate <DiscoveryNode > nodePredicate ,
92
- String proxyAddress , ConnectionManager connectionManager ) {
74
+ RemoteClusterConnection (Settings settings , String clusterAlias , TransportService transportService ,
75
+ ConnectionManager connectionManager ) {
93
76
this .transportService = transportService ;
94
- this .maxNumRemoteConnections = maxNumRemoteConnections ;
95
77
this .clusterAlias = clusterAlias ;
96
78
this .remoteConnectionManager = new RemoteConnectionManager (clusterAlias , connectionManager );
97
- this .connectionStrategy = new SniffConnectionStrategy (clusterAlias , transportService , remoteConnectionManager ,
98
- proxyAddress , maxNumRemoteConnections , nodePredicate ,
99
- Collections .unmodifiableList (seedNodes ));
79
+ this .connectionStrategy = new SniffConnectionStrategy (clusterAlias , transportService , remoteConnectionManager , settings );
100
80
// we register the transport service here as a listener to make sure we notify handlers on disconnect etc.
101
81
connectionManager .addListener (transportService );
102
- this .seedNodes = Collections .unmodifiableList (seedNodes );
103
- this .proxyAddress = proxyAddress ;
104
82
this .skipUnavailable = RemoteClusterService .REMOTE_CLUSTER_SKIP_UNAVAILABLE
105
83
.getConcreteSettingForNamespace (clusterAlias ).get (settings );
106
84
this .threadPool = transportService .threadPool ;
@@ -125,11 +103,11 @@ boolean isSkipUnavailable() {
125
103
* Ensures that this cluster is connected. If the cluster is connected this operation
126
104
* will invoke the listener immediately.
127
105
*/
128
- void ensureConnected (ActionListener <Void > voidActionListener ) {
106
+ void ensureConnected (ActionListener <Void > listener ) {
129
107
if (remoteConnectionManager .size () == 0 ) {
130
- connectionStrategy .connect (voidActionListener );
108
+ connectionStrategy .connect (listener );
131
109
} else {
132
- voidActionListener .onResponse (null );
110
+ listener .onResponse (null );
133
111
}
134
112
}
135
113
@@ -215,14 +193,6 @@ public boolean isClosed() {
215
193
return connectionStrategy .isClosed ();
216
194
}
217
195
218
- List <Tuple <String , Supplier <DiscoveryNode >>> getSeedNodes () {
219
- return seedNodes ;
220
- }
221
-
222
- String getProxyAddress () {
223
- return proxyAddress ;
224
- }
225
-
226
196
// for testing only
227
197
boolean assertNoRunningConnections () {
228
198
return connectionStrategy .assertNoRunningConnections ();
@@ -236,13 +206,24 @@ boolean isNodeConnected(final DiscoveryNode node) {
236
206
* Get the information about remote nodes to be rendered on {@code _remote/info} requests.
237
207
*/
238
208
public RemoteConnectionInfo getConnectionInfo () {
239
- return new RemoteConnectionInfo (
209
+ if (connectionStrategy instanceof SniffConnectionStrategy ) {
210
+ SniffConnectionStrategy sniffStrategy = (SniffConnectionStrategy ) this .connectionStrategy ;
211
+ return new RemoteConnectionInfo (
212
+ clusterAlias ,
213
+ sniffStrategy .getSeedNodes (),
214
+ sniffStrategy .getMaxConnections (),
215
+ getNumNodesConnected (),
216
+ initialConnectionTimeout ,
217
+ skipUnavailable );
218
+ } else {
219
+ return new RemoteConnectionInfo (
240
220
clusterAlias ,
241
- seedNodes . stream (). map ( Tuple :: v1 ). collect ( Collectors . toList () ),
242
- maxNumRemoteConnections ,
221
+ Collections . emptyList ( ),
222
+ 0 ,
243
223
getNumNodesConnected (),
244
224
initialConnectionTimeout ,
245
225
skipUnavailable );
226
+ }
246
227
}
247
228
248
229
int getNumNodesConnected () {
@@ -256,4 +237,22 @@ private static ConnectionManager createConnectionManager(ConnectionProfile conne
256
237
ConnectionManager getConnectionManager () {
257
238
return remoteConnectionManager .getConnectionManager ();
258
239
}
240
+
241
+ public boolean shouldRebuildConnection (Settings newSettings ) {
242
+ return connectionStrategy .shouldRebuildConnection (newSettings );
243
+ }
244
+
245
+ static ConnectionProfile buildConnectionProfileFromSettings (Settings settings , String clusterName ) {
246
+ return new ConnectionProfile .Builder ()
247
+ .setConnectTimeout (TransportSettings .CONNECT_TIMEOUT .get (settings ))
248
+ .setHandshakeTimeout (TransportSettings .CONNECT_TIMEOUT .get (settings ))
249
+ .addConnections (6 , TransportRequestOptions .Type .REG , TransportRequestOptions .Type .PING ) // TODO make this configurable?
250
+ // we don't want this to be used for anything else but search
251
+ .addConnections (0 , TransportRequestOptions .Type .BULK ,
252
+ TransportRequestOptions .Type .STATE ,
253
+ TransportRequestOptions .Type .RECOVERY )
254
+ .setCompressionEnabled (RemoteClusterService .REMOTE_CLUSTER_COMPRESS .getConcreteSettingForNamespace (clusterName ).get (settings ))
255
+ .setPingInterval (RemoteClusterService .REMOTE_CLUSTER_PING_SCHEDULE .getConcreteSettingForNamespace (clusterName ).get (settings ))
256
+ .build ();
257
+ }
259
258
}
0 commit comments