You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2013/10/15 02:28:23 UTC

git commit: [HELIX-216] Allow HelixAdmin addResource to accept the old rebalancing types, rb=13720

Updated Branches:
  refs/heads/master 1f66035bf -> f2a645589


[HELIX-216] Allow HelixAdmin addResource to accept the old rebalancing types, rb=13720


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

Branch: refs/heads/master
Commit: f2a64558914e96255873656242b3d0e76b2eb7b4
Parents: 1f66035
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Mon Oct 14 17:27:43 2013 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Mon Oct 14 17:27:43 2013 -0700

----------------------------------------------------------------------
 .../apache/helix/manager/zk/ZKHelixAdmin.java   |  8 ++------
 .../java/org/apache/helix/model/IdealState.java | 21 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f2a64558/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
index 754df7b..99668d3 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
@@ -615,15 +615,11 @@ public class ZKHelixAdmin implements HelixAdmin {
       throw new HelixException("cluster " + clusterName + " is not setup yet");
     }
 
-    RebalanceMode mode = RebalanceMode.SEMI_AUTO;
-    try {
-      mode = RebalanceMode.valueOf(rebalancerMode);
-    } catch (Exception e) {
-      logger.error("", e);
-    }
     IdealState idealState = new IdealState(resourceName);
     idealState.setNumPartitions(partitions);
     idealState.setStateModelDefRef(stateModelRef);
+    RebalanceMode mode =
+        idealState.rebalanceModeFromString(rebalancerMode, RebalanceMode.SEMI_AUTO);
     idealState.setRebalanceMode(mode);
     idealState.setReplicas("" + 0);
     idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f2a64558/helix-core/src/main/java/org/apache/helix/model/IdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/IdealState.java b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
index 90a2dff..be30913 100644
--- a/helix-core/src/main/java/org/apache/helix/model/IdealState.java
+++ b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
@@ -518,4 +518,25 @@ public class IdealState extends HelixProperty {
     }
     return property;
   }
+
+  /**
+   * Parse a RebalanceMode from a string. It can also understand IdealStateModeProperty values.
+   * @param mode string containing a RebalanceMode value
+   * @param defaultMode the mode to use if the string is not valid
+   * @return converted RebalanceMode value
+   */
+  public RebalanceMode rebalanceModeFromString(String mode, RebalanceMode defaultMode) {
+    RebalanceMode rebalanceMode = defaultMode;
+    try {
+      rebalanceMode = RebalanceMode.valueOf(mode);
+    } catch (Exception rebalanceModeException) {
+      try {
+        IdealStateModeProperty oldMode = IdealStateModeProperty.valueOf(mode);
+        rebalanceMode = normalizeRebalanceMode(oldMode);
+      } catch (Exception e) {
+        logger.error(e);
+      }
+    }
+    return rebalanceMode;
+  }
 }