mgao0 commented on code in PR #1995:
URL: https://github.com/apache/helix/pull/1995#discussion_r843360527


##########
helix-core/src/main/java/org/apache/helix/cloud/event/helix/DefaultCloudEventCallbackImpl.java:
##########
@@ -43,27 +56,50 @@ public void disableInstance(HelixManager manager, Object 
eventInfo) {
    * @param eventInfo Detailed information about the event
    */
   public void enableInstance(HelixManager manager, Object eventInfo) {
-    // To be implemented
-    throw new NotImplementedException();
+    String instanceName = manager.getInstanceName();
+    HelixDataAccessor accessor = manager.getHelixDataAccessor();
+    if (!InstanceValidationUtil.isEnabled(accessor, instanceName) && 
InstanceValidationUtil
+        .getInstanceHelixDisabledType(accessor, instanceName)
+        .equals(InstanceConstants.InstanceDisabledType.CLOUD_EVENT.name())) {
+      manager.getClusterManagmentTool()
+          .enableInstance(manager.getClusterName(), instanceName, true);
+    }
   }
 
   /**
-   *
+   * Put cluster into maintenance mode if the cluster is not currently in 
maintenance mode
    * @param manager The helix manager associated with the listener
    * @param eventInfo Detailed information about the event
    */
   public void enterMaintenanceMode(HelixManager manager, Object eventInfo) {
-    // To be implemented
-    throw new NotImplementedException();
+    if 
(!manager.getClusterManagmentTool().isInMaintenanceMode(manager.getClusterName()))
 {
+      manager.getClusterManagmentTool()
+          .manuallyEnableMaintenanceMode(manager.getClusterName(), true, String
+              .format(_reason, "enterMaintenanceMode", _className, manager,
+                  System.currentTimeMillis()), null);
+    }
   }
 
   /**
-   *
+   * Exit maintenance mode for the cluster, if there is no more live instances 
disabled for cloud event
    * @param manager The helix manager associated with the listener
    * @param eventInfo Detailed information about the event
    */
   public void exitMaintenanceMode(HelixManager manager, Object eventInfo) {
-    // To be implemented
-    throw new NotImplementedException();
+    List<String> instances =
+        
manager.getClusterManagmentTool().getInstancesInCluster(manager.getClusterName());
+    // Check if there is any disabled live instance that was disabled due to 
cloud event,
+    // if none left, exit maintenance mode
+    HelixDataAccessor accessor = manager.getHelixDataAccessor();
+    if (instances.stream().noneMatch(
+        instance -> !InstanceValidationUtil.isEnabled(accessor, instance) && 
InstanceValidationUtil
+            .getInstanceHelixDisabledType(accessor, instance)

Review Comment:
   Updated



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