helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject helix git commit: [HELIX-570] Add default state model definitions if not already exists when controller starts, rb=31397
Date Wed, 18 Mar 2015 00:13:30 GMT
Repository: helix
Updated Branches:
  refs/heads/helix-0.6.x 5dc6fe7c3 -> 9e47455df


[HELIX-570] Add default state model definitions if not already exists when controller starts, rb=31397


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

Branch: refs/heads/helix-0.6.x
Commit: 9e47455df56d473a47a5686a0902cead3006cbed
Parents: 5dc6fe7
Author: zzhang <zzhang@apache.org>
Authored: Tue Mar 17 17:13:15 2015 -0700
Committer: zzhang <zzhang@apache.org>
Committed: Tue Mar 17 17:13:15 2015 -0700

----------------------------------------------------------------------
 .../helix/controller/HelixControllerMain.java   |   9 -
 .../apache/helix/manager/zk/ZKHelixManager.java |  22 +-
 .../model/BuiltInStateModelDefinitions.java     |  42 ++
 .../apache/helix/model/LeaderStandbySMD.java    | 150 +++++++
 .../org/apache/helix/model/MasterSlaveSMD.java  | 150 +++++++
 .../apache/helix/model/OnlineOfflineSMD.java    | 127 ++++++
 .../apache/helix/model/ScheduledTaskSMD.java    | 132 ++++++
 .../helix/model/StateModelDefinition.java       |   7 +-
 .../apache/helix/model/StorageSchemataSMD.java  | 131 ++++++
 .../java/org/apache/helix/model/TaskSMD.java    | 177 ++++++++
 .../org/apache/helix/tools/ClusterSetup.java    |  18 +-
 .../helix/tools/StateModelConfigGenerator.java  | 411 +------------------
 .../helix/integration/IntegrationTest.java      |   2 +-
 .../manager/zk/TestAddBuiltInStateModelDef.java |  82 ++++
 14 files changed, 1040 insertions(+), 420 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/controller/HelixControllerMain.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/HelixControllerMain.java b/helix-core/src/main/java/org/apache/helix/controller/HelixControllerMain.java
index b6c16b5..5f222f9 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/HelixControllerMain.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/HelixControllerMain.java
@@ -135,8 +135,6 @@ public class HelixControllerMain {
       manager.addConfigChangeListener(controller);
       manager.addLiveInstanceChangeListener(controller);
       manager.addIdealStateChangeListener(controller);
-      // no need for controller to listen on external-view
-      // manager.addExternalViewChangeListener(controller);
       manager.addControllerListener(controller);
     } catch (ZkInterruptedException e) {
       logger
@@ -164,18 +162,11 @@ public class HelixControllerMain {
         DistClusterControllerStateModelFactory stateModelFactory =
             new DistClusterControllerStateModelFactory(zkConnectString);
 
-        // StateMachineEngine genericStateMachineHandler = new
-        // StateMachineEngine();
         StateMachineEngine stateMach = manager.getStateMachineEngine();
         stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
-        // manager.getMessagingService().registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
-        // genericStateMachineHandler);
         manager.connect();
       } else {
         logger.error("cluster controller mode:" + controllerMode + " NOT supported");
-        // throw new
-        // IllegalArgumentException("Unsupported cluster controller mode:" +
-        // controllerMode);
       }
     } catch (Exception e) {
       logger.error("Exception while starting controller", e);

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
----------------------------------------------------------------------
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 3328279..d6dfe60 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
@@ -60,6 +60,7 @@ import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
 import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
 import org.apache.helix.healthcheck.ParticipantHealthReportTask;
 import org.apache.helix.messaging.DefaultMessagingService;
+import org.apache.helix.model.BuiltInStateModelDefinitions;
 import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
 import org.apache.helix.model.LiveInstance;
 import org.apache.helix.monitoring.ZKPathDataDumpTask;
@@ -453,6 +454,18 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
     return baseDataAccessor;
   }
 
