Skip to content

Commit

Permalink
Correctly state cluster is in maintenance mode when maintenance znode…
Browse files Browse the repository at this point in the history
… is empty (#2559)

helix-rest maintenanceSignal detects cluster in maintenance mode when maintenance znode is empty
  • Loading branch information
GrantPSpencer authored Jul 21, 2023
1 parent 4b180a5 commit f3cf2dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,16 @@ public Response getClusterMaintenanceHistory(@PathParam("clusterId") String clus
@GET
@Path("{clusterId}/controller/maintenanceSignal")
public Response getClusterMaintenanceSignal(@PathParam("clusterId") String clusterId) {
HelixDataAccessor dataAccessor = getDataAccssor(clusterId);
MaintenanceSignal maintenanceSignal =
dataAccessor.getProperty(dataAccessor.keyBuilder().maintenance());
if (maintenanceSignal != null) {
Map<String, String> maintenanceInfo = maintenanceSignal.getRecord().getSimpleFields();
boolean inMaintenanceMode = getHelixAdmin().isInMaintenanceMode(clusterId);

if (inMaintenanceMode) {
HelixDataAccessor dataAccessor = getDataAccssor(clusterId);
MaintenanceSignal maintenanceSignal = dataAccessor.getProperty(dataAccessor.keyBuilder().maintenance());

Map<String, String> maintenanceInfo = (maintenanceSignal != null) ?
maintenanceSignal.getRecord().getSimpleFields() : new HashMap<>();
maintenanceInfo.put(ClusterProperties.clusterName.name(), clusterId);

return JSONRepresentation(maintenanceInfo);
}
return notFound(String.format("Cluster %s is not in maintenance mode!", clusterId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,33 @@ public void testEnableDisableMaintenanceMode() throws IOException {
}

@Test(dependsOnMethods = "testEnableDisableMaintenanceMode")
public void testEmptyMaintenanceSignal() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();

// Create empty maintenance znode
ZNRecord record = new ZNRecord("test_maintenance_node");
ZKUtil.createOrUpdate(_gZkClient, "/"+cluster+"/CONTROLLER/MAINTENANCE", record, true, true);

// Verify maintenance mode enabled
Assert.assertTrue(isMaintenanceModeEnabled(cluster));
get("clusters/" + cluster + "/controller/maintenanceSignal", null,
Response.Status.OK.getStatusCode(), true);


// Disable maintenance mode
post("clusters/" + cluster, ImmutableMap.of("command", "disableMaintenanceMode"),
Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());

// Verify no longer in maintenance mode
Assert.assertFalse(isMaintenanceModeEnabled(cluster));
get("clusters/" + cluster + "/controller/maintenanceSignal", null,
Response.Status.NOT_FOUND.getStatusCode(), false);
System.out.println("End test :" + TestHelper.getTestMethodName());

}

@Test(dependsOnMethods = "testEmptyMaintenanceSignal")
public void testGetControllerLeadershipHistory() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
Expand Down

0 comments on commit f3cf2dd

Please sign in to comment.