20
20
import org .elasticsearch .common .io .stream .StreamInput ;
21
21
import org .elasticsearch .common .io .stream .StreamOutput ;
22
22
import org .elasticsearch .common .io .stream .Writeable ;
23
- import org .elasticsearch .common .util .concurrent .ThreadContext ;
24
23
import org .elasticsearch .common .xcontent .ObjectParser ;
25
24
import org .elasticsearch .common .xcontent .ToXContent ;
26
25
import org .elasticsearch .common .xcontent .XContentBuilder ;
@@ -293,7 +292,7 @@ public Builder deleteJob(String jobId, PersistentTasksCustomMetaData tasks) {
293
292
return this ;
294
293
}
295
294
296
- public Builder putDatafeed (DatafeedConfig datafeedConfig , ThreadContext threadContext ) {
295
+ public Builder putDatafeed (DatafeedConfig datafeedConfig , Map < String , String > headers ) {
297
296
if (datafeeds .containsKey (datafeedConfig .getId ())) {
298
297
throw new ResourceAlreadyExistsException ("A datafeed with id [" + datafeedConfig .getId () + "] already exists" );
299
298
}
@@ -302,13 +301,13 @@ public Builder putDatafeed(DatafeedConfig datafeedConfig, ThreadContext threadCo
302
301
Job job = jobs .get (jobId );
303
302
DatafeedJobValidator .validate (datafeedConfig , job );
304
303
305
- if (threadContext != null ) {
304
+ if (headers . isEmpty () == false ) {
306
305
// Adjust the request, adding security headers from the current thread context
307
306
DatafeedConfig .Builder builder = new DatafeedConfig .Builder (datafeedConfig );
308
- Map <String , String > headers = threadContext . getHeaders () .entrySet ().stream ()
307
+ Map <String , String > securityHeaders = headers .entrySet ().stream ()
309
308
.filter (e -> ClientHelper .SECURITY_HEADER_FILTERS .contains (e .getKey ()))
310
309
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
311
- builder .setHeaders (headers );
310
+ builder .setHeaders (securityHeaders );
312
311
datafeedConfig = builder .build ();
313
312
}
314
313
@@ -328,15 +327,15 @@ private void checkJobIsAvailableForDatafeed(String jobId) {
328
327
}
329
328
}
330
329
331
- public Builder updateDatafeed (DatafeedUpdate update , PersistentTasksCustomMetaData persistentTasks , ThreadContext threadContext ) {
330
+ public Builder updateDatafeed (DatafeedUpdate update , PersistentTasksCustomMetaData persistentTasks , Map < String , String > headers ) {
332
331
String datafeedId = update .getId ();
333
332
DatafeedConfig oldDatafeedConfig = datafeeds .get (datafeedId );
334
333
if (oldDatafeedConfig == null ) {
335
334
throw ExceptionsHelper .missingDatafeedException (datafeedId );
336
335
}
337
336
checkDatafeedIsStopped (() -> Messages .getMessage (Messages .DATAFEED_CANNOT_UPDATE_IN_CURRENT_STATE , datafeedId ,
338
337
DatafeedState .STARTED ), datafeedId , persistentTasks );
339
- DatafeedConfig newDatafeedConfig = update .apply (oldDatafeedConfig , threadContext );
338
+ DatafeedConfig newDatafeedConfig = update .apply (oldDatafeedConfig , headers );
340
339
if (newDatafeedConfig .getJobId ().equals (oldDatafeedConfig .getJobId ()) == false ) {
341
340
checkJobIsAvailableForDatafeed (newDatafeedConfig .getJobId ());
342
341
}
0 commit comments