+  /**
+   * Add Helix built-in state model definitions if not exist
+   */
+  private void addBuiltInStateModelDefinitions() {
+    PropertyKey.Builder keyBuilder = _dataAccessor.keyBuilder();
+    for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
+      PropertyKey key = keyBuilder.stateModelDef(def.getStateModelDefinition().getId());
+      // creation succeeds only if not exist
+      _dataAccessor.createProperty(key, def.getStateModelDefinition());
+    }
+  }
+
   void createClient() throws Exception {
     PathBasedZkSerializer zkSerializer =
         ChainedPathZkSerializer.builder(new ZNRecordStreamingSerializer()).build();
@@ -465,6 +478,11 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
     _dataAccessor = new ZKHelixDataAccessor(_clusterName, _instanceType, _baseDataAccessor);
     _configAccessor = new ConfigAccessor(_zkclient);
 
+    if (_instanceType == InstanceType.CONTROLLER
+        || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) {
+      addBuiltInStateModelDefinitions();
+    }
+
     int retryCount = 0;
 
     _zkclient.subscribeStateChanges(this);
@@ -499,10 +517,6 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
 
     switch (_instanceType) {
     case CONTROLLER:
-      if (_controller == null) {
-        _controller = new GenericHelixController();
-      }
-      break;
     case CONTROLLER_PARTICIPANT:
       if (_controller == null) {
         _controller = new GenericHelixController();

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/BuiltInStateModelDefinitions.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/BuiltInStateModelDefinitions.java b/helix-core/src/main/java/org/apache/helix/model/BuiltInStateModelDefinitions.java
new file mode 100644
index 0000000..e060c67
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/BuiltInStateModelDefinitions.java
@@ -0,0 +1,42 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Helix Built-in State Model Definitions
+ */
+public enum BuiltInStateModelDefinitions {
+  MasterSlave(new MasterSlaveSMD()),
+  LeaderStandby(new LeaderStandbySMD()),
+  StorageSchemata(new StorageSchemataSMD()),
+  OnlineOffline(new OnlineOfflineSMD()),
+  ScheduledTask(new ScheduledTaskSMD()),
+  Task(new TaskSMD());
+
+  private final StateModelDefinition def;
+
+  private BuiltInStateModelDefinitions(StateModelDefinition def) {
+    this.def = def;
+  }
+
+  public StateModelDefinition getStateModelDefinition() {
+    return def;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/LeaderStandbySMD.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/LeaderStandbySMD.java b/helix-core/src/main/java/org/apache/helix/model/LeaderStandbySMD.java
new file mode 100644
index 0000000..092f8ba
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/LeaderStandbySMD.java
@@ -0,0 +1,150 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.HelixDefinedState;
+import org.apache.helix.ZNRecord;
+
+/**
+ * Helix built-in Leader-standby state model definition
+ */
+public final class LeaderStandbySMD extends StateModelDefinition {
+  public static final String name = "LeaderStandby";
+  public enum States {
+    LEADER,
+    STANDBY,
+    OFFLINE
+  }
+
+  public LeaderStandbySMD() {
+    super(generateConfigForLeaderStandby());
+  }
+
+  /**
+   * Build Leader-standby state model definition
+   * @return
+   */
+  public static StateModelDefinition build() {
+    StateModelDefinition.Builder builder =new StateModelDefinition.Builder(name);
+    // init state
+    builder.initialState(States.OFFLINE.name());
+
+    // add states
+    builder.addState(States.LEADER.name(), 0);
+    builder.addState(States.STANDBY.name(), 1);
+    builder.addState(States.OFFLINE.name(), 2);
+    for (HelixDefinedState state : HelixDefinedState.values()) {
+      builder.addState(state.name());
+    }
+
+    // add transitions
+    builder.addTransition(States.LEADER.name(), States.STANDBY.name(), 0);
+    builder.addTransition(States.STANDBY.name(), States.LEADER.name(), 1);
+    builder.addTransition(States.OFFLINE.name(), States.STANDBY.name(), 2);
+    builder.addTransition(States.STANDBY.name(), States.OFFLINE.name(), 3);
+    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
+
+    // bounds
+    builder.upperBound(States.LEADER.name(), 1);
+    builder.dynamicUpperBound(States.STANDBY.name(), "R");
+
+    return builder.build();
+  }
+
+  /**
+   * Generate Leader-standby state model definition
+   * Replaced by LeaderStandbySMD#build()
+   * @return
+   */
+  @Deprecated
+  public static ZNRecord generateConfigForLeaderStandby() {
+    ZNRecord record = new ZNRecord("LeaderStandby");
+    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
+    List<String> statePriorityList = new ArrayList<String>();
+    statePriorityList.add("LEADER");
+    statePriorityList.add("STANDBY");
+    statePriorityList.add("OFFLINE");
+    statePriorityList.add("DROPPED");
+    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
+        statePriorityList);
+    for (String state : statePriorityList) {
+      String key = state + ".meta";
+      Map<String, String> metadata = new HashMap<String, String>();
+      if (state.equals("LEADER")) {
+        metadata.put("count", "1");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("STANDBY")) {
+        metadata.put("count", "R");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("OFFLINE")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("DROPPED")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+
+    }
+
+    for (String state : statePriorityList) {
+      String key = state + ".next";
+      if (state.equals("LEADER")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("STANDBY", "STANDBY");
+        metadata.put("OFFLINE", "STANDBY");
+        metadata.put("DROPPED", "STANDBY");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("STANDBY")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("LEADER", "LEADER");
+        metadata.put("OFFLINE", "OFFLINE");
+        metadata.put("DROPPED", "OFFLINE");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("OFFLINE")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("STANDBY", "STANDBY");
+        metadata.put("LEADER", "STANDBY");
+        metadata.put("DROPPED", "DROPPED");
+        record.setMapField(key, metadata);
+      }
+
+    }
+    List<String> stateTransitionPriorityList = new ArrayList<String>();
+    stateTransitionPriorityList.add("LEADER-STANDBY");
+    stateTransitionPriorityList.add("STANDBY-LEADER");
+    stateTransitionPriorityList.add("OFFLINE-STANDBY");
+    stateTransitionPriorityList.add("STANDBY-OFFLINE");
+    stateTransitionPriorityList.add("OFFLINE-DROPPED");
+
+    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
+        stateTransitionPriorityList);
+    return record;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/MasterSlaveSMD.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/MasterSlaveSMD.java b/helix-core/src/main/java/org/apache/helix/model/MasterSlaveSMD.java
new file mode 100644
index 0000000..f2eca27
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/MasterSlaveSMD.java
@@ -0,0 +1,150 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.HelixDefinedState;
+import org.apache.helix.ZNRecord;
+
+/**
+ * Helix built-in Master-slave state model definition
+ */
+public final class MasterSlaveSMD extends StateModelDefinition {
+  public static final String name = "MasterSlave";
+
+  public enum States {
+    MASTER,
+    SLAVE,
+    OFFLINE
+  }
+
+  public MasterSlaveSMD() {
+    super(generateConfigForMasterSlave());
+  }
+
+  /**
+   * Build Master-slave state model definition
+   * @return
+   */
+  public static StateModelDefinition build() {
+    StateModelDefinition.Builder builder =new StateModelDefinition.Builder(name);
+    // init state
+    builder.initialState(States.OFFLINE.name());
+
+    // add states
+    builder.addState(States.MASTER.name(), 0);
+    builder.addState(States.SLAVE.name(), 1);
+    builder.addState(States.OFFLINE.name(), 2);
+    for (HelixDefinedState state : HelixDefinedState.values()) {
+      builder.addState(state.name());
+    }
+
+    // add transitions
+    builder.addTransition(States.MASTER.name(), States.SLAVE.name(), 0);
+    builder.addTransition(States.SLAVE.name(), States.MASTER.name(), 1);
+    builder.addTransition(States.OFFLINE.name(), States.SLAVE.name(), 2);
+    builder.addTransition(States.SLAVE.name(), States.OFFLINE.name(), 3);
+    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
+
+    // bounds
+    builder.upperBound(States.MASTER.name(), 1);
+    builder.dynamicUpperBound(States.SLAVE.name(), "R");
+
+    return builder.build();
+  }
+
+  /**
+   * Generate Master-slave state model definition
+   * Replaced by MasterSlaveSMD#build()
+   * @return
+   */
+  @Deprecated
+  public static ZNRecord generateConfigForMasterSlave() {
+    ZNRecord record = new ZNRecord("MasterSlave");
+    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
+    List<String> statePriorityList = new ArrayList<String>();
+    statePriorityList.add("MASTER");
+    statePriorityList.add("SLAVE");
+    statePriorityList.add("OFFLINE");
+    statePriorityList.add("DROPPED");
+    statePriorityList.add("ERROR");
+    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
+        statePriorityList);
+    for (String state : statePriorityList) {
+      String key = state + ".meta";
+      Map<String, String> metadata = new HashMap<String, String>();
+      if (state.equals("MASTER")) {
+        metadata.put("count", "1");
+        record.setMapField(key, metadata);
+      } else if (state.equals("SLAVE")) {
+        metadata.put("count", "R");
+        record.setMapField(key, metadata);
+      } else if (state.equals("OFFLINE")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      } else if (state.equals("DROPPED")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      } else if (state.equals("ERROR")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+    }
+    for (String state : statePriorityList) {
+      String key = state + ".next";
+      if (state.equals("MASTER")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("SLAVE", "SLAVE");
+        metadata.put("OFFLINE", "SLAVE");
+        metadata.put("DROPPED", "SLAVE");
+        record.setMapField(key, metadata);
+      } else if (state.equals("SLAVE")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("MASTER", "MASTER");
+        metadata.put("OFFLINE", "OFFLINE");
+        metadata.put("DROPPED", "OFFLINE");
+        record.setMapField(key, metadata);
+      } else if (state.equals("OFFLINE")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("SLAVE", "SLAVE");
+        metadata.put("MASTER", "SLAVE");
+        metadata.put("DROPPED", "DROPPED");
+        record.setMapField(key, metadata);
+      } else if (state.equals("ERROR")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("OFFLINE", "OFFLINE");
+        record.setMapField(key, metadata);
+      }
+    }
+    List<String> stateTransitionPriorityList = new ArrayList<String>();
+    stateTransitionPriorityList.add("MASTER-SLAVE");
+    stateTransitionPriorityList.add("SLAVE-MASTER");
+    stateTransitionPriorityList.add("OFFLINE-SLAVE");
+    stateTransitionPriorityList.add("SLAVE-OFFLINE");
+    stateTransitionPriorityList.add("OFFLINE-DROPPED");
+    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
+        stateTransitionPriorityList);
+    return record;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/OnlineOfflineSMD.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/OnlineOfflineSMD.java b/helix-core/src/main/java/org/apache/helix/model/OnlineOfflineSMD.java
new file mode 100644
index 0000000..56c477d
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/OnlineOfflineSMD.java
@@ -0,0 +1,127 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.HelixDefinedState;
+import org.apache.helix.ZNRecord;
+
+/**
+ * Helix built-in Online-offline state model definition
+ */
+public final class OnlineOfflineSMD extends StateModelDefinition {
+  public static final String name = "OnlineOffline";
+  public enum States {
+    ONLINE,
+    OFFLINE
+  }
+
+  public OnlineOfflineSMD() {
+    super(generateConfigForOnlineOffline());
+  }
+
+  /**
+   * Build OnlineOffline state model definition
+   * @return
+   */
+  public static StateModelDefinition build() {
+    StateModelDefinition.Builder builder =new StateModelDefinition.Builder(name);
+    // init state
+    builder.initialState(States.OFFLINE.name());
+
+    // add states
+    builder.addState(States.ONLINE.name(), 0);
+    builder.addState(States.OFFLINE.name(), 1);
+    for (HelixDefinedState state : HelixDefinedState.values()) {
+      builder.addState(state.name());
+    }
+
+    // add transitions
+    builder.addTransition(States.ONLINE.name(), States.OFFLINE.name(), 0);
+    builder.addTransition(States.OFFLINE.name(), States.ONLINE.name(), 1);
+    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
+
+    // bounds
+    builder.dynamicUpperBound(States.ONLINE.name(), "R");
+
+    return builder.build();
+  }
+
+  /**
+   * Generate OnlineOffline state model definition
+   * Replaced by OnlineOfflineSMD#build()
+   * @return
+   */
+  @Deprecated
+  public static ZNRecord generateConfigForOnlineOffline() {
+    ZNRecord record = new ZNRecord("OnlineOffline");
+    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
+    List<String> statePriorityList = new ArrayList<String>();
+    statePriorityList.add("ONLINE");
+    statePriorityList.add("OFFLINE");
+    statePriorityList.add("DROPPED");
+    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
+        statePriorityList);
+    for (String state : statePriorityList) {
+      String key = state + ".meta";
+      Map<String, String> metadata = new HashMap<String, String>();
+      if (state.equals("ONLINE")) {
+        metadata.put("count", "R");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("OFFLINE")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("DROPPED")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+    }
+
+    for (String state : statePriorityList) {
+      String key = state + ".next";
+      if (state.equals("ONLINE")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("OFFLINE", "OFFLINE");
+        metadata.put("DROPPED", "OFFLINE");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("OFFLINE")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("ONLINE", "ONLINE");
+        metadata.put("DROPPED", "DROPPED");
+        record.setMapField(key, metadata);
+      }
+    }
+    List<String> stateTransitionPriorityList = new ArrayList<String>();
+    stateTransitionPriorityList.add("OFFLINE-ONLINE");
+    stateTransitionPriorityList.add("ONLINE-OFFLINE");
+    stateTransitionPriorityList.add("OFFLINE-DROPPED");
+
+    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
+        stateTransitionPriorityList);
+    return record;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/ScheduledTaskSMD.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/ScheduledTaskSMD.java b/helix-core/src/main/java/org/apache/helix/model/ScheduledTaskSMD.java
new file mode 100644
index 0000000..c85e5dd
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/ScheduledTaskSMD.java
@@ -0,0 +1,132 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.HelixDefinedState;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.DefaultSchedulerMessageHandlerFactory;
+import org.apache.helix.model.builder.StateTransitionTableBuilder;
+
+/**
+ * Helix built-in SchedulerTaskQueue state model definition
+ */
+public final class ScheduledTaskSMD extends StateModelDefinition {
+  public static final String name = DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE;
+
+  public enum States {
+    COMPLETED,
+    OFFLINE
+  }
+
+  public ScheduledTaskSMD() {
+    super(generateConfigForScheduledTaskQueue());
+  }
+
+  /**
+   * Build SchedulerTaskQueue state model definition
+   * @return
+   */
+  public static StateModelDefinition build() {
+    StateModelDefinition.Builder builder =new StateModelDefinition.Builder(name);
+    // init state
+    builder.initialState(States.OFFLINE.name());
+
+    // add states
+    builder.addState(States.COMPLETED.name(), 0);
+    builder.addState(States.OFFLINE.name(), 1);
+    for (HelixDefinedState state : HelixDefinedState.values()) {
+      builder.addState(state.name());
+    }
+
+    // add transitions
+    builder.addTransition(States.COMPLETED.name(), States.OFFLINE.name(), 0);
+    builder.addTransition(States.OFFLINE.name(), States.COMPLETED.name(), 1);
+    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
+
+    // bounds
+    builder.dynamicUpperBound(States.COMPLETED.name(), "1");
+
+    return builder.build();
+  }
+
+  /**
+   * Generate SchedulerTaskQueue state model definition
+   * Replaced by SchedulerTaskQueueSMD#build()
+   * @return
+   */
+  @Deprecated
+  public static ZNRecord generateConfigForScheduledTaskQueue() {
+    ZNRecord record = new ZNRecord(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE);
+    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
+    List<String> statePriorityList = new ArrayList<String>();
+    statePriorityList.add("COMPLETED");
+    statePriorityList.add("OFFLINE");
+    statePriorityList.add("DROPPED");
+    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
+        statePriorityList);
+    for (String state : statePriorityList) {
+      String key = state + ".meta";
+      Map<String, String> metadata = new HashMap<String, String>();
+      if (state.equals("COMPLETED")) {
+        metadata.put("count", "1");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("OFFLINE")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("DROPPED")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+    }
+
+    List<String> states = new ArrayList<String>();
+    states.add("COMPLETED");
+    states.add("DROPPED");
+    states.add("OFFLINE");
+
+    List<Transition> transitions = new ArrayList<Transition>();
+    transitions.add(new Transition("OFFLINE", "COMPLETED"));
+    transitions.add(new Transition("OFFLINE", "DROPPED"));
+    transitions.add(new Transition("COMPLETED", "DROPPED"));
+
+    StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
+    Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);
+
+    for (String state : statePriorityList) {
+      String key = state + ".next";
+      record.setMapField(key, next.get(state));
+    }
+    List<String> stateTransitionPriorityList = new ArrayList<String>();
+    stateTransitionPriorityList.add("OFFLINE-COMPLETED");
+    stateTransitionPriorityList.add("OFFLINE-DROPPED");
+    stateTransitionPriorityList.add("COMPLETED-DROPPED");
+
+    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
+        stateTransitionPriorityList);
+    return record;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java b/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
index e99e173..b5eb58b 100644
--- a/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
+++ b/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
@@ -171,8 +171,6 @@ public class StateModelDefinition extends HelixProperty {
    * @return name of the initial state
    */
   public String getInitialState() {
-    // return _record.getSimpleField(StateModelDefinitionProperty.INITIAL_STATE
-    // .toString());
     return _initialState;
   }
 
@@ -215,7 +213,7 @@ public class StateModelDefinition extends HelixProperty {
     /**
      * initial state of a replica when it starts, most commonly used initial
      * state is OFFLINE
-     * @param state
+     * @param initialState
      */
     public Builder initialState(String initialState) {
       this.initialState = initialState;
@@ -228,7 +226,8 @@ public class StateModelDefinition extends HelixProperty {
      * STATE2 has a constraint of 3 but only one node is up then Helix will uses
      * the priority to see STATE constraint has to be given higher preference <br/>
      * Use -1 to indicates states with no constraints, like OFFLINE
-     * @param states
+     * @param state
+     * @param priority
      */
     public Builder addState(String state, int priority) {
       statesMap.put(state, priority);

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/StorageSchemataSMD.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/StorageSchemataSMD.java b/helix-core/src/main/java/org/apache/helix/model/StorageSchemataSMD.java
new file mode 100644
index 0000000..46d54a9
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/StorageSchemataSMD.java
@@ -0,0 +1,131 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.HelixDefinedState;
+import org.apache.helix.ZNRecord;
+
+/**
+ * Helix built-in StorageSchemata state model definition
+ */
+public final class StorageSchemataSMD extends StateModelDefinition {
+  public static final String name = "STORAGE_DEFAULT_SM_SCHEMATA";
+  public enum States {
+    MASTER,
+    OFFLINE
+  }
+
+  public StorageSchemataSMD() {
+    super(generateConfigForStorageSchemata());
+  }
+
+  /**
+   * Build StorageSchemata state model definition
+   * @return
+   */
+  public static StateModelDefinition build() {
+    StateModelDefinition.Builder builder =new StateModelDefinition.Builder(name);
+    // init state
+    builder.initialState(States.OFFLINE.name());
+
+    // add states
+    builder.addState(States.MASTER.name(), 0);
+    builder.addState(States.OFFLINE.name(), 1);
+    for (HelixDefinedState state : HelixDefinedState.values()) {
+      builder.addState(state.name());
+    }
+
+    // add transitions
+    builder.addTransition(States.MASTER.name(), States.OFFLINE.name(), 0);
+    builder.addTransition(States.OFFLINE.name(), States.MASTER.name(), 1);
+    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
+
+    // bounds
+    builder.dynamicUpperBound(States.MASTER.name(), "N");
+
+    return builder.build();
+  }
+
+  /**
+   * Generate StorageSchemata state model definition
+   * Replaced by StorageSchemataSMD#build()
+   * @return
+   */
+  @Deprecated
+  public static ZNRecord generateConfigForStorageSchemata() {
+    ZNRecord record = new ZNRecord("STORAGE_DEFAULT_SM_SCHEMATA");
+    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
+    List<String> statePriorityList = new ArrayList<String>();
+    statePriorityList.add("MASTER");
+    statePriorityList.add("OFFLINE");
+    statePriorityList.add("DROPPED");
+    statePriorityList.add("ERROR");
+    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
+        statePriorityList);
+    for (String state : statePriorityList) {
+      String key = state + ".meta";
+      Map<String, String> metadata = new HashMap<String, String>();
+      if (state.equals("MASTER")) {
+        metadata.put("count", "N");
+        record.setMapField(key, metadata);
+      } else if (state.equals("OFFLINE")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      } else if (state.equals("DROPPED")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      } else if (state.equals("ERROR")) {
+        metadata.put("count", "-1");
+        record.setMapField(key, metadata);
+      }
+    }
+    for (String state : statePriorityList) {
+      String key = state + ".next";
+      if (state.equals("MASTER")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("OFFLINE", "OFFLINE");
+        metadata.put("DROPPED", "OFFLINE");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("OFFLINE")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("MASTER", "MASTER");
+        metadata.put("DROPPED", "DROPPED");
+        record.setMapField(key, metadata);
+      }
+      if (state.equals("ERROR")) {
+        Map<String, String> metadata = new HashMap<String, String>();
+        metadata.put("OFFLINE", "OFFLINE");
+        record.setMapField(key, metadata);
+      }
+    }
+    List<String> stateTransitionPriorityList = new ArrayList<String>();
+    stateTransitionPriorityList.add("MASTER-OFFLINE");
+    stateTransitionPriorityList.add("OFFLINE-MASTER");
+    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
+        stateTransitionPriorityList);
+    return record;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/model/TaskSMD.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/TaskSMD.java b/helix-core/src/main/java/org/apache/helix/model/TaskSMD.java
new file mode 100644
index 0000000..d826358
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/TaskSMD.java
@@ -0,0 +1,177 @@
+package org.apache.helix.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.HelixDefinedState;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.builder.StateTransitionTableBuilder;
+import org.apache.helix.task.TaskConstants;
+import org.apache.helix.task.TaskPartitionState;
+
+/**
+ * Helix built-in Task state model definition
+ */
+public final class TaskSMD extends StateModelDefinition {
+  public TaskSMD() {
+    super(generateConfigForTaskStateModel());
+  }
+
+  /**
+   * Build Task state model definition
+   * @return
+   */
+  public static StateModelDefinition build() {
+    StateModelDefinition.Builder builder =new StateModelDefinition.Builder(TaskConstants.STATE_MODEL_NAME);
+    // init state
+    builder.initialState(TaskPartitionState.INIT.name());
+
+    // add states
+    builder.addState(TaskPartitionState.INIT.name(), 01);
+    builder.addState(TaskPartitionState.RUNNING.name(), 1);
+    builder.addState(TaskPartitionState.STOPPED.name(), 2);
+    builder.addState(TaskPartitionState.COMPLETED.name(), 3);
+    builder.addState(TaskPartitionState.TIMED_OUT.name(), 4);
+    builder.addState(TaskPartitionState.TASK_ERROR.name(), 5);
+    builder.addState(TaskPartitionState.DROPPED.name());
+
+    // add transitions
+    builder.addTransition(TaskPartitionState.INIT.name(), TaskPartitionState.RUNNING.name(), 0);
+    builder.addTransition(TaskPartitionState.RUNNING.name(), TaskPartitionState.STOPPED.name(), 1);
+    builder.addTransition(TaskPartitionState.RUNNING.name(), TaskPartitionState.COMPLETED.name(), 2);
+    builder.addTransition(TaskPartitionState.RUNNING.name(), TaskPartitionState.TIMED_OUT.name(), 3);
+    builder.addTransition(TaskPartitionState.RUNNING.name(), TaskPartitionState.TASK_ERROR.name(), 4);
+    builder.addTransition(TaskPartitionState.STOPPED.name(), TaskPartitionState.RUNNING.name(), 5);
+
+    // All states have a transition to DROPPED.
+    builder.addTransition(TaskPartitionState.INIT.name(), TaskPartitionState.DROPPED.name(), 6);
+    builder.addTransition(TaskPartitionState.RUNNING.name(), TaskPartitionState.DROPPED.name(), 7);
+    builder.addTransition(TaskPartitionState.COMPLETED.name(), TaskPartitionState.DROPPED.name(), 8);
+    builder.addTransition(TaskPartitionState.STOPPED.name(), TaskPartitionState.DROPPED.name(), 9);
+    builder.addTransition(TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.DROPPED.name(), 10);
+    builder.addTransition(TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.DROPPED.name(), 11);
+
+    // All states, except DROPPED, have a transition to INIT.
+    builder.addTransition(TaskPartitionState.RUNNING.name(), TaskPartitionState.INIT.name(), 12);
+    builder.addTransition(TaskPartitionState.COMPLETED.name(), TaskPartitionState.INIT.name(), 13);
+    builder.addTransition(TaskPartitionState.STOPPED.name(), TaskPartitionState.INIT.name(), 14);
+    builder.addTransition(TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.INIT.name(), 15);
+    builder.addTransition(TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.INIT.name(), 16);
+
+    return builder.build();
+  }
+
+  /**
+   * Generate Task state model definition
+   * Replaced by TaskSMD#build()
+   * @return
+   */
+  @Deprecated
+  public static ZNRecord generateConfigForTaskStateModel() {
+    ZNRecord record = new ZNRecord(TaskConstants.STATE_MODEL_NAME);
+
+    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), TaskPartitionState.INIT.name());
+    List<String> statePriorityList = new ArrayList<String>();
+    statePriorityList.add(TaskPartitionState.INIT.name());
+    statePriorityList.add(TaskPartitionState.RUNNING.name());
+    statePriorityList.add(TaskPartitionState.STOPPED.name());
+    statePriorityList.add(TaskPartitionState.COMPLETED.name());
+    statePriorityList.add(TaskPartitionState.TIMED_OUT.name());
+    statePriorityList.add(TaskPartitionState.TASK_ERROR.name());
+    statePriorityList.add(TaskPartitionState.DROPPED.name());
+    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(), statePriorityList);
+    for (String state : statePriorityList) {
+      String key = state + ".meta";
+      Map<String, String> metadata = new HashMap<String, String>();
+      metadata.put("count", "-1");
+      record.setMapField(key, metadata);
+    }
+
+    List<String> states = new ArrayList<String>();
+    states.add(TaskPartitionState.INIT.name());
+    states.add(TaskPartitionState.RUNNING.name());
+    states.add(TaskPartitionState.STOPPED.name());
+    states.add(TaskPartitionState.COMPLETED.name());
+    states.add(TaskPartitionState.TIMED_OUT.name());
+    states.add(TaskPartitionState.TASK_ERROR.name());
+    states.add(TaskPartitionState.DROPPED.name());
+
+    List<Transition> transitions = new ArrayList<Transition>();
+    transitions.add(new Transition(TaskPartitionState.INIT.name(), TaskPartitionState.RUNNING.name()));
+    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.STOPPED.name()));
+    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.COMPLETED.name()));
+    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.TIMED_OUT.name()));
+    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.TASK_ERROR.name()));
+    transitions.add(new Transition(TaskPartitionState.STOPPED.name(), TaskPartitionState.RUNNING.name()));
+
+    // All states have a transition to DROPPED.
+    transitions.add(new Transition(TaskPartitionState.INIT.name(), TaskPartitionState.DROPPED.name()));
+    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.DROPPED.name()));
+    transitions.add(new Transition(TaskPartitionState.COMPLETED.name(), TaskPartitionState.DROPPED.name()));
+    transitions.add(new Transition(TaskPartitionState.STOPPED.name(), TaskPartitionState.DROPPED.name()));
+    transitions.add(new Transition(TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.DROPPED.name()));
+    transitions.add(new Transition(TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.DROPPED.name()));
+
+    // All states, except DROPPED, have a transition to INIT.
+    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.INIT.name()));
+    transitions.add(new Transition(TaskPartitionState.COMPLETED.name(), TaskPartitionState.INIT.name()));
+    transitions.add(new Transition(TaskPartitionState.STOPPED.name(), TaskPartitionState.INIT.name()));
+    transitions.add(new Transition(TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.INIT.name()));
+    transitions.add(new Transition(TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.INIT.name()));
+
+    StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
+    Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);
+
+    for (String state : statePriorityList) {
+      String key = state + ".next";
+      record.setMapField(key, next.get(state));
+    }
+
+    List<String> stateTransitionPriorityList = new ArrayList<String>();
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.INIT.name(), TaskPartitionState.RUNNING.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.STOPPED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.COMPLETED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.TIMED_OUT.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.TASK_ERROR.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.STOPPED.name(), TaskPartitionState.RUNNING.name()));
+
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.INIT.name(), TaskPartitionState.DROPPED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.DROPPED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.COMPLETED.name(), TaskPartitionState.DROPPED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.STOPPED.name(), TaskPartitionState.DROPPED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.DROPPED.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.DROPPED.name()));
+
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.INIT.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.COMPLETED.name(), TaskPartitionState.INIT.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.STOPPED.name(), TaskPartitionState.INIT.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.INIT.name()));
+    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.INIT.name()));
+
+    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
+                        stateTransitionPriorityList);
+
+    return record;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java b/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
index 40bc398..4234ce1 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
@@ -48,6 +48,7 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.manager.zk.ZkClient;
 import org.apache.helix.model.ClusterConstraints;
 import org.apache.helix.model.ClusterConstraints.ConstraintType;
