Browse Source

AMBARI-728. Initial work on ServiceComponentNode FSM. (Contributed by hitesh)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1384147 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 12 years ago
parent
commit
5195019cd3
24 changed files with 480 additions and 183 deletions
  1. 2 0
      AMBARI-666-CHANGES.txt
  2. 3 3
      ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
  3. 3 3
      ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
  4. 4 4
      ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
  5. 11 11
      ambari-server/src/main/java/org/apache/ambari/server/agent/DiskInfo.java
  6. 4 4
      ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeat.java
  7. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
  8. 4 4
      ambari-server/src/main/java/org/apache/ambari/server/agent/NodeInfo.java
  9. 4 4
      ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java
  10. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/agent/rest/HeartBeatResponse.java
  11. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
  12. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
  13. 0 8
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java
  14. 160 98
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java
  15. 70 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeLiveState.java
  16. 40 37
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java
  17. 42 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/StackVersion.java
  18. 18 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobCompletedEvent.java
  19. 18 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobFailedEvent.java
  20. 18 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobProgressUpdateEvent.java
  21. 18 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobType.java
  22. 18 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/job/NewJobEvent.java
  23. 18 0
      ambari-server/src/test/java/org/apache/ambari/server/state/live/job/TestJobImpl.java
  24. 18 0
      ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-728. Initial work on ServiceComponentNode FSM. (hitesh)
+
   AMBARI-724. Add tabs, dynamic form generation, validation errors, and info
   popovers for Customize Services page in Installer (yusaku) 
 

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java

