1919
2020package org .elasticsearch .client .ml .dataframe ;
2121
22+ import org .elasticsearch .Version ;
23+ import org .elasticsearch .client .dataframe .transforms .util .TimeUtil ;
2224import org .elasticsearch .common .Nullable ;
2325import org .elasticsearch .common .ParseField ;
2426import org .elasticsearch .common .Strings ;
2527import org .elasticsearch .common .unit .ByteSizeValue ;
2628import org .elasticsearch .common .xcontent .ObjectParser ;
29+ import org .elasticsearch .common .xcontent .ObjectParser .ValueType ;
2730import org .elasticsearch .common .xcontent .ToXContentObject ;
2831import org .elasticsearch .common .xcontent .XContentBuilder ;
2932import org .elasticsearch .common .xcontent .XContentParser ;
3033import org .elasticsearch .common .xcontent .XContentParserUtils ;
3134import org .elasticsearch .search .fetch .subphase .FetchSourceContext ;
3235
3336import java .io .IOException ;
37+ import java .time .Instant ;
3438import java .util .Objects ;
3539
36- import static org .elasticsearch .common .xcontent .ObjectParser .ValueType .OBJECT_ARRAY_BOOLEAN_OR_STRING ;
37- import static org .elasticsearch .common .xcontent .ObjectParser .ValueType .VALUE ;
38-
3940public class DataFrameAnalyticsConfig implements ToXContentObject {
4041
4142 public static DataFrameAnalyticsConfig fromXContent (XContentParser parser ) {
@@ -52,6 +53,8 @@ public static Builder builder(String id) {
5253 private static final ParseField ANALYSIS = new ParseField ("analysis" );
5354 private static final ParseField ANALYZED_FIELDS = new ParseField ("analyzed_fields" );
5455 private static final ParseField MODEL_MEMORY_LIMIT = new ParseField ("model_memory_limit" );
56+ private static final ParseField CREATE_TIME = new ParseField ("create_time" );
57+ private static final ParseField VERSION = new ParseField ("version" );
5558
5659 private static ObjectParser <Builder , Void > PARSER = new ObjectParser <>("data_frame_analytics_config" , true , Builder ::new );
5760
@@ -63,9 +66,24 @@ public static Builder builder(String id) {
6366 PARSER .declareField (Builder ::setAnalyzedFields ,
6467 (p , c ) -> FetchSourceContext .fromXContent (p ),
6568 ANALYZED_FIELDS ,
66- OBJECT_ARRAY_BOOLEAN_OR_STRING );
69+ ValueType . OBJECT_ARRAY_BOOLEAN_OR_STRING );
6770 PARSER .declareField (Builder ::setModelMemoryLimit ,
68- (p , c ) -> ByteSizeValue .parseBytesSizeValue (p .text (), MODEL_MEMORY_LIMIT .getPreferredName ()), MODEL_MEMORY_LIMIT , VALUE );
71+ (p , c ) -> ByteSizeValue .parseBytesSizeValue (p .text (), MODEL_MEMORY_LIMIT .getPreferredName ()),
72+ MODEL_MEMORY_LIMIT ,
73+ ValueType .VALUE );
74+ PARSER .declareField (Builder ::setCreateTime ,
75+ p -> TimeUtil .parseTimeFieldToInstant (p , CREATE_TIME .getPreferredName ()),
76+ CREATE_TIME ,
77+ ValueType .VALUE );
78+ PARSER .declareField (Builder ::setVersion ,
79+ p -> {
80+ if (p .currentToken () == XContentParser .Token .VALUE_STRING ) {
81+ return Version .fromString (p .text ());
82+ }
83+ throw new IllegalArgumentException ("Unsupported token [" + p .currentToken () + "]" );
84+ },
85+ VERSION ,
86+ ValueType .STRING );
6987 }
7088
7189 private static DataFrameAnalysis parseAnalysis (XContentParser parser ) throws IOException {
@@ -82,15 +100,20 @@ private static DataFrameAnalysis parseAnalysis(XContentParser parser) throws IOE
82100 private final DataFrameAnalysis analysis ;
83101 private final FetchSourceContext analyzedFields ;
84102 private final ByteSizeValue modelMemoryLimit ;
103+ private final Instant createTime ;
104+ private final Version version ;
85105
86106 private DataFrameAnalyticsConfig (String id , DataFrameAnalyticsSource source , DataFrameAnalyticsDest dest , DataFrameAnalysis analysis ,
87- @ Nullable FetchSourceContext analyzedFields , @ Nullable ByteSizeValue modelMemoryLimit ) {
107+ @ Nullable FetchSourceContext analyzedFields , @ Nullable ByteSizeValue modelMemoryLimit ,
108+ @ Nullable Instant createTime , @ Nullable Version version ) {
88109 this .id = Objects .requireNonNull (id );
89110 this .source = Objects .requireNonNull (source );
90111 this .dest = Objects .requireNonNull (dest );
91112 this .analysis = Objects .requireNonNull (analysis );
92113 this .analyzedFields = analyzedFields ;
93114 this .modelMemoryLimit = modelMemoryLimit ;
115+ this .createTime = createTime == null ? null : Instant .ofEpochMilli (createTime .toEpochMilli ());;
116+ this .version = version ;
94117 }
95118
96119 public String getId () {
@@ -117,6 +140,14 @@ public ByteSizeValue getModelMemoryLimit() {
117140 return modelMemoryLimit ;
118141 }
119142
143+ public Instant getCreateTime () {
144+ return createTime ;
145+ }
146+
147+ public Version getVersion () {
148+ return version ;
149+ }
150+
120151 @ Override
121152 public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
122153 builder .startObject ();
@@ -132,6 +163,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
132163 if (modelMemoryLimit != null ) {
133164 builder .field (MODEL_MEMORY_LIMIT .getPreferredName (), modelMemoryLimit .getStringRep ());
134165 }
166+ if (createTime != null ) {
167+ builder .timeField (CREATE_TIME .getPreferredName (), CREATE_TIME .getPreferredName () + "_string" , createTime .toEpochMilli ());
168+ }
169+ if (version != null ) {
170+ builder .field (VERSION .getPreferredName (), version );
171+ }
135172 builder .endObject ();
136173 return builder ;
137174 }
@@ -147,12 +184,14 @@ public boolean equals(Object o) {
147184 && Objects .equals (dest , other .dest )
148185 && Objects .equals (analysis , other .analysis )
149186 && Objects .equals (analyzedFields , other .analyzedFields )
150- && Objects .equals (modelMemoryLimit , other .modelMemoryLimit );
187+ && Objects .equals (modelMemoryLimit , other .modelMemoryLimit )
188+ && Objects .equals (createTime , other .createTime )
189+ && Objects .equals (version , other .version );
151190 }
152191
153192 @ Override
154193 public int hashCode () {
155- return Objects .hash (id , source , dest , analysis , analyzedFields , getModelMemoryLimit () );
194+ return Objects .hash (id , source , dest , analysis , analyzedFields , modelMemoryLimit , createTime , version );
156195 }
157196
158197 @ Override
@@ -168,6 +207,8 @@ public static class Builder {
168207 private DataFrameAnalysis analysis ;
169208 private FetchSourceContext analyzedFields ;
170209 private ByteSizeValue modelMemoryLimit ;
210+ private Instant createTime ;
211+ private Version version ;
171212
172213 private Builder () {}
173214
@@ -201,8 +242,18 @@ public Builder setModelMemoryLimit(ByteSizeValue modelMemoryLimit) {
201242 return this ;
202243 }
203244
245+ public Builder setCreateTime (Instant createTime ) {
246+ this .createTime = createTime ;
247+ return this ;
248+ }
249+
250+ public Builder setVersion (Version version ) {
251+ this .version = version ;
252+ return this ;
253+ }
254+
204255 public DataFrameAnalyticsConfig build () {
205- return new DataFrameAnalyticsConfig (id , source , dest , analysis , analyzedFields , modelMemoryLimit );
256+ return new DataFrameAnalyticsConfig (id , source , dest , analysis , analyzedFields , modelMemoryLimit , createTime , version );
206257 }
207258 }
208259}
0 commit comments