+import org.apache.helix.model.BuiltInStateModelDefinitions;
 import org.apache.helix.model.ConstraintItem;
 import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.HelixConfigScope;
@@ -149,19 +150,10 @@ public class ClusterSetup {
   public void addCluster(String clusterName, boolean overwritePrevious) {
     _admin.addCluster(clusterName, overwritePrevious);
 
-    // StateModelConfigGenerator generator = new StateModelConfigGenerator();
-    addStateModelDef(clusterName, "MasterSlave",
-        new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave()));
-    addStateModelDef(clusterName, "LeaderStandby", new StateModelDefinition(
-        StateModelConfigGenerator.generateConfigForLeaderStandby()));
-    addStateModelDef(clusterName, "StorageSchemata", new StateModelDefinition(
-        StateModelConfigGenerator.generateConfigForStorageSchemata()));
-    addStateModelDef(clusterName, "OnlineOffline", new StateModelDefinition(
-        StateModelConfigGenerator.generateConfigForOnlineOffline()));
-    addStateModelDef(clusterName, "ScheduledTask", new StateModelDefinition(
-        StateModelConfigGenerator.generateConfigForScheduledTaskQueue()));
-    addStateModelDef(clusterName, "Task",
-        new StateModelDefinition(StateModelConfigGenerator.generateConfigForTaskStateModel()));
+    for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
+      addStateModelDef(clusterName, def.getStateModelDefinition().getId(),
+                       def.getStateModelDefinition());
+    }
   }
 
   public void activateCluster(String clusterName, String grandCluster, boolean enable) {

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/main/java/org/apache/helix/tools/StateModelConfigGenerator.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/StateModelConfigGenerator.java b/helix-core/src/main/java/org/apache/helix/tools/StateModelConfigGenerator.java
index b8b3aeb..d5600e9 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/StateModelConfigGenerator.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/StateModelConfigGenerator.java
@@ -19,425 +19,58 @@ package org.apache.helix.tools;
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.manager.zk.DefaultSchedulerMessageHandlerFactory;
 import org.apache.helix.manager.zk.ZNRecordSerializer;
-import org.apache.helix.model.StateModelDefinition.StateModelDefinitionProperty;
-import org.apache.helix.model.Transition;
-import org.apache.helix.model.builder.StateTransitionTableBuilder;
-import org.apache.helix.task.TaskPartitionState;
-import org.apache.helix.task.TaskConstants;
-
+import org.apache.helix.model.LeaderStandbySMD;
+import org.apache.helix.model.MasterSlaveSMD;
+import org.apache.helix.model.OnlineOfflineSMD;
+import org.apache.helix.model.ScheduledTaskSMD;
+import org.apache.helix.model.TaskSMD;
+import org.apache.helix.model.StorageSchemataSMD;
 
 // TODO refactor to use StateModelDefinition.Builder
+@Deprecated
 public class StateModelConfigGenerator {
 
   public static void main(String[] args) {
     ZNRecordSerializer serializer = new ZNRecordSerializer();
-    StateModelConfigGenerator generator = new StateModelConfigGenerator();
-    System.out.println(new String(serializer.serialize(generator.generateConfigForMasterSlave())));
+    System.out.println(new String(serializer.serialize(generateConfigForMasterSlave())));
   }
 
   /**
-   * count -1 dont care any numeric value > 0 will be tried to be satisfied based on
+   * count -1 don't care any numeric value > 0 will be tried to be satisfied based on
    * priority N all nodes in the cluster will be assigned to this state if possible R all
    * remaining nodes in the preference list will be assigned to this state, applies only
    * to last state
    */
 
+  @Deprecated
   public static ZNRecord generateConfigForStorageSchemata() {
-    ZNRecord record = new ZNRecord("STORAGE_DEFAULT_SM_SCHEMATA");
-    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
-    List<String> statePriorityList = new ArrayList<String>();
-    statePriorityList.add("MASTER");
-    statePriorityList.add("OFFLINE");
-    statePriorityList.add("DROPPED");
-    statePriorityList.add("ERROR");
-    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
-        statePriorityList);
-    for (String state : statePriorityList) {
-      String key = state + ".meta";
-      Map<String, String> metadata = new HashMap<String, String>();
-      if (state.equals("MASTER")) {
-        metadata.put("count", "N");
-        record.setMapField(key, metadata);
-      } else if (state.equals("OFFLINE")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      } else if (state.equals("DROPPED")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      } else if (state.equals("ERROR")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-    }
-    for (String state : statePriorityList) {
-      String key = state + ".next";
-      if (state.equals("MASTER")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("OFFLINE", "OFFLINE");
-        metadata.put("DROPPED", "OFFLINE");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("OFFLINE")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("MASTER", "MASTER");
-        metadata.put("DROPPED", "DROPPED");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("ERROR")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("OFFLINE", "OFFLINE");
-        record.setMapField(key, metadata);
-      }
-    }
-    List<String> stateTransitionPriorityList = new ArrayList<String>();
-    stateTransitionPriorityList.add("MASTER-OFFLINE");
-    stateTransitionPriorityList.add("OFFLINE-MASTER");
-    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-        stateTransitionPriorityList);
-    return record;
+    return StorageSchemataSMD.generateConfigForStorageSchemata();
   }
 
+  @Deprecated
   public static ZNRecord generateConfigForMasterSlave() {
-    ZNRecord record = new ZNRecord("MasterSlave");
-    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
-    List<String> statePriorityList = new ArrayList<String>();
-    statePriorityList.add("MASTER");
-    statePriorityList.add("SLAVE");
-    statePriorityList.add("OFFLINE");
-    statePriorityList.add("DROPPED");
-    statePriorityList.add("ERROR");
-    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
-        statePriorityList);
-    for (String state : statePriorityList) {
-      String key = state + ".meta";
-      Map<String, String> metadata = new HashMap<String, String>();
-      if (state.equals("MASTER")) {
-        metadata.put("count", "1");
-        record.setMapField(key, metadata);
-      } else if (state.equals("SLAVE")) {
-        metadata.put("count", "R");
-        record.setMapField(key, metadata);
-      } else if (state.equals("OFFLINE")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      } else if (state.equals("DROPPED")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      } else if (state.equals("ERROR")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-    }
-    for (String state : statePriorityList) {
-      String key = state + ".next";
-      if (state.equals("MASTER")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("SLAVE", "SLAVE");
-        metadata.put("OFFLINE", "SLAVE");
-        metadata.put("DROPPED", "SLAVE");
-        record.setMapField(key, metadata);
-      } else if (state.equals("SLAVE")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("MASTER", "MASTER");
-        metadata.put("OFFLINE", "OFFLINE");
-        metadata.put("DROPPED", "OFFLINE");
-        record.setMapField(key, metadata);
-      } else if (state.equals("OFFLINE")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("SLAVE", "SLAVE");
-        metadata.put("MASTER", "SLAVE");
-        metadata.put("DROPPED", "DROPPED");
-        record.setMapField(key, metadata);
-      } else if (state.equals("ERROR")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("OFFLINE", "OFFLINE");
-        record.setMapField(key, metadata);
-      }
-    }
-    List<String> stateTransitionPriorityList = new ArrayList<String>();
-    stateTransitionPriorityList.add("MASTER-SLAVE");
-    stateTransitionPriorityList.add("SLAVE-MASTER");
-    stateTransitionPriorityList.add("OFFLINE-SLAVE");
-    stateTransitionPriorityList.add("SLAVE-OFFLINE");
-    stateTransitionPriorityList.add("OFFLINE-DROPPED");
-    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-        stateTransitionPriorityList);
-    return record;
-    // ZNRecordSerializer serializer = new ZNRecordSerializer();
-    // System.out.println(new String(serializer.serialize(record)));
+    return MasterSlaveSMD.generateConfigForMasterSlave();
   }
 
