Skip to content

Commit

Permalink
delete connector successfully if model index is missing
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
(cherry picked from commit 63762db)
  • Loading branch information
Zhangxunmt committed Jul 12, 2023
1 parent 5ff9015 commit 5705643
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.common.inject.Inject;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.ml.common.MLModel;
import org.opensearch.ml.common.exception.MLValidationException;
Expand Down Expand Up @@ -85,6 +86,10 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
);
}
}, e -> {
if (e instanceof IndexNotFoundException) {
deleteConnector(deleteRequest, connectorId, actionListener);
return;
}
log.error("Failed to delete ML connector: " + connectorId, e);
actionListener.onFailure(e);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@
import org.opensearch.action.search.ShardSearchFailure;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.get.GetResult;
import org.opensearch.ml.common.MLModel;
import org.opensearch.ml.common.connector.HttpConnector;
import org.opensearch.ml.common.exception.MLValidationException;
import org.opensearch.ml.common.transport.connector.MLConnectorDeleteRequest;
import org.opensearch.ml.helper.ConnectorAccessControlHelper;
import org.opensearch.ml.model.MLModelManager;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.opensearch.search.aggregations.InternalAggregations;
Expand Down Expand Up @@ -74,15 +73,9 @@ public class DeleteConnectorTransportActionTests extends OpenSearchTestCase {
@Mock
NamedXContentRegistry xContentRegistry;

@Mock
private MLModelManager mlModelManager;

@Rule
public ExpectedException exceptionRule = ExpectedException.none();

@Mock
ClusterService clusterService;

DeleteConnectorTransportAction deleteConnectorTransportAction;
MLConnectorDeleteRequest mlConnectorDeleteRequest;
ThreadContext threadContext;
Expand Down Expand Up @@ -131,6 +124,24 @@ public void testDeleteConnector_Success() throws IOException {
verify(actionListener).onResponse(deleteResponse);
}

public void testDeleteConnector_ModelIndexNotFoundSuccess() throws IOException {
doAnswer(invocation -> {
ActionListener<DeleteResponse> listener = invocation.getArgument(1);
listener.onResponse(deleteResponse);
return null;
}).when(client).delete(any(), any());

SearchResponse searchResponse = getEmptySearchResponse();
doAnswer(invocation -> {
ActionListener<Exception> actionListener = invocation.getArgument(1);
actionListener.onFailure(new IndexNotFoundException("ml_model index not found!"));
return null;
}).when(client).search(any(), any());

deleteConnectorTransportAction.doExecute(null, mlConnectorDeleteRequest, actionListener);
verify(actionListener).onResponse(deleteResponse);
}

public void testDeleteConnector_ConnectorNotFound() throws IOException {
when(deleteResponse.getResult()).thenReturn(DocWriteResponse.Result.NOT_FOUND);

Expand Down

0 comments on commit 5705643

Please sign in to comment.