88package org .elasticsearch .client .ml .job .config ;
99
1010import org .elasticsearch .client .common .TimeUtil ;
11+ import org .elasticsearch .client .ml .datafeed .DatafeedConfig ;
1112import org .elasticsearch .common .xcontent .ParseField ;
1213import org .elasticsearch .common .Strings ;
1314import org .elasticsearch .core .TimeValue ;
2425import java .util .List ;
2526import java .util .Map ;
2627import java .util .Objects ;
28+ import java .util .Optional ;
2729
2830/**
2931 * This class represents a configured and created Job. The creation time is set
@@ -60,6 +62,7 @@ public class Job implements ToXContentObject {
6062 public static final ParseField DELETING = new ParseField ("deleting" );
6163 public static final ParseField ALLOW_LAZY_OPEN = new ParseField ("allow_lazy_open" );
6264 public static final ParseField BLOCKED = new ParseField ("blocked" );
65+ public static final ParseField DATAFEED_CONFIG = new ParseField ("datafeed_config" );
6366
6467 public static final ObjectParser <Builder , Void > PARSER = new ObjectParser <>("job_details" , true , Builder ::new );
6568
@@ -92,6 +95,7 @@ public class Job implements ToXContentObject {
9295 PARSER .declareBoolean (Builder ::setDeleting , DELETING );
9396 PARSER .declareBoolean (Builder ::setAllowLazyOpen , ALLOW_LAZY_OPEN );
9497 PARSER .declareObject (Builder ::setBlocked , Blocked .PARSER , BLOCKED );
98+ PARSER .declareObject (Builder ::setDatafeed , DatafeedConfig .PARSER , DATAFEED_CONFIG );
9599 }
96100
97101 private final String jobId ;
@@ -116,14 +120,15 @@ public class Job implements ToXContentObject {
116120 private final Boolean deleting ;
117121 private final Boolean allowLazyOpen ;
118122 private final Blocked blocked ;
123+ private final DatafeedConfig datafeedConfig ;
119124
120125 private Job (String jobId , String jobType , List <String > groups , String description ,
121126 Date createTime , Date finishedTime ,
122127 AnalysisConfig analysisConfig , AnalysisLimits analysisLimits , DataDescription dataDescription ,
123128 ModelPlotConfig modelPlotConfig , Long renormalizationWindowDays , TimeValue backgroundPersistInterval ,
124129 Long modelSnapshotRetentionDays , Long dailyModelSnapshotRetentionAfterDays , Long resultsRetentionDays ,
125130 Map <String , Object > customSettings , String modelSnapshotId , String resultsIndexName , Boolean deleting ,
126- Boolean allowLazyOpen , Blocked blocked ) {
131+ Boolean allowLazyOpen , Blocked blocked , DatafeedConfig datafeedConfig ) {
127132
128133 this .jobId = jobId ;
129134 this .jobType = jobType ;
@@ -146,6 +151,7 @@ private Job(String jobId, String jobType, List<String> groups, String descriptio
146151 this .deleting = deleting ;
147152 this .allowLazyOpen = allowLazyOpen ;
148153 this .blocked = blocked ;
154+ this .datafeedConfig = datafeedConfig ;
149155 }
150156
151157 /**
@@ -286,6 +292,14 @@ public Blocked getBlocked() {
286292 return blocked ;
287293 }
288294
295+ /**
296+ * The currently configured datafeed for the job
297+ * @return Optional of the datafeed config. Will be none if a datafeed is not configured for this job
298+ */
299+ public Optional <DatafeedConfig > getDatafeedConfig () {
300+ return Optional .ofNullable (datafeedConfig );
301+ }
302+
289303 @ Override
290304 public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
291305 builder .startObject ();
@@ -350,6 +364,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
350364 if (blocked != null ) {
351365 builder .field (BLOCKED .getPreferredName (), blocked );
352366 }
367+ if (datafeedConfig != null ) {
368+ builder .field (DATAFEED_CONFIG .getPreferredName (), datafeedConfig , params );
369+ }
353370 builder .endObject ();
354371 return builder ;
355372 }
@@ -385,15 +402,16 @@ public boolean equals(Object other) {
385402 && Objects .equals (this .resultsIndexName , that .resultsIndexName )
386403 && Objects .equals (this .deleting , that .deleting )
387404 && Objects .equals (this .allowLazyOpen , that .allowLazyOpen )
388- && Objects .equals (this .blocked , that .blocked );
405+ && Objects .equals (this .blocked , that .blocked )
406+ && Objects .equals (this .datafeedConfig , that .datafeedConfig );
389407 }
390408
391409 @ Override
392410 public int hashCode () {
393411 return Objects .hash (jobId , jobType , groups , description , createTime , finishedTime ,
394412 analysisConfig , analysisLimits , dataDescription , modelPlotConfig , renormalizationWindowDays ,
395413 backgroundPersistInterval , modelSnapshotRetentionDays , dailyModelSnapshotRetentionAfterDays , resultsRetentionDays ,
396- customSettings , modelSnapshotId , resultsIndexName , deleting , allowLazyOpen , blocked );
414+ customSettings , modelSnapshotId , resultsIndexName , deleting , allowLazyOpen , blocked , datafeedConfig );
397415 }
398416
399417 @ Override
@@ -428,6 +446,7 @@ public static class Builder {
428446 private Boolean deleting ;
429447 private Boolean allowLazyOpen ;
430448 private Blocked blocked ;
449+ private DatafeedConfig .Builder datafeedConfig ;
431450
432451 private Builder () {
433452 }
@@ -458,6 +477,7 @@ public Builder(Job job) {
458477 this .deleting = job .getDeleting ();
459478 this .allowLazyOpen = job .getAllowLazyOpen ();
460479 this .blocked = job .getBlocked ();
480+ this .datafeedConfig = job .getDatafeedConfig ().isPresent () ? new DatafeedConfig .Builder (job .datafeedConfig ) : null ;
461481 }
462482
463483 public Builder setId (String id ) {
@@ -569,6 +589,11 @@ Builder setBlocked(Blocked blocked) {
569589 return this ;
570590 }
571591
592+ public Builder setDatafeed (DatafeedConfig .Builder datafeed ) {
593+ this .datafeedConfig = datafeed ;
594+ return this ;
595+ }
596+
572597 /**
573598 * Builds a job.
574599 *
@@ -581,7 +606,8 @@ public Job build() {
581606 id , jobType , groups , description , createTime , finishedTime ,
582607 analysisConfig , analysisLimits , dataDescription , modelPlotConfig , renormalizationWindowDays ,
583608 backgroundPersistInterval , modelSnapshotRetentionDays , dailyModelSnapshotRetentionAfterDays , resultsRetentionDays ,
584- customSettings , modelSnapshotId , resultsIndexName , deleting , allowLazyOpen , blocked );
609+ customSettings , modelSnapshotId , resultsIndexName , deleting , allowLazyOpen , blocked ,
610+ datafeedConfig == null ? null : datafeedConfig .build ());
585611 }
586612 }
587613}
0 commit comments