+  @Deprecated
   public static ZNRecord generateConfigForLeaderStandby() {
-    ZNRecord record = new ZNRecord("LeaderStandby");
-    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
-    List<String> statePriorityList = new ArrayList<String>();
-    statePriorityList.add("LEADER");
-    statePriorityList.add("STANDBY");
-    statePriorityList.add("OFFLINE");
-    statePriorityList.add("DROPPED");
-    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
-        statePriorityList);
-    for (String state : statePriorityList) {
-      String key = state + ".meta";
-      Map<String, String> metadata = new HashMap<String, String>();
-      if (state.equals("LEADER")) {
-        metadata.put("count", "1");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("STANDBY")) {
-        metadata.put("count", "R");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("OFFLINE")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("DROPPED")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-
-    }
-
-    for (String state : statePriorityList) {
-      String key = state + ".next";
-      if (state.equals("LEADER")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("STANDBY", "STANDBY");
-        metadata.put("OFFLINE", "STANDBY");
-        metadata.put("DROPPED", "STANDBY");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("STANDBY")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("LEADER", "LEADER");
-        metadata.put("OFFLINE", "OFFLINE");
-        metadata.put("DROPPED", "OFFLINE");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("OFFLINE")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("STANDBY", "STANDBY");
-        metadata.put("LEADER", "STANDBY");
-        metadata.put("DROPPED", "DROPPED");
-        record.setMapField(key, metadata);
-      }
-
-    }
-    List<String> stateTransitionPriorityList = new ArrayList<String>();
-    stateTransitionPriorityList.add("LEADER-STANDBY");
-    stateTransitionPriorityList.add("STANDBY-LEADER");
-    stateTransitionPriorityList.add("OFFLINE-STANDBY");
-    stateTransitionPriorityList.add("STANDBY-OFFLINE");
-    stateTransitionPriorityList.add("OFFLINE-DROPPED");
-
-    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-        stateTransitionPriorityList);
-    return record;
-    // ZNRecordSerializer serializer = new ZNRecordSerializer();
-    // System.out.println(new String(serializer.serialize(record)));
+    return LeaderStandbySMD.generateConfigForLeaderStandby();
   }
 
