incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1179513 - in /incubator/ambari/trunk: ./ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache/ambari/resource/statemachine/
Date Thu, 06 Oct 2011 06:08:19 GMT
Author: ddas
Date: Thu Oct  6 06:08:19 2011
New Revision: 1179513

URL: http://svn.apache.org/viewvc?rev=1179513&view=rev
Log:
AMBARI-45. Rename the Role/Cluster/Service classes in the statemachine package to RoleFSM/ClusterFSM/ServiceFSM.
Contributed by Devaraj Das.

Added:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterFSM.java
      - copied, changed from r1179479, 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/ClusterStateFSM.java
      - copied, changed from r1179479, incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterState.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleFSM.java
      - copied, changed from r1179479, incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Role.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceFSM.java
      - copied, changed from r1179479, incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Service.java
Removed:
    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/ClusterState.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Role.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Service.java
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
    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/ClusterEvent.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/RoleEvent.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/ServiceEvent.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=1179513&r1=1179512&r2=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Oct  6 06:08:19 2011
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-45. Rename the Role/Cluster/Service classes in the statemachine package to 
+  RoleFSM/ClusterFSM/ServiceFSM (ddas)
+
   AMBARI-37. Tidies up a bit the statemachine API and related classes (ddas)
 
   AMBARI-36. Add CLI interface document to Ambari site (vgogate)

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java?rev=1179513&r1=1179512&r2=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
Thu Oct  6 06:08:19 2011
@@ -40,7 +40,7 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.PackageRepository;
 import org.apache.ambari.common.rest.entities.Property;
 import org.apache.ambari.common.rest.entities.Role;
