19
19
20
20
package org .elasticsearch .client .ml .dataframe ;
21
21
22
+ import org .elasticsearch .Version ;
23
+ import org .elasticsearch .client .dataframe .transforms .util .TimeUtil ;
22
24
import org .elasticsearch .common .Nullable ;
23
25
import org .elasticsearch .common .ParseField ;
24
26
import org .elasticsearch .common .Strings ;
25
27
import org .elasticsearch .common .unit .ByteSizeValue ;
26
28
import org .elasticsearch .common .xcontent .ObjectParser ;
29
+ import org .elasticsearch .common .xcontent .ObjectParser .ValueType ;
27
30
import org .elasticsearch .common .xcontent .ToXContentObject ;
28
31
import org .elasticsearch .common .xcontent .XContentBuilder ;
29
32
import org .elasticsearch .common .xcontent .XContentParser ;
30
33
import org .elasticsearch .common .xcontent .XContentParserUtils ;
31
34
import org .elasticsearch .search .fetch .subphase .FetchSourceContext ;
32
35
33
36
import java .io .IOException ;
37
+ import java .time .Instant ;
34
38
import java .util .Objects ;
35
39
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
-
39
40
public class DataFrameAnalyticsConfig implements ToXContentObject {
40
41
41
42
public static DataFrameAnalyticsConfig fromXContent (XContentParser parser ) {
@@ -52,6 +53,8 @@ public static Builder builder(String id) {
52
53
private static final ParseField ANALYSIS = new ParseField ("analysis" );
53
54
private static final ParseField ANALYZED_FIELDS = new ParseField ("analyzed_fields" );
54
55
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" );
55
58
56
59
private static ObjectParser <Builder , Void > PARSER = new ObjectParser <>("data_frame_analytics_config" , true , Builder ::new );
57
60
@@ -63,9 +66,24 @@ public static Builder builder(String id) {
63
66
PARSER .declareField (Builder ::setAnalyzedFields ,
64
67
(p , c ) -> FetchSourceContext .fromXContent (p ),
65
68
ANALYZED_FIELDS ,
66
- OBJECT_ARRAY_BOOLEAN_OR_STRING );
69
+ ValueType . OBJECT_ARRAY_BOOLEAN_OR_STRING );
67
70
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 );
69
87
}
70
88
71
89
private static DataFrameAnalysis parseAnalysis (XContentParser parser ) throws IOException {
@@ -82,15 +100,20 @@ private static DataFrameAnalysis parseAnalysis(XContentParser parser) throws IOE
82
100
private final DataFrameAnalysis analysis ;
83
101
private final FetchSourceContext analyzedFields ;
84
102
private final ByteSizeValue modelMemoryLimit ;
103
+ private final Instant createTime ;
104
+ private final Version version ;
85
105
86
106
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 ) {
88
109
this .id = Objects .requireNonNull (id );
89
110
this .source = Objects .requireNonNull (source );
90
111
this .dest = Objects .requireNonNull (dest );
91
112
this .analysis = Objects .requireNonNull (analysis );
92
113
this .analyzedFields = analyzedFields ;
93
114
this .modelMemoryLimit = modelMemoryLimit ;
115
+ this .createTime = createTime == null ? null : Instant .ofEpochMilli (createTime .toEpochMilli ());;
116
+ this .version = version ;
94
117
}
95
118
96
119
public String getId () {
@@ -117,6 +140,14 @@ public ByteSizeValue getModelMemoryLimit() {
117
140
return modelMemoryLimit ;
118
141
}
119
142
143
+ public Instant getCreateTime () {
144
+ return createTime ;
145
+ }
146
+
147
+ public Version getVersion () {
148
+ return version ;
149
+ }
150
+
120
151
@ Override
121
152
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
122
153
builder .startObject ();
@@ -132,6 +163,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
132
163
if (modelMemoryLimit != null ) {
133
164
builder .field (MODEL_MEMORY_LIMIT .getPreferredName (), modelMemoryLimit .getStringRep ());
134
165
}
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
+ }
135
172
builder .endObject ();
136
173
return builder ;
137
174
}
@@ -147,12 +184,14 @@ public boolean equals(Object o) {
147
184
&& Objects .equals (dest , other .dest )
148
185
&& Objects .equals (analysis , other .analysis )
149
186
&& 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 );
151
190
}
152
191
153
192
@ Override
154
193
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 );
156
195
}
157
196
158
197
@ Override
@@ -168,6 +207,8 @@ public static class Builder {
168
207
private DataFrameAnalysis analysis ;
169
208
private FetchSourceContext analyzedFields ;
170
209
private ByteSizeValue modelMemoryLimit ;
210
+ private Instant createTime ;
211
+ private Version version ;
171
212
172
213
private Builder () {}
173
214
@@ -201,8 +242,18 @@ public Builder setModelMemoryLimit(ByteSizeValue modelMemoryLimit) {
201
242
return this ;
202
243
}
203
244
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
+
204
255
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 );
206
257
}
207
258
}
208
259
}
0 commit comments