+  @Deprecated
   public static ZNRecord generateConfigForOnlineOffline() {
-    ZNRecord record = new ZNRecord("OnlineOffline");
-    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
-    List<String> statePriorityList = new ArrayList<String>();
-    statePriorityList.add("ONLINE");
-    statePriorityList.add("OFFLINE");
-    statePriorityList.add("DROPPED");
-    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
-        statePriorityList);
-    for (String state : statePriorityList) {
-      String key = state + ".meta";
-      Map<String, String> metadata = new HashMap<String, String>();
-      if (state.equals("ONLINE")) {
-        metadata.put("count", "R");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("OFFLINE")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("DROPPED")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-    }
-
-    for (String state : statePriorityList) {
-      String key = state + ".next";
-      if (state.equals("ONLINE")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("OFFLINE", "OFFLINE");
-        metadata.put("DROPPED", "OFFLINE");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("OFFLINE")) {
-        Map<String, String> metadata = new HashMap<String, String>();
-        metadata.put("ONLINE", "ONLINE");
-        metadata.put("DROPPED", "DROPPED");
-        record.setMapField(key, metadata);
-      }
-    }
-    List<String> stateTransitionPriorityList = new ArrayList<String>();
-    stateTransitionPriorityList.add("OFFLINE-ONLINE");
-    stateTransitionPriorityList.add("ONLINE-OFFLINE");
-    stateTransitionPriorityList.add("OFFLINE-DROPPED");
-
-    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-        stateTransitionPriorityList);
-    return record;
-    // ZNRecordSerializer serializer = new ZNRecordSerializer();
-    // System.out.println(new String(serializer.serialize(record)));
+    return OnlineOfflineSMD.generateConfigForOnlineOffline();
   }
 
