bitflicker64 opened a new pull request, #3233:
URL: https://github.com/apache/hugegraph/pull/3233

   ## Purpose of the PR
   
   - Part 1 of #3231
   
   `GET /v1/task/balanceLeaders` declares `throws PDException` and has no 
handler. When PD refuses the leader balance, for example within 180 s of a 
`balancePartitions` call while the balance-shard key is set, the caller gets a 
bare Spring 500 (`{"timestamp":...,"status":500,"error":"Internal Server 
Error","path":"/v1/task/balanceLeaders"}`) and the reason (`balance shard is 
processing, please try later!`, `TaskScheduleService.java:478`) only reaches 
the PD log. The sibling task endpoints `patrolStores`, `patrolPartitions` and 
`splitPartitions` catch the exception and answer `toJSON(e)`.
   
   Part 2 of #3231 (what the task endpoints answer on a follower or on a no-op, 
and whether the body reports what was done) is out of scope here. It needs a 
design decision and stays open in the issue. This PR does not change response 
semantics beyond the error path below.
   
   ## Main Changes
   
   - `TaskAPI.balanceLeaders` now catches `PDException` and returns 
`toJSON(e)`, copying the handler used by `patrolStores`, `patrolPartitions` and 
`splitPartitions`, including `produces = APPLICATION_JSON_VALUE` and 
`@ResponseBody`.
   - The refused case now answers `{"status":1001,"error":"balance shard is 
processing, please try later!"}` with the same HTTP status the siblings use for 
their error bodies.
   - The success body is unchanged. The leader map is serialized with 
`API.toJSON(Object)` (Jackson), so `{"1":2}` stays `{"1":2}` and the content 
type stays `application/json`.
   - New unit test `TaskAPIBalanceLeadersTest` in `hg-pd-service`, next to 
`StoreAPIReadyTest`.
   
   ## Verifying these changes
   
   - [ ] Trivial rework / code cleanup without any test coverage. (No Need)
   - [ ] Already covered by existing tests, such as *(please modify tests 
here)*.
   - [x] Need tests and can be verified as follows:
       - `TaskAPIBalanceLeadersTest.testRefusedBalanceReturnsErrorBody`: a 
`PDRestService` stub throws `PDException(1001, "balance shard is processing, 
please try later!")`; the endpoint returns a body with `status` 1001 and that 
`error` text.
       - `TaskAPIBalanceLeadersTest.testSuccessfulBalanceKeepsBody`: a stub 
returns `{1: 2}`; the endpoint returns `{"1":2}`, the same body as before.
       - Run on JDK 11: `mvn test -pl hugegraph-pd/hg-pd-service -am 
-Dtest='StoreAPIReadyTest,TaskAPIBalanceLeadersTest,AuthenticationTest' 
-DfailIfNoTests=false` gives 15 tests, 0 failures (all test classes in 
`hg-pd-service`). `mvn editorconfig:check -pl hugegraph-pd/hg-pd-service` 
passes.
   
   ## Does this PR potentially affect the following parts?
   
   - [ ]  Dependencies ([add/update 
license](https://hugegraph.apache.org/docs/contribution-guidelines/contribute/#321-check-licenses)
 info & 
[regenerate_known_dependencies.sh](../install-dist/scripts/dependency/regenerate_known_dependencies.sh))
   - [ ]  Modify configurations
   - [x]  The public API (error response of `GET /v1/task/balanceLeaders` only; 
the success body is unchanged)
   - [ ]  Other affects (typed here)
   - [ ]  Nope
   
   
   ## Documentation Status
   
   Select one option and provide the documentation location when applicable.
   
   - [ ] `Doc - TODO`: required documentation is pending; complete it before 
merging.
   - [ ] `Doc - Done`: documentation is included here or linked below.
   - [x] `Doc - No Need`: no user-visible documentation is affected.
   
   Documentation files in this PR or paired hugegraph-doc PR:
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to