Skip to content

Commit a67b4da

Browse files
authored
Fixed NPE for connector retrying policy (opensearch-project#3909)
* Fixed NPE for connector when retrying Signed-off-by: Owais <[email protected]> * Addressed PR comment Signed-off-by: Owais <[email protected]> --------- Signed-off-by: Owais <[email protected]>
1 parent 109662d commit a67b4da

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

plugin/src/main/java/org/opensearch/ml/action/models/UpdateModelTransportAction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ private void updateRemoteOrTextEmbeddingModel(
283283
if (newConnectorId == null) {
284284
if (updateModelInput.getConnector() != null) {
285285
Connector connector = mlModel.getConnector();
286+
if (connector == null) {
287+
wrappedListener
288+
.onFailure(
289+
new OpenSearchStatusException(
290+
"Cannot update connector settings for this model. The model was created with a connector_id and does not have an inline connector.",
291+
RestStatus.BAD_REQUEST
292+
)
293+
);
294+
return;
295+
}
286296
connector.update(updateModelInput.getConnector(), mlEngine::encrypt);
287297
connector.validateConnectorURL(trustedConnectorEndpointsRegex);
288298
updateModelInput.setUpdatedConnector(connector);

plugin/src/test/java/org/opensearch/ml/action/models/UpdateModelTransportActionTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,30 @@ public void testUpdateLocalModelWithExternalRemoteInformation() {
734734
assertEquals("Trying to update the connector or connector_id field on a local model.", argumentCaptor.getValue().getMessage());
735735
}
736736

737+
@Test
738+
public void testRetryConnectorWhenNotProvidedInRequestBody() {
739+
MLModel testUpdateModelCacheModel = prepareMLModel("REMOTE_INTERNAL", MLModelState.DEPLOYED);
740+
doAnswer(invocation -> {
741+
ActionListener<MLModel> listener = invocation.getArgument(4);
742+
listener.onResponse(testUpdateModelCacheModel);
743+
return null;
744+
}).when(mlModelManager).getModel(eq("test_model_id"), any(), any(), any(), isA(ActionListener.class));
745+
746+
doAnswer(invocation -> {
747+
ActionListener<MLUpdateModelCacheNodesResponse> listener = invocation.getArgument(2);
748+
listener.onResponse(updateModelCacheNodesResponse);
749+
return null;
750+
}).when(client).execute(any(), any(), isA(ActionListener.class));
751+
testUpdateModelCacheModel.setConnector(null);
752+
transportUpdateModelAction.doExecute(task, prepareRemoteRequest("REMOTE_INTERNAL"), actionListener);
753+
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(Exception.class);
754+
verify(actionListener).onFailure(argumentCaptor.capture());
755+
assertEquals(
756+
"Cannot update connector settings for this model. The model was created with a connector_id and does not have an inline connector.",
757+
argumentCaptor.getValue().getMessage()
758+
);
759+
}
760+
737761
@Test
738762
public void testUpdateLocalModelWithInternalRemoteInformation() {
739763
transportUpdateModelAction.doExecute(task, prepareRemoteRequest("REMOTE_INTERNAL"), actionListener);

0 commit comments

Comments
 (0)