incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1178872 - in /incubator/ambari/trunk: ./ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache/ambari/resource/statemachine/
Date Tue, 04 Oct 2011 17:40:20 GMT
Author: ddas
Date: Tue Oct  4 17:40:19 2011
New Revision: 1178872

URL: http://svn.apache.org/viewvc?rev=1178872&view=rev
Log:
AMBARI-34. Address the start cluster part of the statemachine implementation, and handle the
heartbeat. Contributed by Devaraj Das.

Modified:
    incubator/ambari/trunk/CHANGES.txt
    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/Cluster.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEventType.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEventType.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleImpl.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEventType.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue Oct  4 17:40:19 2011
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-34. Address the start cluster part of the statemachine implementation,
+  and handle the heartbeat. (ddas)
+
   AMBARI-32. Remove stack resource Remove the Stack resource from Ambari (vgogate)
 
   AMBARI-25. Clean up the configuration entity to collapse some levels. 

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=1178872&r1=1178871&r2=1178872&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
Tue Oct  4 17:40:19 2011
@@ -92,6 +92,9 @@ public class HeartbeatHandler {
       List<ServerStatus> roleStatuses = heartbeat.getServersStatus();
       
       //what servers are running currently
+      //ADD LOGIC FOR CAPTURING THE CLUSTER-ID THE SERVERS BELONG TO
+      //IF THEY BELONG TO THE CLUSTER-ID THIS AGENT IS PART OF, WELL AND GOOD
+      //IF NOT, THEN SEND COMMANDS TO STOP THE SERVERS
       StartedComponentServers componentServers = new StartedComponentServers();
       for (ServerStatus status : roleStatuses) {
         componentServers.roleServerStarted(status.getComponent(), 
@@ -121,7 +124,7 @@ public class HeartbeatHandler {
               if (retryCount > MAX_RETRY_COUNT) {
                 //LOG the failure to start the role server
                 StateMachineInvoker.getAMBARIEventHandler()
-                .handle(new RoleEvent(RoleEventType.S_START_FAILURE, role));
+                .handle(new RoleEvent(RoleEventType.START_FAILURE, role));
                 retryCountForRole.reset(role);
                 continue;
               }
@@ -134,7 +137,7 @@ public class HeartbeatHandler {
             if (roleServerRunning) {
               retryCountForRole.reset(role);
               StateMachineInvoker.getAMBARIEventHandler()
-              .handle(new RoleEvent(RoleEventType.S_START_SUCCESS, role));
+              .handle(new RoleEvent(RoleEventType.START_SUCCESS, role));
             }
           }
           //check whether the agent should stop any server
@@ -142,9 +145,9 @@ public class HeartbeatHandler {
             if (roleServerRunning) {
               short retryCount = retryCountForRole.get(role);
               if (retryCount > MAX_RETRY_COUNT) {
-                //LOG the failure to start the role server
+                //LOG the failure to stop the role server
                 StateMachineInvoker.getAMBARIEventHandler()
-                .handle(new RoleEvent(RoleEventType.S_STOP_FAILURE, role));
+                .handle(new RoleEvent(RoleEventType.STOP_FAILURE, role));
                 retryCountForRole.reset(role);
                 continue;
               }
@@ -157,7 +160,7 @@ public class HeartbeatHandler {
             if (!roleServerRunning) {
               retryCountForRole.reset(role);
               StateMachineInvoker.getAMBARIEventHandler()
-              .handle(new RoleEvent(RoleEventType.S_STOP_SUCCESS, role));
+              .handle(new RoleEvent(RoleEventType.STOP_SUCCESS, role));
             }
           }
         }
@@ -173,15 +176,15 @@ public class HeartbeatHandler {
   private static class StartedComponentServers {
     private Map<String, Map<String, Boolean>> startedComponentServerMap =
         new HashMap<String, Map<String, Boolean>>();
-    void roleServerStarted(String component, String server) {
+    void roleServerStarted(String component, String roleServer) {
       Map<String, Boolean> serverStartedMap = null;
       if ((serverStartedMap = startedComponentServerMap.get(component))
           != null) {
-        serverStartedMap.put(server, true);
+        serverStartedMap.put(roleServer, true);
         return;
       }
       serverStartedMap = new HashMap<String, Boolean>();
-      serverStartedMap.put(server, true);
+      serverStartedMap.put(roleServer, true);
       startedComponentServerMap.put(component, serverStartedMap);
     }
     boolean isStarted(String component, String server) {

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java
Tue Oct  4 17:40:19 2011
@@ -22,7 +22,7 @@ import java.util.Map;
 
 public interface Cluster extends LifeCycle {
   public List<Service> getServices();
-  public ClusterState getClusterState();
+  public ClusterState getState();
   public Map<String, String> getServiceStates();
   public String getClusterName();
   public void addServices(List<Service> services);

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEventType.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEventType.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEventType.java
Tue Oct  4 17:40:19 2011
@@ -20,27 +20,27 @@ package org.apache.ambari.resource.state
 public enum ClusterEventType {
   
   //Producer:Client, Cluster
-  S_START,
+  START,
 
   //Producer:Client, Cluster
-  S_STOP,
+  STOP,
 
   //Producer: Service
-  S_START_SUCCESS,
+  START_SUCCESS,
   
   //Producer: Service
-  S_START_FAILURE,
+  START_FAILURE,
   
   //Producer: Service
-  S_STOP_SUCCESS,
+  STOP_SUCCESS,
   
   //Producer: Service
-  S_STOP_FAILURE,
+  STOP_FAILURE,
   
   //Producer: Client
-  S_RELEASE_NODES,
+  RELEASE_NODES,
   
   //Producer: Client
-  S_ADD_NODES
+  ADD_NODES
   
 }
\ No newline at end of file

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=1178872&r1=1178871&r2=1178872&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
Tue Oct  4 17:40:19 2011
@@ -38,14 +38,14 @@ import org.apache.ambari.event.EventHand
 public class ClusterImpl implements Cluster, EventHandler<ClusterEvent> {
 
   /* The state machine for the cluster looks like:
-   * INACTIVE --S_START--> STARTING --S_START_SUCCESS from all services--> ACTIVE
-   *                                --S_START_FAILURE from any service--> FAIL
-   * ACTIVE --S_STOP--> STOPPING --S_STOP_SUCCESS from all services--> INACTIVE
-   *                             --S_STOP_FAILURE from any service--> UNCLEAN_STOP
-   * FAIL --S_STOP--> STOPPING --S_STOP_SUCCESS--> INACTIVE
-   *                           --S_STOP_FAILURE--> UNCLEAN_STOP
-   * INACTIVE --S_RELEASE_NODES--> ATTIC
-   * ATTIC --S_ADD_NODES--> INACTIVE
+   * INACTIVE --START--> STARTING --START_SUCCESS from all services--> ACTIVE
+   *                                --START_FAILURE from any service--> FAIL
+   * ACTIVE --STOP--> STOPPING --STOP_SUCCESS from all services--> INACTIVE
+   *                             --STOP_FAILURE from any service--> UNCLEAN_STOP
+   * FAIL --STOP--> STOPPING --STOP_SUCCESS--> INACTIVE
+   *                           --STOP_FAILURE--> UNCLEAN_STOP
+   * INACTIVE --RELEASE_NODES--> ATTIC
+   * ATTIC --ADD_NODES--> INACTIVE
    */
 
   private static final StateMachineFactory
@@ -54,32 +54,31 @@ public class ClusterImpl implements Clus
   new StateMachineFactory
   <ClusterImpl,ClusterState,ClusterEventType,ClusterEvent>(ClusterState.INACTIVE)
   .addTransition(ClusterState.INACTIVE, ClusterState.STARTING, 
-      ClusterEventType.S_START, new StartClusterTransition())
+      ClusterEventType.START, new StartClusterTransition())
   .addTransition(ClusterState.STARTING, EnumSet.of(ClusterState.ACTIVE, 
-      ClusterState.STARTING), ClusterEventType.S_START_SUCCESS, 
+      ClusterState.STARTING), ClusterEventType.START_SUCCESS, 
       new ServiceStartedTransition())
   .addTransition(ClusterState.STARTING, ClusterState.FAIL, 
-      ClusterEventType.S_START_FAILURE)
+      ClusterEventType.START_FAILURE)
   .addTransition(ClusterState.ACTIVE, ClusterState.STOPPING, 
-      ClusterEventType.S_STOP)
+      ClusterEventType.STOP)
   .addTransition(ClusterState.STOPPING, ClusterState.INACTIVE, 
-      ClusterEventType.S_STOP_SUCCESS)
+      ClusterEventType.STOP_SUCCESS)
   .addTransition(ClusterState.STOPPING, ClusterState.UNCLEAN_STOP, 
-      ClusterEventType.S_STOP_FAILURE)
+      ClusterEventType.STOP_FAILURE)
   .addTransition(ClusterState.FAIL, ClusterState.STOPPING, 
-      ClusterEventType.S_STOP)
+      ClusterEventType.STOP)
   .addTransition(ClusterState.STOPPING, ClusterState.INACTIVE, 
-      ClusterEventType.S_STOP_SUCCESS)
+      ClusterEventType.STOP_SUCCESS)
   .addTransition(ClusterState.STOPPING, ClusterState.UNCLEAN_STOP, 
-      ClusterEventType.S_STOP_FAILURE)
+      ClusterEventType.STOP_FAILURE)
   .addTransition(ClusterState.INACTIVE, ClusterState.ATTIC, 
-      ClusterEventType.S_RELEASE_NODES)
+      ClusterEventType.RELEASE_NODES)
   .addTransition(ClusterState.ATTIC, ClusterState.INACTIVE, 
-      ClusterEventType.S_ADD_NODES)
+      ClusterEventType.ADD_NODES)
   .installTopology();
   
   private List<Service> services;
