17
17
import org .opensearch .core .xcontent .XContentParser ;
18
18
import org .opensearch .ml .common .connector .Connector ;
19
19
import org .opensearch .ml .common .model .Guardrails ;
20
+ import org .opensearch .ml .common .model .MLDeploySetting ;
20
21
import org .opensearch .ml .common .model .MLModelConfig ;
21
22
import org .opensearch .ml .common .controller .MLRateLimiter ;
22
23
import org .opensearch .ml .common .model .TextEmbeddingModelConfig ;
23
24
import org .opensearch .ml .common .transport .connector .MLCreateConnectorInput ;
25
+ import org .opensearch .ml .common .transport .register .MLRegisterModelInput ;
24
26
25
27
import java .io .IOException ;
26
28
import java .time .Instant ;
@@ -39,6 +41,7 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
39
41
public static final String IS_ENABLED_FIELD = "is_enabled" ; // optional
40
42
public static final String RATE_LIMITER_FIELD = "rate_limiter" ; // optional
41
43
public static final String MODEL_CONFIG_FIELD = "model_config" ; // optional
44
+ public static final String DEPLOY_SETTING_FIELD = "deploy_setting" ; // optional
42
45
public static final String UPDATED_CONNECTOR_FIELD = "updated_connector" ; // passively set when updating the
43
46
// internal connector
44
47
public static final String CONNECTOR_ID_FIELD = "connector_id" ; // optional
@@ -47,8 +50,6 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
47
50
// request
48
51
public static final String GUARDRAILS_FIELD = "guardrails" ;
49
52
50
- private static final Version MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS = Version .V_2_13_0 ;
51
-
52
53
@ Getter
53
54
private String modelId ;
54
55
private String description ;
@@ -58,6 +59,7 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
58
59
private Boolean isEnabled ;
59
60
private MLRateLimiter rateLimiter ;
60
61
private MLModelConfig modelConfig ;
62
+ private MLDeploySetting deploySetting ;
61
63
private Connector updatedConnector ;
62
64
private String connectorId ;
63
65
private MLCreateConnectorInput connector ;
@@ -66,7 +68,7 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
66
68
67
69
@ Builder (toBuilder = true )
68
70
public MLUpdateModelInput (String modelId , String description , String version , String name , String modelGroupId ,
69
- Boolean isEnabled , MLRateLimiter rateLimiter , MLModelConfig modelConfig ,
71
+ Boolean isEnabled , MLRateLimiter rateLimiter , MLModelConfig modelConfig , MLDeploySetting deploySetting ,
70
72
Connector updatedConnector , String connectorId , MLCreateConnectorInput connector , Instant lastUpdateTime , Guardrails guardrails ) {
71
73
this .modelId = modelId ;
72
74
this .description = description ;
@@ -76,6 +78,7 @@ public MLUpdateModelInput(String modelId, String description, String version, St
76
78
this .isEnabled = isEnabled ;
77
79
this .rateLimiter = rateLimiter ;
78
80
this .modelConfig = modelConfig ;
81
+ this .deploySetting = deploySetting ;
79
82
this .updatedConnector = updatedConnector ;
80
83
this .connectorId = connectorId ;
81
84
this .connector = connector ;
@@ -105,10 +108,13 @@ public MLUpdateModelInput(StreamInput in) throws IOException {
105
108
connector = new MLCreateConnectorInput (in );
106
109
}
107
110
lastUpdateTime = in .readOptionalInstant ();
108
- if (streamInputVersion .onOrAfter (MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS )) {
111
+ if (streamInputVersion .onOrAfter (MLRegisterModelInput . MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS_AND_AUTO_DEPLOY )) {
109
112
if (in .readBoolean ()) {
110
113
this .guardrails = new Guardrails (in );
111
114
}
115
+ if (in .readBoolean ()) {
116
+ this .deploySetting = new MLDeploySetting (in );
117
+ }
112
118
}
113
119
}
114
120
@@ -137,6 +143,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
137
143
if (modelConfig != null ) {
138
144
builder .field (MODEL_CONFIG_FIELD , modelConfig );
139
145
}
146
+ if (deploySetting != null ) {
147
+ builder .field (DEPLOY_SETTING_FIELD , deploySetting );
148
+ }
140
149
if (updatedConnector != null ) {
141
150
builder .field (UPDATED_CONNECTOR_FIELD , updatedConnector );
142
151
}
@@ -180,6 +189,9 @@ public XContentBuilder toXContentForUpdateRequestDoc(XContentBuilder builder, Pa
180
189
if (modelConfig != null ) {
181
190
builder .field (MODEL_CONFIG_FIELD , modelConfig );
182
191
}
192
+ if (deploySetting != null ) {
193
+ builder .field (DEPLOY_SETTING_FIELD , deploySetting );
194
+ }
183
195
// Notice that we serialize the updatedConnector to the connector field, in order to be compatible with original internal connector field format.
184
196
if (updatedConnector != null ) {
185
197
builder .field (CONNECTOR_FIELD , updatedConnector );
@@ -232,13 +244,19 @@ public void writeTo(StreamOutput out) throws IOException {
232
244
out .writeBoolean (false );
233
245
}
234
246
out .writeOptionalInstant (lastUpdateTime );
235
- if (streamOutputVersion .onOrAfter (MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS )) {
247
+ if (streamOutputVersion .onOrAfter (MLRegisterModelInput . MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS_AND_AUTO_DEPLOY )) {
236
248
if (guardrails != null ) {
237
249
out .writeBoolean (true );
238
250
guardrails .writeTo (out );
239
251
} else {
240
252
out .writeBoolean (false );
241
253
}
254
+ if (deploySetting != null ) {
255
+ out .writeBoolean (true );
256
+ deploySetting .writeTo (out );
257
+ } else {
258
+ out .writeBoolean (false );
259
+ }
242
260
}
243
261
}
244
262
@@ -251,6 +269,7 @@ public static MLUpdateModelInput parse(XContentParser parser) throws IOException
251
269
Boolean isEnabled = null ;
252
270
MLRateLimiter rateLimiter = null ;
253
271
MLModelConfig modelConfig = null ;
272
+ MLDeploySetting deploySetting = null ;
254
273
Connector updatedConnector = null ;
255
274
String connectorId = null ;
256
275
MLCreateConnectorInput connector = null ;
@@ -280,6 +299,9 @@ public static MLUpdateModelInput parse(XContentParser parser) throws IOException
280
299
case MODEL_CONFIG_FIELD :
281
300
modelConfig = TextEmbeddingModelConfig .parse (parser );
282
301
break ;
302
+ case DEPLOY_SETTING_FIELD :
303
+ deploySetting = MLDeploySetting .parse (parser );
304
+ break ;
283
305
case CONNECTOR_ID_FIELD :
284
306
connectorId = parser .text ();
285
307
break ;
@@ -297,6 +319,6 @@ public static MLUpdateModelInput parse(XContentParser parser) throws IOException
297
319
// Model ID can only be set through RestRequest. Model version can only be set
298
320
// automatically.
299
321
return new MLUpdateModelInput (modelId , description , version , name , modelGroupId , isEnabled , rateLimiter ,
300
- modelConfig , updatedConnector , connectorId , connector , lastUpdateTime , guardrails );
322
+ modelConfig , deploySetting , updatedConnector , connectorId , connector , lastUpdateTime , guardrails );
301
323
}
302
324
}
0 commit comments