13
13
import java .util .ArrayList ;
14
14
import java .util .Arrays ;
15
15
import java .util .List ;
16
+ import java .util .Map ;
16
17
18
+ import org .opensearch .Version ;
17
19
import org .opensearch .commons .authuser .User ;
18
20
import org .opensearch .core .common .io .stream .StreamInput ;
19
21
import org .opensearch .core .common .io .stream .StreamOutput ;
@@ -45,6 +47,8 @@ public class MLTask implements ToXContentObject, Writeable {
45
47
public static final String LAST_UPDATE_TIME_FIELD = "last_update_time" ;
46
48
public static final String ERROR_FIELD = "error" ;
47
49
public static final String IS_ASYNC_TASK_FIELD = "is_async" ;
50
+ public static final String REMOTE_JOB_FIELD = "remote_job" ;
51
+ public static final Version MINIMAL_SUPPORTED_VERSION_FOR_BATCH_PREDICTION_JOB = CommonValue .VERSION_2_17_0 ;
48
52
49
53
@ Setter
50
54
private String taskId ;
@@ -66,6 +70,8 @@ public class MLTask implements ToXContentObject, Writeable {
66
70
private String error ;
67
71
private User user ; // TODO: support document level access control later
68
72
private boolean async ;
73
+ @ Setter
74
+ private Map <String , Object > remoteJob ;
69
75
70
76
@ Builder (toBuilder = true )
71
77
public MLTask (
@@ -82,7 +88,8 @@ public MLTask(
82
88
Instant lastUpdateTime ,
83
89
String error ,
84
90
User user ,
85
- boolean async
91
+ boolean async ,
92
+ Map <String , Object > remoteJob
86
93
) {
87
94
this .taskId = taskId ;
88
95
this .modelId = modelId ;
@@ -98,9 +105,11 @@ public MLTask(
98
105
this .error = error ;
99
106
this .user = user ;
100
107
this .async = async ;
108
+ this .remoteJob = remoteJob ;
101
109
}
102
110
103
111
public MLTask (StreamInput input ) throws IOException {
112
+ Version streamInputVersion = input .getVersion ();
104
113
this .taskId = input .readOptionalString ();
105
114
this .modelId = input .readOptionalString ();
106
115
this .taskType = input .readEnum (MLTaskType .class );
@@ -123,10 +132,16 @@ public MLTask(StreamInput input) throws IOException {
123
132
this .user = null ;
124
133
}
125
134
this .async = input .readBoolean ();
135
+ if (streamInputVersion .onOrAfter (MLTask .MINIMAL_SUPPORTED_VERSION_FOR_BATCH_PREDICTION_JOB )) {
136
+ if (input .readBoolean ()) {
137
+ this .remoteJob = input .readMap (s -> s .readString (), s -> s .readGenericValue ());
138
+ }
139
+ }
126
140
}
127
141
128
142
@ Override
129
143
public void writeTo (StreamOutput out ) throws IOException {
144
+ Version streamOutputVersion = out .getVersion ();
130
145
out .writeOptionalString (taskId );
131
146
out .writeOptionalString (modelId );
132
147
out .writeEnum (taskType );
@@ -150,6 +165,14 @@ public void writeTo(StreamOutput out) throws IOException {
150
165
out .writeBoolean (false );
151
166
}
152
167
out .writeBoolean (async );
168
+ if (streamOutputVersion .onOrAfter (MLTask .MINIMAL_SUPPORTED_VERSION_FOR_BATCH_PREDICTION_JOB )) {
169
+ if (remoteJob != null ) {
170
+ out .writeBoolean (true );
171
+ out .writeMap (remoteJob , StreamOutput ::writeString , StreamOutput ::writeGenericValue );
172
+ } else {
173
+ out .writeBoolean (false );
174
+ }
175
+ }
153
176
}
154
177
155
178
@ Override
@@ -195,6 +218,9 @@ public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params
195
218
builder .field (USER , user );
196
219
}
197
220
builder .field (IS_ASYNC_TASK_FIELD , async );
221
+ if (remoteJob != null ) {
222
+ builder .field (REMOTE_JOB_FIELD , remoteJob );
223
+ }
198
224
return builder .endObject ();
199
225
}
200
226
@@ -218,6 +244,7 @@ public static MLTask parse(XContentParser parser) throws IOException {
218
244
String error = null ;
219
245
User user = null ;
220
246
boolean async = false ;
247
+ Map <String , Object > remoteJob = null ;
221
248
222
249
ensureExpectedToken (XContentParser .Token .START_OBJECT , parser .currentToken (), parser );
223
250
while (parser .nextToken () != XContentParser .Token .END_OBJECT ) {
@@ -275,6 +302,9 @@ public static MLTask parse(XContentParser parser) throws IOException {
275
302
case IS_ASYNC_TASK_FIELD :
276
303
async = parser .booleanValue ();
277
304
break ;
305
+ case REMOTE_JOB_FIELD :
306
+ remoteJob = parser .map ();
307
+ break ;
278
308
default :
279
309
parser .skipChildren ();
280
310
break ;
@@ -296,6 +326,7 @@ public static MLTask parse(XContentParser parser) throws IOException {
296
326
.error (error )
297
327
.user (user )
298
328
.async (async )
329
+ .remoteJob (remoteJob )
299
330
.build ();
300
331
}
301
332
}
0 commit comments