Skip to content

Commit 3854e38

Browse files
Move RCS settings to RemoteClusterSettings class (#133092)
Relocates all Settings from RemoteClusterService to a RemoteClusterSettings class. Note that a RemoteClusterSettingsTests class already exists that tests some of these settings. This is one part in a series of refactors to use a LinkedProjectConfig data class in RemoteClusterService and its related classes. Relates: ES-12656, ES-12569
1 parent 8ae8a10 commit 3854e38

File tree

18 files changed

+196
-175
lines changed

18 files changed

+196
-175
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.elasticsearch.transport.AbstractTransportRequest;
6161
import org.elasticsearch.transport.RemoteClusterConnection;
6262
import org.elasticsearch.transport.RemoteClusterService;
63+
import org.elasticsearch.transport.RemoteClusterSettings;
6364
import org.elasticsearch.transport.RemoteConnectionInfo;
6465
import org.elasticsearch.transport.TransportService;
6566
import org.elasticsearch.transport.Transports;
@@ -493,7 +494,7 @@ void start(Task task, Collection<String> remotes, ActionListener<Map<String, Rem
493494
RemoteClusterStats makeRemoteClusterStats(String clusterAlias) {
494495
RemoteClusterConnection remoteConnection = remoteClusterService.getRemoteClusterConnection(clusterAlias);
495496
RemoteConnectionInfo remoteConnectionInfo = remoteConnection.getConnectionInfo();
496-
var compression = RemoteClusterService.REMOTE_CLUSTER_COMPRESS.getConcreteSettingForNamespace(clusterAlias).get(settings);
497+
var compression = RemoteClusterSettings.REMOTE_CLUSTER_COMPRESS.getConcreteSettingForNamespace(clusterAlias).get(settings);
497498
return new RemoteClusterStats(
498499
remoteConnectionInfo.getModeInfo().modeName(),
499500
remoteConnection.isSkipUnavailable(),

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
import org.elasticsearch.threadpool.ThreadPool;
135135
import org.elasticsearch.transport.ProxyConnectionStrategy;
136136
import org.elasticsearch.transport.RemoteClusterPortSettings;
137-
import org.elasticsearch.transport.RemoteClusterService;
137+
import org.elasticsearch.transport.RemoteClusterSettings;
138138
import org.elasticsearch.transport.RemoteConnectionStrategy;
139139
import org.elasticsearch.transport.SniffConnectionStrategy;
140140
import org.elasticsearch.transport.TransportService;
@@ -366,13 +366,13 @@ public void apply(Settings value, Settings current, Settings previous) {
366366
SearchService.DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS,
367367
TransportSearchAction.SHARD_COUNT_LIMIT_SETTING,
368368
TransportSearchAction.DEFAULT_PRE_FILTER_SHARD_SIZE,
369-
RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE,
369+
RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE,
370370
SniffConnectionStrategy.REMOTE_CONNECTIONS_PER_CLUSTER,
371-
RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING,
372-
RemoteClusterService.REMOTE_NODE_ATTRIBUTE,
373-
RemoteClusterService.REMOTE_CLUSTER_PING_SCHEDULE,
374-
RemoteClusterService.REMOTE_CLUSTER_COMPRESS,
375-
RemoteClusterService.REMOTE_CLUSTER_COMPRESSION_SCHEME,
371+
RemoteClusterSettings.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING,
372+
RemoteClusterSettings.REMOTE_NODE_ATTRIBUTE,
373+
RemoteClusterSettings.REMOTE_CLUSTER_PING_SCHEDULE,
374+
RemoteClusterSettings.REMOTE_CLUSTER_COMPRESS,
375+
RemoteClusterSettings.REMOTE_CLUSTER_COMPRESSION_SCHEME,
376376
RemoteConnectionStrategy.REMOTE_CONNECTION_MODE,
377377
ProxyConnectionStrategy.PROXY_ADDRESS,
378378
ProxyConnectionStrategy.REMOTE_SOCKET_CONNECTIONS,
@@ -605,7 +605,7 @@ public void apply(Settings value, Settings current, Settings previous) {
605605
SimulatePipelineTransportAction.INGEST_NODE_TRANSPORT_ACTION_TIMEOUT,
606606
WriteAckDelay.WRITE_ACK_DELAY_INTERVAL,
607607
WriteAckDelay.WRITE_ACK_DELAY_RANDOMNESS_BOUND,
608-
RemoteClusterService.REMOTE_CLUSTER_CREDENTIALS,
608+
RemoteClusterSettings.REMOTE_CLUSTER_CREDENTIALS,
609609
RemoteClusterPortSettings.REMOTE_CLUSTER_SERVER_ENABLED,
610610
RemoteClusterPortSettings.HOST,
611611
RemoteClusterPortSettings.PUBLISH_HOST,

server/src/main/java/org/elasticsearch/transport/RemoteClusterAware.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ void validateAndUpdateRemoteCluster(String clusterAlias, Settings settings) {
229229
*/
230230
public void listenForUpdates(ClusterSettings clusterSettings) {
231231
List<Setting.AffixSetting<?>> remoteClusterSettings = List.of(
232-
RemoteClusterService.REMOTE_CLUSTER_COMPRESS,
233-
RemoteClusterService.REMOTE_CLUSTER_PING_SCHEDULE,
232+
RemoteClusterSettings.REMOTE_CLUSTER_COMPRESS,
233+
RemoteClusterSettings.REMOTE_CLUSTER_PING_SCHEDULE,
234234
RemoteConnectionStrategy.REMOTE_CONNECTION_MODE,
235235
SniffConnectionStrategy.REMOTE_CLUSTERS_PROXY,
236236
SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS,

server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* remote case we only connect to a subset of the nodes in the cluster in an uni-directional fashion.
3838
*
3939
* This class also handles the discovery of nodes from the remote cluster. The initial list of seed nodes is only used to discover all nodes
40-
* in the remote cluster and connects to all eligible nodes, for details see {@link RemoteClusterService#REMOTE_NODE_ATTRIBUTE}.
40+
* in the remote cluster and connects to all eligible nodes, for details see {@link RemoteClusterSettings#REMOTE_NODE_ATTRIBUTE}.
4141
*
4242
* In the case of a disconnection, this class will issue a re-connect task to establish at most
4343
* {@link SniffConnectionStrategy#REMOTE_CONNECTIONS_PER_CLUSTER} until either all eligible nodes are exhausted or the maximum number of
@@ -83,10 +83,10 @@ public final class RemoteClusterConnection implements Closeable {
8383
this.connectionStrategy = RemoteConnectionStrategy.buildStrategy(clusterAlias, transportService, remoteConnectionManager, settings);
8484
// we register the transport service here as a listener to make sure we notify handlers on disconnect etc.
8585
this.remoteConnectionManager.addListener(transportService);
86-
this.skipUnavailable = RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace(clusterAlias)
86+
this.skipUnavailable = RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace(clusterAlias)
8787
.get(settings);
8888
this.threadPool = transportService.threadPool;
89-
initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
89+
initialConnectionTimeout = RemoteClusterSettings.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
9090
}
9191

9292
/**

server/src/main/java/org/elasticsearch/transport/RemoteClusterCredentialsManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.Map;
2222
import java.util.Set;
2323

24-
import static org.elasticsearch.transport.RemoteClusterService.REMOTE_CLUSTER_CREDENTIALS;
24+
import static org.elasticsearch.transport.RemoteClusterSettings.REMOTE_CLUSTER_CREDENTIALS;
2525

2626
public class RemoteClusterCredentialsManager {
2727
private static final Logger logger = LogManager.getLogger(RemoteClusterCredentialsManager.class);

server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

Lines changed: 9 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import org.elasticsearch.cluster.project.ProjectResolver;
2929
import org.elasticsearch.common.Strings;
3030
import org.elasticsearch.common.settings.ClusterSettings;
31-
import org.elasticsearch.common.settings.SecureSetting;
32-
import org.elasticsearch.common.settings.SecureString;
33-
import org.elasticsearch.common.settings.Setting;
3431
import org.elasticsearch.common.settings.Settings;
3532
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
3633
import org.elasticsearch.common.util.concurrent.EsExecutors;
@@ -43,9 +40,7 @@
4340

4441
import java.io.Closeable;
4542
import java.io.IOException;
46-
import java.util.Arrays;
4743
import java.util.HashMap;
48-
import java.util.Iterator;
4944
import java.util.List;
5045
import java.util.Map;
5146
import java.util.Set;
@@ -59,9 +54,6 @@
5954
import java.util.stream.Collectors;
6055
import java.util.stream.Stream;
6156

62-
import static org.elasticsearch.common.settings.Setting.boolSetting;
63-
import static org.elasticsearch.common.settings.Setting.enumSetting;
64-
import static org.elasticsearch.common.settings.Setting.timeSetting;
6557
import static org.elasticsearch.transport.RemoteClusterPortSettings.REMOTE_CLUSTER_SERVER_ENABLED;
6658

6759
/**
@@ -75,76 +67,6 @@ public final class RemoteClusterService extends RemoteClusterAware
7567

7668
private static final Logger logger = LogManager.getLogger(RemoteClusterService.class);
7769

78-
/**
79-
* The initial connect timeout for remote cluster connections
80-
*/
81-
public static final Setting<TimeValue> REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING = Setting.positiveTimeSetting(
82-
"cluster.remote.initial_connect_timeout",
83-
TimeValue.timeValueSeconds(30),
84-
Setting.Property.NodeScope
85-
);
86-
87-
/**
88-
* The name of a node attribute to select nodes that should be connected to in the remote cluster.
89-
* For instance a node can be configured with {@code node.attr.gateway: true} in order to be eligible as a gateway node between
90-
* clusters. In that case {@code cluster.remote.node.attr: gateway} can be used to filter out other nodes in the remote cluster.
91-
* The value of the setting is expected to be a boolean, {@code true} for nodes that can become gateways, {@code false} otherwise.
92-
*/
93-
public static final Setting<String> REMOTE_NODE_ATTRIBUTE = Setting.simpleString(
94-
"cluster.remote.node.attr",
95-
Setting.Property.NodeScope
96-
);
97-
98-
public static final Setting.AffixSetting<Boolean> REMOTE_CLUSTER_SKIP_UNAVAILABLE = Setting.affixKeySetting(
99-
"cluster.remote.",
100-
"skip_unavailable",
101-
(ns, key) -> boolSetting(key, true, new RemoteConnectionEnabled<>(ns, key), Setting.Property.Dynamic, Setting.Property.NodeScope)
102-
);
103-
104-
public static final Setting.AffixSetting<TimeValue> REMOTE_CLUSTER_PING_SCHEDULE = Setting.affixKeySetting(
105-
"cluster.remote.",
106-
"transport.ping_schedule",
107-
(ns, key) -> timeSetting(
108-
key,
109-
TransportSettings.PING_SCHEDULE,
110-
new RemoteConnectionEnabled<>(ns, key),
111-
Setting.Property.Dynamic,
112-
Setting.Property.NodeScope
113-
)
114-
);
115-
116-
public static final Setting.AffixSetting<Compression.Enabled> REMOTE_CLUSTER_COMPRESS = Setting.affixKeySetting(
117-
"cluster.remote.",
118-
"transport.compress",
119-
(ns, key) -> enumSetting(
120-
Compression.Enabled.class,
121-
key,
122-
TransportSettings.TRANSPORT_COMPRESS,
123-
new RemoteConnectionEnabled<>(ns, key),
124-
Setting.Property.Dynamic,
125-
Setting.Property.NodeScope
126-
)
127-
);
128-
129-
public static final Setting.AffixSetting<Compression.Scheme> REMOTE_CLUSTER_COMPRESSION_SCHEME = Setting.affixKeySetting(
130-
"cluster.remote.",
131-
"transport.compression_scheme",
132-
(ns, key) -> enumSetting(
133-
Compression.Scheme.class,
134-
key,
135-
TransportSettings.TRANSPORT_COMPRESSION_SCHEME,
136-
new RemoteConnectionEnabled<>(ns, key),
137-
Setting.Property.Dynamic,
138-
Setting.Property.NodeScope
139-
)
140-
);
141-
142-
public static final Setting.AffixSetting<SecureString> REMOTE_CLUSTER_CREDENTIALS = Setting.affixKeySetting(
143-
"cluster.remote.",
144-
"credentials",
145-
key -> SecureSetting.secureString(key, null)
146-
);
147-
14870
public static final String REMOTE_CLUSTER_HANDSHAKE_ACTION_NAME = "cluster:internal/remote_cluster/handshake";
14971

15072
private final boolean isRemoteClusterClient;
@@ -343,7 +265,11 @@ public RemoteClusterConnection getRemoteClusterConnection(String cluster) {
343265
@Override
344266
public void listenForUpdates(ClusterSettings clusterSettings) {
345267
super.listenForUpdates(clusterSettings);
346-
clusterSettings.addAffixUpdateConsumer(REMOTE_CLUSTER_SKIP_UNAVAILABLE, this::updateSkipUnavailable, (alias, value) -> {});
268+
clusterSettings.addAffixUpdateConsumer(
269+
RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE,
270+
this::updateSkipUnavailable,
271+
(alias, value) -> {}
272+
);
347273
}
348274

349275
private synchronized void updateSkipUnavailable(String clusterAlias, Boolean skipUnavailable) {
@@ -535,7 +461,7 @@ enum RemoteClusterConnectionStatus {
535461
void initializeRemoteClusters() {
536462
@FixForMultiProject(description = "Refactor for initializing connections to linked projects for each origin project supported.")
537463
final var projectId = projectResolver.getProjectId();
538-
final TimeValue timeValue = REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
464+
final TimeValue timeValue = RemoteClusterSettings.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
539465
final PlainActionFuture<Void> future = new PlainActionFuture<>();
540466
Set<String> enabledClusters = RemoteClusterAware.getEnabledRemoteClusters(settings);
541467

@@ -630,9 +556,9 @@ public enum DisconnectedStrategy {
630556
FAIL_IF_DISCONNECTED,
631557

632558
/**
633-
* Behave according to the {@link #REMOTE_CLUSTER_SKIP_UNAVAILABLE} setting for this remote cluster: if this setting is
634-
* {@code false} (the default) then behave like {@link #RECONNECT_IF_DISCONNECTED}, but if it is {@code true} then behave like
635-
* {@link #FAIL_IF_DISCONNECTED}.
559+
* Behave according to the {@link RemoteClusterSettings#REMOTE_CLUSTER_SKIP_UNAVAILABLE} setting for this remote cluster: if this
560+
* setting is {@code false} (the default) then behave like {@link #RECONNECT_IF_DISCONNECTED}, but if it is {@code true} then behave
561+
* like {@link #FAIL_IF_DISCONNECTED}.
636562
*/
637563
RECONNECT_UNLESS_SKIP_UNAVAILABLE
638564
}
@@ -737,39 +663,4 @@ private Map<String, RemoteClusterConnection> getConnectionsMapForProject(Project
737663
assert ProjectId.DEFAULT.equals(projectId) : "Only the default project ID should be used when multiple projects are not supported";
738664
return remoteClusters.get(projectId);
739665
}
740-
741-
private static class RemoteConnectionEnabled<T> implements Setting.Validator<T> {
742-
743-
private final String clusterAlias;
744-
private final String key;
745-
746-
private RemoteConnectionEnabled(String clusterAlias, String key) {
747-
this.clusterAlias = clusterAlias;
748-
this.key = key;
749-
}
750-
751-
@Override
752-
public void validate(T value) {}
753-
754-
@Override
755-
public void validate(T value, Map<Setting<?>, Object> settings, boolean isPresent) {
756-
if (isPresent && RemoteConnectionStrategy.isConnectionEnabled(clusterAlias, settings) == false) {
757-
throw new IllegalArgumentException("Cannot configure setting [" + key + "] if remote cluster is not enabled.");
758-
}
759-
}
760-
761-
@Override
762-
public Iterator<Setting<?>> settings() {
763-
return Stream.concat(
764-
Stream.of(RemoteConnectionStrategy.REMOTE_CONNECTION_MODE.getConcreteSettingForNamespace(clusterAlias)),
765-
settingsStream()
766-
).iterator();
767-
}
768-
769-
private Stream<Setting<?>> settingsStream() {
770-
return Arrays.stream(RemoteConnectionStrategy.ConnectionStrategy.values())
771-
.flatMap(strategy -> strategy.getEnablementSettings().get())
772-
.map(as -> as.getConcreteSettingForNamespace(clusterAlias));
773-
}
774-
};
775666
}

0 commit comments

Comments
 (0)