-import org.apache.ambari.resource.statemachine.ClusterState;
+import org.apache.ambari.resource.statemachine.ClusterStateFSM;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
@@ -224,7 +224,7 @@ public class Blueprints {
             String bpRevision = c.getClusterDefinition().getBlueprintRevision();
             
             // TODO: May be don't consider ATTIC clusters
-            if (c.getClusterState().getState().equals(ClusterState.ATTIC)) {
+            if (c.getClusterState().getState().equals(ClusterStateFSM.ATTIC)) {
                 continue;
             }
             Blueprint bpx = Blueprints.getInstance().blueprints.get(bpName).get(new Integer(bpRevision));

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=1179513&r1=1179512&r2=1179513&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
Thu Oct  6 06:08:19 2011
@@ -41,10 +41,11 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.components.ClusterContext;
 import org.apache.ambari.components.impl.ClusterContextImpl;
 import org.apache.ambari.components.impl.HDFSPluginImpl;
-import org.apache.ambari.resource.statemachine.Role;
+import org.apache.ambari.resource.statemachine.ClusterFSM;
+import org.apache.ambari.resource.statemachine.RoleFSM;
 import org.apache.ambari.resource.statemachine.RoleEvent;
 import org.apache.ambari.resource.statemachine.RoleEventType;
-import org.apache.ambari.resource.statemachine.Service;
+import org.apache.ambari.resource.statemachine.ServiceFSM;
 import org.apache.ambari.resource.statemachine.StateMachineInvoker;
 
 public class HeartbeatHandler {
@@ -104,16 +105,15 @@ public class HeartbeatHandler {
       }
 
       //get the state machine reference to the cluster
-      org.apache.ambari.resource.statemachine.Cluster clusterSMobject = 
-          StateMachineInvoker
+      ClusterFSM clusterSMobject = StateMachineInvoker
           .getStateMachineClusterInstance(state.getClusterName());
       //the state machine reference to the services
-      List<Service> clusterServices = clusterSMobject.getServices();
+      List<ServiceFSM> clusterServices = clusterSMobject.getServices();
       //go through all the services, and check which role should be started
-      for (Service service : clusterServices) {
-        List<Role> roles = service.getRoles();
+      for (ServiceFSM service : clusterServices) {
+        List<RoleFSM> roles = service.getRoles();
         
-        for (Role role : roles) {
+        for (RoleFSM role : roles) {
           boolean roleServerRunning = componentServers.isStarted(
               role.getAssociatedService().getServiceName(),
               role.getRoleName());
@@ -175,6 +175,11 @@ public class HeartbeatHandler {
     return r;
   }
   
+  private static class InstalledComponents {
+    private Map<String, Boolean> installedComponentMap =
+        new HashMap<String, Boolean>();
+    
+  }
   private static class StartedComponentServers {
     private Map<String, Map<String, Boolean>> startedComponentServerMap =
         new HashMap<String, Map<String, Boolean>>();

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEvent.java?rev=1179513&r1=1179512&r2=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEvent.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterEvent.java
Thu Oct  6 06:08:19 2011
@@ -20,23 +20,23 @@ package org.apache.ambari.resource.state
 import org.apache.ambari.event.AbstractEvent;
 
 public class ClusterEvent extends AbstractEvent<ClusterEventType> {
-  private Cluster cluster;
-  private Service service;
-  public ClusterEvent(ClusterEventType type, Cluster cluster) {
+  private ClusterFSM cluster;
+  private ServiceFSM service;
+  public ClusterEvent(ClusterEventType type, ClusterFSM cluster) {
     super(type);
     this.cluster = cluster;
   }
   //Need this to create an event that has details about the service
   //that moved into a different state
-  public ClusterEvent(ClusterEventType type, Cluster cluster, Service service) {
+  public ClusterEvent(ClusterEventType type, ClusterFSM cluster, ServiceFSM service) {
     super(type);
     this.cluster = cluster;
     this.service = service;
   }
-  public Cluster getCluster() {
+  public ClusterFSM getCluster() {
     return cluster;
   }
-  public Service getServiceCausingTransition() {
+  public ServiceFSM getServiceCausingTransition() {
     return service;
   }
 }

Copied: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterFSM.java
(from r1179479, 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/ClusterFSM.java?p2=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterFSM.java&p1=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java&r1=1179479&r2=1179513&rev=1179513&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/ClusterFSM.java
Thu Oct  6 06:08:19 2011
@@ -20,10 +20,10 @@ package org.apache.ambari.resource.state
 import java.util.List;
 import java.util.Map;
 
-public interface Cluster extends LifeCycle {
-  public List<Service> getServices();
-  public ClusterState getState();
+public interface ClusterFSM extends LifeCycle {
+  public List<ServiceFSM> getServices();
+  public ClusterStateFSM getState();
   public Map<String, String> getServiceStates();
-  public String getClusterName();
+  public String getClusterID();
   public void terminate();
 }

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=1179513&r1=1179512&r2=1179513&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
Thu Oct  6 06:08:19 2011
@@ -28,13 +28,15 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import org.apache.ambari.common.rest.entities.Cluster;
+import org.apache.ambari.common.rest.entities.ClusterState;
 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;
 import org.apache.ambari.event.EventHandler;
 
-public class ClusterImpl implements Cluster, EventHandler<ClusterEvent> {
+public class ClusterImpl implements ClusterFSM, EventHandler<ClusterEvent> {
 
   /* The state machine for the cluster looks like:
    * INACTIVE --START--> STARTING --START_SUCCESS from all services--> ACTIVE
@@ -48,63 +50,63 @@ public class ClusterImpl implements Clus
    */
 
   private static final StateMachineFactory
-  <ClusterImpl,ClusterState,ClusterEventType,ClusterEvent> stateMachineFactory 
-          = new StateMachineFactory<ClusterImpl,ClusterState,ClusterEventType,
-          ClusterEvent>(ClusterState.INACTIVE)
+  <ClusterImpl,ClusterStateFSM,ClusterEventType,ClusterEvent> stateMachineFactory 
+          = new StateMachineFactory<ClusterImpl,ClusterStateFSM,ClusterEventType,
+          ClusterEvent>(ClusterStateFSM.INACTIVE)
   
-  .addTransition(ClusterState.INACTIVE, ClusterState.STARTING, 
+  .addTransition(ClusterStateFSM.INACTIVE, ClusterStateFSM.STARTING, 
       ClusterEventType.START, new StartClusterTransition())
       
-  .addTransition(ClusterState.STARTING, EnumSet.of(ClusterState.ACTIVE, 
-      ClusterState.STARTING), ClusterEventType.START_SUCCESS, 
+  .addTransition(ClusterStateFSM.STARTING, EnumSet.of(ClusterStateFSM.ACTIVE, 
+      ClusterStateFSM.STARTING), ClusterEventType.START_SUCCESS, 
       new ServiceStartedTransition())
       
-  .addTransition(ClusterState.STARTING, ClusterState.FAIL, 
+  .addTransition(ClusterStateFSM.STARTING, ClusterStateFSM.FAIL, 
       ClusterEventType.START_FAILURE)
       
-  .addTransition(ClusterState.ACTIVE, ClusterState.STOPPING, 
+  .addTransition(ClusterStateFSM.ACTIVE, ClusterStateFSM.STOPPING, 
       ClusterEventType.STOP, new StopClusterTransition())
       
-  .addTransition(ClusterState.STOPPING, EnumSet.of(ClusterState.INACTIVE,
-      ClusterState.STOPPING), ClusterEventType.STOP_SUCCESS,
+  .addTransition(ClusterStateFSM.STOPPING, EnumSet.of(ClusterStateFSM.INACTIVE,
+      ClusterStateFSM.STOPPING), ClusterEventType.STOP_SUCCESS,
       new ServiceStoppedTransition())
       
-  .addTransition(ClusterState.STOPPING, ClusterState.UNCLEAN_STOP, 
+  .addTransition(ClusterStateFSM.STOPPING, ClusterStateFSM.UNCLEAN_STOP, 
       ClusterEventType.STOP_FAILURE)
       
-  .addTransition(ClusterState.FAIL, ClusterState.STOPPING, 
+  .addTransition(ClusterStateFSM.FAIL, ClusterStateFSM.STOPPING, 
       ClusterEventType.STOP)
       
-  .addTransition(ClusterState.STOPPING, ClusterState.INACTIVE, 
+  .addTransition(ClusterStateFSM.STOPPING, ClusterStateFSM.INACTIVE, 
       ClusterEventType.STOP_SUCCESS)
       
-  .addTransition(ClusterState.STOPPING, ClusterState.UNCLEAN_STOP, 
+  .addTransition(ClusterStateFSM.STOPPING, ClusterStateFSM.UNCLEAN_STOP, 
       ClusterEventType.STOP_FAILURE)
       
-  .addTransition(ClusterState.INACTIVE, ClusterState.ATTIC, 
+  .addTransition(ClusterStateFSM.INACTIVE, ClusterStateFSM.ATTIC, 
       ClusterEventType.RELEASE_NODES)
       
-  .addTransition(ClusterState.ATTIC, ClusterState.INACTIVE, 
+  .addTransition(ClusterStateFSM.ATTIC, ClusterStateFSM.INACTIVE, 
       ClusterEventType.ADD_NODES)
       
   .installTopology();
   
-  private List<Service> services;
-  private StateMachine<ClusterState, ClusterEventType, ClusterEvent> 
+  private List<ServiceFSM> services;
+  private StateMachine<ClusterStateFSM, ClusterEventType, ClusterEvent> 
           stateMachine;
   private Lock readLock;
   private Lock writeLock;
-  private String clusterName;
-  private Iterator<Service> iterator;
+  private Cluster cluster;
+  private Iterator<ServiceFSM> iterator;
     
-  public ClusterImpl(String name, List<String> services) throws IOException {
-    this.clusterName = name;
+  public ClusterImpl(Cluster cluster) throws IOException {
+    this.cluster = cluster;
     ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
     this.readLock = readWriteLock.readLock();
     this.writeLock = readWriteLock.writeLock();
     this.stateMachine = stateMachineFactory.make(this);
-    List<Service> serviceImpls = new ArrayList<Service>();
-    for (String service : services) {
+    List<ServiceFSM> serviceImpls = new ArrayList<ServiceFSM>();
+    for (String service : cluster.getClusterDefinition().getActiveServices()) {
       ServiceImpl serviceImpl = new ServiceImpl(this, service);
       serviceImpls.add(serviceImpl);
     }
@@ -112,7 +114,7 @@ public class ClusterImpl implements Clus
   }
   
   @Override
-  public ClusterState getState() {
+  public ClusterStateFSM getState() {
     return stateMachine.getCurrentState();
   }
   
@@ -122,7 +124,7 @@ public class ClusterImpl implements Clus
   }
 
   @Override
-  public List<Service> getServices() {
+  public List<ServiceFSM> getServices() {
     return services;
   }
   
@@ -130,7 +132,7 @@ public class ClusterImpl implements Clus
     return stateMachine;
   }
   
-  private Service getFirstService() {
+  private ServiceFSM getFirstService() {
     //this call should reset the iterator
     iterator = services.iterator();
     if (iterator.hasNext()) {
@@ -139,19 +141,24 @@ public class ClusterImpl implements Clus
     return null;
   }
   
-  private Service getNextService() {
+  private ServiceFSM getNextService() {
     if (iterator.hasNext()) {
       return iterator.next();
     }
     return null;
   }
   
+  private ClusterState getClusterState() {
+    return cluster.getClusterState();
+  }
+  
   static class StartClusterTransition implements 
   SingleArcTransition<ClusterImpl, ClusterEvent>  {
 
     @Override
     public void transition(ClusterImpl operand, ClusterEvent event) {
-      Service service = operand.getFirstService();
+      operand.getClusterState().setState(operand.getState().name());
+      ServiceFSM service = operand.getFirstService();
       if (service != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(
             new ServiceEvent(ServiceEventType.START, service));
@@ -165,7 +172,8 @@ public class ClusterImpl implements Clus
     
     @Override
     public void transition(ClusterImpl operand, ClusterEvent event) {
-      Service service = operand.getFirstService();
+      operand.getClusterState().setState(operand.getState().name());
+      ServiceFSM service = operand.getFirstService();
       if (service != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(
             new ServiceEvent(ServiceEventType.STOP, service));
@@ -174,36 +182,38 @@ public class ClusterImpl implements Clus
   }
   
   static class ServiceStoppedTransition implements
-  MultipleArcTransition<ClusterImpl, ClusterEvent, ClusterState> {
+  MultipleArcTransition<ClusterImpl, ClusterEvent, ClusterStateFSM> {
 
     @Override
-    public ClusterState transition(ClusterImpl operand, ClusterEvent event) {
+    public ClusterStateFSM transition(ClusterImpl operand, ClusterEvent event) {
+      operand.getClusterState().setState(operand.getState().name());
       //check whether all services stopped, and if not remain in the STOPPING
       //state, else move to the INACTIVE state
-      Service service = operand.getNextService();
+      ServiceFSM service = operand.getNextService();
       if (service != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(new ServiceEvent(
             ServiceEventType.STOP, service));
-        return ClusterState.STOPPING;
+        return ClusterStateFSM.STOPPING;
       }
-      return ClusterState.INACTIVE;
+      return ClusterStateFSM.INACTIVE;
     }
     
   }
   
   static class ServiceStartedTransition implements 
-  MultipleArcTransition<ClusterImpl, ClusterEvent, ClusterState>  {
+  MultipleArcTransition<ClusterImpl, ClusterEvent, ClusterStateFSM>  {
     @Override
-    public ClusterState transition(ClusterImpl operand, ClusterEvent event) {
+    public ClusterStateFSM transition(ClusterImpl operand, ClusterEvent event){
+      operand.getClusterState().setState(operand.getState().name());
       //check whether all services started, and if not remain in the STARTING
       //state, else move to the ACTIVE state
-      Service service = operand.getFirstService();
+      ServiceFSM service = operand.getFirstService();
       if (service != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(new ServiceEvent(
             ServiceEventType.START, service));
-        return ClusterState.STARTING;
+        return ClusterStateFSM.STARTING;
       }
-      return ClusterState.ACTIVE;
+      return ClusterStateFSM.ACTIVE;
     }
     
   }
@@ -211,7 +221,7 @@ public class ClusterImpl implements Clus
   @Override
   public Map<String, String> getServiceStates() {
     Map<String, String> serviceStateMap = new HashMap<String,String>();
-    for (Service s : services) {
+    for (ServiceFSM s : services) {
       serviceStateMap.put(s.getServiceName(), s.getServiceState().toString());
     }
     return serviceStateMap;
@@ -236,7 +246,7 @@ public class ClusterImpl implements Clus
   }
 
   @Override
-  public String getClusterName() {
-    return clusterName;
+  public String getClusterID() {
+    return cluster.getID();
   }
 }

Copied: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java
(from r1179479, incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterState.java)
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java?p2=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java&p1=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterState.java&r1=1179479&r2=1179513&rev=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterState.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java
Thu Oct  6 06:08:19 2011
@@ -17,6 +17,6 @@
 */
 package org.apache.ambari.resource.statemachine;
 
-public enum ClusterState {
+public enum ClusterStateFSM {
   INACTIVE, STARTING, ACTIVE, FAIL, ATTIC, STOPPING, UNCLEAN_STOP
 }
\ No newline at end of file

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEvent.java?rev=1179513&r1=1179512&r2=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEvent.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleEvent.java
Thu Oct  6 06:08:19 2011
@@ -21,13 +21,13 @@ import org.apache.ambari.event.AbstractE
 
 
 public class RoleEvent extends AbstractEvent<RoleEventType> {
-  Role role;
-  public RoleEvent(RoleEventType eventType, Role role) {
+  RoleFSM role;
+  public RoleEvent(RoleEventType eventType, RoleFSM role) {
     super (eventType);
     this.role = role;
   }
   
-  public Role getRole() {
+  public RoleFSM getRole() {
     return role;
   }
 

Copied: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleFSM.java
(from r1179479, incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Role.java)
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleFSM.java?p2=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleFSM.java&p1=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Role.java&r1=1179479&r2=1179513&rev=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Role.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/RoleFSM.java
Thu Oct  6 06:08:19 2011
@@ -17,13 +17,13 @@
 */
 package org.apache.ambari.resource.statemachine;
 
-public interface Role extends LifeCycle {
+public interface RoleFSM extends LifeCycle {
   
   public RoleState getRoleState();
   
   public String getRoleName();
   
-  public Service getAssociatedService();
+  public ServiceFSM getAssociatedService();
   
   public boolean shouldStop();
   

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=1179513&r1=1179512&r2=1179513&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
Thu Oct  6 06:08:19 2011
@@ -25,7 +25,7 @@ import org.apache.ambari.common.state.St
 import org.apache.ambari.common.state.StateMachineFactory;
 import org.apache.ambari.event.EventHandler;
 
-public class RoleImpl implements Role, EventHandler<RoleEvent> {
+public class RoleImpl implements RoleFSM, EventHandler<RoleEvent> {
 
   private RoleState myState;
   private String roleName;
@@ -33,7 +33,7 @@ public class RoleImpl implements Role, E
   private int totalRoleInstancesStarted;
   private int totalRolesFailedToStart;
   private int totalInstancesDesired;
-  private Service service;
+  private ServiceFSM service;
   
   /* The state machine for the role looks like:
    * INACTIVE --S_START--> STARTING --S_START_SUCCESS--> ACTIVE
@@ -94,11 +94,11 @@ public class RoleImpl implements Role, E
   private final StateMachine<RoleState, RoleEventType, RoleEvent>
       stateMachine;
   
-  public RoleImpl(Service service, String roleName) {
+  public RoleImpl(ServiceFSM service, String roleName) {
     this(service, roleName, 1, 1);
   }
   
-  public RoleImpl(Service service, String roleName, int totalInstancesDesired, int totalInstancesRequired)
{
+  public RoleImpl(ServiceFSM service, String roleName, int totalInstancesDesired, int totalInstancesRequired)
{
     this.roleName = roleName;
     this.service = service;
     this.myState = RoleState.INACTIVE;
@@ -127,7 +127,7 @@ public class RoleImpl implements Role, E
   }
 
   @Override
-  public Service getAssociatedService() {
+  public ServiceFSM getAssociatedService() {
     return service;
   }
   
@@ -136,7 +136,7 @@ public class RoleImpl implements Role, E
 
     @Override
     public RoleState transition(RoleImpl operand, RoleEvent event) {
-      Service service = operand.getAssociatedService();
+      ServiceFSM service = operand.getAssociatedService();
       ++operand.totalRoleInstancesStarted;
       if (operand.totalInstancesRequired <= operand.totalRoleInstancesStarted){
         StateMachineInvoker.getAMBARIEventHandler().handle(
@@ -155,7 +155,7 @@ public class RoleImpl implements Role, E
 
     @Override
     public RoleState transition(RoleImpl operand, RoleEvent event) {
-      Service service = operand.getAssociatedService();
+      ServiceFSM service = operand.getAssociatedService();
       ++operand.totalRolesFailedToStart;
       //if number of remaining instances required to declare a role as 'started'
       //is more than the total number of available nodes that haven't reported
@@ -179,7 +179,7 @@ public class RoleImpl implements Role, E
     
     @Override
     public void transition(RoleImpl operand, RoleEvent event) {
-      Service service = operand.getAssociatedService();
+      ServiceFSM service = operand.getAssociatedService();
       StateMachineInvoker.getAMBARIEventHandler().handle(
           new ServiceEvent(ServiceEventType.ROLE_STOPPED, service,
               operand));

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEvent.java?rev=1179513&r1=1179512&r2=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEvent.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceEvent.java
Thu Oct  6 06:08:19 2011
@@ -21,25 +21,25 @@ import org.apache.ambari.event.AbstractE
 
 
 public class ServiceEvent extends AbstractEvent<ServiceEventType> {
-  private Service service;
-  private Role role;
+  private ServiceFSM service;
+  private RoleFSM role;
   
-  public ServiceEvent(ServiceEventType eventType, Service service) {
+  public ServiceEvent(ServiceEventType eventType, ServiceFSM service) {
     super (eventType);
     this.service = service;
   }
   
-  public ServiceEvent(ServiceEventType eventType, Service service, Role role) {
+  public ServiceEvent(ServiceEventType eventType, ServiceFSM service, RoleFSM role) {
     super (eventType);
     this.service = service;
     this.role = role;
   }
   
-  public Service getService() {
+  public ServiceFSM getService() {
     return service;
   }
   
-  public Role getRole() {
+  public RoleFSM getRole() {
     return role;
   }
 

Copied: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceFSM.java
(from r1179479, incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Service.java)
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceFSM.java?p2=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceFSM.java&p1=incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Service.java&r1=1179479&r2=1179513&rev=1179513&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Service.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceFSM.java
Thu Oct  6 06:08:19 2011
@@ -19,16 +19,16 @@ package org.apache.ambari.resource.state
 
 import java.util.List;
 
-public interface Service extends LifeCycle {
+public interface ServiceFSM extends LifeCycle {
   
   public ServiceState getServiceState();
   
   public String getServiceName();
   
-  public Cluster getAssociatedCluster();
+  public ClusterFSM getAssociatedCluster();
   
   public boolean isActive();
   
-  public List<Role> getRoles();
+  public List<RoleFSM> getRoles();
 
 }

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=1179513&r1=1179512&r2=1179513&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
Thu Oct  6 06:08:19 2011
@@ -22,8 +22,6 @@ import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 import org.apache.ambari.common.state.MultipleArcTransition;
 import org.apache.ambari.common.state.SingleArcTransition;
@@ -33,10 +31,10 @@ import org.apache.ambari.components.Comp
 import org.apache.ambari.components.impl.HDFSPluginImpl;
 import org.apache.ambari.event.EventHandler;
 
-public class ServiceImpl implements Service, EventHandler<ServiceEvent> {
+public class ServiceImpl implements ServiceFSM, EventHandler<ServiceEvent> {
 
   private ServiceState myState;
-  private Cluster cluster;
+  private ClusterFSM cluster;
   private ComponentPlugin plugin;
   
   /* The state machine for the service looks like:
@@ -91,11 +89,11 @@ public class ServiceImpl implements Serv
   
   private final StateMachine<ServiceState, ServiceEventType, ServiceEvent>
       stateMachine;
-  private final List<Role> serviceRoles = new ArrayList<Role>();
-  private Iterator<Role> iterator;
+  private final List<RoleFSM> serviceRoles = new ArrayList<RoleFSM>();
+  private Iterator<RoleFSM> iterator;
   private final String serviceName;
   
-  public ServiceImpl(Cluster cluster, String serviceName) throws IOException {
+  public ServiceImpl(ClusterFSM cluster, String serviceName) throws IOException {
     this.cluster = cluster;
     this.serviceName = serviceName;
     this.myState = ServiceState.INACTIVE;
@@ -125,7 +123,7 @@ public class ServiceImpl implements Serv
   }
 
   @Override
-  public Cluster getAssociatedCluster() {
+  public ClusterFSM getAssociatedCluster() {
     return cluster;
   }
   
@@ -134,11 +132,11 @@ public class ServiceImpl implements Serv
     return serviceName;
   }
   
-  public void addRoles(List<Role> roles) {
+  public void addRoles(List<RoleFSM> roles) {
     this.serviceRoles.addAll(roles);
   }
   
-  private Role getFirstRole() {
+  private RoleFSM getFirstRole() {
     //this call should reset the iterator
     iterator = serviceRoles.iterator();
     if (iterator.hasNext()) {
@@ -147,7 +145,7 @@ public class ServiceImpl implements Serv
     return null;
   }
   
-  private Role getNextRole() {
+  private RoleFSM getNextRole() {
     if (iterator.hasNext()) {
       return iterator.next();
     }
@@ -159,7 +157,7 @@ public class ServiceImpl implements Serv
 
     @Override
     public void transition(ServiceImpl operand, ServiceEvent event) {
-      Role firstRole = operand.getFirstRole();
+      RoleFSM firstRole = operand.getFirstRole();
       if (firstRole != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(
                             new RoleEvent(RoleEventType.START, firstRole));
@@ -172,7 +170,7 @@ public class ServiceImpl implements Serv
     
     @Override
     public void transition(ServiceImpl operand, ServiceEvent event) {
-      Role firstRole = operand.getFirstRole();
+      RoleFSM firstRole = operand.getFirstRole();
       if (firstRole != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(
                             new RoleEvent(RoleEventType.STOP, firstRole));
@@ -187,7 +185,7 @@ public class ServiceImpl implements Serv
     public ServiceState transition(ServiceImpl operand, ServiceEvent event) {
       //check whether all roles started, and if not remain in the STARTING
       //state, else move to the ACTIVE state
-      Role role = operand.getNextRole();
+      RoleFSM role = operand.getNextRole();
       if (role != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(new RoleEvent(
             RoleEventType.START, role));
@@ -205,13 +203,14 @@ public class ServiceImpl implements Serv
     public ServiceState transition(ServiceImpl operand, ServiceEvent event) {
       //check whether all roles stopped, and if not, remain in the STOPPING
       //state, else move to the INACTIVE state
-      Role role = operand.getNextRole();
+      RoleFSM role = operand.getNextRole();
       if (role != null) {
         StateMachineInvoker.getAMBARIEventHandler().handle(new RoleEvent(
             RoleEventType.STOP, role));
         return ServiceState.STOPPING;
       } else {
-        if (operand.getAssociatedCluster().getState() == ClusterState.STOPPING) {
+        if (operand.getAssociatedCluster().getState() 
+            == ClusterStateFSM.STOPPING) {
           //since we support stopping services explicitly (without stopping the 
           //associated cluster), we need to check what the cluster state is
           //before sending it any event
@@ -242,7 +241,7 @@ public class ServiceImpl implements Serv
   }
 
   @Override
-  public List<Role> getRoles() {
+  public List<RoleFSM> getRoles() {
     return serviceRoles;
   }
 }

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=1179513&r1=1179512&r2=1179513&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
Thu Oct  6 06:08:19 2011
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import org.apache.ambari.common.rest.entities.Cluster;
 import org.apache.ambari.event.AsyncDispatcher;
 import org.apache.ambari.event.Dispatcher;
 import org.apache.ambari.event.EventHandler;
@@ -69,17 +70,16 @@ public class StateMachineInvoker {
     }
   }
   
-  private static ConcurrentMap<String, Cluster> clusters = 
-      new ConcurrentHashMap<String, Cluster>();
+  private static ConcurrentMap<String, ClusterFSM> clusters = 
+      new ConcurrentHashMap<String, ClusterFSM>();
   
-  public static Cluster createCluster(String clusterId, 
-      List<String> services) throws IOException {
-    ClusterImpl cluster = new ClusterImpl(clusterId, services);
-    clusters.put(clusterId, cluster);
-    return cluster;
+  public static ClusterFSM createCluster(Cluster cluster) throws IOException {
+    ClusterImpl clusterFSM = new ClusterImpl(cluster);
+    clusters.put(cluster.getID(), clusterFSM);
+    return clusterFSM;
   }
   
-  public static Cluster getStateMachineClusterInstance(String clusterId) {
+  public static ClusterFSM getStateMachineClusterInstance(String clusterId) {
     return clusters.get(clusterId);
   }    
 }



Mime
View raw message