Skip to content

Commit 5705643

Browse files
committed
delete connector successfully if model index is missing
Signed-off-by: Xun Zhang <[email protected]> (cherry picked from commit 63762db)
1 parent 5ff9015 commit 5705643

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

plugin/src/main/java/org/opensearch/ml/action/connector/DeleteConnectorTransportAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.opensearch.common.inject.Inject;
2121
import org.opensearch.common.util.concurrent.ThreadContext;
2222
import org.opensearch.core.xcontent.NamedXContentRegistry;
23+
import org.opensearch.index.IndexNotFoundException;
2324
import org.opensearch.index.query.QueryBuilders;
2425
import org.opensearch.ml.common.MLModel;
2526
import org.opensearch.ml.common.exception.MLValidationException;
@@ -85,6 +86,10 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
8586
);
8687
}
8788
}, e -> {
89+
if (e instanceof IndexNotFoundException) {
90+
deleteConnector(deleteRequest, connectorId, actionListener);
91+
return;
92+
}
8893
log.error("Failed to delete ML connector: " + connectorId, e);
8994
actionListener.onFailure(e);
9095
}));

plugin/src/test/java/org/opensearch/ml/action/connector/DeleteConnectorTransportActionTests.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,20 @@
3030
import org.opensearch.action.search.ShardSearchFailure;
3131
import org.opensearch.action.support.ActionFilters;
3232
import org.opensearch.client.Client;
33-
import org.opensearch.cluster.service.ClusterService;
3433
import org.opensearch.common.bytes.BytesReference;
3534
import org.opensearch.common.settings.Settings;
3635
import org.opensearch.common.util.concurrent.ThreadContext;
3736
import org.opensearch.common.xcontent.XContentFactory;
3837
import org.opensearch.core.xcontent.NamedXContentRegistry;
3938
import org.opensearch.core.xcontent.ToXContent;
4039
import org.opensearch.core.xcontent.XContentBuilder;
40+
import org.opensearch.index.IndexNotFoundException;
4141
import org.opensearch.index.get.GetResult;
4242
import org.opensearch.ml.common.MLModel;
4343
import org.opensearch.ml.common.connector.HttpConnector;
4444
import org.opensearch.ml.common.exception.MLValidationException;
4545
import org.opensearch.ml.common.transport.connector.MLConnectorDeleteRequest;
4646
import org.opensearch.ml.helper.ConnectorAccessControlHelper;
47-
import org.opensearch.ml.model.MLModelManager;
4847
import org.opensearch.search.SearchHit;
4948
import org.opensearch.search.SearchHits;
5049
import org.opensearch.search.aggregations.InternalAggregations;
@@ -74,15 +73,9 @@ public class DeleteConnectorTransportActionTests extends OpenSearchTestCase {
7473
@Mock
7574
NamedXContentRegistry xContentRegistry;
7675

77-
@Mock
78-
private MLModelManager mlModelManager;
79-
8076
@Rule
8177
public ExpectedException exceptionRule = ExpectedException.none();
8278

83-
@Mock
84-
ClusterService clusterService;
85-
8679
DeleteConnectorTransportAction deleteConnectorTransportAction;
8780
MLConnectorDeleteRequest mlConnectorDeleteRequest;
8881
ThreadContext threadContext;
@@ -131,6 +124,24 @@ public void testDeleteConnector_Success() throws IOException {
131124
verify(actionListener).onResponse(deleteResponse);
132125
}
133126

127+
public void testDeleteConnector_ModelIndexNotFoundSuccess() throws IOException {
128+
doAnswer(invocation -> {
129+
ActionListener<DeleteResponse> listener = invocation.getArgument(1);
130+
listener.onResponse(deleteResponse);
131+
return null;
132+
}).when(client).delete(any(), any());
133+
134+
SearchResponse searchResponse = getEmptySearchResponse();
135+
doAnswer(invocation -> {
136+
ActionListener<Exception> actionListener = invocation.getArgument(1);
137+
actionListener.onFailure(new IndexNotFoundException("ml_model index not found!"));
138+
return null;
139+
}).when(client).search(any(), any());
140+
141+
deleteConnectorTransportAction.doExecute(null, mlConnectorDeleteRequest, actionListener);
142+
verify(actionListener).onResponse(deleteResponse);
143+
}
144+
134145
public void testDeleteConnector_ConnectorNotFound() throws IOException {
135146
when(deleteResponse.getResult()).thenReturn(DocWriteResponse.Result.NOT_FOUND);
136147

0 commit comments

Comments
 (0)