You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ki...@apache.org on 2012/11/07 01:28:00 UTC
[2/2] git commit: Quick start code and bug fixes in state model
builder
Quick start code and bug fixes in state model builder
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/4de35d19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/4de35d19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/4de35d19
Branch: refs/heads/master
Commit: 4de35d1913fb6d35b620a2e53c08c0b944bf53af
Parents: 2bf4315
Author: Kishore Gopalakrishna <g....@gmail.com>
Authored: Tue Nov 6 16:27:05 2012 -0800
Committer: Kishore Gopalakrishna <g....@gmail.com>
Committed: Tue Nov 6 16:27:05 2012 -0800
----------------------------------------------------------------------
helix-core/pom.xml | 4 +
.../src/main/java/org/apache/helix/HelixAdmin.java | 9 +
.../helix/controller/HelixControllerMain.java | 3 +-
.../org/apache/helix/examples/ExampleProcess.java | 29 +-
.../examples/MasterSlaveStateModelFactory.java | 186 ++++++----
.../java/org/apache/helix/examples/Quickstart.java | 274 +++++++++++++++
.../apache/helix/manager/file/FileHelixAdmin.java | 16 +-
.../org/apache/helix/manager/zk/ZKHelixAdmin.java | 58 ++-
.../apache/helix/manager/zk/ZKHelixManager.java | 10 +-
.../java/org/apache/helix/model/IdealState.java | 153 +++++----
.../org/apache/helix/model/InstanceConfig.java | 2 +-
.../apache/helix/model/StateModelDefinition.java | 81 +++--
.../statemachine/StateTransitionTableBuilder.java | 16 +-
.../main/java/org/apache/helix/tools/ZKDumper.java | 2 +-
14 files changed, 629 insertions(+), 214 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/pom.xml
----------------------------------------------------------------------
diff --git a/helix-core/pom.xml b/helix-core/pom.xml
index aa51168..8a62303 100644
--- a/helix-core/pom.xml
+++ b/helix-core/pom.xml
@@ -179,6 +179,10 @@ under the License.
<name>zk-log-analyzer</name>
</program>
<program>
+ <mainClass>org.apache.helix.examples.Quickstart</mainClass>
+ <name>quickstart</name>
+ </program>
+ <program>
<mainClass>org.apache.helix.tools.JmxDumper</mainClass>
<name>JmxDumper</name>
</program>
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixAdmin.java b/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
index 992904b..746e9ad 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
@@ -93,6 +93,15 @@ public interface HelixAdmin
String resourceName,
int numResources,
String stateModelRef);
+ /**
+ *
+ * @param clusterName
+ * @param resourceName
+ * @param idealstate
+ */
+ void addResource(String clusterName,
+ String resourceName,
+ IdealState idealstate);
/**
* Add a resource to a cluster
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/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 917583c..338e03c 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
@@ -199,8 +199,7 @@ public class HelixControllerMain
}
} catch (Exception e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("Exception while starting controller",e);
}
return manager;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java b/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
index f374c8c..58b861e 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
@@ -39,7 +39,6 @@ import org.apache.helix.participant.statemachine.StateModel;
import org.apache.helix.participant.statemachine.StateModelFactory;
import org.apache.helix.tools.ClusterStateVerifier;
-
public class ExampleProcess
{
@@ -59,7 +58,7 @@ public class ExampleProcess
private final String stateModelType;
private HelixManager manager;
-// private StateMachineEngine genericStateMachineHandler;
+ // private StateMachineEngine genericStateMachineHandler;
private String _file = null;
private StateModelFactory<StateModel> stateModelFactory;
@@ -81,17 +80,12 @@ public class ExampleProcess
if (_file == null)
{
manager = HelixManagerFactory.getZKHelixManager(clusterName,
- instanceName,
- InstanceType.PARTICIPANT,
- zkConnectString);
+ instanceName, InstanceType.PARTICIPANT, zkConnectString);
- }
- else
+ } else
{
manager = HelixManagerFactory.getStaticFileHelixManager(clusterName,
- instanceName,
- InstanceType.PARTICIPANT,
- _file);
+ instanceName, InstanceType.PARTICIPANT, _file);
}
@@ -105,9 +99,10 @@ public class ExampleProcess
{
stateModelFactory = new LeaderStandbyStateModelFactory(delay);
}
-// genericStateMachineHandler = new StateMachineEngine();
-// genericStateMachineHandler.registerStateModelFactory(stateModelType, stateModelFactory);
-
+ // genericStateMachineHandler = new StateMachineEngine();
+ // genericStateMachineHandler.registerStateModelFactory(stateModelType,
+ // stateModelFactory);
+
StateMachineEngine stateMach = manager.getStateMachineEngine();
stateMach.registerStateModelFactory(stateModelType, stateModelFactory);
manager.connect();
@@ -121,6 +116,11 @@ public class ExampleProcess
}
}
+ public void stop()
+ {
+ manager.disconnect();
+ }
+
@SuppressWarnings("static-access")
private static Options constructCommandLineOptions()
{
@@ -191,7 +191,8 @@ public class ExampleProcess
public static void printUsage(Options cliOptions)
{
HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.printHelp("java " + ExampleProcess.class.getName(), cliOptions);
+ helpFormatter.printHelp("java " + ExampleProcess.class.getName(),
+ cliOptions);
}
public static CommandLine processCommandLineArgs(String[] cliArgs)
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java b/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
index 1a9b551..732e59e 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
@@ -25,79 +25,123 @@ import org.apache.helix.participant.statemachine.StateModel;
import org.apache.helix.participant.statemachine.StateModelFactory;
@SuppressWarnings("rawtypes")
-public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel> {
- int _delay;
-
- public MasterSlaveStateModelFactory(int delay) {
- _delay = delay;
- }
-
- @Override
- public StateModel createNewStateModel(String stateUnitKey) {
- MasterSlaveStateModel stateModel = new MasterSlaveStateModel();
- stateModel.setDelay(_delay);
- stateModel.setStateUnitKey(stateUnitKey);
- return stateModel;
- }
-
- public static class MasterSlaveStateModel extends StateModel {
- int _transDelay = 0;
- String stateUnitKey;
-
- public String getStateUnitKey() {
- return stateUnitKey;
- }
-
- public void setStateUnitKey(String stateUnitKey) {
- this.stateUnitKey = stateUnitKey;
- }
-
- public void setDelay(int delay) {
- _transDelay = delay > 0 ? delay : 0;
- }
-
- public void onBecomeSlaveFromOffline(Message message,
- NotificationContext context) {
-
- System.out.println("MasterSlaveStateModel.onBecomeSlaveFromOffline() for "+ stateUnitKey);
- sleep();
- }
-
- private void sleep() {
- try {
- Thread.sleep(_transDelay);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void onBecomeSlaveFromMaster(Message message,
- NotificationContext context) {
- System.out.println("MasterSlaveStateModel.onBecomeSlaveFromMaster() for "+ stateUnitKey);
- sleep();
-
- }
-
- public void onBecomeMasterFromSlave(Message message,
- NotificationContext context) {
- System.out.println("MasterSlaveStateModel.onBecomeMasterFromSlave() for "+ stateUnitKey);
- sleep();
-
- }
-
- public void onBecomeOfflineFromSlave(Message message,
- NotificationContext context) {
- System.out.println("MasterSlaveStateModel.onBecomeOfflineFromSlave() for "+ stateUnitKey);
- sleep();
-
- }
-
- public void onBecomeDroppedFromOffline(Message message,
- NotificationContext context) {
- System.out.println("ObBecomeDroppedFromOffline() for "+ stateUnitKey);
+public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel>
+{
+ int _delay;
+
+ String _instanceName = "";
+
+ public MasterSlaveStateModelFactory(int delay)
+ {
+ _delay = delay;
+ }
+
+ public MasterSlaveStateModelFactory(String instanceName)
+ {
+ _instanceName = instanceName;
+ _delay = 10;
+ }
+
+ public MasterSlaveStateModelFactory()
+ {
+ this(10);
+ }
+
+ @Override
+ public StateModel createNewStateModel(String partitionName)
+ {
+ MasterSlaveStateModel stateModel = new MasterSlaveStateModel();
+ stateModel.setInstanceName(_instanceName);
+ stateModel.setDelay(_delay);
+ stateModel.setPartitionName(partitionName);
+ return stateModel;
+ }
+
+ public static class MasterSlaveStateModel extends StateModel
+ {
+ int _transDelay = 0;
+ String partitionName;
+ String _instanceName = "";
+
+ public String getPartitionName()
+ {
+ return partitionName;
+ }
+
+ public void setPartitionName(String partitionName)
+ {
+ this.partitionName = partitionName;
+ }
+
+ public void setDelay(int delay)
+ {
+ _transDelay = delay > 0 ? delay : 0;
+ }
+
+ public void setInstanceName(String instanceName)
+ {
+ _instanceName = instanceName;
+ }
+
+ public void onBecomeSlaveFromOffline(Message message,
+ NotificationContext context)
+ {
+
+ System.out.println(_instanceName + " transitioning from "
+ + message.getFromState() + " to " + message.getToState() + " for "
+ + partitionName);
+ sleep();
+ }
+
+ private void sleep()
+ {
+ try
+ {
+ Thread.sleep(_transDelay);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void onBecomeSlaveFromMaster(Message message,
+ NotificationContext context)
+ {
+ System.out.println(_instanceName + " transitioning from "
+ + message.getFromState() + " to " + message.getToState() + " for "
+ + partitionName);
+ sleep();
+
+ }
+
+ public void onBecomeMasterFromSlave(Message message,
+ NotificationContext context)
+ {
+ System.out.println(_instanceName + " transitioning from "
+ + message.getFromState() + " to " + message.getToState() + " for "
+ + partitionName);
+ sleep();
+
+ }
+
+ public void onBecomeOfflineFromSlave(Message message,
+ NotificationContext context)
+ {
+ System.out.println(_instanceName + " transitioning from "
+ + message.getFromState() + " to " + message.getToState() + " for "
+ + partitionName);
+ sleep();
+
+ }
+
+ public void onBecomeDroppedFromOffline(Message message,
+ NotificationContext context)
+ {
+ System.out.println(_instanceName + " Dropping partition "
+ + partitionName);
sleep();
}
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/examples/Quickstart.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/Quickstart.java b/helix-core/src/main/java/org/apache/helix/examples/Quickstart.java
new file mode 100644
index 0000000..f386353
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/examples/Quickstart.java
@@ -0,0 +1,274 @@
+package org.apache.helix.examples;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+
+import org.I0Itec.zkclient.IDefaultNameSpace;
+import org.I0Itec.zkclient.ZkClient;
+import org.I0Itec.zkclient.ZkServer;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixManager;
+import org.apache.helix.HelixManagerFactory;
+import org.apache.helix.InstanceType;
+import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.manager.zk.ZKHelixAdmin;
+import org.apache.helix.manager.zk.ZNRecordSerializer;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.participant.StateMachineEngine;
+
+public class Quickstart
+{
+
+ private static String ZK_ADDRESS = "localhost:2199";
+ private static String CLUSTER_NAME = "HELIX_QUICKSTART";
+ private static int NUM_NODES = 2;
+ private static final String RESOURCE_NAME = "MyResource";
+ private static final int NUM_PARTITIONS = 6;
+ private static final int NUM_REPLICAS = 2;
+
+ private static final String STATE_MODEL_NAME = "MyStateModel";
+
+ // states
+ private static final String SLAVE = "SLAVE";
+ private static final String OFFLINE = "OFFLINE";
+ private static final String MASTER = "MASTER";
+ private static final String DROPPED = "DROPPED";
+
+ private static List<InstanceConfig> INSTANCE_CONFIG_LIST;
+ private static List<MyProcess> PROCESS_LIST;
+ private static HelixAdmin admin;
+ static
+ {
+ INSTANCE_CONFIG_LIST = new ArrayList<InstanceConfig>();
+ PROCESS_LIST = new ArrayList<Quickstart.MyProcess>();
+ for (int i = 0; i < NUM_NODES; i++)
+ {
+ int port = 12000 + i;
+ InstanceConfig instanceConfig = new InstanceConfig("localhost_" + port);
+ instanceConfig.setHostName("localhost");
+ instanceConfig.setPort("" + port);
+ instanceConfig.setInstanceEnabled(true);
+ INSTANCE_CONFIG_LIST.add(instanceConfig);
+ }
+
+ }
+
+ public static void setup()
+ {
+ admin = new ZKHelixAdmin(ZK_ADDRESS);
+ // create cluster
+ echo("Creating cluster: " + CLUSTER_NAME);
+ admin.addCluster(CLUSTER_NAME, true);
+
+ // Add nodes to the cluster
+ echo("Adding " + NUM_NODES + " participants to the cluster");
+ for (int i = 0; i < NUM_NODES; i++)
+ {
+ admin.addInstance(CLUSTER_NAME, INSTANCE_CONFIG_LIST.get(i));
+ echo("\t Added participant: "
+ + INSTANCE_CONFIG_LIST.get(i).getInstanceName());
+ }
+
+ // Add a state model
+ StateModelDefinition myStateModel = defineStateModel();
+ echo("Configuring StateModel: " + "MyStateModel with 1 Master and 1 Slave");
+ admin.addStateModelDef(CLUSTER_NAME, STATE_MODEL_NAME, myStateModel);
+
+ // Add a resource with 6 partitions and 2 replicas
+ echo("Adding a resource MyResource: " + "with 6 partitions and 2 replicas");
+ admin.addResource(CLUSTER_NAME, RESOURCE_NAME, NUM_PARTITIONS,
+ STATE_MODEL_NAME, "AUTO");
+ // this will set up the ideal state, it calculates the preference list for
+ // each partition similar to consistent hashing
+ admin.rebalance(CLUSTER_NAME, RESOURCE_NAME, NUM_REPLICAS);
+ }
+
+ private static StateModelDefinition defineStateModel()
+ {
+ StateModelDefinition.Builder builder = new StateModelDefinition.Builder(
+ STATE_MODEL_NAME);
+ // Add states and their rank to indicate priority. Lower the rank higher the
+ // priority
+ builder.addState(MASTER, 1);
+ builder.addState(SLAVE, 2);
+ builder.addState(OFFLINE);
+ builder.addState(DROPPED);
+ // Set the initial state when the node starts
+ builder.initialState(OFFLINE);
+
+ // Add transitions between the states.
+ builder.addTransition(OFFLINE, SLAVE);
+ builder.addTransition(SLAVE, OFFLINE);
+ builder.addTransition(SLAVE, MASTER);
+ builder.addTransition(MASTER, SLAVE);
+ builder.addTransition(OFFLINE, DROPPED);
+
+ // set constraints on states.
+ // static constraint
+ builder.upperBound(MASTER, 1);
+ // dynamic constraint, R means it should be derived based on the replication
+ // factor.
+ builder.dynamicUpperBound(SLAVE, "R");
+
+ StateModelDefinition statemodelDefinition = builder.build();
+ return statemodelDefinition;
+ }
+
+ public static void startController()
+ {
+ // start controller
+ echo("Starting Helix Controller");
+ HelixControllerMain.startHelixController(ZK_ADDRESS, CLUSTER_NAME,
+ "localhost_9100", HelixControllerMain.STANDALONE);
+ }
+
+ public static void startNodes() throws Exception
+ {
+ echo("Starting Participants");
+ for (int i = 0; i < NUM_NODES; i++)
+ {
+ MyProcess process = new MyProcess(INSTANCE_CONFIG_LIST.get(i).getId());
+ PROCESS_LIST.add(process);
+ process.start();
+ echo("\t Started Participant: " + INSTANCE_CONFIG_LIST.get(i).getId());
+ }
+ }
+
+ public static void startZookeeper()
+ {
+ echo("STARTING Zookeeper at " + ZK_ADDRESS);
+ IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace()
+ {
+ @Override
+ public void createDefaultNameSpace(ZkClient zkClient)
+ {
+ }
+ };
+ new File("/tmp/helix-quickstart").mkdirs();
+ // start zookeeper
+ ZkServer server = new ZkServer("/tmp/helix-quickstart/dataDir",
+ "/tmp/helix-quickstart/logDir", defaultNameSpace, 2199);
+ server.start();
+ }
+
+ public static void echo(Object obj)
+ {
+ System.out.println(obj);
+ }
+
+ public static void main(String[] args) throws Exception
+ {
+ startZookeeper();
+ setup();
+ startNodes();
+ startController();
+ Thread.sleep(5000);
+ printState("After starting 2 nodes");
+ addNode();
+ Thread.sleep(5000);
+ printState("After adding a third node");
+ stopNode();
+ Thread.sleep(5000);
+ printState("After the 3rd node stops/crashes");
+ Thread.currentThread().join();
+ System.exit(0);
+ }
+
+ private static void addNode() throws Exception
+ {
+
+ NUM_NODES = NUM_NODES + 1;
+ int port = 12000 + NUM_NODES - 1;
+ InstanceConfig instanceConfig = new InstanceConfig("localhost_" + port);
+ instanceConfig.setHostName("localhost");
+ instanceConfig.setPort("" + port);
+ instanceConfig.setInstanceEnabled(true);
+ echo("ADDING NEW NODE :" + instanceConfig.getInstanceName()+ ". Partitions will move from old nodes to the new node.");
+ admin.addInstance(CLUSTER_NAME, instanceConfig);
+ INSTANCE_CONFIG_LIST.add(instanceConfig);
+ MyProcess process = new MyProcess(instanceConfig.getInstanceName());
+ PROCESS_LIST.add(process);
+ admin.rebalance(CLUSTER_NAME, RESOURCE_NAME, 3);
+ process.start();
+ }
+
+ private static void stopNode()
+ {
+ int nodeId = NUM_NODES - 1;
+ echo("STOPPING " + INSTANCE_CONFIG_LIST.get(nodeId).getInstanceName()+". Mastership will be transferred to the remaining nodes");
+ PROCESS_LIST.get(nodeId).stop();
+ }
+
+ private static void printState(String msg)
+ {
+ System.out.println("CLUSTER STATE: "+ msg);
+ ExternalView resourceExternalView = admin.getResourceExternalView(
+ CLUSTER_NAME, RESOURCE_NAME);
+ TreeSet<String> sortedSet = new TreeSet<String>(
+ resourceExternalView.getPartitionSet());
+ StringBuilder sb = new StringBuilder("\t\t");
+ for (int i = 0; i < NUM_NODES; i++)
+ {
+ sb.append(INSTANCE_CONFIG_LIST.get(i).getInstanceName()).append("\t");
+ }
+ System.out.println(sb);
+ for (String partitionName : sortedSet)
+ {
+ sb.delete(0, sb.length() - 1);
+ sb.append(partitionName).append("\t");
+ for (int i = 0; i < NUM_NODES; i++)
+ {
+ Map<String, String> stateMap = resourceExternalView
+ .getStateMap(partitionName);
+ if (stateMap != null
+ && stateMap.containsKey(INSTANCE_CONFIG_LIST.get(i)
+ .getInstanceName()))
+ {
+ sb.append(
+ stateMap.get(INSTANCE_CONFIG_LIST.get(i).getInstanceName())
+ .charAt(0)).append("\t\t");
+ } else
+ {
+ sb.append("-").append("\t\t");
+ }
+ }
+ System.out.println(sb);
+ }
+ System.out.println("###################################################################");
+ }
+
+ static final class MyProcess
+ {
+ private final String instanceName;
+ private HelixManager manager;
+
+ public MyProcess(String instanceName)
+ {
+ this.instanceName = instanceName;
+ }
+
+ public void start() throws Exception
+ {
+ manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME,
+ instanceName, InstanceType.PARTICIPANT, ZK_ADDRESS);
+
+ MasterSlaveStateModelFactory stateModelFactory = new MasterSlaveStateModelFactory(
+ instanceName);
+
+ StateMachineEngine stateMach = manager.getStateMachineEngine();
+ stateMach.registerStateModelFactory(STATE_MODEL_NAME, stateModelFactory);
+ manager.connect();
+ }
+
+ public void stop()
+ {
+ manager.disconnect();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
index fe7f67b..0a0a593 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
@@ -428,15 +428,12 @@ public class FileHelixAdmin implements HelixAdmin
@Override
public void setConfig(ConfigScope scope, Map<String, String> properties)
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
-
}
@Override
public Map<String, String> getConfig(ConfigScope scope, Set<String> keys)
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
}
@@ -445,14 +442,12 @@ public class FileHelixAdmin implements HelixAdmin
String clusterName,
String... keys)
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
}
@Override
public void removeConfig(ConfigScope scope, Set<String> keys)
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
}
@@ -460,14 +455,12 @@ public class FileHelixAdmin implements HelixAdmin
@Override
public void rebalance(String clusterName, String resourceName, int replica)
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
}
@Override
public void addIdealState(String clusterName, String resourceName, String idealStateFile) throws IOException
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
}
@@ -476,7 +469,6 @@ public class FileHelixAdmin implements HelixAdmin
String stateModelDefName,
String stateModelDefFile) throws IOException
{
- // TODO Auto-generated method stub
throw new UnsupportedOperationException("unsupported operation");
}
@@ -485,7 +477,13 @@ public class FileHelixAdmin implements HelixAdmin
String constraintId,
Map<String, String> constraints)
{
- // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("unsupported operation");
+ }
+
+ @Override
+ public void addResource(String clusterName, String resourceName,
+ IdealState idealstate)
+ {
throw new UnsupportedOperationException("unsupported operation");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/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 3a7e103..4499d4b 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
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import org.I0Itec.zkclient.DataUpdater;
import org.I0Itec.zkclient.exception.ZkNoNodeException;
@@ -87,6 +88,14 @@ public class ZKHelixAdmin implements HelixAdmin
_configAccessor = new ConfigAccessor(zkClient);
}
+ public ZKHelixAdmin(String zkAddress)
+ {
+ _zkClient = new ZkClient(zkAddress);
+ _zkClient.setZkSerializer(new ZNRecordSerializer());
+ _zkClient.waitUntilConnected(30, TimeUnit.SECONDS);
+ _configAccessor = new ConfigAccessor(_zkClient);
+ }
+
@Override
public void addInstance(String clusterName, InstanceConfig instanceConfig)
{
@@ -644,6 +653,33 @@ public class ZKHelixAdmin implements HelixAdmin
}
@Override
+ public void addResource(String clusterName,
+ String resourceName,
+ IdealState idealstate)
+ {
+ String stateModelRef = idealstate.getStateModelDefRef();
+ String stateModelDefPath =
+ PropertyPathConfig.getPath(PropertyType.STATEMODELDEFS,
+ clusterName,
+ stateModelRef);
+ if (!_zkClient.exists(stateModelDefPath))
+ {
+ throw new HelixException("State model " + stateModelRef
+ + " not found in the cluster STATEMODELDEFS path");
+ }
+
+ String idealStatePath = HelixUtil.getIdealStatePath(clusterName);
+ String dbIdealStatePath = idealStatePath + "/" + resourceName;
+ if (_zkClient.exists(dbIdealStatePath))
+ {
+ throw new HelixException("Skip the operation. DB ideal state directory exists:"
+ + dbIdealStatePath);
+ }
+
+ ZKUtil.createChildren(_zkClient, idealStatePath, idealstate.getRecord());
+ }
+
+ @Override
public void addResource(String clusterName,
String resourceName,
int partitions,
@@ -676,26 +712,8 @@ public class ZKHelixAdmin implements HelixAdmin
{
idealState.setBucketSize(bucketSize);
}
+ addResource(clusterName, resourceName, idealState);
- String stateModelDefPath =
- PropertyPathConfig.getPath(PropertyType.STATEMODELDEFS,
- clusterName,
- stateModelRef);
- if (!_zkClient.exists(stateModelDefPath))
- {
- throw new HelixException("State model " + stateModelRef
- + " not found in the cluster STATEMODELDEFS path");
- }
-
- String idealStatePath = HelixUtil.getIdealStatePath(clusterName);
- String dbIdealStatePath = idealStatePath + "/" + resourceName;
- if (_zkClient.exists(dbIdealStatePath))
- {
- throw new HelixException("Skip the operation. DB ideal state directory exists:"
- + dbIdealStatePath);
- }
-
- ZKUtil.createChildren(_zkClient, idealStatePath, idealState.getRecord());
}
@Override
@@ -1273,4 +1291,6 @@ public class ZKHelixAdmin implements HelixAdmin
}
}, AccessOption.PERSISTENT);
}
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/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 c0bdb38..8ae785b 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
@@ -36,9 +36,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Set;
import java.util.Timer;
-import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.TimeUnit;
import org.I0Itec.zkclient.ZkConnection;
@@ -46,12 +44,14 @@ import org.apache.helix.BaseDataAccessor;
import org.apache.helix.ClusterMessagingService;
import org.apache.helix.ConfigAccessor;
import org.apache.helix.ConfigChangeListener;
+import org.apache.helix.ConfigScope.ConfigScopeProperty;
import org.apache.helix.ControllerChangeListener;
import org.apache.helix.CurrentStateChangeListener;
import org.apache.helix.DataAccessor;
import org.apache.helix.ExternalViewChangeListener;
import org.apache.helix.HealthStateChangeListener;
import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixConstants.ChangeType;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixException;
import org.apache.helix.HelixManager;
@@ -61,12 +61,10 @@ import org.apache.helix.InstanceType;
import org.apache.helix.LiveInstanceChangeListener;
import org.apache.helix.MessageListener;
import org.apache.helix.PreConnectCallback;
+import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.ZNRecord;
-import org.apache.helix.ConfigScope.ConfigScopeProperty;
-import org.apache.helix.HelixConstants.ChangeType;
-import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.controller.restlet.ZKPropertyTransferServer;
import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
@@ -75,8 +73,8 @@ import org.apache.helix.messaging.DefaultMessagingService;
import org.apache.helix.messaging.handling.MessageHandlerFactory;
import org.apache.helix.model.CurrentState;
import org.apache.helix.model.LiveInstance;
-import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.Message.MessageType;
+import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.monitoring.ZKPathDataDumpTask;
import org.apache.helix.participant.DistClusterControllerElection;
import org.apache.helix.participant.HelixStateMachineEngine;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/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 0cc0f01..ad629f0 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
@@ -32,7 +32,6 @@ import org.apache.helix.HelixProperty;
import org.apache.helix.ZNRecord;
import org.apache.log4j.Logger;
-
/**
* The ideal states of all partition in a resource
*/
@@ -40,12 +39,7 @@ public class IdealState extends HelixProperty
{
public enum IdealStateProperty
{
- NUM_PARTITIONS,
- STATE_MODEL_DEF_REF,
- STATE_MODEL_FACTORY_NAME,
- REPLICAS,
- IDEAL_STATE_MODE,
- REBALANCE_TIMER_PERIOD
+ NUM_PARTITIONS, STATE_MODEL_DEF_REF, STATE_MODEL_FACTORY_NAME, REPLICAS, IDEAL_STATE_MODE, REBALANCE_TIMER_PERIOD
}
public static final String QUERY_LIST = "PREFERENCE_LIST_QUERYS";
@@ -55,7 +49,8 @@ public class IdealState extends HelixProperty
AUTO, CUSTOMIZED, AUTO_REBALANCE
}
- private static final Logger logger = Logger.getLogger(IdealState.class.getName());
+ private static final Logger logger = Logger.getLogger(IdealState.class
+ .getName());
public IdealState(String resourceName)
{
@@ -74,23 +69,25 @@ public class IdealState extends HelixProperty
public void setIdealStateMode(String mode)
{
- _record.setSimpleField(IdealStateProperty.IDEAL_STATE_MODE.toString(), mode);
+ _record
+ .setSimpleField(IdealStateProperty.IDEAL_STATE_MODE.toString(), mode);
}
public IdealStateModeProperty getIdealStateMode()
{
- String mode = _record.getSimpleField(IdealStateProperty.IDEAL_STATE_MODE.toString());
+ String mode = _record.getSimpleField(IdealStateProperty.IDEAL_STATE_MODE
+ .toString());
try
{
return IdealStateModeProperty.valueOf(mode);
- }
- catch (Exception e)
+ } catch (Exception e)
{
return IdealStateModeProperty.AUTO;
}
}
- public void setPartitionState(String partitionName, String instanceName, String state)
+ public void setPartitionState(String partitionName, String instanceName,
+ String state)
{
Map<String, String> mapField = _record.getMapField(partitionName);
if (mapField == null)
@@ -106,12 +103,10 @@ public class IdealState extends HelixProperty
|| getIdealStateMode() == IdealStateModeProperty.AUTO_REBALANCE)
{
return _record.getListFields().keySet();
- }
- else if (getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
+ } else if (getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
{
return _record.getMapFields().keySet();
- }
- else
+ } else
{
logger.error("Invalid ideal state mode:" + getResourceName());
return Collections.emptySet();
@@ -132,27 +127,23 @@ public class IdealState extends HelixProperty
if (prefList != null)
{
return new TreeSet<String>(prefList);
- }
- else
+ } else
{
logger.warn(partitionName + " does NOT exist");
return Collections.emptySet();
}
- }
- else if (getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
+ } else if (getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
{
Map<String, String> stateMap = _record.getMapField(partitionName);
if (stateMap != null)
{
return new TreeSet<String>(stateMap.keySet());
- }
- else
+ } else
{
logger.warn(partitionName + " does NOT exist");
return Collections.emptySet();
}
- }
- else
+ } else
{
logger.error("Invalid ideal state mode: " + getResourceName());
return Collections.emptySet();
@@ -175,30 +166,31 @@ public class IdealState extends HelixProperty
public String getStateModelDefRef()
{
- return _record.getSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF.toString());
+ return _record.getSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF
+ .toString());
}
public void setStateModelDefRef(String stateModel)
{
- _record.setSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF.toString(), stateModel);
+ _record.setSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF.toString(),
+ stateModel);
}
public void setNumPartitions(int numPartitions)
{
_record.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(),
- String.valueOf(numPartitions));
+ String.valueOf(numPartitions));
}
public int getNumPartitions()
{
- String numPartitionStr =
- _record.getSimpleField(IdealStateProperty.NUM_PARTITIONS.toString());
+ String numPartitionStr = _record
+ .getSimpleField(IdealStateProperty.NUM_PARTITIONS.toString());
try
{
return Integer.parseInt(numPartitionStr);
- }
- catch (Exception e)
+ } catch (Exception e)
{
logger.error("Can't parse number of partitions: " + numPartitionStr, e);
return -1;
@@ -212,9 +204,11 @@ public class IdealState extends HelixProperty
public String getReplicas()
{
- // HACK: if replica doesn't exists, use the length of the first list field instead
+ // HACK: if replica doesn't exists, use the length of the first list field
+ // instead
// TODO: remove it when Dbus fixed the IdealState writer
- String replica = _record.getSimpleField(IdealStateProperty.REPLICAS.toString());
+ String replica = _record.getSimpleField(IdealStateProperty.REPLICAS
+ .toString());
if (replica == null)
{
String firstPartition = null;
@@ -224,27 +218,31 @@ public class IdealState extends HelixProperty
if (_record.getListFields().size() == 0)
{
replica = "0";
- }
- else
+ } else
{
- firstPartition = new ArrayList<String>(_record.getListFields().keySet()).get(0);
- replica = Integer.toString(firstPartition == null ? 0 : _record.getListField(firstPartition).size());
+ firstPartition = new ArrayList<String>(_record.getListFields()
+ .keySet()).get(0);
+ replica = Integer.toString(firstPartition == null ? 0 : _record
+ .getListField(firstPartition).size());
}
- logger.warn("could NOT found replicas in idealState. Use size of the first list instead. replica: "
- + replica + ", 1st partition: " + firstPartition);
+ logger
+ .warn("could NOT found replicas in idealState. Use size of the first list instead. replica: "
+ + replica + ", 1st partition: " + firstPartition);
break;
case CUSTOMIZED:
if (_record.getMapFields().size() == 0)
{
replica = "0";
- }
- else
+ } else
{
- firstPartition = new ArrayList<String>(_record.getMapFields().keySet()).get(0);
- replica = Integer.toString(firstPartition == null ? 0 : _record.getMapField(firstPartition).size());
+ firstPartition = new ArrayList<String>(_record.getMapFields()
+ .keySet()).get(0);
+ replica = Integer.toString(firstPartition == null ? 0 : _record
+ .getMapField(firstPartition).size());
}
- logger.warn("could NOT found replicas in idealState. Use size of the first map instead. replica: "
- + replica + ", 1st partition: " + firstPartition);
+ logger
+ .warn("could NOT found replicas in idealState. Use size of the first map instead. replica: "
+ + replica + ", 1st partition: " + firstPartition);
break;
default:
replica = "0";
@@ -258,31 +256,33 @@ public class IdealState extends HelixProperty
public void setStateModelFactoryName(String name)
{
- _record.setSimpleField(IdealStateProperty.STATE_MODEL_FACTORY_NAME.toString(), name);
+ _record.setSimpleField(
+ IdealStateProperty.STATE_MODEL_FACTORY_NAME.toString(), name);
}
public String getStateModelFactoryName()
{
- String ftyName = _record.getSimpleField(IdealStateProperty.STATE_MODEL_FACTORY_NAME.toString());
+ String ftyName = _record
+ .getSimpleField(IdealStateProperty.STATE_MODEL_FACTORY_NAME.toString());
if (ftyName == null)
{
ftyName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
}
- return ftyName;
+ return ftyName;
}
public int getRebalanceTimerPeriod()
{
- if (_record.getSimpleFields()
- .containsKey(IdealStateProperty.REBALANCE_TIMER_PERIOD.toString()))
+ if (_record.getSimpleFields().containsKey(
+ IdealStateProperty.REBALANCE_TIMER_PERIOD.toString()))
{
try
{
- int result =
- Integer.parseInt(_record.getSimpleField(IdealStateProperty.REBALANCE_TIMER_PERIOD.toString()));
+ int result = Integer.parseInt(_record
+ .getSimpleField(IdealStateProperty.REBALANCE_TIMER_PERIOD
+ .toString()));
return result;
- }
- catch (Exception e)
+ } catch (Exception e)
{
logger.error("", e);
}
@@ -295,25 +295,56 @@ public class IdealState extends HelixProperty
{
if (getNumPartitions() < 0)
{
- logger.error("idealState:" + _record + " does not have number of partitions (was "
- + getNumPartitions() + ").");
+ logger.error("idealState:" + _record
+ + " does not have number of partitions (was " + getNumPartitions()
+ + ").");
return false;
}
if (getStateModelDefRef() == null)
{
- logger.error("idealStates:" + _record + " does not have state model definition.");
+ logger.error("idealStates:" + _record
+ + " does not have state model definition.");
return false;
}
- if (getIdealStateMode() == IdealStateModeProperty.AUTO && getReplicas() == null)
+ if (getIdealStateMode() == IdealStateModeProperty.AUTO
+ && getReplicas() == null)
{
logger.error("idealStates:" + _record + " does not have replica.");
return false;
}
return true;
}
- public static class Builder{
-
+
+ public static class CustomBuilder
+ {
+ public void set(String partitionName, String instanceName, String state)
+ {
+
+ }
+
+ }
+
+ public static class AutoModeBuilder
+ {
+ public void setNumPartitions(int partitions)
+ {
+
+ }
+
+ public void replicas(int replicas)
+ {
+
+ }
+
+ }
+
+ public static class SemiAutoBuilder
+ {
+ public void set(String partitionName, String... instancePreferenceList)
+ {
+
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/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 9b0eed6..15171e8 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
@@ -78,7 +78,7 @@ public class InstanceConfig extends HelixProperty
public boolean getInstanceEnabled()
{
String isEnabled = _record.getSimpleField(InstanceConfigProperty.HELIX_ENABLED.toString());
- return Boolean.parseBoolean(isEnabled);
+ return isEnabled == null || Boolean.parseBoolean(isEnabled);
}
public void setInstanceEnabled(boolean enabled)
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/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 f10251c..eea9da2 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
@@ -175,10 +175,10 @@ public class StateModelDefinition extends HelixProperty
*
* @param state
*/
- public void initialState(String initialState)
+ public Builder initialState(String initialState)
{
this.initialState = initialState;
-
+ return this;
}
/**
@@ -190,9 +190,21 @@ public class StateModelDefinition extends HelixProperty
*
* @param states
*/
- public void addState(String state, int priority)
+ public Builder addState(String state, int priority)
{
statesMap.put(state, priority);
+ return this;
+ }
+
+ /**
+ * Sets the priority to Integer.MAX_VALUE
+ *
+ * @param state
+ */
+ public Builder addState(String state)
+ {
+ addState(state, Integer.MAX_VALUE);
+ return this;
}
/**
@@ -207,31 +219,42 @@ public class StateModelDefinition extends HelixProperty
* @param toState
* @param priority
*/
- public void addTransition(String fromState, String toState, int priority)
+ public Builder addTransition(String fromState, String toState, int priority)
{
transitionMap.put(new Transition(fromState, toState), priority);
+ return this;
+ }
+
+ public Builder addTransition(String fromState, String toState)
+ {
+ addTransition(fromState, toState, Integer.MAX_VALUE);
+ return this;
}
- public void upperBound(String state, int upperBound)
+ public Builder upperBound(String state, int upperBound)
{
stateConstraintMap.put(state, String.valueOf(upperBound));
+ return this;
}
/**
* You can use this to have the bounds dynamically change based on other
- * parameters. Currently support 2 values R --> Refers to the number of
- * replicas specified during resource creation. This allows having different
- * replication factor for each resource without having to create a different
- * state machine. N --> Refers to all nodes in the cluster. Useful for
- * resources that need to exist on all nodes. This way one can add/remove
- * nodes without having the change the bounds.
+ * parameters. <br/>
+ * Currently support 2 values <br/>
+ * R --> Refers to the number of replicas specified during resource
+ * creation. This allows having different replication factor for each
+ * resource without having to create a different state machine. <br/>
+ * N --> Refers to all nodes in the cluster. Useful for resources that need
+ * to exist on all nodes. This way one can add/remove nodes without having
+ * the change the bounds.
*
* @param state
* @param bound
*/
- public void dynamicUpperBound(String state, String bound)
+ public Builder dynamicUpperBound(String state, String bound)
{
stateConstraintMap.put(state, bound);
+ return this;
}
public StateModelDefinition build()
@@ -249,22 +272,24 @@ public class StateModelDefinition extends HelixProperty
}
};
Collections.sort(statePriorityList, c1);
- ArrayList<String> transitionPriorityList = new ArrayList<String>(
- transitionMap.size());
- for (Transition t : transitionMap.keySet())
- {
- transitionPriorityList.add(t.toString());
- }
- Comparator<? super String> c2 = new Comparator<String>()
- {
+ ArrayList<Transition> transitionList = new ArrayList<Transition>(
+ transitionMap.keySet());
+ Comparator<? super Transition> c2 = new Comparator<Transition>()
+ {
@Override
- public int compare(String o1, String o2)
+ public int compare(Transition o1, Transition o2)
{
- return statesMap.get(o1).compareTo(statesMap.get(o2));
+ return transitionMap.get(o1).compareTo(transitionMap.get(o2));
}
};
- Collections.sort(transitionPriorityList, c2);
+ Collections.sort(transitionList, c2);
+ List<String> transitionPriorityList = new ArrayList<String>(
+ transitionList.size());
+ for (Transition t : transitionList)
+ {
+ transitionPriorityList.add(t.toString());
+ }
record.setSimpleField(
StateModelDefinitionProperty.INITIAL_STATE.toString(), initialState);
@@ -283,10 +308,16 @@ public class StateModelDefinition extends HelixProperty
{
record.setMapField(state + ".next", transitionTable.get(state));
}
- for (String state : stateConstraintMap.keySet())
+ for (String state : statePriorityList)
{
HashMap<String, String> metadata = new HashMap<String, String>();
- metadata.put("count", stateConstraintMap.get(state));
+ if (stateConstraintMap.get(state) != null)
+ {
+ metadata.put("count", stateConstraintMap.get(state));
+ } else
+ {
+ metadata.put("count", "-1");
+ }
record.setMapField(state + ".meta", metadata);
}
return new StateModelDefinition(record);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateTransitionTableBuilder.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateTransitionTableBuilder.java b/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateTransitionTableBuilder.java
index c731b40..655c1ea 100644
--- a/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateTransitionTableBuilder.java
+++ b/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateTransitionTableBuilder.java
@@ -151,29 +151,35 @@ public class StateTransitionTableBuilder
&& (pathVal1 + pathVal2) < pathValCur)
{
setPathVal(path, fromState, toState, pathVal1 + pathVal2);
- setNext(next, fromState, toState, intermediateState);
+ setNext(next, fromState, toState, getNext(next, fromState, intermediateState));
}
}
}
}
-
return next;
}
public static void main(String[] args)
{
List<String> states = new ArrayList<String>();
- states.add("OFFLINE");
- states.add("SLAVE");
+ //[MASTER, SLAVE, DROPPED, OFFLINE]
+ //[SLAVE-OFFLINE, OFFLINE-SLAVE, SLAVE-MASTER, OFFLINE-DROPPED, MASTER-SLAVE]
states.add("MASTER");
+ states.add("SLAVE");
+ states.add("DROPPED");
+ states.add("OFFLINE");
+
List<Transition> transitions = new ArrayList<Transition>();
+ transitions.add(new Transition("SLAVE", "OFFLINE"));
transitions.add(new Transition("OFFLINE", "SLAVE"));
transitions.add(new Transition("SLAVE", "MASTER"));
+ transitions.add(new Transition("OFFLINE", "DROPPED"));
transitions.add(new Transition("MASTER", "SLAVE"));
- transitions.add(new Transition("SLAVE", "OFFLINE"));
+
StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);
+ System.out.println(next);
printPath(states, next);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/4de35d19/helix-core/src/main/java/org/apache/helix/tools/ZKDumper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ZKDumper.java b/helix-core/src/main/java/org/apache/helix/tools/ZKDumper.java
index 5910e55..9f11443 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/ZKDumper.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/ZKDumper.java
@@ -54,7 +54,7 @@ public class ZKDumper
static Options options;
private String suffix = "";
//enable by default
- private boolean removeSuffix=true;
+ private boolean removeSuffix=false;
public String getSuffix()
{