27
27
import java .util .Map ;
28
28
29
29
import static org .opensearch .core .xcontent .XContentParserUtils .ensureExpectedToken ;
30
- import static org .opensearch .ml .common .utils .StringUtils .getParameterMap ;
30
+ import static org .opensearch .ml .common .utils .StringUtils .* ;
31
31
32
32
@ Data
33
33
public class MLCreateConnectorInput implements ToXContentObject , Writeable {
@@ -47,6 +47,7 @@ public class MLCreateConnectorInput implements ToXContentObject, Writeable {
47
47
public static final String DRY_RUN_FIELD = "dry_run" ;
48
48
49
49
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_CLIENT_CONFIG = Version .V_2_13_0 ;
50
+ private static final Version MINIMAL_SUPPORTED_VERSION_FOR_MODEL_INTERFACE = Version .V_2_13_0 ;
50
51
51
52
public static final String DRY_RUN_CONNECTOR_NAME = "dryRunConnector" ;
52
53
@@ -63,6 +64,7 @@ public class MLCreateConnectorInput implements ToXContentObject, Writeable {
63
64
private boolean dryRun ;
64
65
private boolean updateConnector ;
65
66
private ConnectorClientConfig connectorClientConfig ;
67
+ private Map <String , String > modelInterface ;
66
68
67
69
68
70
@ Builder (toBuilder = true )
@@ -78,7 +80,8 @@ public MLCreateConnectorInput(String name,
78
80
AccessMode access ,
79
81
boolean dryRun ,
80
82
boolean updateConnector ,
81
- ConnectorClientConfig connectorClientConfig
83
+ ConnectorClientConfig connectorClientConfig ,
84
+ Map <String , String > modelInterface
82
85
83
86
) {
84
87
if (!dryRun && !updateConnector ) {
@@ -105,6 +108,7 @@ public MLCreateConnectorInput(String name,
105
108
this .dryRun = dryRun ;
106
109
this .updateConnector = updateConnector ;
107
110
this .connectorClientConfig = connectorClientConfig ;
111
+ this .modelInterface = modelInterface ;
108
112
109
113
}
110
114
@@ -125,6 +129,7 @@ public static MLCreateConnectorInput parse(XContentParser parser, boolean update
125
129
AccessMode access = null ;
126
130
boolean dryRun = false ;
127
131
ConnectorClientConfig connectorClientConfig = null ;
132
+ Map <String , String > modelInterface = new HashMap <>();
128
133
129
134
ensureExpectedToken (XContentParser .Token .START_OBJECT , parser .currentToken (), parser );
130
135
while (parser .nextToken () != XContentParser .Token .END_OBJECT ) {
@@ -176,13 +181,16 @@ public static MLCreateConnectorInput parse(XContentParser parser, boolean update
176
181
case AbstractConnector .CLIENT_CONFIG_FIELD :
177
182
connectorClientConfig = ConnectorClientConfig .parse (parser );
178
183
break ;
184
+ case AbstractConnector .MODEL_INTERFACE_FIELD :
185
+ modelInterface = getInterfaceMap (parser .map ());
186
+ break ;
179
187
default :
180
188
parser .skipChildren ();
181
189
break ;
182
190
}
183
191
}
184
192
return new MLCreateConnectorInput (name , description , version , protocol , parameters , credential , actions ,
185
- backendRoles , addAllBackendRoles , access , dryRun , updateConnector , connectorClientConfig );
193
+ backendRoles , addAllBackendRoles , access , dryRun , updateConnector , connectorClientConfig , modelInterface );
186
194
}
187
195
188
196
@ Override
@@ -221,6 +229,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
221
229
if (connectorClientConfig != null ) {
222
230
builder .field (AbstractConnector .CLIENT_CONFIG_FIELD , connectorClientConfig );
223
231
}
232
+ if (modelInterface != null ) {
233
+ builder .field (AbstractConnector .MODEL_INTERFACE_FIELD , modelInterface );
234
+ }
224
235
builder .endObject ();
225
236
return builder ;
226
237
}
@@ -276,6 +287,14 @@ public void writeTo(StreamOutput output) throws IOException {
276
287
output .writeBoolean (false );
277
288
}
278
289
}
290
+ if (streamOutputVersion .onOrAfter (MINIMAL_SUPPORTED_VERSION_FOR_MODEL_INTERFACE )) {
291
+ if (modelInterface != null ) {
292
+ output .writeBoolean (true );
293
+ output .writeMap (modelInterface , StreamOutput ::writeString , StreamOutput ::writeString );
294
+ } else {
295
+ output .writeBoolean (false );
296
+ }
297
+ }
279
298
}
280
299
281
300
public MLCreateConnectorInput (StreamInput input ) throws IOException {
@@ -311,6 +330,10 @@ public MLCreateConnectorInput(StreamInput input) throws IOException {
311
330
this .connectorClientConfig = new ConnectorClientConfig (input );
312
331
}
313
332
}
314
-
333
+ if (streamInputVersion .onOrAfter (MINIMAL_SUPPORTED_VERSION_FOR_MODEL_INTERFACE )) {
334
+ if (input .readBoolean ()) {
335
+ modelInterface = input .readMap (StreamInput ::readString , StreamInput ::readString );
336
+ }
337
+ }
315
338
}
316
339
}
0 commit comments