@@ -97,6 +97,8 @@ public final class TaskInfo implements Writeable, ToXContentFragment {
9797
9898 private final TaskResourceStats resourceStats ;
9999
100+ private final Object searchSource ;
101+
100102 public TaskInfo (
101103 TaskId taskId ,
102104 String type ,
@@ -124,6 +126,7 @@ public TaskInfo(
124126 parentTaskId ,
125127 headers ,
126128 resourceStats ,
129+ null ,
127130 null
128131 );
129132 }
@@ -142,6 +145,40 @@ public TaskInfo(
142145 Map <String , String > headers ,
143146 TaskResourceStats resourceStats ,
144147 Long cancellationStartTime
148+ ) {
149+ this (
150+ taskId ,
151+ type ,
152+ action ,
153+ description ,
154+ status ,
155+ startTime ,
156+ runningTimeNanos ,
157+ cancellable ,
158+ cancelled ,
159+ parentTaskId ,
160+ headers ,
161+ resourceStats ,
162+ cancellationStartTime ,
163+ null
164+ );
165+ }
166+
167+ public TaskInfo (
168+ TaskId taskId ,
169+ String type ,
170+ String action ,
171+ String description ,
172+ Task .Status status ,
173+ long startTime ,
174+ long runningTimeNanos ,
175+ boolean cancellable ,
176+ boolean cancelled ,
177+ TaskId parentTaskId ,
178+ Map <String , String > headers ,
179+ TaskResourceStats resourceStats ,
180+ Long cancellationStartTime ,
181+ Object searchSource
145182 ) {
146183 if (cancellable == false && cancelled == true ) {
147184 throw new IllegalArgumentException ("task cannot be cancelled" );
@@ -159,6 +196,7 @@ public TaskInfo(
159196 this .headers = headers ;
160197 this .resourceStats = resourceStats ;
161198 this .cancellationStartTime = cancellationStartTime ;
199+ this .searchSource = searchSource ;
162200 }
163201
164202 /**
@@ -194,6 +232,8 @@ public TaskInfo(StreamInput in) throws IOException {
194232 } else {
195233 cancellationStartTime = null ;
196234 }
235+ // For now, searchSource is not serialized over the wire
236+ searchSource = null ;
197237 }
198238
199239 @ Override
@@ -300,6 +340,13 @@ public TaskResourceStats getResourceStats() {
300340 return resourceStats ;
301341 }
302342
343+ /**
344+ * Returns the search source for this task if this is a search task
345+ */
346+ public Object getSearchSource () {
347+ return searchSource ;
348+ }
349+
303350 @ Override
304351 public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
305352 builder .field ("node" , taskId .getNodeId ());
@@ -335,6 +382,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
335382 if (cancellationStartTime != null ) {
336383 builder .humanReadableField ("cancellation_time_millis" , "cancellation_time" , new TimeValue (cancellationStartTime ));
337384 }
385+ // if (searchSource != null && params.paramAsBoolean("detailed", false)) {
386+ if (searchSource != null ) {
387+ builder .field ("search_source" , searchSource );
388+ }
338389 return builder ;
339390 }
340391
@@ -367,18 +418,19 @@ public static TaskInfo fromXContent(XContentParser parser) {
367418 TaskId parentTaskId = parentTaskIdString == null ? TaskId .EMPTY_TASK_ID : new TaskId (parentTaskIdString );
368419 return new TaskInfo (
369420 id ,
370- type ,
371- action ,
372- description ,
373- status ,
374- startTime ,
375- runningTimeNanos ,
376- cancellable ,
377- cancelled ,
421+ type ,
422+ action ,
423+ description ,
424+ status ,
425+ startTime ,
426+ runningTimeNanos ,
427+ cancellable ,
428+ cancelled ,
378429 parentTaskId ,
379- headers ,
380- resourceStats ,
381- cancellationStartTime
430+ headers ,
431+ resourceStats ,
432+ cancellationStartTime ,
433+ null // searchSource not parsed from XContent yet
382434 );
383435 });
384436 static {
@@ -424,7 +476,8 @@ public boolean equals(Object obj) {
424476 && Objects .equals (status , other .status )
425477 && Objects .equals (headers , other .headers )
426478 && Objects .equals (resourceStats , other .resourceStats )
427- && Objects .equals (cancellationStartTime , other .cancellationStartTime );
479+ && Objects .equals (cancellationStartTime , other .cancellationStartTime )
480+ && Objects .equals (searchSource , other .searchSource );
428481 }
429482
430483 @ Override
@@ -442,7 +495,8 @@ public int hashCode() {
442495 status ,
443496 headers ,
444497 resourceStats ,
445- cancellationStartTime
498+ cancellationStartTime ,
499+ searchSource
446500 );
447501 }
448502}
0 commit comments