You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ji...@apache.org on 2020/04/23 19:27:53 UTC

[helix] 07/23: add listener and config for customized view aggregation (#815)

This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git

commit ca7af925154747e900e1a2370472b1e348ec7ee9
Author: zhangmeng916 <56...@users.noreply.github.com>
AuthorDate: Wed Feb 26 16:34:27 2020 -0800

    add listener and config for customized view aggregation (#815)
    
    Add listeners for customized state and customized state aggregation config in Helix managers
---
 .../main/java/org/apache/helix/HelixConstants.java |  2 +
 .../main/java/org/apache/helix/HelixManager.java   | 22 ++++++++++-
 .../main/java/org/apache/helix/PropertyType.java   |  2 +-
 ...mizedStateAggregationConfigChangeListener.java} | 41 +++++++++-----------
 .../listeners/CustomizedStateChangeListener.java}  | 44 ++++++++++------------
 .../helix/controller/stages/AttributeName.java     |  1 +
 .../apache/helix/manager/zk/ZKHelixManager.java    | 19 ++++++++++
 .../controller/stages/DummyClusterManager.java     | 16 ++++++++
 .../manager/TestParticipantManager.java            |  2 +-
 .../java/org/apache/helix/mock/MockManager.java    | 15 ++++++++
 .../helix/participant/MockZKHelixManager.java      | 16 ++++++++
 11 files changed, 129 insertions(+), 51 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/HelixConstants.java b/helix-core/src/main/java/org/apache/helix/HelixConstants.java
index b0783bf..27f82c6 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixConstants.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixConstants.java
@@ -30,9 +30,11 @@ public interface HelixConstants {
     CONFIG (PropertyType.CONFIGS),
     INSTANCE_CONFIG (PropertyType.CONFIGS),
     RESOURCE_CONFIG (PropertyType.CONFIGS),
+    CUSTOMIZED_STATE_AGGREGATION_CONFIG (PropertyType.CONFIGS),
     CLUSTER_CONFIG (PropertyType.CONFIGS),
     LIVE_INSTANCE (PropertyType.LIVEINSTANCES),
     CURRENT_STATE (PropertyType.CURRENTSTATES),
+    CUSTOMIZED_STATE (PropertyType.CUSTOMIZEDSTATES),
     MESSAGE (PropertyType.MESSAGES),
     EXTERNAL_VIEW (PropertyType.EXTERNALVIEW),
     CUSTOMIZED_VIEW (PropertyType.CUSTOMIZEDVIEW),
diff --git a/helix-core/src/main/java/org/apache/helix/HelixManager.java b/helix-core/src/main/java/org/apache/helix/HelixManager.java
index 2be5ce4..a499b14 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixManager.java
@@ -26,6 +26,8 @@ import org.apache.helix.api.listeners.ClusterConfigChangeListener;
 import org.apache.helix.api.listeners.ConfigChangeListener;
 import org.apache.helix.api.listeners.ControllerChangeListener;
 import org.apache.helix.api.listeners.CurrentStateChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateAggregationConfigChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateChangeListener;
 import org.apache.helix.api.listeners.ExternalViewChangeListener;
 import org.apache.helix.api.listeners.CustomizedViewChangeListener;
 import org.apache.helix.api.listeners.IdealStateChangeListener;
@@ -39,6 +41,7 @@ import org.apache.helix.controller.pipeline.Pipeline;
 import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
 import org.apache.helix.manager.zk.ZKHelixManager;
 import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.CustomizedStateAggregationConfig;
 import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
 import org.apache.helix.participant.HelixStateMachineEngine;
 import org.apache.helix.participant.StateMachineEngine;
@@ -158,6 +161,15 @@ public interface HelixManager {
   void addResourceConfigChangeListener(ResourceConfigChangeListener listener) throws Exception;
 
   /**
+   * @see CustomizedStateAggregationConfigChangeListener#onCustomizedStateAggregationConfigChange(CustomizedStateAggregationConfig,
+   *      NotificationContext)
+   * @param listener
+   */
+
+  void addCustomizedStateAggregationConfigChangeListener(
+      CustomizedStateAggregationConfigChangeListener listener) throws Exception;
+
+  /**
    * @see ClusterConfigChangeListener#onClusterConfigChange(ClusterConfig, NotificationContext)
    * @param listener
    */
@@ -215,6 +227,14 @@ public interface HelixManager {
       String sessionId) throws Exception;
 
   /**
+   * @see CustomizedStateChangeListener#onCustomizedStateChange(String, List, NotificationContext)
+   * @param listener
+   * @param instanceName
+   */
+  void addCustomizedStateChangeListener(CustomizedStateChangeListener listener, String instanceName,
+      String stateName) throws Exception;
+
+  /**
    * @see ExternalViewChangeListener#onExternalViewChange(List, NotificationContext)
    * @param listener
    */
@@ -425,4 +445,4 @@ public interface HelixManager {
    * @return ParticipantHealthReportCollector
    */
   ParticipantHealthReportCollector getHealthReportCollector();
-}
+}
\ No newline at end of file
diff --git a/helix-core/src/main/java/org/apache/helix/PropertyType.java b/helix-core/src/main/java/org/apache/helix/PropertyType.java
index 363db21..03a6ce8 100644
--- a/helix-core/src/main/java/org/apache/helix/PropertyType.java
+++ b/helix-core/src/main/java/org/apache/helix/PropertyType.java
@@ -216,4 +216,4 @@ public enum PropertyType {
   public boolean isCached() {
     return isCached;
   }
-}
+}
\ No newline at end of file
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java b/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateAggregationConfigChangeListener.java
similarity index 53%
copy from helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
copy to helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateAggregationConfigChangeListener.java
index b570568..2617ef3 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
+++ b/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateAggregationConfigChangeListener.java
@@ -1,4 +1,4 @@
-package org.apache.helix.controller.stages;
+package org.apache.helix.api.listeners;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -9,7 +9,7 @@ package org.apache.helix.controller.stages;
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
@@ -19,25 +19,18 @@ package org.apache.helix.controller.stages;
  * under the License.
  */
 
