Updated Branches: refs/heads/helix-0.6.2-release 7db3d060e -> a3a2e87a8
[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/b23f983a Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/b23f983a Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/b23f983a Branch: refs/heads/helix-0.6.2-release Commit: b23f983ae2f2bf92cf7b3a12ed24b0cc9eb4e9a6 Parents: 7db3d06 Author: Kanak Biscuitwala <[email protected]> Authored: Mon Oct 14 17:27:43 2013 -0700 Committer: Kanak Biscuitwala <[email protected]> Committed: Fri Oct 18 16:31:03 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/b23f983a/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 08a8208..169b2bb 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 @@ -619,15 +619,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/b23f983a/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 463369a..7a4fcad 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 @@ -484,4 +484,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; + } }