+  @Deprecated
   public static ZNRecord generateConfigForScheduledTaskQueue() {
-    ZNRecord record = new ZNRecord(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE);
-    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
-    List<String> statePriorityList = new ArrayList<String>();
-    statePriorityList.add("COMPLETED");
-    statePriorityList.add("OFFLINE");
-    statePriorityList.add("DROPPED");
-    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
-        statePriorityList);
-    for (String state : statePriorityList) {
-      String key = state + ".meta";
-      Map<String, String> metadata = new HashMap<String, String>();
-      if (state.equals("COMPLETED")) {
-        metadata.put("count", "1");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("OFFLINE")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-      if (state.equals("DROPPED")) {
-        metadata.put("count", "-1");
-        record.setMapField(key, metadata);
-      }
-    }
-
-    List<String> states = new ArrayList<String>();
-    states.add("COMPLETED");
-    states.add("DROPPED");
-    states.add("OFFLINE");
-
-    List<Transition> transitions = new ArrayList<Transition>();
-    transitions.add(new Transition("OFFLINE", "COMPLETED"));
-    transitions.add(new Transition("OFFLINE", "DROPPED"));
-    transitions.add(new Transition("COMPLETED", "DROPPED"));
-
-    StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
-    Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);
-
-    for (String state : statePriorityList) {
-      String key = state + ".next";
-      record.setMapField(key, next.get(state));
-    }
-    List<String> stateTransitionPriorityList = new ArrayList<String>();
-    stateTransitionPriorityList.add("OFFLINE-COMPLETED");
-    stateTransitionPriorityList.add("OFFLINE-DROPPED");
-    stateTransitionPriorityList.add("COMPLETED-DROPPED");
-
-    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-        stateTransitionPriorityList);
-    return record;
+    return ScheduledTaskSMD.generateConfigForScheduledTaskQueue();
   }
 
