2828import org .elasticsearch .xpack .core .XPackPlugin ;
2929import org .elasticsearch .xpack .core .ml .MlTasks ;
3030import org .elasticsearch .xpack .core .ml .datafeed .DatafeedConfig ;
31+ import org .elasticsearch .xpack .core .ml .job .config .Job ;
3132import org .elasticsearch .xpack .core .ml .job .messages .Messages ;
3233import org .elasticsearch .xpack .core .ml .utils .ExceptionsHelper ;
3334
3435import java .io .IOException ;
36+ import java .util .Collections ;
37+ import java .util .List ;
3538import java .util .Objects ;
3639import java .util .function .LongSupplier ;
3740
@@ -147,6 +150,8 @@ public boolean equals(Object obj) {
147150
148151 public static class DatafeedParams implements XPackPlugin .XPackPersistentTaskParams {
149152
153+ public static final ParseField INDICES = new ParseField ("indices" );
154+
150155 public static ObjectParser <DatafeedParams , Void > PARSER = new ObjectParser <>(MlTasks .DATAFEED_TASK_NAME , true , DatafeedParams ::new );
151156 static {
152157 PARSER .declareString ((params , datafeedId ) -> params .datafeedId = datafeedId , DatafeedConfig .ID );
@@ -155,6 +160,8 @@ public static class DatafeedParams implements XPackPlugin.XPackPersistentTaskPar
155160 PARSER .declareString (DatafeedParams ::setEndTime , END_TIME );
156161 PARSER .declareString ((params , val ) ->
157162 params .setTimeout (TimeValue .parseTimeValue (val , TIMEOUT .getPreferredName ())), TIMEOUT );
163+ PARSER .declareString (DatafeedParams ::setJobId , Job .ID );
164+ PARSER .declareStringArray (DatafeedParams ::setDatafeedIndices , INDICES );
158165 }
159166
160167 static long parseDateOrThrow (String date , ParseField paramName , LongSupplier now ) {
@@ -194,6 +201,10 @@ public DatafeedParams(StreamInput in) throws IOException {
194201 startTime = in .readVLong ();
195202 endTime = in .readOptionalLong ();
196203 timeout = TimeValue .timeValueMillis (in .readVLong ());
204+ if (in .getVersion ().onOrAfter (Version .CURRENT )) {
205+ jobId = in .readOptionalString ();
206+ datafeedIndices = in .readList (StreamInput ::readString );
207+ }
197208 }
198209
199210 DatafeedParams () {
@@ -203,6 +214,9 @@ public DatafeedParams(StreamInput in) throws IOException {
203214 private long startTime ;
204215 private Long endTime ;
205216 private TimeValue timeout = TimeValue .timeValueSeconds (20 );
217+ private List <String > datafeedIndices = Collections .emptyList ();
218+ private String jobId ;
219+
206220
207221 public String getDatafeedId () {
208222 return datafeedId ;
@@ -232,6 +246,22 @@ public void setTimeout(TimeValue timeout) {
232246 this .timeout = timeout ;
233247 }
234248
249+ public String getJobId () {
250+ return jobId ;
251+ }
252+
253+ public void setJobId (String jobId ) {
254+ this .jobId = jobId ;
255+ }
256+
257+ public List <String > getDatafeedIndices () {
258+ return datafeedIndices ;
259+ }
260+
261+ public void setDatafeedIndices (List <String > datafeedIndices ) {
262+ this .datafeedIndices = datafeedIndices ;
263+ }
264+
235265 @ Override
236266 public String getWriteableName () {
237267 return MlTasks .DATAFEED_TASK_NAME ;
@@ -248,6 +278,10 @@ public void writeTo(StreamOutput out) throws IOException {
248278 out .writeVLong (startTime );
249279 out .writeOptionalLong (endTime );
250280 out .writeVLong (timeout .millis ());
281+ if (out .getVersion ().onOrAfter (Version .CURRENT )) {
282+ out .writeOptionalString (jobId );
283+ out .writeStringList (datafeedIndices );
284+ }
251285 }
252286
253287 @ Override
@@ -259,13 +293,19 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
259293 builder .field (END_TIME .getPreferredName (), String .valueOf (endTime ));
260294 }
261295 builder .field (TIMEOUT .getPreferredName (), timeout .getStringRep ());
296+ if (jobId != null ) {
297+ builder .field (Job .ID .getPreferredName (), jobId );
298+ }
299+ if (datafeedIndices .isEmpty () == false ) {
300+ builder .field (INDICES .getPreferredName (), datafeedIndices );
301+ }
262302 builder .endObject ();
263303 return builder ;
264304 }
265305
266306 @ Override
267307 public int hashCode () {
268- return Objects .hash (datafeedId , startTime , endTime , timeout );
308+ return Objects .hash (datafeedId , startTime , endTime , timeout , jobId , datafeedIndices );
269309 }
270310
271311 @ Override
@@ -280,7 +320,9 @@ public boolean equals(Object obj) {
280320 return Objects .equals (datafeedId , other .datafeedId ) &&
281321 Objects .equals (startTime , other .startTime ) &&
282322 Objects .equals (endTime , other .endTime ) &&
283- Objects .equals (timeout , other .timeout );
323+ Objects .equals (timeout , other .timeout ) &&
324+ Objects .equals (jobId , other .jobId ) &&
325+ Objects .equals (datafeedIndices , other .datafeedIndices );
284326 }
285327 }
286328
0 commit comments