incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1220334 - in /incubator/ambari/trunk/controller/src: main/java/org/apache/ambari/controller/HeartbeatHandler.java main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java test/java/org/apache/ambari/controller/TestHeartbeat.java
Date Sun, 18 Dec 2011 04:54:32 GMT
Author: ddas
Date: Sun Dec 18 04:54:32 2011
New Revision: 1220334

URL: http://svn.apache.org/viewvc?rev=1220334&view=rev
Log:
AMBARI-148.Fixed a bug in FSM

Modified:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
    incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java?rev=1220334&r1=1220333&r2=1220334&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
Sun Dec 18 04:54:32 2011
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.controller;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -134,14 +135,17 @@ public class HeartbeatHandler {
         List<ServiceFSM> clusterServices = clusterFsm.getServices();
         //go through all the components, and check which role should be started
         for (ServiceFSM service : clusterServices) {
+          ComponentPlugin plugin = 
+              cluster.getComponentDefinition(service.getServiceName());
+          //check whether all the dependent components have started up
+          if (!dependentComponentsActive(plugin, clusterFsm)) {
+            continue;
+          }
           List<RoleFSM> roles = service.getRoles();
           for (RoleFSM role : roles) {
             boolean nodePlayingRole = 
                 nodePlayingRole(hostname, role.getRoleName());
-            if (nodePlayingRole) {
-              ComponentPlugin plugin = 
-                  cluster.getComponentDefinition(service.getServiceName());
-
+            if (nodePlayingRole) {          
               //check whether the agent should start any server
               if (role.shouldStart()) {
                 Action action = 
@@ -186,6 +190,26 @@ public class HeartbeatHandler {
     return createResponse(responseId,allActions,heartbeat);
   }
   
+  private boolean dependentComponentsActive(ComponentPlugin plugin, 
+      ClusterFSM cluster) throws IOException {
+    String[] dependents = plugin.getRequiredComponents();
+    if (dependents == null || dependents.length == 0) {
+      return true;
+    }
+    List<ServiceFSM> componentFsms = cluster.getServices();
+    
+    for (ServiceFSM component : componentFsms) {
+      for (String dependent : dependents) {
+        if (component.getServiceName().equals(dependent)) {
+          if (!component.isActive()) {
+            return false;
+          }
+        }
+      }
+    }
+    return true;
+  }
+  
   private ControllerResponse createResponse(short responseId, 
       List<Action> allActions, HeartBeat heartbeat) {
     ControllerResponse r = new ControllerResponse();

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java?rev=1220334&r1=1220333&r2=1220334&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
Sun Dec 18 04:54:32 2011
@@ -215,7 +215,7 @@ public class ClusterImpl implements Clus
     public ClusterStateFSM transition(ClusterImpl operand, ClusterEvent event){
       //check whether all services started, and if not remain in the STARTING
       //state, else move to the ACTIVE state
-      ServiceFSM service = operand.getFirstService();
+      ServiceFSM service = operand.getNextService();
       if (service != null) {
         stateMachineInvoker.getAMBARIEventHandler().handle(new ServiceEvent(
             ServiceEventType.START, service));

Modified: incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java?rev=1220334&r1=1220333&r2=1220334&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
(original)
+++ incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
Sun Dec 18 04:54:32 2011
@@ -104,6 +104,7 @@ public class TestHeartbeat {
     invoker = injector.getInstance(StateMachineInvokerInterface.class);
     plugin = mock(ComponentPlugin.class);
     when(plugin.getActiveRoles()).thenReturn(roles);
+    when(plugin.getRequiredComponents()).thenReturn(null);
     cdef = mock(ClusterDefinition.class);
     when(cdef.getEnabledServices()).thenReturn(Arrays.asList("comp1"));
     cluster = mock(Cluster.class);



Mime
View raw message