@@ -103,9 +103,8 @@ public boolean isCcrAllowed() {
103
103
* @param leaderIndex the name of the leader index
104
104
* @param onFailure the failure consumer
105
105
* @param consumer the consumer for supplying the leader index metadata and historyUUIDs of all leader shards
106
- * @param <T> the type of response the listener is waiting for
107
106
*/
108
- public < T > void checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUUIDs (
107
+ public void checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUUIDs (
109
108
final Client client ,
110
109
final String clusterAlias ,
111
110
final String leaderIndex ,
@@ -118,8 +117,8 @@ public <T> void checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUU
118
117
request .indices (leaderIndex );
119
118
checkRemoteClusterLicenseAndFetchClusterState (
120
119
client ,
121
- Collections .emptyMap (),
122
120
clusterAlias ,
121
+ client .getRemoteClusterClient (clusterAlias ),
123
122
request ,
124
123
onFailure ,
125
124
leaderClusterState -> {
@@ -151,22 +150,20 @@ public <T> void checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUU
151
150
*
152
151
* @param client the client
153
152
* @param clusterAlias the remote cluster alias
154
- * @param headers the headers to use for leader client
155
153
* @param request the cluster state request
156
154
* @param onFailure the failure consumer
157
155
* @param leaderClusterStateConsumer the leader cluster state consumer
158
156
*/
159
157
public void checkRemoteClusterLicenseAndFetchClusterState (
160
158
final Client client ,
161
- final Map <String , String > headers ,
162
159
final String clusterAlias ,
163
160
final ClusterStateRequest request ,
164
161
final Consumer <Exception > onFailure ,
165
162
final Consumer <ClusterState > leaderClusterStateConsumer ) {
166
163
checkRemoteClusterLicenseAndFetchClusterState (
167
164
client ,
168
- headers ,
169
165
clusterAlias ,
166
+ systemClient (client .getRemoteClusterClient (clusterAlias )),
170
167
request ,
171
168
onFailure ,
172
169
leaderClusterStateConsumer ,
@@ -182,18 +179,17 @@ public void checkRemoteClusterLicenseAndFetchClusterState(
182
179
*
183
180
* @param client the client
184
181
* @param clusterAlias the remote cluster alias
185
- * @param headers the headers to use for leader client
182
+ * @param leaderClient the leader client to use to execute cluster state API
186
183
* @param request the cluster state request
187
184
* @param onFailure the failure consumer
188
185
* @param leaderClusterStateConsumer the leader cluster state consumer
189
186
* @param nonCompliantLicense the supplier for when the license state of the remote cluster is non-compliant
190
187
* @param unknownLicense the supplier for when the license state of the remote cluster is unknown due to failure
191
- * @param <T> the type of response the listener is waiting for
192
188
*/
193
- private < T > void checkRemoteClusterLicenseAndFetchClusterState (
189
+ private void checkRemoteClusterLicenseAndFetchClusterState (
194
190
final Client client ,
195
- final Map <String , String > headers ,
196
191
final String clusterAlias ,
192
+ final Client leaderClient ,
197
193
final ClusterStateRequest request ,
198
194
final Consumer <Exception > onFailure ,
199
195
final Consumer <ClusterState > leaderClusterStateConsumer ,
@@ -207,7 +203,6 @@ private <T> void checkRemoteClusterLicenseAndFetchClusterState(
207
203
@ Override
208
204
public void onResponse (final RemoteClusterLicenseChecker .LicenseCheck licenseCheck ) {
209
205
if (licenseCheck .isSuccess ()) {
210
- final Client leaderClient = wrapClient (client .getRemoteClusterClient (clusterAlias ), headers );
211
206
final ActionListener <ClusterStateResponse > clusterStateListener =
212
207
ActionListener .wrap (s -> leaderClusterStateConsumer .accept (s .getState ()), onFailure );
213
208
// following an index in remote cluster, so use remote client to fetch leader index metadata
@@ -361,6 +356,21 @@ void doExecute(Action<Response> action, Request request, ActionListener<Response
361
356
}
362
357
}
363
358
359
+ private static Client systemClient (Client client ) {
360
+ final ThreadContext threadContext = client .threadPool ().getThreadContext ();
361
+ return new FilterClient (client ) {
362
+ @ Override
363
+ protected <Request extends ActionRequest , Response extends ActionResponse >
364
+ void doExecute (Action <Response > action , Request request , ActionListener <Response > listener ) {
365
+ final Supplier <ThreadContext .StoredContext > supplier = threadContext .newRestorableContext (false );
366
+ try (ThreadContext .StoredContext ignore = threadContext .stashContext ()) {
367
+ threadContext .markAsSystemContext ();
368
+ super .doExecute (action , request , new ContextPreservingActionListener <>(supplier , listener ));
369
+ }
370
+ }
371
+ };
372
+ }
373
+
364
374
private static ThreadContext .StoredContext stashWithHeaders (ThreadContext threadContext , Map <String , String > headers ) {
365
375
final ThreadContext .StoredContext storedContext = threadContext .stashContext ();
366
376
threadContext .copyHeaders (headers .entrySet ());
0 commit comments