J-HowHuang commented on code in PR #16886:
URL: https://github.com/apache/pinot/pull/16886#discussion_r2389520095


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTenantRestletResource.java:
##########
@@ -701,6 +703,46 @@ public SuccessResponse deleteTenant(
         Response.Status.INTERNAL_SERVER_ERROR);
   }
 
+  @DELETE
+  @Produces(MediaType.APPLICATION_JSON)
+  @Authenticate(AccessType.DELETE)
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.REBALANCE_TENANT_TABLES)
+  @Path("/tenants/rebalance/{jobId}")
+  @ApiOperation(value = "Cancels a running tenant rebalance job")
+  @ApiResponses(value = {
+      @ApiResponse(code = 200, message = "Success", response = 
SuccessResponse.class),
+      @ApiResponse(code = 404, message = "Tenant rebalance job not found"),
+      @ApiResponse(code = 500, message = "Internal server error during 
cancelling the rebalance job")
+  })
+  public SuccessResponse cancelRebalance(
+      @ApiParam(value = "Tenant rebalance job id", required = true) 
@PathParam("jobId") String jobId) {
+    Map<String, String> jobMetadata =
+        _pinotHelixResourceManager.getControllerJobZKMetadata(jobId, 
ControllerJobTypes.TENANT_REBALANCE);
+    if (jobMetadata == null) {
+      throw new ControllerApplicationException(LOGGER, "Failed to cancel 
tenant rebalance job: " + jobId,
+          Response.Status.NOT_FOUND);
+    }
+    try {
+      ZkBasedTenantRebalanceObserver observer =
+          new ZkBasedTenantRebalanceObserver(jobId, 
jobMetadata.get(CommonConstants.ControllerJob.TENANT_NAME),
+              _pinotHelixResourceManager);
+      Pair<List<String>, Boolean> result = observer.cancelJob(true);
+      if (result.getRight()) {
+        return new SuccessResponse(
+            "Successfully cancelled tenant rebalance job: " + jobId + ". 
Cancelled " + result.getLeft().size()
+                + " table rebalance jobs: " + result.getLeft());
+      } else {
+        throw new ControllerApplicationException(LOGGER,
+            "Failed to cancel tenant rebalance job: " + jobId + ", yet " + 
result.getLeft().size()
+                + " table rebalance jobs are cancelled successfully: " + 
result.getLeft(),
+            Response.Status.INTERNAL_SERVER_ERROR);

Review Comment:
   Added



-- 
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