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
@@ -141,6 +144,8 @@ public boolean equals(Object obj) {
141144
142145 public static class DatafeedParams implements XPackPlugin .XPackPersistentTaskParams {
143146
147+ public static final ParseField INDICES = new ParseField ("indices" );
148+
144149 public static ObjectParser <DatafeedParams , Void > PARSER = new ObjectParser <>(MlTasks .DATAFEED_TASK_NAME , true , DatafeedParams ::new );
145150 static {
146151 PARSER .declareString ((params , datafeedId ) -> params .datafeedId = datafeedId , DatafeedConfig .ID );
@@ -149,6 +154,8 @@ public static class DatafeedParams implements XPackPlugin.XPackPersistentTaskPar
149154 PARSER .declareString (DatafeedParams ::setEndTime , END_TIME );
150155 PARSER .declareString ((params , val ) ->
151156 params .setTimeout (TimeValue .parseTimeValue (val , TIMEOUT .getPreferredName ())), TIMEOUT );
157+ PARSER .declareString (DatafeedParams ::setJobId , Job .ID );
158+ PARSER .declareStringArray (DatafeedParams ::setDatafeedIndices , INDICES );
152159 }
153160
154161 static long parseDateOrThrow (String date , ParseField paramName , LongSupplier now ) {
@@ -188,6 +195,10 @@ public DatafeedParams(StreamInput in) throws IOException {
188195 startTime = in .readVLong ();
189196 endTime = in .readOptionalLong ();
190197 timeout = TimeValue .timeValueMillis (in .readVLong ());
198+ if (in .getVersion ().onOrAfter (Version .CURRENT )) {
199+ jobId = in .readOptionalString ();
200+ datafeedIndices = in .readList (StreamInput ::readString );
201+ }
191202 }
192203
193204 DatafeedParams () {
@@ -197,6 +208,9 @@ public DatafeedParams(StreamInput in) throws IOException {
197208 private long startTime ;
198209 private Long endTime ;
199210 private TimeValue timeout = TimeValue .timeValueSeconds (20 );
211+ private List <String > datafeedIndices = Collections .emptyList ();
212+ private String jobId ;
213+
200214
201215 public String getDatafeedId () {
202216 return datafeedId ;
@@ -226,6 +240,22 @@ public void setTimeout(TimeValue timeout) {
226240 this .timeout = timeout ;
227241 }
228242
243+ public String getJobId () {
244+ return jobId ;
245+ }
246+
247+ public void setJobId (String jobId ) {
248+ this .jobId = jobId ;
249+ }
250+
251+ public List <String > getDatafeedIndices () {
252+ return datafeedIndices ;
253+ }
254+
255+ public void setDatafeedIndices (List <String > datafeedIndices ) {
256+ this .datafeedIndices = datafeedIndices ;
257+ }
258+
229259 @ Override
230260 public String getWriteableName () {
231261 return MlTasks .DATAFEED_TASK_NAME ;
@@ -242,6 +272,10 @@ public void writeTo(StreamOutput out) throws IOException {
242272 out .writeVLong (startTime );
243273 out .writeOptionalLong (endTime );
244274 out .writeVLong (timeout .millis ());
275+ if (out .getVersion ().onOrAfter (Version .CURRENT )) {
276+ out .writeOptionalString (jobId );
277+ out .writeStringList (datafeedIndices );
278+ }
245279 }
246280
247281 @ Override
@@ -253,13 +287,19 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
253287 builder .field (END_TIME .getPreferredName (), String .valueOf (endTime ));
254288 }
255289 builder .field (TIMEOUT .getPreferredName (), timeout .getStringRep ());
290+ if (jobId != null ) {
291+ builder .field (Job .ID .getPreferredName (), jobId );
292+ }
293+ if (datafeedIndices .isEmpty () == false ) {
294+ builder .field (INDICES .getPreferredName (), datafeedIndices );
295+ }
256296 builder .endObject ();
257297 return builder ;
258298 }
259299
260300 @ Override
261301 public int hashCode () {
262- return Objects .hash (datafeedId , startTime , endTime , timeout );
302+ return Objects .hash (datafeedId , startTime , endTime , timeout , jobId , datafeedIndices );
263303 }
264304
265305 @ Override
@@ -274,7 +314,9 @@ public boolean equals(Object obj) {
274314 return Objects .equals (datafeedId , other .datafeedId ) &&
275315 Objects .equals (startTime , other .startTime ) &&
276316 Objects .equals (endTime , other .endTime ) &&
277- Objects .equals (timeout , other .timeout );
317+ Objects .equals (timeout , other .timeout ) &&
318+ Objects .equals (jobId , other .jobId ) &&
319+ Objects .equals (datafeedIndices , other .datafeedIndices );
278320 }
279321 }
280322
0 commit comments