diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/PerInstanceAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/PerInstanceAccessor.java index b920f66ce8..b1b4f82642 100644 --- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/PerInstanceAccessor.java +++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/PerInstanceAccessor.java @@ -436,15 +436,11 @@ public Response updateInstance(@PathParam("clusterId") String clusterId, admin.setInstanceOperation(clusterId, instanceName, state); break; case canCompleteSwap: - if (!admin.canCompleteSwap(clusterId, instanceName)) { - return badRequest("Swap is not ready to be completed!"); - } - break; + return OK(OBJECT_MAPPER.writeValueAsString( + Map.of("successful", admin.canCompleteSwap(clusterId, instanceName)))); case completeSwapIfPossible: - if (!admin.completeSwapIfPossible(clusterId, instanceName)) { - return badRequest("Swap is not ready to be completed!"); - } - break; + return OK(OBJECT_MAPPER.writeValueAsString( + Map.of("successful", admin.completeSwapIfPossible(clusterId, instanceName)))); case addInstanceTag: if (!validInstance(node, instanceName)) { return badRequest("Instance names are not match!"); diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java index 273019bd3f..a8675202a3 100644 --- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java +++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java @@ -501,6 +501,26 @@ public void updateInstance() throws IOException { instanceConfig = _configAccessor.getInstanceConfig(CLUSTER_NAME, INSTANCE_NAME); Assert.assertEquals( instanceConfig.getInstanceOperation(), ""); + + // test canCompleteSwap + Response canCompleteSwapResponse = + new JerseyUriRequestBuilder("clusters/{}/instances/{}?command=canCompleteSwap").format( + CLUSTER_NAME, INSTANCE_NAME).post(this, entity); + Assert.assertEquals(canCompleteSwapResponse.getStatus(), Response.Status.OK.getStatusCode()); + Map responseMap = + OBJECT_MAPPER.readValue(canCompleteSwapResponse.readEntity(String.class), Map.class); + Assert.assertFalse((boolean) responseMap.get("successful")); + + // test completeSwapIfPossible + Response completeSwapIfPossibleResponse = new JerseyUriRequestBuilder( + "clusters/{}/instances/{}?command=completeSwapIfPossible").format(CLUSTER_NAME, + INSTANCE_NAME).post(this, entity); + Assert.assertEquals(completeSwapIfPossibleResponse.getStatus(), + Response.Status.OK.getStatusCode()); + responseMap = + OBJECT_MAPPER.readValue(completeSwapIfPossibleResponse.readEntity(String.class), Map.class); + Assert.assertFalse((boolean) responseMap.get("successful")); + System.out.println("End test :" + TestHelper.getTestMethodName()); }