helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject helix git commit: Make more user friendly API change
Date Thu, 30 Mar 2017 22:57:41 GMT
Repository: helix
Updated Branches:
  refs/heads/helix-0.6.x c9216c48e -> 7038c78eb


Make more user friendly API change

Current API provide a map that returns resource to disabled partitions that combined in one
String. Change to return a map that returns resource to list of disabled partitions.


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/7038c78e
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/7038c78e
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/7038c78e

Branch: refs/heads/helix-0.6.x
Commit: 7038c78eb5737f706621265bbba6a3bfe09c081f
Parents: c9216c4
Author: Junkai Xue <jxue@linkedin.com>
Authored: Thu Mar 30 15:45:26 2017 -0700
Committer: Junkai Xue <jxue@linkedin.com>
Committed: Thu Mar 30 15:50:36 2017 -0700

----------------------------------------------------------------------
 .../controller/stages/ReadClusterDataStage.java |  2 +-
 .../org/apache/helix/model/InstanceConfig.java  | 24 ++++++++++++++++----
 .../monitoring/mbeans/ClusterStatusMonitor.java | 10 ++++----
 .../monitoring/mbeans/InstanceMonitor.java      |  6 ++---
 .../helix/manager/zk/TestZkHelixAdmin.java      | 10 +++-----
 5 files changed, 31 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/7038c78e/helix-core/src/main/java/org/apache/helix/controller/stages/ReadClusterDataStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/ReadClusterDataStage.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/ReadClusterDataStage.java