-  public static ZNRecord generateConfigForTaskStateModel()
-  {
-    ZNRecord record = new ZNRecord(TaskConstants.STATE_MODEL_NAME);
-
-    record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), TaskPartitionState.INIT.name());
-    List<String> statePriorityList = new ArrayList<String>();
-    statePriorityList.add(TaskPartitionState.INIT.name());
-    statePriorityList.add(TaskPartitionState.RUNNING.name());
-    statePriorityList.add(TaskPartitionState.STOPPED.name());
-    statePriorityList.add(TaskPartitionState.COMPLETED.name());
-    statePriorityList.add(TaskPartitionState.TIMED_OUT.name());
-    statePriorityList.add(TaskPartitionState.TASK_ERROR.name());
-    statePriorityList.add(TaskPartitionState.DROPPED.name());
-    record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(), statePriorityList);
-    for (String state : statePriorityList)
-    {
-      String key = state + ".meta";
-      Map<String, String> metadata = new HashMap<String, String>();
-      metadata.put("count", "-1");
-      record.setMapField(key, metadata);
-    }
-
-    List<String> states = new ArrayList<String>();
-    states.add(TaskPartitionState.INIT.name());
-    states.add(TaskPartitionState.RUNNING.name());
-    states.add(TaskPartitionState.STOPPED.name());
-    states.add(TaskPartitionState.COMPLETED.name());
-    states.add(TaskPartitionState.TIMED_OUT.name());
-    states.add(TaskPartitionState.TASK_ERROR.name());
-    states.add(TaskPartitionState.DROPPED.name());
-
-    List<Transition> transitions = new ArrayList<Transition>();
-    transitions.add(new Transition(TaskPartitionState.INIT.name(), TaskPartitionState.RUNNING.name()));
-    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.STOPPED.name()));
-    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.COMPLETED.name()));
-    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.TIMED_OUT.name()));
-    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.TASK_ERROR.name()));
-    transitions.add(new Transition(TaskPartitionState.STOPPED.name(), TaskPartitionState.RUNNING.name()));
-
-    // All states have a transition to DROPPED.
-    transitions.add(new Transition(TaskPartitionState.INIT.name(), TaskPartitionState.DROPPED.name()));
-    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.DROPPED.name()));
-    transitions.add(new Transition(TaskPartitionState.COMPLETED.name(), TaskPartitionState.DROPPED.name()));
-    transitions.add(new Transition(TaskPartitionState.STOPPED.name(), TaskPartitionState.DROPPED.name()));
-    transitions.add(new Transition(TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.DROPPED.name()));
-    transitions.add(new Transition(TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.DROPPED.name()));
-
-    // All states, except DROPPED, have a transition to INIT.
-    transitions.add(new Transition(TaskPartitionState.RUNNING.name(), TaskPartitionState.INIT.name()));
-    transitions.add(new Transition(TaskPartitionState.COMPLETED.name(), TaskPartitionState.INIT.name()));
-    transitions.add(new Transition(TaskPartitionState.STOPPED.name(), TaskPartitionState.INIT.name()));
-    transitions.add(new Transition(TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.INIT.name()));
-    transitions.add(new Transition(TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.INIT.name()));
-
-    StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
-    Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);
-
-    for (String state : statePriorityList)
-    {
-      String key = state + ".next";
-      record.setMapField(key, next.get(state));
-    }
-
-    List<String> stateTransitionPriorityList = new ArrayList<String>();
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.INIT.name(), TaskPartitionState.RUNNING.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.STOPPED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.COMPLETED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.TIMED_OUT.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.TASK_ERROR.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.STOPPED.name(), TaskPartitionState.RUNNING.name()));
-
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.INIT.name(), TaskPartitionState.DROPPED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.DROPPED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.COMPLETED.name(), TaskPartitionState.DROPPED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.STOPPED.name(), TaskPartitionState.DROPPED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.DROPPED.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.DROPPED.name()));
-
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.RUNNING.name(), TaskPartitionState.INIT.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.COMPLETED.name(), TaskPartitionState.INIT.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.STOPPED.name(), TaskPartitionState.INIT.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TIMED_OUT.name(), TaskPartitionState.INIT.name()));
-    stateTransitionPriorityList.add(String.format("%s-%s", TaskPartitionState.TASK_ERROR.name(), TaskPartitionState.INIT.name()));
-
-    record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-                        stateTransitionPriorityList);
-
-    return record;
+  @Deprecated
+  public static ZNRecord generateConfigForTaskStateModel() {
+    return TaskSMD.generateConfigForTaskStateModel();
   }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/test/java/org/apache/helix/integration/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/IntegrationTest.java b/helix-core/src/test/java/org/apache/helix/integration/IntegrationTest.java
