1717import org .opensearch .core .xcontent .XContentParser ;
1818import org .opensearch .ml .common .connector .Connector ;
1919import org .opensearch .ml .common .model .Guardrails ;
20+ import org .opensearch .ml .common .model .MLDeploySetting ;
2021import org .opensearch .ml .common .model .MLModelConfig ;
2122import org .opensearch .ml .common .controller .MLRateLimiter ;
2223import org .opensearch .ml .common .model .TextEmbeddingModelConfig ;
2324import org .opensearch .ml .common .transport .connector .MLCreateConnectorInput ;
25+ import org .opensearch .ml .common .transport .register .MLRegisterModelInput ;
2426
2527import java .io .IOException ;
2628import java .time .Instant ;
@@ -39,6 +41,7 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
3941 public static final String IS_ENABLED_FIELD = "is_enabled" ; // optional
4042 public static final String RATE_LIMITER_FIELD = "rate_limiter" ; // optional
4143 public static final String MODEL_CONFIG_FIELD = "model_config" ; // optional
44+ public static final String DEPLOY_SETTING_FIELD = "deploy_setting" ; // optional
4245 public static final String UPDATED_CONNECTOR_FIELD = "updated_connector" ; // passively set when updating the
4346 // internal connector
4447 public static final String CONNECTOR_ID_FIELD = "connector_id" ; // optional
@@ -47,8 +50,6 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
4750 // request
4851 public static final String GUARDRAILS_FIELD = "guardrails" ;
4952
50- private static final Version MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS = Version .V_2_13_0 ;
51-
5253 @ Getter
5354 private String modelId ;
5455 private String description ;
@@ -58,6 +59,7 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
5859 private Boolean isEnabled ;
5960 private MLRateLimiter rateLimiter ;
6061 private MLModelConfig modelConfig ;
62+ private MLDeploySetting deploySetting ;
6163 private Connector updatedConnector ;
6264 private String connectorId ;
6365 private MLCreateConnectorInput connector ;
@@ -66,7 +68,7 @@ public class MLUpdateModelInput implements ToXContentObject, Writeable {
6668
6769 @ Builder (toBuilder = true )
6870 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 ,
7072 Connector updatedConnector , String connectorId , MLCreateConnectorInput connector , Instant lastUpdateTime , Guardrails guardrails ) {
7173 this .modelId = modelId ;
7274 this .description = description ;
@@ -76,6 +78,7 @@ public MLUpdateModelInput(String modelId, String description, String version, St
7678 this .isEnabled = isEnabled ;
7779 this .rateLimiter = rateLimiter ;
7880 this .modelConfig = modelConfig ;
81+ this .deploySetting = deploySetting ;
7982 this .updatedConnector = updatedConnector ;
8083 this .connectorId = connectorId ;
8184 this .connector = connector ;
@@ -105,10 +108,13 @@ public MLUpdateModelInput(StreamInput in) throws IOException {
105108 connector = new MLCreateConnectorInput (in );
106109 }
107110 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 )) {
109112 if (in .readBoolean ()) {
110113 this .guardrails = new Guardrails (in );
111114 }
115+ if (in .readBoolean ()) {
116+ this .deploySetting = new MLDeploySetting (in );
117+ }
112118 }
113119 }
114120
@@ -137,6 +143,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
137143 if (modelConfig != null ) {
138144 builder .field (MODEL_CONFIG_FIELD , modelConfig );
139145 }
146+ if (deploySetting != null ) {
147+ builder .field (DEPLOY_SETTING_FIELD , deploySetting );
148+ }
140149 if (updatedConnector != null ) {
141150 builder .field (UPDATED_CONNECTOR_FIELD , updatedConnector );
142151 }
@@ -180,6 +189,9 @@ public XContentBuilder toXContentForUpdateRequestDoc(XContentBuilder builder, Pa
180189 if (modelConfig != null ) {
181190 builder .field (MODEL_CONFIG_FIELD , modelConfig );
182191 }
192+ if (deploySetting != null ) {
193+ builder .field (DEPLOY_SETTING_FIELD , deploySetting );
194+ }
183195 // Notice that we serialize the updatedConnector to the connector field, in order to be compatible with original internal connector field format.
184196 if (updatedConnector != null ) {
185197 builder .field (CONNECTOR_FIELD , updatedConnector );
@@ -232,13 +244,19 @@ public void writeTo(StreamOutput out) throws IOException {
232244 out .writeBoolean (false );
233245 }
234246 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 )) {
236248 if (guardrails != null ) {
237249 out .writeBoolean (true );
238250 guardrails .writeTo (out );
239251 } else {
240252 out .writeBoolean (false );
241253 }
254+ if (deploySetting != null ) {
255+ out .writeBoolean (true );
256+ deploySetting .writeTo (out );
257+ } else {
258+ out .writeBoolean (false );
259+ }
242260 }
243261 }
244262
@@ -251,6 +269,7 @@ public static MLUpdateModelInput parse(XContentParser parser) throws IOException
251269 Boolean isEnabled = null ;
252270 MLRateLimiter rateLimiter = null ;
253271 MLModelConfig modelConfig = null ;
272+ MLDeploySetting deploySetting = null ;
254273 Connector updatedConnector = null ;
255274 String connectorId = null ;
256275 MLCreateConnectorInput connector = null ;
@@ -280,6 +299,9 @@ public static MLUpdateModelInput parse(XContentParser parser) throws IOException
280299 case MODEL_CONFIG_FIELD :
281300 modelConfig = TextEmbeddingModelConfig .parse (parser );
282301 break ;
302+ case DEPLOY_SETTING_FIELD :
303+ deploySetting = MLDeploySetting .parse (parser );
304+ break ;
283305 case CONNECTOR_ID_FIELD :
284306 connectorId = parser .text ();
285307 break ;
@@ -297,6 +319,6 @@ public static MLUpdateModelInput parse(XContentParser parser) throws IOException
297319 // Model ID can only be set through RestRequest. Model version can only be set
298320 // automatically.
299321 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 );
301323 }
302324}
0 commit comments