Skip to content

Commit

Permalink
Expose Evacuate Finished API in Helix-Rest (#2694)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantPSpencer authored Nov 14, 2023
1 parent 4168e6b commit 75c5521
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public enum Command {
setInstanceOperation, // TODO: Name is just a place holder, may change in future
canCompleteSwap,
completeSwapIfPossible,
onDemandRebalance
onDemandRebalance,
isEvacuateFinished
}

@Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ public Response updateInstance(@PathParam("clusterId") String clusterId,
OBJECT_MAPPER.getTypeFactory()
.constructCollectionType(List.class, String.class)));
break;
case isEvacuateFinished:
boolean evacuateFinished;
try {
evacuateFinished = admin.isEvacuateFinished(clusterId, instanceName);
} catch (HelixException e) {
LOG.error(String.format("Encountered error when checking if evacuation finished for cluster: "
+ "{}, instance: {}", clusterId, instanceName), e);
return serverError(e);
}
return OK(OBJECT_MAPPER.writeValueAsString(Map.of("successful", evacuateFinished)));
default:
LOG.error("Unsupported command :" + command);
return badRequest("Unsupported command :" + command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,39 @@ public void updateInstance() throws IOException {
OBJECT_MAPPER.readValue(completeSwapIfPossibleResponse.readEntity(String.class), Map.class);
Assert.assertFalse((boolean) responseMap.get("successful"));

// test isEvacuateFinished on instance with EVACUATE but has currentState
new JerseyUriRequestBuilder("clusters/{}/instances/{}?command=setInstanceOperation&instanceOperation=EVACUATE")
.format(CLUSTER_NAME, INSTANCE_NAME).post(this, entity);
instanceConfig = _configAccessor.getInstanceConfig(CLUSTER_NAME, INSTANCE_NAME);
Assert.assertEquals(
instanceConfig.getInstanceOperation(), InstanceConstants.InstanceOperation.EVACUATE.toString());

Response response = new JerseyUriRequestBuilder("clusters/{}/instances/{}?command=isEvacuateFinished")
.format(CLUSTER_NAME, INSTANCE_NAME).post(this, entity);
Map<String, Boolean> evacuateFinishedresult = OBJECT_MAPPER.readValue(response.readEntity(String.class), Map.class);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertFalse(evacuateFinishedresult.get("successful"));

// test isEvacuateFinished on instance with EVACUATE and no currentState
// Create new instance so no currentState or messages assigned to it
String test_instance_name = INSTANCE_NAME + "_foo";
InstanceConfig newInstanceConfig = new InstanceConfig(test_instance_name);
Entity instanceEntity = Entity.entity(OBJECT_MAPPER.writeValueAsString(newInstanceConfig.getRecord()),
MediaType.APPLICATION_JSON_TYPE);
new JerseyUriRequestBuilder("clusters/{}/instances/{}").format(CLUSTER_NAME, test_instance_name)
.put(this, instanceEntity);

new JerseyUriRequestBuilder("clusters/{}/instances/{}?command=setInstanceOperation&instanceOperation=EVACUATE")
.format(CLUSTER_NAME, test_instance_name).post(this, entity);
instanceConfig = _configAccessor.getInstanceConfig(CLUSTER_NAME, test_instance_name);
Assert.assertEquals(
instanceConfig.getInstanceOperation(), InstanceConstants.InstanceOperation.EVACUATE.toString());

response = new JerseyUriRequestBuilder("clusters/{}/instances/{}?command=isEvacuateFinished")
.format(CLUSTER_NAME, test_instance_name).post(this, entity);
evacuateFinishedresult = OBJECT_MAPPER.readValue(response.readEntity(String.class), Map.class);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertTrue(evacuateFinishedresult.get("successful"));
System.out.println("End test :" + TestHelper.getTestMethodName());
}

Expand Down

0 comments on commit 75c5521

Please sign in to comment.