6
6
package org .opensearch .ml .common ;
7
7
8
8
import static org .opensearch .core .xcontent .XContentParserUtils .ensureExpectedToken ;
9
+ import static org .opensearch .ml .common .CommonValue .TENANT_ID_FIELD ;
9
10
import static org .opensearch .ml .common .CommonValue .USER ;
11
+ import static org .opensearch .ml .common .CommonValue .VERSION_2_19_0 ;
10
12
11
13
import java .io .IOException ;
12
14
import java .time .Instant ;
@@ -72,6 +74,7 @@ public class MLTask implements ToXContentObject, Writeable {
72
74
private boolean async ;
73
75
@ Setter
74
76
private Map <String , Object > remoteJob ;
77
+ private String tenantId ;
75
78
76
79
@ Builder (toBuilder = true )
77
80
public MLTask (
@@ -89,7 +92,8 @@ public MLTask(
89
92
String error ,
90
93
User user ,
91
94
boolean async ,
92
- Map <String , Object > remoteJob
95
+ Map <String , Object > remoteJob ,
96
+ String tenantId
93
97
) {
94
98
this .taskId = taskId ;
95
99
this .modelId = modelId ;
@@ -106,6 +110,7 @@ public MLTask(
106
110
this .user = user ;
107
111
this .async = async ;
108
112
this .remoteJob = remoteJob ;
113
+ this .tenantId = tenantId ;
109
114
}
110
115
111
116
public MLTask (StreamInput input ) throws IOException {
@@ -134,9 +139,10 @@ public MLTask(StreamInput input) throws IOException {
134
139
this .async = input .readBoolean ();
135
140
if (streamInputVersion .onOrAfter (MLTask .MINIMAL_SUPPORTED_VERSION_FOR_BATCH_PREDICTION_JOB )) {
136
141
if (input .readBoolean ()) {
137
- this .remoteJob = input .readMap (s -> s . readString (), s -> s . readGenericValue () );
142
+ this .remoteJob = input .readMap (StreamInput :: readString , StreamInput :: readGenericValue );
138
143
}
139
144
}
145
+ tenantId = streamInputVersion .onOrAfter (VERSION_2_19_0 ) ? input .readOptionalString () : null ;
140
146
}
141
147
142
148
@ Override
@@ -173,6 +179,9 @@ public void writeTo(StreamOutput out) throws IOException {
173
179
out .writeBoolean (false );
174
180
}
175
181
}
182
+ if (streamOutputVersion .onOrAfter (VERSION_2_19_0 )) {
183
+ out .writeOptionalString (tenantId );
184
+ }
176
185
}
177
186
178
187
@ Override
@@ -221,12 +230,14 @@ public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params
221
230
if (remoteJob != null ) {
222
231
builder .field (REMOTE_JOB_FIELD , remoteJob );
223
232
}
233
+ if (tenantId != null ) {
234
+ builder .field (TENANT_ID_FIELD , tenantId );
235
+ }
224
236
return builder .endObject ();
225
237
}
226
238
227
239
public static MLTask fromStream (StreamInput in ) throws IOException {
228
- MLTask mlTask = new MLTask (in );
229
- return mlTask ;
240
+ return new MLTask (in );
230
241
}
231
242
232
243
public static MLTask parse (XContentParser parser ) throws IOException {
@@ -245,6 +256,7 @@ public static MLTask parse(XContentParser parser) throws IOException {
245
256
User user = null ;
246
257
boolean async = false ;
247
258
Map <String , Object > remoteJob = null ;
259
+ String tenantId = null ;
248
260
249
261
ensureExpectedToken (XContentParser .Token .START_OBJECT , parser .currentToken (), parser );
250
262
while (parser .nextToken () != XContentParser .Token .END_OBJECT ) {
@@ -305,6 +317,9 @@ public static MLTask parse(XContentParser parser) throws IOException {
305
317
case REMOTE_JOB_FIELD :
306
318
remoteJob = parser .map ();
307
319
break ;
320
+ case TENANT_ID_FIELD :
321
+ tenantId = parser .textOrNull ();
322
+ break ;
308
323
default :
309
324
parser .skipChildren ();
310
325
break ;
@@ -327,6 +342,7 @@ public static MLTask parse(XContentParser parser) throws IOException {
327
342
.user (user )
328
343
.async (async )
329
344
.remoteJob (remoteJob )
345
+ .tenantId (tenantId )
330
346
.build ();
331
347
}
332
348
}
0 commit comments