-public enum AttributeName {
-  RESOURCES,
-  RESOURCES_TO_REBALANCE,
-  BEST_POSSIBLE_STATE,
-  CURRENT_STATE,
-  INTERMEDIATE_STATE,
-  MESSAGES_ALL,
-  MESSAGES_SELECTED,
-  MESSAGES_THROTTLE,
-  LOCAL_STATE,
-  EVENT_CREATE_TIME,
-  helixmanager,
-  clusterStatusMonitor,
-  changeContext,
-  instanceName,
-  eventData,
-  AsyncFIFOWorkerPool,
-  PipelineType,
-  LastRebalanceFinishTimeStamp,
-  ControllerDataProvider,
-  STATEFUL_REBALANCER
-}
+import org.apache.helix.NotificationContext;
+import org.apache.helix.model.CustomizedStateAggregationConfig;
+
+/**
+ * Interface to implement to listen for changes to customized state aggregation configurations.
+ */
+public interface CustomizedStateAggregationConfigChangeListener {
+  /**
+   * Invoked when customized state aggregation config changes
+   * @param customizedStateAggregationConfig
+   * @param context
+   */
+  void onCustomizedStateAggregationConfigChange(CustomizedStateAggregationConfig customizedStateAggregationConfig,
+      NotificationContext context);
+}
\ No newline at end of file
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java b/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateChangeListener.java
similarity index 51%
copy from helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
copy to helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateChangeListener.java
index b570568..0753f67 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
+++ b/helix-core/src/main/java/org/apache/helix/api/listeners/CustomizedStateChangeListener.java
@@ -1,4 +1,4 @@
-package org.apache.helix.controller.stages;
+package org.apache.helix.api.listeners;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -9,7 +9,7 @@ package org.apache.helix.controller.stages;
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
@@ -19,25 +19,21 @@ package org.apache.helix.controller.stages;
  * under the License.
  */
 
