helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: [HELIX-100] Remove creating transitions from plain strings
Date Thu, 03 Oct 2013 17:55:51 GMT
Updated Branches:
  refs/heads/helix-logical-model 743308634 -> dd701d6d6


[HELIX-100] Remove creating transitions from plain strings


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

Branch: refs/heads/helix-logical-model
Commit: dd701d6d672b1688d64d741b13fc7d5aca371496
Parents: 7433086
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Thu Oct 3 10:55:03 2013 -0700
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Thu Oct 3 10:55:03 2013 -0700

----------------------------------------------------------------------
 .../org/apache/helix/model/StateModelDefinition.java     |  4 +++-
 .../src/main/java/org/apache/helix/model/Transition.java | 11 -----------
 .../helix/model/builder/StateTransitionTableBuilder.java | 10 +++++-----
 .../apache/helix/tools/StateModelConfigGenerator.java    | 11 ++++++-----
 .../java/org/apache/helix/examples/NewModelExample.java  |  3 ++-
 5 files changed, 16 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/dd701d6d/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 af06ecc..3a8542b 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
@@ -164,7 +164,9 @@ public class StateModelDefinition extends HelixProperty {
   public List<Transition> getStateTransitionPriorityList() {
     ImmutableList.Builder<Transition> builder = new ImmutableList.Builder<Transition>();
     for (String transition : getStateTransitionPriorityStringList()) {
-      builder.add(Transition.from(transition));
+      String fromState = transition.substring(0, transition.indexOf('-'));
+      String toState = transition.substring(transition.indexOf('-') + 1);
+      builder.add(Transition.from(State.from(fromState), State.from(toState)));
     }
     return builder.build();
   }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/dd701d6d/helix-core/src/main/java/org/apache/helix/model/Transition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/Transition.java b/helix-core/src/main/java/org/apache/helix/model/Transition.java
index 4d4bac9..16fc937 100644
--- a/helix-core/src/main/java/org/apache/helix/model/Transition.java
+++ b/helix-core/src/main/java/org/apache/helix/model/Transition.java
@@ -74,17 +74,6 @@ public class Transition {
 
   /**
    * Create a new transition
-   * @param transition string representing a transition, e.g. "STATE1-STATE2"
-   * @return Transition
-   */
-  public static Transition from(String transition) {
-    String fromState = transition.substring(0, transition.indexOf('-'));
-    String toState = transition.substring(transition.indexOf('-') + 1);
-    return new Transition(State.from(fromState), State.from(toState));
-  }
-
-  /**
-   * Create a new transition
    * @param fromState string source state
    * @param toState string destination state
    * @return Transition

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/dd701d6d/helix-core/src/main/java/org/apache/helix/model/builder/StateTransitionTableBuilder.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/builder/StateTransitionTableBuilder.java
b/helix-core/src/main/java/org/apache/helix/model/builder/StateTransitionTableBuilder.java
index e2a3f75..4c6edf7 100644
--- a/helix-core/src/main/java/org/apache/helix/model/builder/StateTransitionTableBuilder.java
+++ b/helix-core/src/main/java/org/apache/helix/model/builder/StateTransitionTableBuilder.java
@@ -163,11 +163,11 @@ public class StateTransitionTableBuilder {
     states.add("OFFLINE");
 
     List<Transition> transitions = new ArrayList<Transition>();
-    transitions.add(Transition.from("SLAVE-OFFLINE"));
-    transitions.add(Transition.from("OFFLINE-SLAVE"));
-    transitions.add(Transition.from("SLAVE-MASTER"));
-    transitions.add(Transition.from("OFFLINE-DROPPED"));
-    transitions.add(Transition.from("MASTER-SLAVE"));
+    transitions.add(Transition.from(State.from("SLAVE"), State.from("OFFLINE")));
+    transitions.add(Transition.from(State.from("OFFLINE"), State.from("SLAVE")));
+    transitions.add(Transition.from(State.from("SLAVE"), State.from("MASTER")));
+    transitions.add(Transition.from(State.from("OFFLINE"), State.from("DROPPED")));
+    transitions.add(Transition.from(State.from("MASTER"), State.from("SLAVE")));
 
     StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
     Map<String, Map<String, String>> next = builder.buildTransitionTable(states,
transitions);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/dd701d6d/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 353ba81..8127626 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
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.helix.ZNRecord;
+import org.apache.helix.api.State;
 import org.apache.helix.manager.zk.DefaultSchedulerMessageHandlerFactory;
 import org.apache.helix.manager.zk.ZNRecordSerializer;
 import org.apache.helix.model.StateModelDefinition.StateModelDefinitionProperty;
@@ -36,8 +37,8 @@ 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(StateModelConfigGenerator
+        .generateConfigForMasterSlave())));
   }
 
   /**
@@ -328,9 +329,9 @@ public class StateModelConfigGenerator {
     states.add("OFFLINE");
 
     List<Transition> transitions = new ArrayList<Transition>();
-    transitions.add(Transition.from("OFFLINE-COMPLETED"));
-    transitions.add(Transition.from("OFFLINE-DROPPED"));
-    transitions.add(Transition.from("COMPLETED-DROPPED"));
+    transitions.add(Transition.from(State.from("OFFLINE"), State.from("COMPLETED")));
+    transitions.add(Transition.from(State.from("OFFLINE"), State.from("DROPPED")));
+    transitions.add(Transition.from(State.from("COMPLETED"), State.from("DROPPED")));
 
     StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
     Map<String, Map<String, String>> next = builder.buildTransitionTable(states,
transitions);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/dd701d6d/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 804df10..7215707 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
@@ -93,7 +93,8 @@ public class NewModelExample {
 
     // add a transition constraint (this time with a resource scope)
     clusterBuilder.addTransitionConstraint(Scope.resource(resource.getId()),
-        lockUnlock.getStateModelDefId(), Transition.from("RELEASED-LOCKED"), 1);
+        lockUnlock.getStateModelDefId(),
+        Transition.from(State.from("RELEASED"), State.from("LOCKED")), 1);
 
     ClusterConfig cluster = clusterBuilder.build();
 


Mime
View raw message