-  private Map<String, Set<String>> roleToNodes;
   private StateMachine<ClusterState, ClusterEventType, ClusterEvent> 
           stateMachine;
   private int numServicesStarted;
@@ -98,7 +97,7 @@ public class ClusterImpl implements Clus
   }
 
   @Override
-  public ClusterState getClusterState() {
+  public ClusterState getState() {
     return stateMachine.getCurrentState();
   }
   
@@ -160,7 +159,7 @@ public class ClusterImpl implements Clus
       if (service != null) {
               //start the first service (plugin)
         StateMachineInvoker.getAMBARIEventHandler().handle(
-            new ServiceEvent(ServiceEventType.S_START, service));
+            new ServiceEvent(ServiceEventType.START, service));
       }
     }
     
@@ -194,19 +193,19 @@ public class ClusterImpl implements Clus
   @Override
   public void activate() {
     StateMachineInvoker.getAMBARIEventHandler().handle(
-        new ClusterEvent(ClusterEventType.S_START, this));
+        new ClusterEvent(ClusterEventType.START, this));
   }
 
   @Override
   public void deactivate() {
     StateMachineInvoker.getAMBARIEventHandler().handle(
-        new ClusterEvent(ClusterEventType.S_STOP, this));
+        new ClusterEvent(ClusterEventType.STOP, this));
   }
 
   @Override
   public void terminate() {
     StateMachineInvoker.getAMBARIEventHandler().handle(
-        new ClusterEvent(ClusterEventType.S_RELEASE_NODES, this));    
+        new ClusterEvent(ClusterEventType.RELEASE_NODES, this));    
   }
 
   @Override

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEventType.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEventType.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEventType.java
Tue Oct  4 17:40:19 2011
@@ -20,21 +20,21 @@ package org.apache.ambari.resource.state
 public enum RoleEventType {
   
   //Producer:Client, Cluster
-  S_START,
+  START,
 
   //Producer:Client, Cluster
-  S_STOP,
+  STOP,
 
   //Producer: Service
-  S_START_SUCCESS,
+  START_SUCCESS,
   
   //Producer: Service
-  S_START_FAILURE,
+  START_FAILURE,
   
   //Producer: Service
-  S_STOP_SUCCESS,
+  STOP_SUCCESS,
   
   //Producer: Service
-  S_STOP_FAILURE,
+  STOP_FAILURE,
   
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleImpl.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleImpl.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleImpl.java
Tue Oct  4 17:40:19 2011
@@ -17,9 +17,11 @@
 */
 package org.apache.ambari.resource.statemachine;
 
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.ambari.common.state.MultipleArcTransition;
 import org.apache.ambari.common.state.SingleArcTransition;
 import org.apache.ambari.common.state.StateMachine;
 import org.apache.ambari.common.state.StateMachineFactory;
@@ -29,10 +31,13 @@ public class RoleImpl implements Role, E
 
   private RoleState myState;
   private String roleName;
-  private List<String> hosts;
+  private int totalRolesRequired;
+  private int totalRolesStarted;
+  private int totalRolesFailedToStart;
+  private int totalRoles;
   private Service service;
   
-  /* The state machine for the service looks like:
+  /* The state machine for the role looks like:
    * INACTIVE --S_START--> STARTING --S_START_SUCCESS--> ACTIVE
    *                                --S_START_FAILURE--> FAIL
    * ACTIVE --S_STOP--> STOPPING --S_STOP_SUCCESS--> INACTIVE
@@ -45,28 +50,62 @@ public class RoleImpl implements Role, E
   <RoleImpl, RoleState, RoleEventType, RoleEvent> stateMachineFactory 
          = new StateMachineFactory<RoleImpl, RoleState, RoleEventType, 
          RoleEvent>(RoleState.INACTIVE)
-         .addTransition(RoleState.INACTIVE, RoleState.STARTING, RoleEventType.S_START, new
RoleStartTransition())
-         .addTransition(RoleState.STARTING, RoleState.ACTIVE, RoleEventType.S_START_SUCCESS,
new SuccessStartTransition())
-         .addTransition(RoleState.ACTIVE, RoleState.ACTIVE, RoleEventType.S_START_SUCCESS)
-         .addTransition(RoleState.STARTING, RoleState.FAIL, RoleEventType.S_START_FAILURE)
-         .addTransition(RoleState.FAIL, RoleState.FAIL, RoleEventType.S_START_FAILURE)
-         .addTransition(RoleState.ACTIVE, RoleState.STOPPING, RoleEventType.S_STOP)
-         .addTransition(RoleState.STOPPING, RoleState.INACTIVE, RoleEventType.S_STOP_SUCCESS)
-         .addTransition(RoleState.STOPPING, RoleState.UNCLEAN_STOP, RoleEventType.S_STOP_FAILURE)
-         .addTransition(RoleState.FAIL, RoleState.STOPPING, RoleEventType.S_STOP)
-         .addTransition(RoleState.STOPPING, RoleState.INACTIVE, RoleEventType.S_STOP_SUCCESS)
-         .addTransition(RoleState.INACTIVE, RoleState.INACTIVE, RoleEventType.S_STOP_SUCCESS)
-         .addTransition(RoleState.STOPPING, RoleState.UNCLEAN_STOP, RoleEventType.S_STOP_FAILURE)
-         .addTransition(RoleState.UNCLEAN_STOP, RoleState.UNCLEAN_STOP, RoleEventType.S_STOP_FAILURE)
+         
+         .addTransition(RoleState.INACTIVE, RoleState.STARTING, 
+             RoleEventType.START)
+             
+         .addTransition(RoleState.STARTING, 
+             EnumSet.of(RoleState.ACTIVE, RoleState.STARTING),
+             RoleEventType.START_SUCCESS, new SuccessfulStartTransition())
+         
+         .addTransition(RoleState.ACTIVE, RoleState.ACTIVE,
+             RoleEventType.START_SUCCESS)
+             
+         .addTransition(RoleState.STARTING, 
+             EnumSet.of(RoleState.FAIL, RoleState.STARTING),
+             RoleEventType.START_FAILURE, new FailedStartTransition())
+             
+         .addTransition(RoleState.FAIL, RoleState.FAIL, 
+             RoleEventType.START_FAILURE)
+             
+         .addTransition(RoleState.ACTIVE, RoleState.STOPPING, 
+             RoleEventType.STOP)
+             
+         .addTransition(RoleState.STOPPING, RoleState.INACTIVE,
+             RoleEventType.STOP_SUCCESS)
+             
+         .addTransition(RoleState.STOPPING, RoleState.UNCLEAN_STOP,
+             RoleEventType.STOP_FAILURE)
+             
+         .addTransition(RoleState.FAIL, RoleState.STOPPING, RoleEventType.STOP)
+         
+         .addTransition(RoleState.STOPPING, RoleState.INACTIVE, 
+             RoleEventType.STOP_SUCCESS)
+             
+         .addTransition(RoleState.INACTIVE, RoleState.INACTIVE,
+             RoleEventType.STOP_SUCCESS)
+             
+         .addTransition(RoleState.STOPPING, RoleState.UNCLEAN_STOP, 
+             RoleEventType.STOP_FAILURE)
+             
+         .addTransition(RoleState.UNCLEAN_STOP, RoleState.UNCLEAN_STOP,
+             RoleEventType.STOP_FAILURE)
+             
          .installTopology();
   
   private final StateMachine<RoleState, RoleEventType, RoleEvent>
       stateMachine;
   
   public RoleImpl(Service service, String roleName) {
+    this(service, roleName, 1, 1);
+  }
+  
+  public RoleImpl(Service service, String roleName, int totalRoles, int totalRolesRequired)
{
     this.roleName = roleName;
     this.service = service;
     this.myState = RoleState.INACTIVE;
+    this.totalRolesRequired = totalRolesRequired;
+    this.totalRoles = totalRoles;
     stateMachine = stateMachineFactory.make(this);
   }
   
@@ -94,27 +133,45 @@ public class RoleImpl implements Role, E
     return service;
   }
   
-  public void addHosts(List<String> hosts) {
-    this.hosts.addAll(hosts);
-  }
-  
-  static class RoleStartTransition implements 
-  SingleArcTransition<RoleImpl, RoleEvent>  {
+  static class SuccessfulStartTransition implements 
+  MultipleArcTransition<RoleImpl, RoleEvent, RoleState>  {
 
     @Override
-    public void transition(RoleImpl operand, RoleEvent event) {
-      //load the plugin and get the command for starting the role 
+    public RoleState transition(RoleImpl operand, RoleEvent event) {
+      ServiceImpl service = (ServiceImpl)operand.getAssociatedService();
+      ++operand.totalRolesStarted;
+      if (operand.totalRolesRequired <= operand.totalRolesStarted) {
+        StateMachineInvoker.getAMBARIEventHandler().handle(
+            new ServiceEvent(ServiceEventType.ROLE_STARTED, service, 
+                operand));
+
+        return RoleState.ACTIVE;
+      } else {
+        return RoleState.STARTING;   
+      }
     }
   }
   
-  static class SuccessStartTransition implements 
-  SingleArcTransition<RoleImpl, RoleEvent>  {
+  static class FailedStartTransition implements 
+  MultipleArcTransition<RoleImpl, RoleEvent, RoleState>  {
 
     @Override
-    public void transition(RoleImpl operand, RoleEvent event) {
+    public RoleState transition(RoleImpl operand, RoleEvent event) {
       ServiceImpl service = (ServiceImpl)operand.getAssociatedService();
-      StateMachineInvoker.getAMBARIEventHandler().handle(
-       new ServiceEvent(ServiceEventType.S_ROLE_STARTED, service, operand));
+      ++operand.totalRolesFailedToStart;
+      //if number of remaining roles required to declare a role as 'started'
+      //is more than the total number of roles that haven't reported back
+      //declare the role failed to start
+      if ((operand.totalRolesRequired - operand.totalRolesStarted) 
+          >= (operand.totalRoles - 
+              (operand.totalRolesStarted + operand.totalRolesFailedToStart))) {
+        StateMachineInvoker.getAMBARIEventHandler().handle(
+            new ServiceEvent(ServiceEventType.START_FAILURE, service, 
+                operand));
+        return RoleState.FAIL;
+      } else {
+        return RoleState.STARTING;   
+      }
     }
   }
 

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEventType.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEventType.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEventType.java
Tue Oct  4 17:40:19 2011
@@ -20,23 +20,23 @@ package org.apache.ambari.resource.state
 public enum ServiceEventType {
   
   //Producer:Client, Cluster
-  S_START,
+  START,
 
   //Producer:Client, Cluster
-  S_STOP,
+  STOP,
 
   //Producer: Service
-  S_START_SUCCESS,
+  START_SUCCESS,
   
   //Producer: Service
-  S_START_FAILURE,
+  START_FAILURE,
   
   //Producer: Service
-  S_STOP_SUCCESS,
+  STOP_SUCCESS,
   
   //Producer: Service
-  S_STOP_FAILURE,
+  STOP_FAILURE,
   
   //Producer: Role
-  S_ROLE_STARTED
+  ROLE_STARTED
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
Tue Oct  4 17:40:19 2011
@@ -51,16 +51,41 @@ public class ServiceImpl implements Serv
   <ServiceImpl, ServiceState, ServiceEventType, ServiceEvent> stateMachineFactory 
          = new StateMachineFactory<ServiceImpl, ServiceState, ServiceEventType, 
          ServiceEvent>(ServiceState.INACTIVE)
-         .addTransition(ServiceState.INACTIVE, ServiceState.STARTING, ServiceEventType.S_START,
new StartServiceTransition())
-         .addTransition(ServiceState.STARTING, EnumSet.of(ServiceState.ACTIVE, ServiceState.STARTING),
ServiceEventType.S_ROLE_STARTED,
+         
+         .addTransition(ServiceState.INACTIVE, ServiceState.STARTING, 
+             ServiceEventType.START, new StartServiceTransition())
+             
+         .addTransition(ServiceState.STARTING, 
+             EnumSet.of(ServiceState.ACTIVE, ServiceState.STARTING), 
+             ServiceEventType.ROLE_STARTED,
              new RoleStartedTransition())
-         .addTransition(ServiceState.STARTING, ServiceState.FAIL, ServiceEventType.S_START_FAILURE)
-         .addTransition(ServiceState.ACTIVE, ServiceState.STOPPING, ServiceEventType.S_STOP)
-         .addTransition(ServiceState.STOPPING, ServiceState.INACTIVE, ServiceEventType.S_STOP_SUCCESS)
-         .addTransition(ServiceState.STOPPING, ServiceState.UNCLEAN_STOP, ServiceEventType.S_STOP_FAILURE)
-         .addTransition(ServiceState.FAIL, ServiceState.STOPPING, ServiceEventType.S_STOP)
-         .addTransition(ServiceState.STOPPING, ServiceState.INACTIVE, ServiceEventType.S_STOP_SUCCESS)
-         .addTransition(ServiceState.STOPPING, ServiceState.UNCLEAN_STOP, ServiceEventType.S_STOP_FAILURE)
+             
+         .addTransition(ServiceState.STARTING, ServiceState.FAIL, 
+             ServiceEventType.START_FAILURE)
+             
+         .addTransition(ServiceState.ACTIVE, ServiceState.ACTIVE, 
+             ServiceEventType.ROLE_STARTED)
+             
+         .addTransition(ServiceState.ACTIVE, ServiceState.STOPPING, 
+             ServiceEventType.STOP)
+             
+         .addTransition(ServiceState.STOPPING, 
+             EnumSet.of(ServiceState.INACTIVE, ServiceState.STOPPING),
+             ServiceEventType.STOP_SUCCESS, 
+             new RoleStoppedTransition())
+             
+         .addTransition(ServiceState.STOPPING, ServiceState.UNCLEAN_STOP, 
+             ServiceEventType.STOP_FAILURE)
+             
+         .addTransition(ServiceState.FAIL, ServiceState.STOPPING, 
+             ServiceEventType.STOP)
+             
+         .addTransition(ServiceState.STOPPING, ServiceState.INACTIVE, 
+             ServiceEventType.STOP_SUCCESS)
+             
+         .addTransition(ServiceState.STOPPING, ServiceState.UNCLEAN_STOP,
+             ServiceEventType.STOP_FAILURE)
+             
          .installTopology();
   
   private final StateMachine<ServiceState, ServiceEventType, ServiceEvent>
@@ -126,7 +151,7 @@ public class ServiceImpl implements Serv
       Role firstRole = operand.getNextRole();
       if (firstRole != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(
-                            new RoleEvent(RoleEventType.S_START, firstRole));
+                            new RoleEvent(RoleEventType.START, firstRole));
       }
     }
     
@@ -142,24 +167,43 @@ public class ServiceImpl implements Serv
       Role role = operand.getNextRole();
       if (role != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(new RoleEvent(
-            RoleEventType.S_START, role));
+            RoleEventType.START, role));
         return ServiceState.STARTING;
       } else {
         return ServiceState.ACTIVE;
       }
     }
   }
+  
+  static class RoleStoppedTransition 
+  implements MultipleArcTransition<ServiceImpl, ServiceEvent, ServiceState>  {
+
+    @Override
+    public ServiceState transition(ServiceImpl operand, ServiceEvent event) {
+      //check whether all roles stopped, and if not remain in the STOPPING
+      //state, else move to the ACTIVE state
+      Role role = operand.getNextRole();
+      if (role != null) {
+        StateMachineInvoker.getAMBARIEventHandler().handle(new RoleEvent(
+            RoleEventType.STOP, role));
+        return ServiceState.STOPPING;
+      } else {
+        return ServiceState.INACTIVE;
+      }
+    }
+    
+  }
 
   @Override
   public void activate() {
     StateMachineInvoker.getAMBARIEventHandler().handle(
-              new ServiceEvent(ServiceEventType.S_START, this));
+              new ServiceEvent(ServiceEventType.START, this));
   }
 
   @Override
   public void deactivate() {
     StateMachineInvoker.getAMBARIEventHandler().handle(
-              new ServiceEvent(ServiceEventType.S_STOP, this));
+              new ServiceEvent(ServiceEventType.STOP, this));
   }
 
   @Override

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java?rev=1178872&r1=1178871&r2=1178872&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java
Tue Oct  4 17:40:19 2011
@@ -72,6 +72,7 @@ public class StateMachineInvoker {
   
   private static ConcurrentMap<String, Cluster> clusters = 
       new ConcurrentHashMap<String, Cluster>();
+  
   public static Cluster createCluster(String clusterId) {
     ClusterImpl cluster = new ClusterImpl(clusterId);
     clusters.put(clusterId, cluster);



Mime
View raw message