-public enum AttributeName {
-  RESOURCES,
-  RESOURCES_TO_REBALANCE,
-  BEST_POSSIBLE_STATE,
-  CURRENT_STATE,
-  INTERMEDIATE_STATE,
-  MESSAGES_ALL,
-  MESSAGES_SELECTED,
-  MESSAGES_THROTTLE,
-  LOCAL_STATE,
-  EVENT_CREATE_TIME,
-  helixmanager,
-  clusterStatusMonitor,
-  changeContext,
-  instanceName,
-  eventData,
-  AsyncFIFOWorkerPool,
-  PipelineType,
-  LastRebalanceFinishTimeStamp,
-  ControllerDataProvider,
-  STATEFUL_REBALANCER
-}
+import java.util.List;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.model.CustomizedState;
+
+/**
+ * Interface to implement to respond to changes in the current state
+ */
+public interface CustomizedStateChangeListener {
+
+  /**
+   * Invoked when customized state changes
+   * @param instanceName name of the instance whose state changed
+   * @param customizedStatesInfo a list of the customized states
+   * @param changeContext the change event and state
+   */
+  void onCustomizedStateChange(String instanceName, List<CustomizedState> customizedStatesInfo,
+      NotificationContext changeContext);
+}
\ No newline at end of file
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java b/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
index b570568..0af0ee5 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/AttributeName.java
@@ -24,6 +24,7 @@ public enum AttributeName {
   RESOURCES_TO_REBALANCE,
   BEST_POSSIBLE_STATE,
   CURRENT_STATE,
+  CUSTOMIZED_STATE,
   INTERMEDIATE_STATE,
   MESSAGES_ALL,
   MESSAGES_SELECTED,
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
index c06ddf1..a6425fa 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
@@ -58,6 +58,8 @@ import org.apache.helix.api.listeners.ConfigChangeListener;
 import org.apache.helix.api.listeners.ControllerChangeListener;
 import org.apache.helix.api.listeners.CurrentStateChangeListener;
 import org.apache.helix.api.listeners.CustomizedViewChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateAggregationConfigChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateChangeListener;
 import org.apache.helix.api.listeners.ExternalViewChangeListener;
 import org.apache.helix.api.listeners.IdealStateChangeListener;
 import org.apache.helix.api.listeners.InstanceConfigChangeListener;
@@ -487,6 +489,15 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
   }
 
   @Override
