helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [1/2] [HELIX-483] Simplify logical config classes
Date Mon, 28 Jul 2014 21:19:59 GMT
Repository: helix
Updated Branches:
  refs/heads/master ce1e926c9 -> ff958b19f


http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/helix-core/src/test/java/org/apache/helix/controller/stages/TestMsgSelectionStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestMsgSelectionStage.java
b/helix-core/src/test/java/org/apache/helix/controller/stages/TestMsgSelectionStage.java
index 46c0fd9..c09e937 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestMsgSelectionStage.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestMsgSelectionStage.java
@@ -25,23 +25,17 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.helix.TestHelper;
-import org.apache.helix.api.HelixVersion;
 import org.apache.helix.api.Participant;
-import org.apache.helix.api.RunningInstance;
-import org.apache.helix.api.Scope;
 import org.apache.helix.api.State;
-import org.apache.helix.api.config.UserConfig;
+import org.apache.helix.api.config.ParticipantConfig;
 import org.apache.helix.api.id.MessageId;
 import org.apache.helix.api.id.ParticipantId;
-import org.apache.helix.api.id.PartitionId;
-import org.apache.helix.api.id.ProcId;
 import org.apache.helix.api.id.ResourceId;
-import org.apache.helix.api.id.SessionId;
 import org.apache.helix.controller.stages.MessageSelectionStage.Bounds;
 import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.LiveInstance;
 import org.apache.helix.model.Message;
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -51,25 +45,24 @@ public class TestMsgSelectionStage {
   public void testMasterXfer() {
     System.out.println("START testMasterXfer at " + new Date(System.currentTimeMillis()));
 
-    Map<ParticipantId, Participant> liveInstances = new HashMap<ParticipantId, Participant>();
-    Set<PartitionId> disabledPartitions = Collections.emptySet();
-    Set<String> tags = Collections.emptySet();
+    Map<ParticipantId, Participant> liveParticipants = new HashMap<ParticipantId,
Participant>();
     Map<ResourceId, CurrentState> currentStateMap = Collections.emptyMap();
     Map<MessageId, Message> messageMap = Collections.emptyMap();
-    RunningInstance runningInstance0 =
-        new RunningInstance(SessionId.from("session_0"), HelixVersion.from("1.2.3.4"),
-            ProcId.from("0"));
-    RunningInstance runningInstance1 =
-        new RunningInstance(SessionId.from("session_1"), HelixVersion.from("1.2.3.4"),
-            ProcId.from("1"));
-    liveInstances.put(ParticipantId.from("localhost_0"),
-        new Participant(ParticipantId.from("localhost_0"), "localhost", 0, true,
-            disabledPartitions, tags, runningInstance0, currentStateMap, messageMap,
-            new UserConfig(Scope.participant(ParticipantId.from("localhost_0"))), null));
-    liveInstances.put(ParticipantId.from("localhost_1"),
-        new Participant(ParticipantId.from("localhost_1"), "localhost", 1, true,
-            disabledPartitions, tags, runningInstance1, currentStateMap, messageMap,
-            new UserConfig(Scope.participant(ParticipantId.from("localhost_1"))), null));
+    ParticipantId participantId0 = ParticipantId.from("localhost_0");
+    ParticipantId participantId1 = ParticipantId.from("localhost_1");
+    LiveInstance[] liveInstances = new LiveInstance[2];
+    for (int i = 0; i < 2; i++) {
+      liveInstances[i] = new LiveInstance("localhost_" + i);
+      liveInstances[i].setSessionId("session_" + i);
+      liveInstances[i].setHelixVersion("1.2.3.4");
+      liveInstances[i].setLiveInstance(i + "@localhost");
+    }
+    liveParticipants.put(participantId0, new Participant(new ParticipantConfig.Builder(
+        participantId0).hostName("localhost").port(0).build(), liveInstances[0], currentStateMap,
+        messageMap, null));
+    liveParticipants.put(participantId1, new Participant(new ParticipantConfig.Builder(
+        participantId1).hostName("localhost").port(1).build(), liveInstances[1], currentStateMap,
+        messageMap, null));
 
     Map<ParticipantId, State> currentStates = new HashMap<ParticipantId, State>();
     currentStates.put(ParticipantId.from("localhost_0"), State.from("SLAVE"));
@@ -92,7 +85,7 @@ public class TestMsgSelectionStage {
     stateTransitionPriorities.put("SLAVE-MASTER", 1);
 
     List<Message> selectedMsg =
-        new MessageSelectionStage().selectMessages(liveInstances, currentStates, pendingStates,
+        new MessageSelectionStage().selectMessages(liveParticipants, currentStates, pendingStates,
             messages, stateConstraints, stateTransitionPriorities, State.from("OFFLINE"));
 
     Assert.assertEquals(selectedMsg.size(), 1);
@@ -105,25 +98,24 @@ public class TestMsgSelectionStage {
     System.out.println("START testMasterXferAfterMasterResume at "
         + new Date(System.currentTimeMillis()));
 
-    Map<ParticipantId, Participant> liveInstances = new HashMap<ParticipantId, Participant>();
-    Set<PartitionId> disabledPartitions = Collections.emptySet();
-    Set<String> tags = Collections.emptySet();
+    Map<ParticipantId, Participant> liveParticipants = new HashMap<ParticipantId,
Participant>();
     Map<ResourceId, CurrentState> currentStateMap = Collections.emptyMap();
     Map<MessageId, Message> messageMap = Collections.emptyMap();
-    RunningInstance runningInstance0 =
-        new RunningInstance(SessionId.from("session_0"), HelixVersion.from("1.2.3.4"),
-            ProcId.from("0"));
-    RunningInstance runningInstance1 =
-        new RunningInstance(SessionId.from("session_1"), HelixVersion.from("1.2.3.4"),
-            ProcId.from("1"));
-    liveInstances.put(ParticipantId.from("localhost_0"),
-        new Participant(ParticipantId.from("localhost_0"), "localhost", 0, true,
-            disabledPartitions, tags, runningInstance0, currentStateMap, messageMap,
-            new UserConfig(Scope.participant(ParticipantId.from("localhost_0"))), null));
-    liveInstances.put(ParticipantId.from("localhost_1"),
-        new Participant(ParticipantId.from("localhost_1"), "localhost", 1, true,
-            disabledPartitions, tags, runningInstance1, currentStateMap, messageMap,
-            new UserConfig(Scope.participant(ParticipantId.from("localhost_1"))), null));
+    ParticipantId participantId0 = ParticipantId.from("localhost_0");
+    ParticipantId participantId1 = ParticipantId.from("localhost_1");
+    LiveInstance[] liveInstances = new LiveInstance[2];
+    for (int i = 0; i < 2; i++) {
+      liveInstances[i] = new LiveInstance("localhost_" + i);
+      liveInstances[i].setSessionId("session_" + i);
+      liveInstances[i].setHelixVersion("1.2.3.4");
+      liveInstances[i].setLiveInstance(i + "@localhost");
+    }
+    liveParticipants.put(participantId0, new Participant(new ParticipantConfig.Builder(
+        participantId0).hostName("localhost").port(0).build(), liveInstances[0], currentStateMap,
+        messageMap, null));
+    liveParticipants.put(participantId1, new Participant(new ParticipantConfig.Builder(
+        participantId1).hostName("localhost").port(1).build(), liveInstances[1], currentStateMap,
+        messageMap, null));
 
     Map<ParticipantId, State> currentStates = new HashMap<ParticipantId, State>();
     currentStates.put(ParticipantId.from("localhost_0"), State.from("SLAVE"));
@@ -145,7 +137,7 @@ public class TestMsgSelectionStage {
     stateTransitionPriorities.put("SLAVE-MASTER", 1);
 
     List<Message> selectedMsg =
-        new MessageSelectionStage().selectMessages(liveInstances, currentStates, pendingStates,
+        new MessageSelectionStage().selectMessages(liveParticipants, currentStates, pendingStates,
             messages, stateConstraints, stateTransitionPriorities, State.from("OFFLINE"));
 
     Assert.assertEquals(selectedMsg.size(), 0);

http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/helix-core/src/test/java/org/apache/helix/controller/strategy/TestNewAutoRebalanceStrategy.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/strategy/TestNewAutoRebalanceStrategy.java
b/helix-core/src/test/java/org/apache/helix/controller/strategy/TestNewAutoRebalanceStrategy.java
index c8ec90a..4535df5 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/strategy/TestNewAutoRebalanceStrategy.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/strategy/TestNewAutoRebalanceStrategy.java
@@ -36,10 +36,9 @@ import java.util.TreeSet;
 import org.apache.helix.HelixDefinedState;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.api.Participant;
-import org.apache.helix.api.Scope;
 import org.apache.helix.api.State;
 import org.apache.helix.api.config.ClusterConfig;
-import org.apache.helix.api.config.UserConfig;
+import org.apache.helix.api.config.ParticipantConfig;
 import org.apache.helix.api.id.ClusterId;
 import org.apache.helix.api.id.MessageId;
 import org.apache.helix.api.id.ParticipantId;
@@ -225,17 +224,10 @@ public class TestNewAutoRebalanceStrategy {
       ClusterId clusterId = ClusterId.from("clusterId");
       ClusterConfig.Builder clusterConfigBuilder =
           new ClusterConfig.Builder(clusterId).addStateModelDefinition(_stateModelDef);
-      for (State state : _stateModelDef.getTypedStatesPriorityList()) {
-        clusterConfigBuilder.addStateUpperBoundConstraint(Scope.cluster(clusterId),
-            _stateModelDef.getStateModelDefId(), state,
-            _stateModelDef.getNumParticipantsPerState(state));
-      }
       ClusterConfig clusterConfig = clusterConfigBuilder.build();
       for (String partition : _partitions) {
         PartitionId partitionId = PartitionId.from(partition);
         Set<ParticipantId> disabledParticipantsForPartition = Collections.emptySet();
-        Set<PartitionId> disabledPartitionIdSet = Collections.emptySet();
-        Set<String> tags = Collections.emptySet();
         Map<MessageId, Message> messageMap = Collections.emptyMap();
         Map<ResourceId, CurrentState> currentStateMap = Collections.emptyMap();
         Map<ParticipantId, Participant> liveParticipantMap =
@@ -243,10 +235,10 @@ public class TestNewAutoRebalanceStrategy {
         // set up some participants
         for (String nodeName : _liveNodes) {
           ParticipantId participantId = ParticipantId.from(nodeName);
+          ParticipantConfig participantConfig =
+              new ParticipantConfig.Builder(participantId).hostName("hostname").port(0).build();
           Participant participant =
-              new Participant(participantId, "hostname", 0, true, disabledPartitionIdSet,
tags,
-                  null, currentStateMap, messageMap, new UserConfig(
-                      Scope.participant(participantId)), null);
+              new Participant(participantConfig, null, currentStateMap, messageMap, null);
           liveParticipantMap.put(participantId, participant);
         }
         List<ParticipantId> participantPreferenceList =

http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
index 911832a..e39615d 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
@@ -88,7 +88,8 @@ public class TestTaskRebalancer extends ZkTestBase {
     // Set up target db
     _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_PARTITIONS,
         MASTER_SLAVE_STATE_MODEL);
-    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
+    _setupTool
+        .rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
 
     Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
     taskFactoryReg.put("Reindex", new TaskFactory() {

http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
b/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
index 163ac5e..9e897a0 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
@@ -90,11 +90,7 @@ public class LogicalModelExample {
         new ClusterConfig.Builder(clusterId).addResource(resource).addParticipant(participant)
             .addStateModelDefinition(lockUnlock).userConfig(userConfig).autoJoin(true);
 
-    // 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)
+    // add a transition constraint (with a resource scope)
     clusterBuilder.addTransitionConstraint(Scope.resource(resource.getId()),
         lockUnlock.getStateModelDefId(),
         Transition.from(State.from("RELEASED"), State.from("LOCKED")), 1);

http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
index fcc137b..b84fae6 100644
--- a/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
@@ -62,7 +62,7 @@ public class ContainerAdmin {
     if (participant != null && participant.isAlive()) {
       Message message = new Message(MessageType.SHUTDOWN, UUID.randomUUID().toString());
       message.setTgtName(participant.getId().toString());
-      message.setTgtSessionId(participant.getRunningInstance().getSessionId());
+      message.setTgtSessionId(participant.getLiveInstance().getSessionId());
       message.setMsgId(message.getId());
       dataAccessor.createProperty(
           dataAccessor.keyBuilder().message(participant.getId().toString(), message.getId()),

http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/NMCallbackHandler.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/NMCallbackHandler.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/NMCallbackHandler.java
index 7d7883e..558d033 100644
--- a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/NMCallbackHandler.java
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/NMCallbackHandler.java
@@ -86,18 +86,18 @@ class NMCallbackHandler implements NMClientAsync.CallbackHandler {
 
   @Override
   public void onStartContainerError(ContainerId containerId, Throwable t) {
-    LOG.error("Failed to start Container " + containerId);
+    LOG.error("Failed to start Container " + containerId, t);
     containers.remove(containerId);
   }
 
   @Override
   public void onGetContainerStatusError(ContainerId containerId, Throwable t) {
-    LOG.error("Failed to query the status of Container " + containerId);
+    LOG.error("Failed to query the status of Container " + containerId, t);
   }
 
   @Override
   public void onStopContainerError(ContainerId containerId, Throwable t) {
-    LOG.error("Failed to stop Container " + containerId);
+    LOG.error("Failed to stop Container " + containerId, t);
     containers.remove(containerId);
   }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/ff958b19/recipes/jobrunner-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/JobRunnerMain.java
----------------------------------------------------------------------
diff --git a/recipes/jobrunner-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/JobRunnerMain.java
b/recipes/jobrunner-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/JobRunnerMain.java
index ddbf27a..e588ea8 100644
--- a/recipes/jobrunner-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/JobRunnerMain.java
+++ b/recipes/jobrunner-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/JobRunnerMain.java
@@ -34,12 +34,12 @@ import org.apache.helix.HelixRole;
 import org.apache.helix.InstanceType;
 import org.apache.helix.api.Cluster;
 import org.apache.helix.api.Participant;
-import org.apache.helix.api.RunningInstance;
 import org.apache.helix.api.accessor.ClusterAccessor;
 import org.apache.helix.api.config.ContainerConfig;
 import org.apache.helix.api.id.ClusterId;
 import org.apache.helix.api.id.Id;
 import org.apache.helix.manager.zk.HelixConnectionAdaptor;
+import org.apache.helix.model.LiveInstance;
 import org.apache.helix.provisioning.ApplicationSpec;
 import org.apache.helix.provisioning.ApplicationSpecFactory;
 import org.apache.helix.provisioning.HelixYarnUtil;
@@ -138,8 +138,8 @@ public class JobRunnerMain {
                 + containerConfig.getState());
           }
           if (participant.isAlive()) {
-            RunningInstance runningInstance = participant.getRunningInstance();
-            System.out.println("\tProcess: " + runningInstance.getPid());
+            LiveInstance runningInstance = participant.getLiveInstance();
+            System.out.println("\tProcess: " + runningInstance.getProcessId());
           }
         }
         System.out.println("----------------");


Mime
View raw message