index bb862f3..0a846d7 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/IntegrationTest.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/IntegrationTest.java
@@ -12,7 +12,7 @@ package org.apache.helix.integration;
  *   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
+ * software distributed under the License is dist_hdlrFtyRegistryributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations

http://git-wip-us.apache.org/repos/asf/helix/blob/9e47455d/helix-core/src/test/java/org/apache/helix/manager/zk/TestAddBuiltInStateModelDef.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestAddBuiltInStateModelDef.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestAddBuiltInStateModelDef.java
new file mode 100644
index 0000000..395fd62
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestAddBuiltInStateModelDef.java
@@ -0,0 +1,82 @@
+package org.apache.helix.manager.zk;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Date;
+
+import org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.model.BuiltInStateModelDefinitions;
+import org.apache.zookeeper.data.Stat;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestAddBuiltInStateModelDef extends ZkUnitTestBase {
+
+  @Test
+  public void test() throws Exception {
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+    HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
+    admin.addCluster(clusterName);
+    admin.addStateModelDef(clusterName, BuiltInStateModelDefinitions.MasterSlave.getStateModelDefinition().getId(),
+                           BuiltInStateModelDefinitions.MasterSlave.getStateModelDefinition());
+    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
+    controller.syncStart();
+
+    // controller shall create all built-in state model definitions
+    final BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    final PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName);
+    boolean ret = TestHelper.verify(new TestHelper.Verifier() {
+
+      @Override
+      public boolean verify() throws Exception {
+        for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
+          String path = keyBuilder.stateModelDef(def.getStateModelDefinition().getId()).getPath();
+          boolean exist = baseAccessor.exists(path, 0);
+          if (!exist) {
+            return false;
+          }
+
+          // make sure MasterSlave is not over-written
+          if (def == BuiltInStateModelDefinitions.MasterSlave) {
+            Stat stat = new Stat();
+            baseAccessor.get(path, stat, 0);
+            if (stat.getVersion() != 0) {
+              return false;
+            }
+          }
+        }
+        return true;
+      }
+    }, 10 * 1000);
+    Assert.assertTrue(ret);
+    controller.syncStop();
+    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+}


Mime
View raw message