index 521d315..971d719 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/ReadClusterDataStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/ReadClusterDataStage.java
@@ -67,7 +67,7 @@ public class ReadClusterDataStage extends AbstractBaseStage {
       Set<String> instanceSet = Sets.newHashSet();
       Set<String> liveInstanceSet = Sets.newHashSet();
       Set<String> disabledInstanceSet = Sets.newHashSet();
-      Map<String, Map<String, String>> disabledPartitions = Maps.newHashMap();
+      Map<String, Map<String, List<String>>> disabledPartitions = Maps.newHashMap();
       Map<String, Set<String>> tags = Maps.newHashMap();
       Map<String, LiveInstance> liveInstanceMap = _cache.getLiveInstances();
       for (Map.Entry<String, InstanceConfig> e : _cache.getInstanceConfigMap().entrySet())
{

http://git-wip-us.apache.org/repos/asf/helix/blob/7038c78e/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
index 8dcd1ef..ce1d47e 100644
--- a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
@@ -317,13 +317,27 @@ public class InstanceConfig extends HelixProperty {
   }
 
   /**
-   * Get a map that mapping resource name to disabled partitions
-   * @return A map of resource name mapping to disabled partitions
-   */
-  public Map<String, String> getDisabledPartitionsMap() {
-    return _record.getMapField(InstanceConfigProperty.HELIX_DISABLED_PARTITION.name());
+  * Get a map that mapping resource name to disabled partitions
+  * @return A map of resource name mapping to disabled partitions. If no
+  *         resource/partitions disabled, return an empty map.
+  */
+  public Map<String, List<String>> getDisabledPartitionsMap() {
+    Map<String, String> disabledPartitionsRawMap =
+        _record.getMapField(InstanceConfigProperty.HELIX_DISABLED_PARTITION.name());
+    if (disabledPartitionsRawMap == null) {
+      return Collections.emptyMap();
+    }
+
+    Map<String, List<String>> disabledPartitionsMap = new HashMap<String,
List<String>>();
+    for (String resourceName : disabledPartitionsRawMap.keySet()) {
+      disabledPartitionsMap.put(resourceName, getDisabledPartitions(resourceName));
+    }
+
+    return disabledPartitionsMap;
   }
 
+
+
   /**
    * Set the enabled state for a partition on this instance across all the resources
    *

http://git-wip-us.apache.org/repos/asf/helix/blob/7038c78e/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
b/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
index 22d7209..468a0ce 100644
--- a/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
+++ b/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
@@ -75,7 +75,7 @@ public class ClusterStatusMonitor implements ClusterStatusMonitorMBean {
   private Set<String> _liveInstances = Collections.emptySet();
   private Set<String> _instances = Collections.emptySet();
   private Set<String> _disabledInstances = Collections.emptySet();
-  private Map<String, Map<String, String>> _disabledPartitions = Collections.emptyMap();
+  private Map<String, Map<String, List<String>>> _disabledPartitions =
Collections.emptyMap();
   private Map<String, Long> _instanceMsgQueueSizes = Maps.newConcurrentMap();
 
   private final ConcurrentHashMap<String, ResourceMonitor> _resourceMbeanMap =
@@ -133,10 +133,10 @@ public class ClusterStatusMonitor implements ClusterStatusMonitorMBean
{
 
   @Override public long getDisabledPartitionsGauge() {
     int numDisabled = 0;
-    for (Map<String, String> perInstance : _disabledPartitions.values()) {
-      for (String partitions : perInstance.values()) {
+    for (Map<String, List<String>> perInstance : _disabledPartitions.values())
{
+      for (List<String> partitions : perInstance.values()) {
         if (partitions != null) {
-          numDisabled += HelixUtil.deserializeByComma(partitions).size();
+          numDisabled += partitions.size();
         }
       }
     }
@@ -200,7 +200,7 @@ public class ClusterStatusMonitor implements ClusterStatusMonitorMBean
{
    * @param tags a map of instance name to the set of tags on it
    */
   public void setClusterInstanceStatus(Set<String> liveInstanceSet, Set<String>
instanceSet,
-      Set<String> disabledInstanceSet, Map<String, Map<String, String>>
disabledPartitions,
+      Set<String> disabledInstanceSet, Map<String, Map<String, List<String>>>
disabledPartitions,
       Map<String, Set<String>> tags) {
     // Unregister beans for instances that are no longer configured
     Set<String> toUnregister = Sets.newHashSet(_instanceMbeanMap.keySet());

http://git-wip-us.apache.org/repos/asf/helix/blob/7038c78e/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/InstanceMonitor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/InstanceMonitor.java
b/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/InstanceMonitor.java
index 46d8a96..722303b 100644
--- a/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/InstanceMonitor.java
+++ b/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/InstanceMonitor.java
@@ -119,7 +119,7 @@ public class InstanceMonitor implements InstanceMonitorMBean {
    * @param isLive true if running, false otherwise
    * @param isEnabled true if enabled, false if disabled
    */
-  public synchronized void updateInstance(Set<String> tags, Map<String, String>
disabledPartitions,
+  public synchronized void updateInstance(Set<String> tags, Map<String, List<String>>
disabledPartitions,
       boolean isLive, boolean isEnabled) {
     if (tags == null || tags.isEmpty()) {
       _tags = ImmutableList.of(ClusterStatusMonitor.DEFAULT_TAG);
@@ -129,9 +129,9 @@ public class InstanceMonitor implements InstanceMonitorMBean {
     }
     _disabledPartitions = 0L;
     if (disabledPartitions != null) {
-      for (String partitions : disabledPartitions.values()) {
+      for (List<String> partitions : disabledPartitions.values()) {
         if (partitions != null) {
-          _disabledPartitions += HelixUtil.deserializeByComma(partitions).size();
+          _disabledPartitions += partitions.size();
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/helix/blob/7038c78e/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
index bb1b079..a431171 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
@@ -429,15 +429,11 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
     Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(),
2);
     Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(),
3);
 
-    // Test enable partition across resources
-    instanceConfig.setInstanceEnabledForPartition("2", true);
-    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(),
1);
-    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(),
2);
-
     // Test disable partition across resources
+    // TODO : Remove this part once setInstanceEnabledForPartition(partition, enabled) is
removed
     instanceConfig.setInstanceEnabledForPartition("10", false);
-    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(),
2);
-    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(),
3);
+    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(),
3);
+    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(),
4);
   }
 
   @Test


Mime
View raw message