30
30
import java .io .IOException ;
31
31
import java .time .Instant ;
32
32
import java .util .Collections ;
33
+ import java .util .List ;
33
34
import java .util .Map ;
34
35
import java .util .Objects ;
35
36
36
37
public class TrainedModelConfig implements ToXContentObject {
37
38
38
- public static final String NAME = "trained_model_doc " ;
39
+ public static final String NAME = "trained_model_config " ;
39
40
40
41
public static final ParseField MODEL_ID = new ParseField ("model_id" );
41
42
public static final ParseField CREATED_BY = new ParseField ("created_by" );
42
43
public static final ParseField VERSION = new ParseField ("version" );
43
44
public static final ParseField DESCRIPTION = new ParseField ("description" );
44
- public static final ParseField CREATED_TIME = new ParseField ("created_time" );
45
- public static final ParseField MODEL_VERSION = new ParseField ("model_version" );
45
+ public static final ParseField CREATE_TIME = new ParseField ("create_time" );
46
46
public static final ParseField DEFINITION = new ParseField ("definition" );
47
- public static final ParseField MODEL_TYPE = new ParseField ("model_type " );
47
+ public static final ParseField TAGS = new ParseField ("tags " );
48
48
public static final ParseField METADATA = new ParseField ("metadata" );
49
49
50
50
public static final ObjectParser <Builder , Void > PARSER = new ObjectParser <>(NAME ,
@@ -55,16 +55,15 @@ public class TrainedModelConfig implements ToXContentObject {
55
55
PARSER .declareString (TrainedModelConfig .Builder ::setCreatedBy , CREATED_BY );
56
56
PARSER .declareString (TrainedModelConfig .Builder ::setVersion , VERSION );
57
57
PARSER .declareString (TrainedModelConfig .Builder ::setDescription , DESCRIPTION );
58
- PARSER .declareField (TrainedModelConfig .Builder ::setCreatedTime ,
59
- (p , c ) -> TimeUtil .parseTimeFieldToInstant (p , CREATED_TIME .getPreferredName ()),
60
- CREATED_TIME ,
58
+ PARSER .declareField (TrainedModelConfig .Builder ::setCreateTime ,
59
+ (p , c ) -> TimeUtil .parseTimeFieldToInstant (p , CREATE_TIME .getPreferredName ()),
60
+ CREATE_TIME ,
61
61
ObjectParser .ValueType .VALUE );
62
- PARSER .declareLong (TrainedModelConfig .Builder ::setModelVersion , MODEL_VERSION );
63
- PARSER .declareString (TrainedModelConfig .Builder ::setModelType , MODEL_TYPE );
64
- PARSER .declareObject (TrainedModelConfig .Builder ::setMetadata , (p , c ) -> p .map (), METADATA );
65
62
PARSER .declareObject (TrainedModelConfig .Builder ::setDefinition ,
66
63
(p , c ) -> TrainedModelDefinition .fromXContent (p ),
67
64
DEFINITION );
65
+ PARSER .declareStringArray (TrainedModelConfig .Builder ::setTags , TAGS );
66
+ PARSER .declareObject (TrainedModelConfig .Builder ::setMetadata , (p , c ) -> p .map (), METADATA );
68
67
}
69
68
70
69
public static TrainedModelConfig .Builder fromXContent (XContentParser parser ) throws IOException {
@@ -75,30 +74,27 @@ public static TrainedModelConfig.Builder fromXContent(XContentParser parser) thr
75
74
private final String createdBy ;
76
75
private final Version version ;
77
76
private final String description ;
78
- private final Instant createdTime ;
79
- private final Long modelVersion ;
80
- private final String modelType ;
81
- private final Map <String , Object > metadata ;
77
+ private final Instant createTime ;
82
78
private final TrainedModelDefinition definition ;
79
+ private final List <String > tags ;
80
+ private final Map <String , Object > metadata ;
83
81
84
82
TrainedModelConfig (String modelId ,
85
83
String createdBy ,
86
84
Version version ,
87
85
String description ,
88
- Instant createdTime ,
89
- Long modelVersion ,
90
- String modelType ,
86
+ Instant createTime ,
91
87
TrainedModelDefinition definition ,
88
+ List <String > tags ,
92
89
Map <String , Object > metadata ) {
93
90
this .modelId = modelId ;
94
91
this .createdBy = createdBy ;
95
92
this .version = version ;
96
- this .createdTime = Instant .ofEpochMilli (createdTime .toEpochMilli ());
97
- this .modelType = modelType ;
93
+ this .createTime = Instant .ofEpochMilli (createTime .toEpochMilli ());
98
94
this .definition = definition ;
99
95
this .description = description ;
96
+ this .tags = tags == null ? null : Collections .unmodifiableList (tags );
100
97
this .metadata = metadata == null ? null : Collections .unmodifiableMap (metadata );
101
- this .modelVersion = modelVersion ;
102
98
}
103
99
104
100
public String getModelId () {
@@ -117,16 +113,12 @@ public String getDescription() {
117
113
return description ;
118
114
}
119
115
120
- public Instant getCreatedTime () {
121
- return createdTime ;
116
+ public Instant getCreateTime () {
117
+ return createTime ;
122
118
}
123
119
124
- public Long getModelVersion () {
125
- return modelVersion ;
126
- }
127
-
128
- public String getModelType () {
129
- return modelType ;
120
+ public List <String > getTags () {
121
+ return tags ;
130
122
}
131
123
132
124
public Map <String , Object > getMetadata () {
@@ -156,18 +148,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
156
148
if (description != null ) {
157
149
builder .field (DESCRIPTION .getPreferredName (), description );
158
150
}
159
- if (createdTime != null ) {
160
- builder .timeField (CREATED_TIME .getPreferredName (), CREATED_TIME .getPreferredName () + "_string" , createdTime .toEpochMilli ());
161
- }
162
- if (modelVersion != null ) {
163
- builder .field (MODEL_VERSION .getPreferredName (), modelVersion );
164
- }
165
- if (modelType != null ) {
166
- builder .field (MODEL_TYPE .getPreferredName (), modelType );
151
+ if (createTime != null ) {
152
+ builder .timeField (CREATE_TIME .getPreferredName (), CREATE_TIME .getPreferredName () + "_string" , createTime .toEpochMilli ());
167
153
}
168
154
if (definition != null ) {
169
155
builder .field (DEFINITION .getPreferredName (), definition );
170
156
}
157
+ if (tags != null ) {
158
+ builder .field (TAGS .getPreferredName (), tags );
159
+ }
171
160
if (metadata != null ) {
172
161
builder .field (METADATA .getPreferredName (), metadata );
173
162
}
@@ -189,10 +178,9 @@ public boolean equals(Object o) {
189
178
Objects .equals (createdBy , that .createdBy ) &&
190
179
Objects .equals (version , that .version ) &&
191
180
Objects .equals (description , that .description ) &&
192
- Objects .equals (createdTime , that .createdTime ) &&
193
- Objects .equals (modelVersion , that .modelVersion ) &&
194
- Objects .equals (modelType , that .modelType ) &&
181
+ Objects .equals (createTime , that .createTime ) &&
195
182
Objects .equals (definition , that .definition ) &&
183
+ Objects .equals (tags , that .tags ) &&
196
184
Objects .equals (metadata , that .metadata );
197
185
}
198
186
@@ -201,12 +189,11 @@ public int hashCode() {
201
189
return Objects .hash (modelId ,
202
190
createdBy ,
203
191
version ,
204
- createdTime ,
205
- modelType ,
192
+ createTime ,
206
193
definition ,
207
194
description ,
208
- metadata ,
209
- modelVersion );
195
+ tags ,
196
+ metadata );
210
197
}
211
198
212
199
@@ -216,11 +203,10 @@ public static class Builder {
216
203
private String createdBy ;
217
204
private Version version ;
218
205
private String description ;
219
- private Instant createdTime ;
220
- private Long modelVersion ;
221
- private String modelType ;
206
+ private Instant createTime ;
222
207
private Map <String , Object > metadata ;
223
- private TrainedModelDefinition .Builder definition ;
208
+ private List <String > tags ;
209
+ private TrainedModelDefinition definition ;
224
210
225
211
public Builder setModelId (String modelId ) {
226
212
this .modelId = modelId ;
@@ -246,18 +232,13 @@ public Builder setDescription(String description) {
246
232
return this ;
247
233
}
248
234
249
- private Builder setCreatedTime (Instant createdTime ) {
250
- this .createdTime = createdTime ;
251
- return this ;
252
- }
253
-
254
- public Builder setModelVersion (Long modelVersion ) {
255
- this .modelVersion = modelVersion ;
235
+ private Builder setCreateTime (Instant createTime ) {
236
+ this .createTime = createTime ;
256
237
return this ;
257
238
}
258
239
259
- public Builder setModelType ( String modelType ) {
260
- this .modelType = modelType ;
240
+ public Builder setTags ( List < String > tags ) {
241
+ this .tags = tags ;
261
242
return this ;
262
243
}
263
244
@@ -267,6 +248,11 @@ public Builder setMetadata(Map<String, Object> metadata) {
267
248
}
268
249
269
250
public Builder setDefinition (TrainedModelDefinition .Builder definition ) {
251
+ this .definition = definition == null ? null : definition .build ();
252
+ return this ;
253
+ }
254
+
255
+ public Builder setDefinition (TrainedModelDefinition definition ) {
270
256
this .definition = definition ;
271
257
return this ;
272
258
}
@@ -277,10 +263,9 @@ public TrainedModelConfig build() {
277
263
createdBy ,
278
264
version ,
279
265
description ,
280
- createdTime ,
281
- modelVersion ,
282
- modelType ,
283
- definition == null ? null : definition .build (),
266
+ createTime ,
267
+ definition ,
268
+ tags ,
284
269
metadata );
285
270
}
286
271
}
0 commit comments