diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java index f81dc7f294..68744cbbe0 100644 --- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java +++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java @@ -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 maintenanceInfo = maintenanceSignal.getRecord().getSimpleFields(); + boolean inMaintenanceMode = getHelixAdmin().isInMaintenanceMode(clusterId); + + if (inMaintenanceMode) { + HelixDataAccessor dataAccessor = getDataAccssor(clusterId); + MaintenanceSignal maintenanceSignal = dataAccessor.getProperty(dataAccessor.keyBuilder().maintenance()); + + Map 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)); diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java index 59cb51c9f1..86c9d5ae3b 100644 --- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java +++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java @@ -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();