You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2022/04/05 01:02:58 UTC

[GitHub] [helix] xyuanlu commented on a diff in pull request #1995: Implement DefaultCloudEventCallbackImpl

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


##########
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:
   Depending on the implementation of `getInstanceHelixDisabledType`, isEnabled could be duplicate.



##########
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:
   Depending on the implementation of `getInstanceHelixDisabledType`, isEnabled could be duplicate.



-- 
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: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org