+  public void addCustomizedStateAggregationConfigChangeListener(
+      CustomizedStateAggregationConfigChangeListener listener) throws Exception {
+    addListener(listener, new Builder(_clusterName).customizedStateAggregationConfig(),
+        ChangeType.CUSTOMIZED_STATE_AGGREGATION_CONFIG, new EventType[] {
+            EventType.NodeDataChanged
+        });
+  }
+
+  @Override
   public void addClusterfigChangeListener(ClusterConfigChangeListener listener) throws Exception{
     addListener(listener, new Builder(_clusterName).clusterConfig(), ChangeType.CLUSTER_CONFIG,
         new EventType[] { EventType.NodeDataChanged
@@ -576,6 +587,14 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
   }
 
   @Override
+  public void addCustomizedStateChangeListener(CustomizedStateChangeListener listener,
+      String instanceName, String customizedStateName) throws Exception {
+    addListener(listener, new Builder(_clusterName).customizedStates(instanceName, customizedStateName),
+        ChangeType.CUSTOMIZED_STATE, new EventType[] { EventType.NodeChildrenChanged
+        });
+  }
+
+  @Override
   public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception {
     addListener(listener, new Builder(_clusterName).externalViews(), ChangeType.EXTERNAL_VIEW,
         new EventType[] { EventType.NodeChildrenChanged });
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
index 076f115..84d413b 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
@@ -37,6 +37,8 @@ import org.apache.helix.api.listeners.ClusterConfigChangeListener;
 import org.apache.helix.api.listeners.ConfigChangeListener;
 import org.apache.helix.api.listeners.ControllerChangeListener;
 import org.apache.helix.api.listeners.CurrentStateChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateAggregationConfigChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateChangeListener;
 import org.apache.helix.api.listeners.ExternalViewChangeListener;
 import org.apache.helix.api.listeners.CustomizedViewChangeListener;
 import org.apache.helix.api.listeners.IdealStateChangeListener;
@@ -132,6 +134,13 @@ public class DummyClusterManager implements HelixManager {
   }
 
   @Override
+  public void addCustomizedStateChangeListener(CustomizedStateChangeListener listener,
+      String instanceName, String sessionId) throws Exception {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
   public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception {
     // TODO Auto-generated method stub
 
@@ -293,6 +302,13 @@ public class DummyClusterManager implements HelixManager {
   }
 
   @Override
+  public void addCustomizedStateAggregationConfigChangeListener(CustomizedStateAggregationConfigChangeListener listener)
+      throws Exception {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
   public void addClusterfigChangeListener(ClusterConfigChangeListener listener)
       throws Exception {
     // TODO Auto-generated method stub
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
index 6e972c5..c7a3752 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
@@ -151,7 +151,7 @@ public class TestParticipantManager extends ZkTestBase {
     // check HelixCallback Monitor
     Set<ObjectInstance> objs =
         _server.queryMBeans(buildCallbackMonitorObjectName(type, clusterName, instanceName), null);
-    Assert.assertEquals(objs.size(), 14);
+    Assert.assertEquals(objs.size(), 16);
 
     // check HelixZkClient Monitors
     objs =
diff --git a/helix-core/src/test/java/org/apache/helix/mock/MockManager.java b/helix-core/src/test/java/org/apache/helix/mock/MockManager.java
index 01e6b9e..f32160b 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/MockManager.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/MockManager.java
@@ -40,6 +40,8 @@ import org.apache.helix.api.listeners.ConfigChangeListener;
 import org.apache.helix.api.listeners.ControllerChangeListener;
 import org.apache.helix.api.listeners.CurrentStateChangeListener;
 import org.apache.helix.api.listeners.CustomizedViewChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateAggregationConfigChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateChangeListener;
 import org.apache.helix.api.listeners.ExternalViewChangeListener;
 import org.apache.helix.api.listeners.IdealStateChangeListener;
 import org.apache.helix.api.listeners.InstanceConfigChangeListener;
@@ -136,6 +138,13 @@ public class MockManager implements HelixManager {
   }
 
   @Override
+  public void addCustomizedStateChangeListener(CustomizedStateChangeListener listener,
+      String instanceName, String sessionId) {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
   public void addExternalViewChangeListener(ExternalViewChangeListener listener) {
     // TODO Auto-generated method stub
 
@@ -164,6 +173,12 @@ public class MockManager implements HelixManager {
   }
 
   @Override
+  public void addCustomizedStateAggregationConfigChangeListener(CustomizedStateAggregationConfigChangeListener listener)
+      throws Exception {
+
+  }
+
+  @Override
   public void addClusterfigChangeListener(ClusterConfigChangeListener listener)
       throws Exception {
 
diff --git a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
index 67efbd5..4abe7c6 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
@@ -39,6 +39,8 @@ import org.apache.helix.api.listeners.ConfigChangeListener;
 import org.apache.helix.api.listeners.ControllerChangeListener;
 import org.apache.helix.api.listeners.CurrentStateChangeListener;
 import org.apache.helix.api.listeners.CustomizedViewChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateAggregationConfigChangeListener;
+import org.apache.helix.api.listeners.CustomizedStateChangeListener;
 import org.apache.helix.api.listeners.ExternalViewChangeListener;
 import org.apache.helix.api.listeners.IdealStateChangeListener;
 import org.apache.helix.api.listeners.InstanceConfigChangeListener;
@@ -124,6 +126,13 @@ public class MockZKHelixManager implements HelixManager {
   }
 
   @Override
+  public void addCustomizedStateAggregationConfigChangeListener(CustomizedStateAggregationConfigChangeListener listener)
+      throws Exception {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
   public void addClusterfigChangeListener(ClusterConfigChangeListener listener)
       throws Exception {
     // TODO Auto-generated method stub
@@ -161,6 +170,13 @@ public class MockZKHelixManager implements HelixManager {
   }
 
   @Override
+  public void addCustomizedStateChangeListener(CustomizedStateChangeListener listener,
+      String instanceName, String sessionId) throws Exception {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
   public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception {
     // TODO Auto-generated method stub