Skip to content

Commit

Permalink
leftover in the 404 Not Found return error
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
(cherry picked from commit 1661246)
  • Loading branch information
Zhangxunmt committed Jul 12, 2023
1 parent 9095c44 commit f1f0e1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.opensearch.index.reindex.DeleteByQueryAction;
import org.opensearch.index.reindex.DeleteByQueryRequest;
import org.opensearch.ml.common.MLModel;
import org.opensearch.ml.common.exception.MLResourceNotFoundException;
import org.opensearch.ml.common.exception.MLValidationException;
import org.opensearch.ml.common.model.MLModelState;
import org.opensearch.ml.common.transport.model.MLModelDeleteAction;
Expand Down Expand Up @@ -159,10 +158,9 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
actionListener.onFailure(e);
}
} else {
actionListener
.onFailure(new IllegalArgumentException("Failed to find model to delete with the provided model id: " + modelId));
actionListener.onFailure(new OpenSearchStatusException("Failed to find model", RestStatus.NOT_FOUND));
}
}, e -> { actionListener.onFailure(new MLResourceNotFoundException("Fail to find model")); }));
}, e -> { actionListener.onFailure(e); }));
} catch (Exception e) {
log.error("Failed to delete ML model " + modelId, e);
actionListener.onFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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.ActionListener;
import org.opensearch.action.bulk.BulkItemResponse;
Expand Down Expand Up @@ -359,7 +360,7 @@ public void testDeleteModel_CheckModelState() throws IOException {
public void testDeleteModel_ModelNotFoundException() throws IOException {
doAnswer(invocation -> {
ActionListener<GetResponse> actionListener = invocation.getArgument(1);
actionListener.onFailure(new Exception());
actionListener.onFailure(new Exception("Fail to find model"));
return null;
}).when(client).get(any(), any());

Expand Down Expand Up @@ -423,9 +424,9 @@ public void testModelNotFound() throws IOException {
return null;
}).when(client).get(any(), any());
deleteModelTransportAction.doExecute(null, mlModelDeleteRequest, actionListener);
ArgumentCaptor<IllegalArgumentException> argumentCaptor = ArgumentCaptor.forClass(IllegalArgumentException.class);
ArgumentCaptor<OpenSearchStatusException> argumentCaptor = ArgumentCaptor.forClass(OpenSearchStatusException.class);
verify(actionListener).onFailure(argumentCaptor.capture());
assertEquals("Failed to find model to delete with the provided model id: test_id", argumentCaptor.getValue().getMessage());
assertEquals("Failed to find model", argumentCaptor.getValue().getMessage());
}

public void testDeleteModelChunks_Success() {
Expand Down

0 comments on commit f1f0e1e

Please sign in to comment.