Skip to content

Commit 8fe39de

Browse files
authored
for inline model connector name isn't required (#3882)
* for inline model connector name isn't required Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * adding unit test Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * test was failing Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> --------- Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
1 parent ac35832 commit 8fe39de

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public ActionRequestValidationException validate() {
4646
return addValidationError("ML Connector input can't be null", null);
4747
}
4848
Map<String, FieldDescriptor> fieldsToValidate = new HashMap<>();
49-
fieldsToValidate.put("Model connector name", new FieldDescriptor(mlCreateConnectorInput.getName(), true));
49+
50+
fieldsToValidate
51+
.put("Model connector name", new FieldDescriptor(mlCreateConnectorInput.getName(), !mlCreateConnectorInput.isDryRun()));
5052
fieldsToValidate.put("Model connector description", new FieldDescriptor(mlCreateConnectorInput.getDescription(), false));
5153

5254
return validateFields(fieldsToValidate);

common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorRequestTests.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.ml.common.transport.connector;
77

88
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertNotNull;
910
import static org.junit.Assert.assertNotSame;
1011
import static org.junit.Assert.assertNull;
1112
import static org.junit.Assert.assertSame;
@@ -267,4 +268,47 @@ public void validateWithEmptyAndInvalidModelConnectorNameAndDescription() {
267268
);
268269
}
269270

271+
@Test
272+
public void validateWithDryRun() {
273+
// Test with dry run set to true
274+
MLCreateConnectorInput dryRunInput = MLCreateConnectorInput
275+
.builder()
276+
.name("") // Empty name, which would normally fail validation
277+
.description("Test description")
278+
.version("1")
279+
.protocol("http")
280+
.parameters(Map.of("input", "test"))
281+
.credential(Map.of("key", "value"))
282+
.actions(List.of())
283+
.access(AccessMode.PUBLIC)
284+
.backendRoles(Arrays.asList("role1"))
285+
.addAllBackendRoles(false)
286+
.dryRun(true) // Set dry run to true
287+
.build();
288+
289+
MLCreateConnectorRequest dryRunRequest = MLCreateConnectorRequest.builder().mlCreateConnectorInput(dryRunInput).build();
290+
ActionRequestValidationException dryRunException = dryRunRequest.validate();
291+
assertNull("Validation should pass when dry run is true, even with empty name", dryRunException);
292+
293+
// Test with dry run set to false (default behavior)
294+
MLCreateConnectorInput nonDryRunInput = MLCreateConnectorInput
295+
.builder()
296+
.name("") // Empty name, which should fail validation
297+
.description("Test description")
298+
.version("1")
299+
.protocol("http")
300+
.parameters(Map.of("input", "test"))
301+
.credential(Map.of("key", "value"))
302+
.actions(List.of())
303+
.access(AccessMode.PUBLIC)
304+
.backendRoles(Arrays.asList("role1"))
305+
.addAllBackendRoles(false)
306+
.dryRun(false) // Set dry run to false
307+
.build();
308+
309+
MLCreateConnectorRequest nonDryRunRequest = MLCreateConnectorRequest.builder().mlCreateConnectorInput(nonDryRunInput).build();
310+
ActionRequestValidationException nonDryRunException = nonDryRunRequest.validate();
311+
assertNotNull("Validation should fail when dry run is false and name is empty", nonDryRunException);
312+
assertTrue(nonDryRunException.getMessage().contains("Model connector name is required"));
313+
}
270314
}

ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/text_embedding/ModelHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void testDownloadPrebuiltModelMetaList() throws PrivilegedActionException
207207
MLRegisterModelInput registerModelInput = MLRegisterModelInput
208208
.builder()
209209
.modelName("huggingface/sentence-transformers/all-mpnet-base-v2")
210-
.version("1.0.1")
210+
.version("1.0.2")
211211
.modelGroupId("mockGroupId")
212212
.modelFormat(modelFormat)
213213
.deployModel(false)
@@ -223,7 +223,7 @@ public void testIsModelAllowed_true() throws PrivilegedActionException {
223223
MLRegisterModelInput registerModelInput = MLRegisterModelInput
224224
.builder()
225225
.modelName("huggingface/sentence-transformers/all-mpnet-base-v2")
226-
.version("1.0.1")
226+
.version("1.0.2")
227227
.modelGroupId("mockGroupId")
228228
.modelFormat(modelFormat)
229229
.deployModel(false)

0 commit comments

Comments
 (0)