@@ -21,13 +21,13 @@ import java.util.List;
 
 public class ActionDBAccessor {
   public void persistAction(HostAction ha) {
-    
+
   }
-  
+
   public Stage getAction(String actionId) {
     return null;
   }
-  
+
   public List<Stage> getAllStages(String requestId) {
     return null;
   }

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java

@@ -29,16 +29,16 @@ public class ActionManager {
   public void sendActions(List<Stage> stages) {
     //Store all these actions to the db
   }
-  
+
   public List<Stage> getRequestStatus(String requestId) {
     return null;
   }
-  
+
   public Stage getActionStatus(String actionId) {
     //fetch the action information from the db
     return null;
   }
-  
+
   public void actionResponse(String hostname, List<CommandReport> report) {
     //persist the action response into the db.
   }

+ 4 - 4
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java

@@ -17,19 +17,19 @@
  */
 package org.apache.ambari.server.actionmanager;
 
-//This class encapsulates the action scheduler thread. 
+//This class encapsulates the action scheduler thread.
 //Action schedule frequently looks at action database and determines if
 //there is an action that can be scheduled.
 public class ActionScheduler implements Runnable {
-  
+
   private final long actionTimeout;
   private final long sleepTime;
-  
+
   public ActionScheduler(long sleepTimeMilliSec, long actionTimeoutMilliSec) {
     this.sleepTime = sleepTimeMilliSec;
     this.actionTimeout = actionTimeoutMilliSec;
   }
-  
+
   @Override
   public void run() {
     try {

+ 11 - 11
ambari-server/src/main/java/org/apache/ambari/server/agent/DiskInfo.java

@@ -31,7 +31,7 @@ import javax.xml.bind.annotation.XmlType;
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {})
-//TODO convert the type safe ints/longs for used/percent/size.  
+//TODO convert the type safe ints/longs for used/percent/size.
 public class DiskInfo {
   @XmlElement
   String available;
@@ -45,16 +45,16 @@ public class DiskInfo {
   String percent;
   @XmlElement
   String size;
-  
+
   /**
    * DiskInfo object that tracks information about a disk.
-   * @param mountpoint 
+   * @param mountpoint
    * @param available
    * @param used
    * @param percent
    * @param size
    */
-  public DiskInfo(String device, String mountpoint, String available, 
+  public DiskInfo(String device, String mountpoint, String available,
       String used, String percent, String size) {
     this.device = device;
     this.mountpoint = mountpoint;
@@ -63,32 +63,32 @@ public class DiskInfo {
     this.percent = percent;
     this.size = size;
   }
-  
+
   /**
    * Needed for JAXB
    */
   public DiskInfo() {}
-  
+
   public String getAvailable() {
     return this.available;
   }
-  
+
   public String getMountPoint() {
     return this.mountpoint;
   }
-  
+
   public String getUsed() {
     return this.used;
   }
-  
+
   public String getPercent() {
     return this.percent;
   }
-  
+
   @Override
   public String toString() {
     return "available=" + this.available + ",mountpoint=" + this.mountpoint
-         + ",used=" + this.used + ",percent=" + this.percent + ",size=" + 
+         + ",used=" + this.used + ",percent=" + this.percent + ",size=" +
         this.size + ",device=" + this.device;
   }
 }

+ 4 - 4
ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeat.java

@@ -28,7 +28,7 @@ import javax.xml.bind.annotation.XmlType;
 
 /**
  *
- * 
+ *
  * Data model for Ambari Agent to send heartbeat to Ambari Server.
  *
  */
@@ -44,7 +44,7 @@ public class HeartBeat {
   List<ComponentStatus> componentStatus;
   //TODO add serialization
   NodeStatus nodeStatus;
-  
+
   @XmlElement
   private short responseId = -1;
   @XmlElement
@@ -80,8 +80,8 @@ public class HeartBeat {
 
   public boolean getIdle() {
     return idle;
-  }  
-  
+  }
+
   public int getInstallScriptHash() {
     return installScriptHash;
   }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java

@@ -25,7 +25,7 @@ import org.apache.ambari.server.agent.rest.HeartBeatResponse;
  */
 public class HeartBeatHandler {
   private String lastCompletedActionId;
-  
+
   public HeartBeatResponse handleHeartBeat(HeartBeat heartbeat) {
     System.out.println(heartbeat.toString());
     return null;

+ 4 - 4
ambari-server/src/main/java/org/apache/ambari/server/agent/NodeInfo.java

@@ -28,7 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 /**
- * 
+ *
  * Data model for Ambari Agent to send hardware profile to Ambari Server.
  *
  */
@@ -99,7 +99,7 @@ public class NodeInfo {
   @XmlElement
   private long uptime_days;
   @XmlElement
-  private long uptime_hours;   
+  private long uptime_hours;
 
   public String getArchitecture() {
     return this.architecture;
@@ -325,7 +325,7 @@ public class NodeInfo {
     this.swapsize = swapsize;
   }
 
-  public String getTimeZone() { 
+  public String getTimeZone() {
     return this.timezone;
   }
 
@@ -364,7 +364,7 @@ public class NodeInfo {
     }
     return ret;
   }
-  
+
   public String toString() {
     return "[memory=" + this.memorytotal + "," +
         "uptime_hours=" + this.uptime_hours + "," +

+ 4 - 4
ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java

@@ -44,7 +44,7 @@ public class Register {
   private String hostname;
   @XmlElement
   private NodeInfo hardwareProfile;
-  
+
   public short getResponseId() {
     return responseId;
   }
@@ -60,7 +60,7 @@ public class Register {
   public String getHostname() {
     return hostname;
   }
- 
+
   public NodeInfo getHardwareProfile() {
     return hardwareProfile;
   }
@@ -72,9 +72,9 @@ public class Register {
   public void setHostname(String hostname) {
     this.hostname = hostname;
   }
- 
+
   public void setHardwareProfile(NodeInfo hardwareProfile) {
-    this.hardwareProfile = hardwareProfile;    
+    this.hardwareProfile = hardwareProfile;
   }
 
   @Override

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/agent/rest/HeartBeatResponse.java

@@ -38,13 +38,13 @@ import org.apache.ambari.server.agent.AgentCommand;
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {})
 public class HeartBeatResponse {
-  
+
   String lastCompletedActionId;
   @XmlElement
   public short responseId;
   @XmlElement
   public String clusterId;
-  
+
   List<AgentCommand> cmds = null;
 
   public short getResponseId() {

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java

@@ -51,7 +51,7 @@ public class AmbariServer {
      ServletHolder sh = new ServletHolder(ServletContainer.class);
      sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
        "com.sun.jersey.api.core.PackagesResourceConfig");
-     sh.setInitParameter("com.sun.jersey.config.property.packages", 
+     sh.setInitParameter("com.sun.jersey.config.property.packages",
        "org.apache.ambari.server.api.rest");
      root.addServlet(sh, "/api/*");
      sh.setInitOrder(2);
@@ -59,7 +59,7 @@ public class AmbariServer {
      ServletHolder agent = new ServletHolder(ServletContainer.class);
      agent.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
        "com.sun.jersey.api.core.PackagesResourceConfig");
-     agent.setInitParameter("com.sun.jersey.config.property.packages", 
+     agent.setInitParameter("com.sun.jersey.config.property.packages",
        "org.apache.ambari.server.agent.rest");
      root.addServlet(agent, "/agent/*");
      agent.setInitOrder(3);

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java

@@ -53,7 +53,7 @@ public interface Cluster {
    * @param nodeName Node name
    * @return ServiceComponentNodeState
    */
-  public ServiceComponentNodeState getServiceComponentNodeState(String service,
+  public ServiceComponentNodeLiveState getServiceComponentNodeState(String service,
       String serviceComponent, String nodeName);
 
   /**
@@ -65,7 +65,7 @@ public interface Cluster {
    */
   public void setServiceComponentNodeState(String service,
       String serviceComponent, String nodeName,
-      ServiceComponentNodeState state);
+      ServiceComponentNodeLiveState state);
 
   /**
    * Send an Event to a given ServiceComponentNode

+ 0 - 8
ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java

@@ -20,7 +20,6 @@ package org.apache.ambari.server.state.live;
 
 import java.util.List;
 
-import org.apache.ambari.server.state.ConfigVersion;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.live.job.Job;
 
@@ -39,13 +38,6 @@ public interface ServiceComponentNode {
    */
   public String getNodeName();
 
-
-  /**
-   * Get the Config Version
-   * @return ConfigVersion
-   */
-  public ConfigVersion getConfigVersion();
-
   /**
    * Get the list of Jobs that are currently being tracked at the
    * ServiceComponentNode level

+ 160 - 98
ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java

@@ -19,205 +19,268 @@
 package org.apache.ambari.server.state.live;
 
 import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import org.apache.ambari.server.state.ConfigVersion;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.fsm.StateMachine;
 import org.apache.ambari.server.state.fsm.StateMachineFactory;
 import org.apache.ambari.server.state.live.job.Job;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class ServiceComponentNodeImpl implements ServiceComponentNode {
 
+  private static final Log LOG =
+      LogFactory.getLog(ServiceComponentNodeImpl.class);
+
+  private final Lock readLock;
+  private final Lock writeLock;
+
+  private ServiceComponentNodeState state;
+
+  private final String serviceComponentName;
+  private final String hostName;
+
   private static final StateMachineFactory
-  <ServiceComponentNodeImpl, ServiceComponentNodeState,
+  <ServiceComponentNodeImpl, ServiceComponentNodeLiveState,
   ServiceComponentNodeEventType, ServiceComponentNodeEvent>
     daemonStateMachineFactory
       = new StateMachineFactory<ServiceComponentNodeImpl,
-          ServiceComponentNodeState, ServiceComponentNodeEventType,
+          ServiceComponentNodeLiveState, ServiceComponentNodeEventType,
           ServiceComponentNodeEvent>
-          (ServiceComponentNodeState.INIT)
+          (ServiceComponentNodeLiveState.INIT)
 
-  // define the state machine of a NodeServiceComponent
+  // define the state machine of a NodeServiceComponent for runnable
+  // components
 
-     .addTransition(ServiceComponentNodeState.INIT,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INIT,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
 
-     .addTransition(ServiceComponentNodeState.INSTALLING,
-         ServiceComponentNodeState.INSTALLED,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLING,
+         ServiceComponentNodeLiveState.INSTALLED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
-     .addTransition(ServiceComponentNodeState.INSTALLING,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLING,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
-     .addTransition(ServiceComponentNodeState.INSTALLING,
-         ServiceComponentNodeState.INSTALL_FAILED,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLING,
+         ServiceComponentNodeLiveState.INSTALL_FAILED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
 
-     .addTransition(ServiceComponentNodeState.INSTALL_FAILED,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALL_FAILED,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
 
-     .addTransition(ServiceComponentNodeState.INSTALLED,
-         ServiceComponentNodeState.STARTING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLED,
+         ServiceComponentNodeLiveState.STARTING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_START)
-     .addTransition(ServiceComponentNodeState.INSTALLED,
-         ServiceComponentNodeState.UNINSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLED,
+         ServiceComponentNodeLiveState.UNINSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_UNINSTALL)
-     .addTransition(ServiceComponentNodeState.INSTALLED,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLED,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
 
-     .addTransition(ServiceComponentNodeState.STARTING,
-         ServiceComponentNodeState.STARTING,
+     .addTransition(ServiceComponentNodeLiveState.STARTING,
+         ServiceComponentNodeLiveState.STARTING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
-     .addTransition(ServiceComponentNodeState.STARTING,
-         ServiceComponentNodeState.STARTED,
+     .addTransition(ServiceComponentNodeLiveState.STARTING,
+         ServiceComponentNodeLiveState.STARTED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
-     .addTransition(ServiceComponentNodeState.STARTING,
-         ServiceComponentNodeState.START_FAILED,
+     .addTransition(ServiceComponentNodeLiveState.STARTING,
+         ServiceComponentNodeLiveState.START_FAILED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
 
-     .addTransition(ServiceComponentNodeState.START_FAILED,
-         ServiceComponentNodeState.STARTING,
+     .addTransition(ServiceComponentNodeLiveState.START_FAILED,
+         ServiceComponentNodeLiveState.STARTING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
 
-     .addTransition(ServiceComponentNodeState.STARTED,
-         ServiceComponentNodeState.STOPPING,
+     .addTransition(ServiceComponentNodeLiveState.STARTED,
+         ServiceComponentNodeLiveState.STOPPING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_STOP)
 
-     .addTransition(ServiceComponentNodeState.STOPPING,
-         ServiceComponentNodeState.STOPPING,
+     .addTransition(ServiceComponentNodeLiveState.STOPPING,
+         ServiceComponentNodeLiveState.STOPPING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
-     .addTransition(ServiceComponentNodeState.STOPPING,
-         ServiceComponentNodeState.INSTALLED,
+     .addTransition(ServiceComponentNodeLiveState.STOPPING,
+         ServiceComponentNodeLiveState.INSTALLED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
-     .addTransition(ServiceComponentNodeState.STOPPING,
-         ServiceComponentNodeState.STOP_FAILED,
+     .addTransition(ServiceComponentNodeLiveState.STOPPING,
+         ServiceComponentNodeLiveState.STOP_FAILED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
 
-     .addTransition(ServiceComponentNodeState.STOP_FAILED,
-         ServiceComponentNodeState.STOPPING,
+     .addTransition(ServiceComponentNodeLiveState.STOP_FAILED,
+         ServiceComponentNodeLiveState.STOPPING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALLING,
-         ServiceComponentNodeState.UNINSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLING,
+         ServiceComponentNodeLiveState.UNINSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
-     .addTransition(ServiceComponentNodeState.UNINSTALLING,
-         ServiceComponentNodeState.UNINSTALLED,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLING,
+         ServiceComponentNodeLiveState.UNINSTALLED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
-     .addTransition(ServiceComponentNodeState.UNINSTALLING,
-         ServiceComponentNodeState.UNINSTALL_FAILED,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLING,
+         ServiceComponentNodeLiveState.UNINSTALL_FAILED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALL_FAILED,
-         ServiceComponentNodeState.UNINSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALL_FAILED,
+         ServiceComponentNodeLiveState.UNINSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALLED,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLED,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALLED,
-         ServiceComponentNodeState.INIT,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLED,
+         ServiceComponentNodeLiveState.INIT,
          ServiceComponentNodeEventType.NODE_SVCCOMP_WIPEOUT)
 
      .installTopology();
 
   private static final StateMachineFactory
-  <ServiceComponentNodeImpl, ServiceComponentNodeState,
+  <ServiceComponentNodeImpl, ServiceComponentNodeLiveState,
   ServiceComponentNodeEventType, ServiceComponentNodeEvent>
     clientStateMachineFactory
       = new StateMachineFactory<ServiceComponentNodeImpl,
-          ServiceComponentNodeState, ServiceComponentNodeEventType,
+          ServiceComponentNodeLiveState, ServiceComponentNodeEventType,
           ServiceComponentNodeEvent>
-          (ServiceComponentNodeState.INIT)
+          (ServiceComponentNodeLiveState.INIT)
 
-  // define the state machine of a NodeServiceComponent
+  // define the state machine of a NodeServiceComponent for client only
+  // components
 
-     .addTransition(ServiceComponentNodeState.INIT,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INIT,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
 
-     .addTransition(ServiceComponentNodeState.INSTALLING,
-         ServiceComponentNodeState.INSTALLED,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLING,
+         ServiceComponentNodeLiveState.INSTALLED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
-     .addTransition(ServiceComponentNodeState.INSTALLING,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLING,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
-     .addTransition(ServiceComponentNodeState.INSTALLING,
-         ServiceComponentNodeState.INSTALL_FAILED,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLING,
+         ServiceComponentNodeLiveState.INSTALL_FAILED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
 
-     .addTransition(ServiceComponentNodeState.INSTALL_FAILED,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALL_FAILED,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
 
-     .addTransition(ServiceComponentNodeState.INSTALLED,
-         ServiceComponentNodeState.UNINSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLED,
+         ServiceComponentNodeLiveState.UNINSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_UNINSTALL)
-     .addTransition(ServiceComponentNodeState.INSTALLED,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.INSTALLED,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALLING,
-         ServiceComponentNodeState.UNINSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLING,
+         ServiceComponentNodeLiveState.UNINSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
-     .addTransition(ServiceComponentNodeState.UNINSTALLING,
-         ServiceComponentNodeState.UNINSTALLED,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLING,
+         ServiceComponentNodeLiveState.UNINSTALLED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
-     .addTransition(ServiceComponentNodeState.UNINSTALLING,
-         ServiceComponentNodeState.UNINSTALL_FAILED,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLING,
+         ServiceComponentNodeLiveState.UNINSTALL_FAILED,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALL_FAILED,
-         ServiceComponentNodeState.UNINSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALL_FAILED,
+         ServiceComponentNodeLiveState.UNINSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALLED,
-         ServiceComponentNodeState.INSTALLING,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLED,
+         ServiceComponentNodeLiveState.INSTALLING,
          ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
 
-     .addTransition(ServiceComponentNodeState.UNINSTALLED,
-         ServiceComponentNodeState.INIT,
+     .addTransition(ServiceComponentNodeLiveState.UNINSTALLED,
+         ServiceComponentNodeLiveState.INIT,
          ServiceComponentNodeEventType.NODE_SVCCOMP_WIPEOUT)
 
      .installTopology();
 
 
-  private final StateMachine<ServiceComponentNodeState,
+  private final StateMachine<ServiceComponentNodeLiveState,
       ServiceComponentNodeEventType, ServiceComponentNodeEvent> stateMachine;
 
-  public ServiceComponentNodeImpl(boolean isClient) {
+  public ServiceComponentNodeImpl(String serviceComponentName,
+      String hostName, boolean isClient) {
     super();
     if (isClient) {
       this.stateMachine = clientStateMachineFactory.make(this);
     } else {
       this.stateMachine = daemonStateMachineFactory.make(this);
     }
+    ReadWriteLock rwLock = new ReentrantReadWriteLock();
+    this.readLock = rwLock.readLock();
+    this.writeLock = rwLock.writeLock();
+    this.serviceComponentName = serviceComponentName;
+    this.hostName = hostName;
   }
 
   @Override
   public ServiceComponentNodeState getState() {
-    // TODO Auto-generated method stub
-    return null;
+    try {
+      readLock.lock();
+      return state;
+    }
+    finally {
+      readLock.unlock();
+    }
   }
 
   @Override
   public void setState(ServiceComponentNodeState state) {
-    // TODO Auto-generated method stub
+    try {
+      writeLock.lock();
+      this.state = state;
+      stateMachine.setCurrentState(state.getLiveState());
+    }
+    finally {
+      writeLock.unlock();
+    }
   }
 
   @Override
   public void handleEvent(ServiceComponentNodeEvent event)
       throws InvalidStateTransitonException {
-    // TODO
-    stateMachine.doTransition(event.getType(), event);
-  }
-
-  @Override
-  public ConfigVersion getConfigVersion() {
-    // TODO Auto-generated method stub
-    return null;
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Handling ServiceComponentNodeEvent event,"
+          + " eventType=" + event.getType().name()
+          + ", event=" + event.toString());
+    }
+    ServiceComponentNodeState oldState = getState();
+    try {
+      writeLock.lock();
+      try {
+        stateMachine.doTransition(event.getType(), event);
+        state.setState(stateMachine.getCurrentState());
+      } catch (InvalidStateTransitonException e) {
+        LOG.error("Can't handle ServiceComponentNodeEvent event at"
+            + " current state"
+            + ", serviceComponentName=" + this.getServiceComponentName()
+            + ", hostName=" + this.getNodeName()
+            + ", currentState=" + oldState
+            + ", eventType=" + event.getType()
+            + ", event=" + event);
+        throw e;
+      }
+    }
+    finally {
+      writeLock.unlock();
+    }
+    if (oldState.getLiveState() != getState().getLiveState()) {
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("ServiceComponentNode transitioned to a new state"
+            + ", serviceComponentName=" + this.getServiceComponentName()
+            + ", hostName=" + this.getNodeName()
+            + ", oldState=" + oldState
+            + ", currentState=" + getState()
+            + ", eventType=" + event.getType().name()
+            + ", event=" + event);
+      }
+    }
   }
 
   @Override
@@ -228,14 +291,13 @@ public class ServiceComponentNodeImpl implements ServiceComponentNode {
 
   @Override
   public String getServiceComponentName() {
-    // TODO Auto-generated method stub
-    return null;
+    return serviceComponentName;
   }
 
   @Override
   public String getNodeName() {
-    // TODO Auto-generated method stub
-    return null;
+    return hostName;
   }
 
+
 }

+ 70 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeLiveState.java

@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.state.live;
+
+public enum ServiceComponentNodeLiveState {
+  /**
+   * Initial/Clean state
+   */
+  INIT,
+  /**
+   * In the process of installing.
+   */
+  INSTALLING,
+  /**
+   * Install failed
+   */
+  INSTALL_FAILED,
+  /**
+   * State when install completed successfully
+   */
+  INSTALLED,
+  /**
+   * In the process of starting.
+   */
+  STARTING,
+  /**
+   * Start failed.
+   */
+  START_FAILED,
+  /**
+   * State when start completed successfully.
+   */
+  STARTED,
+  /**
+   * In the process of stopping.
+   */
+  STOPPING,
+  /**
+   * Stop failed
+   */
+  STOP_FAILED,
+  /**
+   * In the process of uninstalling.
+   */
+  UNINSTALLING,
+  /**
+   * Uninstall failed.
+   */
+  UNINSTALL_FAILED,
+  /**
+   * State when uninstall completed successfully.
+   */
+  UNINSTALLED
+}

+ 40 - 37
ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java

@@ -18,53 +18,56 @@
 
 package org.apache.ambari.server.state.live;
 
-public enum ServiceComponentNodeState {
-  /**
-   * Initial/Clean state
-   */
-  INIT,
-  /**
-   * In the process of installing.
-   */
-  INSTALLING,
-  /**
-   * Install failed
-   */
-  INSTALL_FAILED,
-  /**
-   * State when install completed successfully
-   */
-  INSTALLED,
-  /**
-   * In the process of starting.
-   */
-  STARTING,
-  /**
-   * Start failed.
-   */
-  START_FAILED,
+import org.apache.ambari.server.state.ConfigVersion;
+
+public class ServiceComponentNodeState {
+
+  private ConfigVersion configVersion;
+  private StackVersion stackVersion;
+  private ServiceComponentNodeLiveState state;
+
+  public ServiceComponentNodeState(ConfigVersion configVersion,
+      StackVersion stackVersion, ServiceComponentNodeLiveState state) {
+    super();
+    this.configVersion = configVersion;
+    this.stackVersion = stackVersion;
+    this.state = state;
+  }
+
   /**
-   * State when start completed successfully.
+   * @return the configVersion
    */
-  STARTED,
+  public ConfigVersion getConfigVersion() {
+    return configVersion;
+  }
   /**
-   * In the process of stopping.
+   * @param configVersion the configVersion to set
    */
-  STOPPING,
+  public void setConfigVersion(ConfigVersion configVersion) {
+    this.configVersion = configVersion;
+  }
   /**
-   * Stop failed
+   * @return the stackVersion
    */
-  STOP_FAILED,
+  public StackVersion getStackVersion() {
+    return stackVersion;
+  }
   /**
-   * In the process of uninstalling.
+   * @param stackVersion the stackVersion to set
    */
-  UNINSTALLING,
+  public void setStackVersion(StackVersion stackVersion) {
+    this.stackVersion = stackVersion;
+  }
   /**
-   * Uninstall failed.
+   * @return the state
    */
-  UNINSTALL_FAILED,
+  public ServiceComponentNodeLiveState getLiveState() {
+    return state;
+  }
   /**
-   * State when uninstall completed successfully.
+   * @param state the state to set
    */
-  UNINSTALLED
+  public void setState(ServiceComponentNodeLiveState state) {
+    this.state = state;
+  }
 }

+ 42 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/StackVersion.java

@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.state.live;
+
+public class StackVersion {
+  private String stackVersion;
+
+  public StackVersion(String stackVersion) {
+    super();
+    this.stackVersion = stackVersion;
+  }
+
+  /**
+   * @return the stackVersion
+   */
+  public String getStackVersion() {
+    return stackVersion;
+  }
+
+  /**
+   * @param stackVersion the stackVersion to set
+   */
+  public void setStackVersion(String stackVersion) {
+    this.stackVersion = stackVersion;
+  }
+}

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobCompletedEvent.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.job;
 
 public class JobCompletedEvent extends JobEvent {

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobFailedEvent.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.job;
 
 public class JobFailedEvent extends JobEvent {

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobProgressUpdateEvent.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.job;
 
 public class JobProgressUpdateEvent extends JobEvent {

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/job/JobType.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.job;
 
 public class JobType {

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/job/NewJobEvent.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.job;
 
 public class NewJobEvent extends JobEvent {

+ 18 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/live/job/TestJobImpl.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.job;
 
 import org.junit.Assert;

+ 18 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state.live.node;
 
 import static org.junit.Assert.fail;