You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2013/09/24 23:21:13 UTC
git commit: Updated example class with constraint setting
Updated Branches:
refs/heads/helix-logical-model fc91d7157 -> 96079e9bd
Updated example class with constraint setting
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/96079e9b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/96079e9b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/96079e9b
Branch: refs/heads/helix-logical-model
Commit: 96079e9bd22d82d2e8590a62ff34747d44042265
Parents: fc91d71
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Tue Sep 24 14:20:42 2013 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Tue Sep 24 14:20:42 2013 -0700
----------------------------------------------------------------------
.../apache/helix/examples/NewModelExample.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/96079e9b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
index ed66ae2..6791bfd 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
@@ -26,6 +26,7 @@ import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.model.Transition;
import org.apache.log4j.Logger;
import com.google.common.collect.Lists;
@@ -77,11 +78,21 @@ public class NewModelExample {
userConfig.setIntField("sampleInt", 1);
// fully specify the cluster with a ClusterConfig
- ClusterConfig cluster =
+ ClusterConfig.Builder clusterBuilder =
new ClusterConfig.Builder(clusterId).addResource(resource).addParticipant(participant)
- .addStateModelDefinition(lockUnlock).userConfig(userConfig).build();
+ .addStateModelDefinition(lockUnlock).userConfig(userConfig);
- // set up accessors to work with Zookeeper-persisted data
+ // add a state constraint that is more restrictive than what is in the state model
+ clusterBuilder.addStateUpperBoundConstraint(Scope.cluster(clusterId),
+ lockUnlock.getStateModelDefId(), State.from("LOCKED"), 1);
+
+ // add a transition constraint (this time with a resource scope)
+ clusterBuilder.addTransitionConstraint(Scope.resource(resource.getId()),
+ lockUnlock.getStateModelDefId(), Transition.from("RELEASED-LOCKED"), 1);
+
+ ClusterConfig cluster = clusterBuilder.build();
+
+ // set up accessors to work with ZooKeeper-persisted data
int timeOutInSec = Integer.parseInt(System.getProperty(ZKHelixAdmin.CONNECTION_TIMEOUT, "30"));
ZkClient zkClient = new ZkClient(args[0], timeOutInSec * 1000);
zkClient.setZkSerializer(new ZNRecordSerializer());
@@ -150,7 +161,7 @@ public class NewModelExample {
StateModelDefinition.Builder stateModelBuilder =
new StateModelDefinition.Builder(stateModelId).addState(LOCKED, 0).addState(RELEASED, 1)
.addState(DROPPED, 2).addTransition(RELEASED, LOCKED, 0)
- .addTransition(LOCKED, RELEASED, 1).upperBound(LOCKED, 1).upperBound(RELEASED, -1)
+ .addTransition(LOCKED, RELEASED, 1).upperBound(LOCKED, 2).upperBound(RELEASED, -1)
.upperBound(DROPPED, -1).initialState(RELEASED);
return stateModelBuilder.build();
}