Skip to content

Commit

Permalink
Fix: RestStatus 500 returned ml validation (opensearch-project#1805)
Browse files Browse the repository at this point in the history
* fix

Signed-off-by: kalyanr <[email protected]>

* fix

Signed-off-by: kalyanr <[email protected]>

* spotless check

Signed-off-by: kalyanr <[email protected]>

* updated tests

Signed-off-by: Kalyan <[email protected]>
Signed-off-by: kalyanr <[email protected]>

---------

Signed-off-by: kalyanr <[email protected]>
Signed-off-by: Kalyan <[email protected]>
  • Loading branch information
rawwar authored Dec 26, 2023
1 parent fc3025c commit 75155b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.List;

import org.opensearch.OpenSearchStatusException;
import org.opensearch.action.ActionRequest;
import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.delete.DeleteRequest;
Expand All @@ -23,6 +24,7 @@
import org.opensearch.common.inject.Inject;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.query.QueryBuilders;
Expand Down Expand Up @@ -87,10 +89,11 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
}
actionListener
.onFailure(
new MLValidationException(
new OpenSearchStatusException(
searchHits.length
+ " models are still using this connector, please delete or update the models first: "
+ Arrays.toString(modelIds.toArray(new String[0]))
+ Arrays.toString(modelIds.toArray(new String[0])),
RestStatus.CONFLICT
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.ResourceNotFoundException;
import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.delete.DeleteResponse;
Expand All @@ -41,7 +42,6 @@
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.utils.TestHelper;
Expand Down Expand Up @@ -178,7 +178,7 @@ public void testDeleteConnector_BlockedByModel() throws IOException {
}).when(client).search(any(), any());

deleteConnectorTransportAction.doExecute(null, mlConnectorDeleteRequest, actionListener);
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(MLValidationException.class);
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(OpenSearchStatusException.class);
verify(actionListener).onFailure(argumentCaptor.capture());
assertEquals(
"1 models are still using this connector, please delete or update the models first: [model_ID]",
Expand Down

0 comments on commit 75155b9

Please sign in to comment.