-
Notifications
You must be signed in to change notification settings - Fork 186
converting illegalstate exception to opensearch status exception with 400 status #4484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughReplaced thrown IllegalStateException with OpenSearchStatusException(..., RestStatus.BAD_REQUEST) across ML action handlers, REST endpoints (including connector and stream handlers), and corresponding tests; added necessary imports and updated test assertions for exception status. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionAction.java (1)
147-156: Inconsistent exception handling across feature-disabled scenarios.While line 151 correctly uses
OpenSearchStatusExceptionwithRestStatus.BAD_REQUESTforLOCAL_MODEL_DISABLED_ERR_MSG, lines 148 and 153 still throwIllegalStateExceptionforREMOTE_INFERENCE_DISABLED_ERR_MSGandBATCH_INFERENCE_DISABLED_ERR_MSG. This creates inconsistent error handling for similar "feature disabled" scenarios.For consistent REST semantics, consider applying the same exception type and status code to all feature-disabled checks.
if (FunctionName.REMOTE.name().equals(modelType) && !mlFeatureEnabledSetting.isRemoteInferenceEnabled()) { - throw new IllegalStateException(REMOTE_INFERENCE_DISABLED_ERR_MSG); + throw new OpenSearchStatusException(REMOTE_INFERENCE_DISABLED_ERR_MSG, RestStatus.BAD_REQUEST); } else if (FunctionName.isDLModel(FunctionName.from(modelType.toUpperCase(Locale.ROOT))) && !mlFeatureEnabledSetting.isLocalModelEnabled()) { throw new OpenSearchStatusException(LOCAL_MODEL_DISABLED_ERR_MSG, RestStatus.BAD_REQUEST); } else if (ActionType.BATCH_PREDICT == actionType && !mlFeatureEnabledSetting.isOfflineBatchInferenceEnabled()) { - throw new IllegalStateException(BATCH_INFERENCE_DISABLED_ERR_MSG); + throw new OpenSearchStatusException(BATCH_INFERENCE_DISABLED_ERR_MSG, RestStatus.BAD_REQUEST); } else if (!ActionType.isValidActionInModelPrediction(actionType)) { throw new IllegalArgumentException("Wrong action type in the rest request path!"); }
🧹 Nitpick comments (1)
plugin/src/test/java/org/opensearch/ml/rest/RestMLRegisterModelActionTests.java (1)
167-173: Updated exception expectation aligns with new local‑model error behavior; consider also asserting statusSwitching the expectation from
IllegalStateExceptiontoOpenSearchStatusExceptionfor the local‑inference‑disabled path matches the new behavior while keeping the message assertion intact. If you want this test to also guard the HTTP mapping, you could switch toassertThrowsand additionally checke.status()forRestStatus.BAD_REQUEST, but that’s optional and can be deferred.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java(1 hunks)plugin/src/main/java/org/opensearch/ml/action/prediction/TransportPredictionTaskAction.java(1 hunks)plugin/src/main/java/org/opensearch/ml/action/register/TransportRegisterModelAction.java(3 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionAction.java(2 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLRegisterModelAction.java(2 hunks)plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelActionTests.java(2 hunks)plugin/src/test/java/org/opensearch/ml/action/prediction/TransportPredictionTaskActionTests.java(1 hunks)plugin/src/test/java/org/opensearch/ml/action/register/TransportRegisterModelActionTests.java(3 hunks)plugin/src/test/java/org/opensearch/ml/rest/RestMLRegisterModelActionTests.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Build and Test MLCommons Plugin on linux (25)
- GitHub Check: Build and Test MLCommons Plugin on linux (21)
- GitHub Check: Build and Test MLCommons Plugin on Windows (25)
- GitHub Check: Build and Test MLCommons Plugin on Windows (21)
🔇 Additional comments (6)
plugin/src/test/java/org/opensearch/ml/action/prediction/TransportPredictionTaskActionTests.java (1)
194-202: LGTM! Test correctly validates exception type and status.The test properly verifies both the exception type (
OpenSearchStatusException) and the HTTP status code (RestStatus.BAD_REQUEST), aligning with the production code changes.plugin/src/test/java/org/opensearch/ml/action/register/TransportRegisterModelActionTests.java (1)
281-289: LGTM! Test correctly updated for new exception semantics.The test appropriately expects
OpenSearchStatusExceptionand validates theRestStatus.BAD_REQUESTstatus code, consistent with the production code changes.plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelActionTests.java (1)
400-403: LGTM! Test correctly validates new exception semantics.The test appropriately expects
OpenSearchStatusExceptionand asserts theRestStatus.BAD_REQUESTstatus, aligning with the production code changes.plugin/src/main/java/org/opensearch/ml/action/prediction/TransportPredictionTaskAction.java (1)
131-133: LGTM! Correct exception type for REST-aware error handling.The change appropriately replaces
IllegalStateExceptionwithOpenSearchStatusExceptioncarryingRestStatus.BAD_REQUEST, providing proper HTTP semantics for client error handling.plugin/src/main/java/org/opensearch/ml/action/register/TransportRegisterModelAction.java (1)
169-171: LGTM! Correct exception type for feature validation.The change appropriately replaces
IllegalStateExceptionwithOpenSearchStatusExceptioncarryingRestStatus.BAD_REQUEST, providing proper HTTP status semantics for disabled feature scenarios.plugin/src/test/java/org/opensearch/ml/rest/RestMLRegisterModelActionTests.java (1)
30-30: Import ofOpenSearchStatusExceptionis appropriate and correctly usedThe added import is needed for the updated test expectation below and is used without introducing any unused-import noise. No changes requested here.
plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java
Show resolved
Hide resolved
plugin/src/main/java/org/opensearch/ml/rest/RestMLRegisterModelAction.java
Show resolved
Hide resolved
Signed-off-by: Dhrubo Saha <[email protected]>
plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Dhrubo Saha <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionStreamAction.java (1)
137-139: Consider applying the same pattern for consistency.Line 138 still throws
IllegalStateExceptionwhen streaming is disabled, while Line 323 now throwsOpenSearchStatusExceptionwithBAD_REQUESTfor disabled remote inference. Both represent "feature disabled" scenarios. For consistency, consider converting this toOpenSearchStatusExceptionas well.Apply this diff for consistency:
if (!mlFeatureEnabledSetting.isStreamEnabled()) { - throw new IllegalStateException(STREAM_DISABLED_ERR_MSG); + throw new OpenSearchStatusException(STREAM_DISABLED_ERR_MSG, RestStatus.BAD_REQUEST); }plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionAction.java (1)
152-153: Consider applying the same pattern for consistency.Line 153 still throws
IllegalStateExceptionwhen batch inference is disabled, while Lines 148 and 151 now throwOpenSearchStatusExceptionwithBAD_REQUEST. All three represent "feature disabled" scenarios. For consistency, consider converting this toOpenSearchStatusExceptionas well.Apply this diff for consistency:
} else if (ActionType.BATCH_PREDICT == actionType && !mlFeatureEnabledSetting.isOfflineBatchInferenceEnabled()) { - throw new IllegalStateException(BATCH_INFERENCE_DISABLED_ERR_MSG); + throw new OpenSearchStatusException(BATCH_INFERENCE_DISABLED_ERR_MSG, RestStatus.BAD_REQUEST); } else if (!ActionType.isValidActionInModelPrediction(actionType)) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java(1 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLCreateConnectorAction.java(2 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionAction.java(2 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionStreamAction.java(1 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLRegisterModelAction.java(2 hunks)plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java(2 hunks)plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelActionTests.java(3 hunks)plugin/src/test/java/org/opensearch/ml/rest/RestMLCreateConnectorActionTests.java(2 hunks)plugin/src/test/java/org/opensearch/ml/rest/RestMLPredictionStreamActionTests.java(2 hunks)plugin/src/test/java/org/opensearch/ml/rest/RestMLRegisterModelActionTests.java(3 hunks)plugin/src/test/java/org/opensearch/ml/rest/RestMLUpdateConnectorActionTests.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- plugin/src/main/java/org/opensearch/ml/rest/RestMLRegisterModelAction.java
- plugin/src/test/java/org/opensearch/ml/rest/RestMLRegisterModelActionTests.java
- plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: spotless
🔇 Additional comments (9)
plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java (1)
21-22: LGTM - Exception handling improved for REST semantics.The change from
IllegalStateExceptiontoOpenSearchStatusExceptionwithRestStatus.BAD_REQUESTproperly signals a 400 status to clients when remote inference is disabled, which is more appropriate than the generic 500 error thatIllegalStateExceptionwould produce.Also applies to: 65-65
plugin/src/test/java/org/opensearch/ml/rest/RestMLUpdateConnectorActionTests.java (1)
28-28: LGTM - Test updated to match the new exception type.The test correctly expects
OpenSearchStatusExceptioninstead ofIllegalStateException, maintaining consistency with the production code changes.Also applies to: 140-140
plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelActionTests.java (2)
371-387: LGTM - Comprehensive test coverage for remote inference disabled scenario.The test correctly verifies both the exception type (
OpenSearchStatusException) and the HTTP status (RestStatus.BAD_REQUEST), ensuring the error response is properly structured.
389-405: LGTM - Comprehensive test coverage for local inference disabled scenario.The test follows the same pattern as the remote inference test, properly validating both exception type and HTTP status code.
plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionStreamAction.java (1)
323-323: LGTM - Consistent exception handling for disabled remote inference.The change aligns with the PR objective and matches the pattern used across other REST actions.
plugin/src/test/java/org/opensearch/ml/rest/RestMLCreateConnectorActionTests.java (1)
30-30: LGTM - Test aligned with production code changes.The test expectation correctly reflects the new exception type for disabled remote inference.
Also applies to: 135-135
plugin/src/test/java/org/opensearch/ml/rest/RestMLPredictionStreamActionTests.java (1)
161-173: LGTM - Thorough validation of exception type and HTTP status.The test properly verifies both the
OpenSearchStatusExceptiontype and theRestStatus.BAD_REQUESTstatus, ensuring the API returns the correct HTTP semantics.plugin/src/main/java/org/opensearch/ml/rest/RestMLPredictionAction.java (1)
147-151: LGTM - Exception handling improved for both remote and local model scenarios.Both disabled inference checks now properly return HTTP 400 status via
OpenSearchStatusException, improving REST API semantics.plugin/src/main/java/org/opensearch/ml/rest/RestMLCreateConnectorAction.java (1)
18-19: LGTM - Proper REST error handling for disabled remote inference.The change to
OpenSearchStatusExceptionwithRestStatus.BAD_REQUESTensures clients receive an appropriate HTTP 400 response instead of a generic server error.Also applies to: 71-71
Signed-off-by: Dhrubo Saha <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4484 +/- ##
=========================================
Coverage 80.15% 80.15%
- Complexity 10227 10238 +11
=========================================
Files 858 858
Lines 44496 44517 +21
Branches 5145 5151 +6
=========================================
+ Hits 35664 35683 +19
- Misses 6668 6670 +2
Partials 2164 2164
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
converting illegalstate exception to opensearch status exception with 400 status
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.