Sfoglia il codice sorgente

AMBARI-695. More basic class restructuring for new design. (Contributed by hitesh)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1380914 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 12 anni fa
parent
commit
42118f0e8e
43 ha cambiato i file con 536 aggiunte e 489 eliminazioni
  1. 2 0
      AMBARI-666-CHANGES.txt
  2. 0 6
      ambari-server/src/main/java/org/apache/ambari/server/AgentVersion.java
  3. 0 37
      ambari-server/src/main/java/org/apache/ambari/server/Cluster.java
  4. 0 11
      ambari-server/src/main/java/org/apache/ambari/server/Config.java
  5. 0 12
      ambari-server/src/main/java/org/apache/ambari/server/ConfigVersion.java
  6. 0 23
      ambari-server/src/main/java/org/apache/ambari/server/Job.java
  7. 0 6
      ambari-server/src/main/java/org/apache/ambari/server/JobId.java
  8. 0 6
      ambari-server/src/main/java/org/apache/ambari/server/NodeHealthStatus.java
  9. 0 47
      ambari-server/src/main/java/org/apache/ambari/server/Service.java
  10. 0 53
      ambari-server/src/main/java/org/apache/ambari/server/ServiceComponent.java
  11. 0 37
      ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNode.java
  12. 0 29
      ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentType.java
  13. 0 30
      ambari-server/src/main/java/org/apache/ambari/server/ServiceType.java
  14. 0 20
      ambari-server/src/main/java/org/apache/ambari/server/fsm/JobEventType.java
  15. 0 13
      ambari-server/src/main/java/org/apache/ambari/server/fsm/JobFSM.java
  16. 0 13
      ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeFSM.java
  17. 0 83
      ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeFSMImpl.java
  18. 0 14
      ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeFSM.java
  19. 5 0
      ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java
  20. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java
  21. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java
  22. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java
  23. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java
  24. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java
  25. 6 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java
  26. 7 2
      ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
  27. 37 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java
  28. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java
  29. 20 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java
  30. 6 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java
  31. 21 14
      ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java
  32. 4 4
      ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java
  33. 25 8
      ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java
  34. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java
  35. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java
  36. 5 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java
  37. 291 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java
  38. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java
  39. 58 0
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java
  40. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java
  41. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java
  42. 37 9
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java
  43. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-695. More basic class restructuring for new design. (hitesh)
+
   AMBARI-694. Class to encapsulate stage. (jitendra)
 
   AMBARI-691. More basic classes for new design. (hitesh)

+ 0 - 6
ambari-server/src/main/java/org/apache/ambari/server/AgentVersion.java

@@ -1,6 +0,0 @@
-package org.apache.ambari.server;
-
-// TODO
-public class AgentVersion {
-
-}

+ 0 - 37
ambari-server/src/main/java/org/apache/ambari/server/Cluster.java

@@ -1,37 +0,0 @@
-package org.apache.ambari.server;
-
-import java.util.List;
-
-/**
- * Cluster represents a set of Nodes and Services deployed on these Nodes
- */
-public interface Cluster {
-
-  /**
-   * Get the Name of the Cluster
-   * @return Cluster Name
-   */
-  public String getName();
-
-  /**
-   * Get enabled Services for this Cluster
-   * @return List of Services
-   */
-  public List<Service> getServices();
-
-  /**
-   * Get the Nodes that belong to this Cluster
-   * @return List of Nodes
-   */
-  public List<Node> getNodes();
-
-  /**
-   * Get the list of Actions that are currently being tracked at the
-   * Cluster level
-   * @return List of Actions
-   */
-  public List<Job> getActions();
-
-
-
-}

+ 0 - 11
ambari-server/src/main/java/org/apache/ambari/server/Config.java

@@ -1,11 +0,0 @@
-package org.apache.ambari.server;
-
-// TODO
-public interface Config {
-
-  public int getSnapshotId();
-
-  // TODO
-  // public ConfigSnapshot getSnapshot();
-
-}

+ 0 - 12
ambari-server/src/main/java/org/apache/ambari/server/ConfigVersion.java

@@ -1,12 +0,0 @@
-package org.apache.ambari.server;
-
-// TODO
-public interface ConfigVersion {
-
-  public Config getServiceConfig();
-
-  public Config getServiceComponentConfig();
-
-  public Config getServiceComponentNodeConfig();
-
-}

+ 0 - 23
ambari-server/src/main/java/org/apache/ambari/server/Job.java

@@ -1,23 +0,0 @@
-package org.apache.ambari.server;
-
-
-public interface Job {
-
-  /**
-   * Get the Action ID for the action
-   * @return ActionId
-   */
-  public JobId getId();
-
-  /**
-   * Get the current state of the Action
-   * @return ActionState
-   */
-  public JobState getState();
-
-
-  // TODO requires some form of ActionType to ensure only one running
-  // action per action type
-  // There may be gotchas such as decomissioning should be allowed to happen
-  // on more than one node at a time
-}

+ 0 - 6
ambari-server/src/main/java/org/apache/ambari/server/JobId.java

@@ -1,6 +0,0 @@
-package org.apache.ambari.server;
-
-// TODO
-public class JobId {
-
-}

+ 0 - 6
ambari-server/src/main/java/org/apache/ambari/server/NodeHealthStatus.java

@@ -1,6 +0,0 @@
-package org.apache.ambari.server;
-
-// TODO
-public class NodeHealthStatus {
-
-}

+ 0 - 47
ambari-server/src/main/java/org/apache/ambari/server/Service.java

@@ -1,47 +0,0 @@
-package org.apache.ambari.server;
-
-import java.util.List;
-
-/**
- * Service Interface for representing various products in the
- * Hadoop eco-system such as HDFS, MAPREDUCE, HBASE.
- */
-public interface Service {
-
-  /**
-   * @return Name of the Service Instance
-   */
-  public String getName();
-
-  /**
-   * Get the Service Type
-   * @return ServiceType
-   */
-  public ServiceType getType();
-
-  /**
-   * Get the ServiceComponents enabled for this Service
-   * @return List of ServiceComponents
-   */
-  public List<ServiceComponent> getServiceComponents();
-
-  /**
-   * Get the list of services that this Service depends on
-   * @return List of Services
-   */
-  public List<Service> getDependencies();
-
-  /**
-   * Get the list of services that depend on this Service
-   * @return List of Services
-   */
-  public List<Service> getDependents();
-
-  /**
-   * Get the list of Actions that are currently being tracked at the
-   * Service level
-   * @return List of Actions
-   */
-  public List<Job> getActions();
-
-}

+ 0 - 53
ambari-server/src/main/java/org/apache/ambari/server/ServiceComponent.java

@@ -1,53 +0,0 @@
-package org.apache.ambari.server;
-
-import java.util.List;
-
-/**
- * ServiceComponent Interface for representing components of the various
- * products in the Hadoop eco-system such as NAMENODE, DATANODE for HDFS.
- */
-public interface ServiceComponent {
-
-  /**
-   * @return Name of the ServiceComponent Instance
-   */
-  public String getName();
-
-  /**
-   * Get the ServiceComponentType for this instance
-   * @return ServiceComponentType
-   */
-  public ServiceComponentType getType();
-
-  /**
-   * Get the Service to which this ServiceComponent belongs to
-   * @return Service of which this ServiceComponent is part of
-   */
-  public Service getService();
-
-  /**
-   * Get the list of components that this ServiceComponent depends on
-   * @return List of ServiceComponents
-   */
-  public List<ServiceComponent> getDependencies();
-
-  /**
-   * Get the list of components that depend on this ServiceComponent
-   * @return List of ServiceComponents
-   */
-  public List<ServiceComponent> getDependents();
-
-  /**
-   * Get the Nodes assigned to this ServiceComponent
-   * @return List of ServiceComponentNodes
-   */
-  public List<ServiceComponentNode> getServiceComponentNodes();
-
-  /**
-   * Get the list of Actions that are currently being tracked at the
-   * ServiceComponent level
-   * @return List of Actions
-   */
-  public List<Job> getActions();
-
-}

+ 0 - 37
ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNode.java

@@ -1,37 +0,0 @@
-package org.apache.ambari.server;
-
-import java.util.List;
-
-public interface ServiceComponentNode {
-
-  /**
-   * Get the ServiceComponent that this object is mapped to
-   * @return ServiceComponent
-   */
-  public ServiceComponent getServiceComponent();
-
-  /**
-   * Get the Node that this object is mapped to
-   * @return Node
-   */
-  public Node getNode();
-
-  /**
-   * Get the State for this ServiceComponentNode
-   * @return
-   */
-  public ServiceComponentNodeState getServiceComponentNodeState();
-
-  /**
-   * Get the Config Version
-   * @return ConfigVersion
-   */
-  public ConfigVersion getConfigVersion();
-
-  /**
-   * Get the list of Actions that are currently being tracked at the
-   * ServiceComponentNode level
-   * @return List of Actions
-   */
-  public List<Job> getActions();
-}

+ 0 - 29
ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentType.java

@@ -1,29 +0,0 @@
-package org.apache.ambari.server;
-
-import java.util.List;
-
-/**
- * TODO
- * Meta-data object for ServiceComponent
- */
-public interface ServiceComponentType {
-
-  /**
-   * Get the ServiceType to which this ServiceComponent belongs to
-   * @return ServiceType of which this ServiceComponent is part of
-   */
-  public ServiceType getServiceType();
-
-  /**
-   * Get the list of components that this ServiceComponent depends on
-   * @return List of ServiceComponentTypes
-   */
-  public List<ServiceComponentType> getDependencies();
-
-  /**
-   * Get the list of components that depend on this ServiceComponent
-   * @return List of ServiceComponentTypes
-   */
-  public List<ServiceComponentType> getDependents();
-
-}

+ 0 - 30
ambari-server/src/main/java/org/apache/ambari/server/ServiceType.java

@@ -1,30 +0,0 @@
-package org.apache.ambari.server;
-
-import java.util.List;
-
-/**
- * TODO
- * Meta-data object for Service
- */
-public interface ServiceType {
-
-  /**
-   * Get the list of ServiceComponentTypes for this Service
-   * @return List of ServiceComponentTypes
-   */
-  public List<ServiceComponentType> getServiceComponents();
-
-  /**
-   * Get the list of services that this Service depends on
-   * @return List of ServiceTypes
-   */
-  public List<ServiceType> getDependencies();
-
-  /**
-   * Get the list of services that depend on this Service
-   * @return List of ServiceTypes
-   */
-  public List<ServiceType> getDependents();
-
-
-}

+ 0 - 20
ambari-server/src/main/java/org/apache/ambari/server/fsm/JobEventType.java

@@ -1,20 +0,0 @@
-package org.apache.ambari.server.fsm;
-
-public enum JobEventType {
-  /**
-   * Initial state for the action when triggered.
-   */
-  ACTION_INIT,
-  /**
-   * Action still in progress.
-   */
-  ACTION_IN_PROGRESS,
-  /**
-   * Action completed successfully.
-   */
-  ACTION_COMPLETED,
-  /**
-   * Action failed to complete successfully.
-   */
-  ACTION_FAILED
-}

+ 0 - 13
ambari-server/src/main/java/org/apache/ambari/server/fsm/JobFSM.java

@@ -1,13 +0,0 @@
-package org.apache.ambari.server.fsm;
-
-import org.apache.ambari.server.JobState;
-
-public interface JobFSM {
-
-  public JobState getState();
-
-  public void setState(JobState state);
-
-  public void handleEvent(JobEvent event)
-      throws InvalidStateTransitonException;
-}

+ 0 - 13
ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeFSM.java

@@ -1,13 +0,0 @@
-package org.apache.ambari.server.fsm;
-
-import org.apache.ambari.server.NodeState;
-
-public interface NodeFSM {
-
-  public NodeState getState();
-
-  public void setState(NodeState state);
-
-  public void handleEvent(NodeEvent event)
-      throws InvalidStateTransitonException;
-}

+ 0 - 83
ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeFSMImpl.java

@@ -1,83 +0,0 @@
-package org.apache.ambari.server.fsm;
-
-import org.apache.ambari.server.NodeState;
-import org.apache.ambari.server.fsm.SingleArcTransition;
-import org.apache.ambari.server.fsm.StateMachineFactory;
-
-public class NodeFSMImpl implements NodeFSM {
-
-  private static final StateMachineFactory
-    <NodeFSMImpl, NodeState, NodeEventType, NodeEvent>
-      stateMachineFactory
-        = new StateMachineFactory<NodeFSMImpl, NodeState, NodeEventType, NodeEvent>
-        (NodeState.INIT)
-
-   // define the state machine of a Node
-
-   .addTransition(NodeState.INIT, NodeState.WAITING_FOR_VERIFICATION,
-       NodeEventType.NODE_REGISTRATION_REQUEST)
-
-   .addTransition(NodeState.WAITING_FOR_VERIFICATION, NodeState.HEALTHY,
-       NodeEventType.NODE_VERIFIED, new NodeVerifiedTransition())
-
-   // TODO - should be able to combine multiple into a single multi-arc
-   // transition
-   .addTransition(NodeState.HEALTHY, NodeState.HEALTHY,
-       NodeEventType.NODE_HEARTBEAT_HEALTHY)
-   .addTransition(NodeState.HEALTHY, NodeState.HEARTBEAT_LOST,
-       NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
-   .addTransition(NodeState.HEALTHY, NodeState.UNHEALTHY,
-       NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
-
-   .addTransition(NodeState.UNHEALTHY, NodeState.HEALTHY,
-       NodeEventType.NODE_HEARTBEAT_HEALTHY)
-   .addTransition(NodeState.UNHEALTHY, NodeState.UNHEALTHY,
-       NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
-   .addTransition(NodeState.UNHEALTHY, NodeState.HEARTBEAT_LOST,
-       NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
-
-   .addTransition(NodeState.HEARTBEAT_LOST, NodeState.HEALTHY,
-       NodeEventType.NODE_HEARTBEAT_HEALTHY)
-   .addTransition(NodeState.HEARTBEAT_LOST, NodeState.UNHEALTHY,
-       NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
-   .addTransition(NodeState.HEARTBEAT_LOST, NodeState.HEARTBEAT_LOST,
-       NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
-   .installTopology();
-
-  private final StateMachine<NodeState, NodeEventType, NodeEvent> stateMachine;
-
-  public NodeFSMImpl() {
-    super();
-    this.stateMachine = stateMachineFactory.make(this);
-  }
-
-  static class NodeVerifiedTransition
-      implements SingleArcTransition<NodeFSMImpl, NodeEvent> {
-
-    @Override
-    public void transition(NodeFSMImpl node, NodeEvent event) {
-      // TODO Auto-generated method stub
-    }
-
-  }
-
-  @Override
-  public NodeState getState() {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public void setState(NodeState state) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void handleEvent(NodeEvent event)
-      throws InvalidStateTransitonException {
-    // TODO Auto-generated method stub
-    stateMachine.doTransition(event.getType(), event);
-  }
-
-}

+ 0 - 14
ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeFSM.java

@@ -1,14 +0,0 @@
-package org.apache.ambari.server.fsm;
-
-import org.apache.ambari.server.ServiceComponentNodeState;;
-
-public interface ServiceComponentNodeFSM {
-
-  public ServiceComponentNodeState getState();
-
-  public void setState(ServiceComponentNodeState state);
-
-  public void handleEvent(ServiceComponentNodeEvent event)
-      throws InvalidStateTransitonException;
-
-}

+ 5 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java

@@ -0,0 +1,5 @@
+package org.apache.ambari.server.state;
+
+public interface ConfigVersion {
+
+}

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/InvalidStateTransitonException.java → ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java

@@ -16,7 +16,7 @@
 * limitations under the License.
 */
 
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.fsm;
 
 // TODO
 public class InvalidStateTransitonException extends Exception {

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/MultipleArcTransition.java → ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java

@@ -16,7 +16,7 @@
 * limitations under the License.
 */
 
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.fsm;
 
 /**
  * Hook for Transition.

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/SingleArcTransition.java → ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java

@@ -16,7 +16,7 @@
 * limitations under the License.
 */
 
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.fsm;
 
 /**
  * Hook for Transition. This lead to state machine to move to

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/StateMachine.java → ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java

@@ -16,7 +16,7 @@
 * limitations under the License.
 */
 
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.fsm;
 
 public interface StateMachine
                  <STATE extends Enum<STATE>,

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/StateMachineFactory.java → ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java

@@ -16,7 +16,7 @@
 * limitations under the License.
 */
 
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.fsm;
 
 import java.util.EnumMap;
 import java.util.HashMap;

+ 6 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java

@@ -0,0 +1,6 @@
+package org.apache.ambari.server.state.live;
+
+// TODO
+public class AgentVersion {
+
+}

+ 7 - 2
ambari-server/src/main/java/org/apache/ambari/server/DiskInfo.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server;
+package org.apache.ambari.server.state.live;
 
 /**
  * Information about a mounted disk on a given node
@@ -25,6 +25,11 @@ public class DiskInfo {
   /**
    * Capacity of the disk in bytes
    */
-  long capacityBytes;
+  long totalCapacityBytes;
+  
+  /**
+   * Current capacity in bytes
+   */
+  long currentCapacityBytes;
 
 }

+ 37 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java

@@ -0,0 +1,37 @@
+package org.apache.ambari.server.state.live;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+
+public interface Job {
+
+  /**
+   * Get the Job ID for the action
+   * @return JobId
+   */
+  public JobId getId();
+
+  // TODO requires some form of JobType to ensure only one running
+  // action per action type
+  // There may be gotchas such as de-commissioning should be allowed to happen
+  // on more than one node at a time  
+  
+  /**
+   * Get the current state of the Job
+   * @return JobState
+   */
+  public JobState getState();
+
+  /**
+   * Set the State of the Job
+   * @param state JobState
+   */
+  public void setState(JobState state);
+
+  /**
+   * Send a JobEvent to the Job's StateMachine
+   * @param event JobEvent
+   * @throws InvalidStateTransitonException
+   */
+  public void handleEvent(JobEvent event)
+      throws InvalidStateTransitonException;
+}

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/JobEvent.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
 import org.apache.ambari.server.fsm.event.AbstractEvent;
 

+ 20 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java

@@ -0,0 +1,20 @@
+package org.apache.ambari.server.state.live;
+
+public enum JobEventType {
+  /**
+   * Initial state for the job when triggered.
+   */
+  JOB_INIT,
+  /**
+   * Job still in progress.
+   */
+  JOB_IN_PROGRESS,
+  /**
+   * Job completed successfully.
+   */
+  JOB_COMPLETED,
+  /**
+   * Job failed to complete successfully.
+   */
+  JOB_FAILED
+}

+ 6 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java

@@ -0,0 +1,6 @@
+package org.apache.ambari.server.state.live;
+
+// TODO
+public class JobId {
+
+}

+ 21 - 14
ambari-server/src/main/java/org/apache/ambari/server/fsm/JobFSMImpl.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java

@@ -1,37 +1,38 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
-import org.apache.ambari.server.JobState;
-import org.apache.ambari.server.fsm.StateMachineFactory;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
 
-public class JobFSMImpl implements JobFSM {
+public class JobImpl implements Job {
 
   private static final StateMachineFactory
-    <JobFSMImpl, JobState, JobEventType, JobEvent>
+    <JobImpl, JobState, JobEventType, JobEvent>
       stateMachineFactory
-        = new StateMachineFactory<JobFSMImpl, JobState,
+        = new StateMachineFactory<JobImpl, JobState,
           JobEventType, JobEvent>
             (JobState.INIT)
 
-    // define the state machine of a Action
+    // define the state machine of a Job
 
     .addTransition(JobState.INIT, JobState.IN_PROGRESS,
-        JobEventType.ACTION_IN_PROGRESS)
+        JobEventType.JOB_IN_PROGRESS)
     .addTransition(JobState.IN_PROGRESS, JobState.IN_PROGRESS,
-        JobEventType.ACTION_IN_PROGRESS)
+        JobEventType.JOB_IN_PROGRESS)
     .addTransition(JobState.IN_PROGRESS, JobState.COMPLETED,
-        JobEventType.ACTION_COMPLETED)
+        JobEventType.JOB_COMPLETED)
     .addTransition(JobState.IN_PROGRESS, JobState.FAILED,
-        JobEventType.ACTION_FAILED)
+        JobEventType.JOB_FAILED)
     .addTransition(JobState.COMPLETED, JobState.INIT,
-        JobEventType.ACTION_INIT)
+        JobEventType.JOB_INIT)
     .addTransition(JobState.FAILED, JobState.INIT,
-        JobEventType.ACTION_INIT)
+        JobEventType.JOB_INIT)
     .installTopology();
 
   private final StateMachine<JobState, JobEventType, JobEvent>
       stateMachine;
 
-  public JobFSMImpl() {
+  public JobImpl() {
     super();
     this.stateMachine = stateMachineFactory.make(this);
   }
@@ -55,4 +56,10 @@ public class JobFSMImpl implements JobFSM {
     stateMachine.doTransition(event.getType(), event);
   }
 
+  @Override
+  public JobId getId() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
 }

+ 4 - 4
ambari-server/src/main/java/org/apache/ambari/server/JobState.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java

@@ -1,13 +1,13 @@
-package org.apache.ambari.server;
+package org.apache.ambari.server.state.live;
 
 public enum JobState {
   /**
-   * Initial state for the Action.
+   * Initial state for the Job.
    * When a new action is triggered or set in motion.
    */
   INIT,
   /**
-   * State when the action is triggered on the cluster,
+   * State when the job is triggered on the cluster,
    */
   IN_PROGRESS,
   /**
@@ -15,7 +15,7 @@ public enum JobState {
    */
   COMPLETED,
   /**
-   * Action failed to complete successfully
+   * Job failed to complete successfully
    */
   FAILED
 }

+ 25 - 8
ambari-server/src/main/java/org/apache/ambari/server/Node.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java

@@ -1,12 +1,10 @@
-package org.apache.ambari.server;
+package org.apache.ambari.server.state.live;
 
 import java.util.List;
 import java.util.Map;
 
-/**
- * Interface for Node of a Cluster. Encapsulates all the required information
- * about a given node.
- */
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+
 public interface Node {
 
   /**
@@ -198,10 +196,29 @@ public interface Node {
   public NodeState getNodeState();
 
   /**
-   * Get the list of Actions that are currently being tracked at the
+   * Get the list of Jobs that are currently being tracked at the
    * Node level
-   * @return List of Actions
+   * @return List of Jobs
+   */
+  public List<Job> getJobs();
+
+  /**
+   * Get Node State
+   * @return NodeState
    */
-  public List<Job> getActions();
+  public NodeState getState();
 
+  /**
+   * Set the State of the Node
+   * @param state Node State
+   */
+  public void setState(NodeState state);
+
+  /**
+   * Send an event to the Node's StateMachine
+   * @param event NodeEvent
+   * @throws InvalidStateTransitonException
+   */
+  public void handleEvent(NodeEvent event)
+      throws InvalidStateTransitonException;
 }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeEvent.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
 import org.apache.ambari.server.fsm.event.AbstractEvent;
 

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeEventType.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
 public enum NodeEventType {
   /**

+ 5 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java

@@ -0,0 +1,5 @@
+package org.apache.ambari.server.state.live;
+
+public interface NodeHealthStatus {
+
+}

+ 291 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java

@@ -0,0 +1,291 @@
+package org.apache.ambari.server.state.live;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.SingleArcTransition;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
+
+public class NodeImpl implements Node {
+
+  private static final StateMachineFactory
+    <NodeImpl, NodeState, NodeEventType, NodeEvent>
+      stateMachineFactory
+        = new StateMachineFactory<NodeImpl, NodeState, NodeEventType, NodeEvent>
+        (NodeState.INIT)
+
+   // define the state machine of a Node
+
+   .addTransition(NodeState.INIT, NodeState.WAITING_FOR_VERIFICATION,
+       NodeEventType.NODE_REGISTRATION_REQUEST)
+
+   .addTransition(NodeState.WAITING_FOR_VERIFICATION, NodeState.HEALTHY,
+       NodeEventType.NODE_VERIFIED, new NodeVerifiedTransition())
+
+   // TODO - should be able to combine multiple into a single multi-arc
+   // transition
+   .addTransition(NodeState.HEALTHY, NodeState.HEALTHY,
+       NodeEventType.NODE_HEARTBEAT_HEALTHY)
+   .addTransition(NodeState.HEALTHY, NodeState.HEARTBEAT_LOST,
+       NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
+   .addTransition(NodeState.HEALTHY, NodeState.UNHEALTHY,
+       NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
+
+   .addTransition(NodeState.UNHEALTHY, NodeState.HEALTHY,
+       NodeEventType.NODE_HEARTBEAT_HEALTHY)
+   .addTransition(NodeState.UNHEALTHY, NodeState.UNHEALTHY,
+       NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
+   .addTransition(NodeState.UNHEALTHY, NodeState.HEARTBEAT_LOST,
+       NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
+
+   .addTransition(NodeState.HEARTBEAT_LOST, NodeState.HEALTHY,
+       NodeEventType.NODE_HEARTBEAT_HEALTHY)
+   .addTransition(NodeState.HEARTBEAT_LOST, NodeState.UNHEALTHY,
+       NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
+   .addTransition(NodeState.HEARTBEAT_LOST, NodeState.HEARTBEAT_LOST,
+       NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
+   .installTopology();
+
+  private final StateMachine<NodeState, NodeEventType, NodeEvent> stateMachine;
+
+  public NodeImpl() {
+    super();
+    this.stateMachine = stateMachineFactory.make(this);
+  }
+
+  static class NodeVerifiedTransition
+      implements SingleArcTransition<NodeImpl, NodeEvent> {
+
+    @Override
+    public void transition(NodeImpl node, NodeEvent event) {
+      // TODO Auto-generated method stub
+    }
+
+  }
+
+  @Override
+  public NodeState getState() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setState(NodeState state) {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void handleEvent(NodeEvent event)
+      throws InvalidStateTransitonException {
+    // TODO Auto-generated method stub
+    stateMachine.doTransition(event.getType(), event);
+  }
+
+  @Override
+  public String getHostName() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setHostName(String hostName) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public String getIPv4() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setIPv4(String ip) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public String getIPv6() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setIPv6(String ip) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public int getCpuCount() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  @Override
+  public void setCpuCount(int cpuCount) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public int getTotalMemBytes() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  @Override
+  public void setTotalMemBytes(int totalMemBytes) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public int getAvailableMemBytes() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  @Override
+  public void setAvailableMemBytes(int availableMemBytes) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public String getOsArch() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setOsArch(String osArch) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public String getOsInfo() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setOsInfo(String osInfo) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public String getOsType() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setOsType(String osType) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public List<DiskInfo> getDisksInfo() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setDisksInfo(List<DiskInfo> disksInfo) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public NodeHealthStatus getHealthStatus() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setHealthStatus(NodeHealthStatus healthStatus) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public Map<String, String> getHostAttributes() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setHostAttributes(Map<String, String> hostAttributes) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public String getRackInfo() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setRackInfo(String rackInfo) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public int getLastRegistrationTime() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  @Override
+  public void setLastRegistrationTime(int lastRegistrationTime) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public int getLastHeartbeatTime() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  @Override
+  public void setLastHeartbeatTime(int lastHeartbeatTime) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public AgentVersion getAgentVersion() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void setAgentVersion(AgentVersion agentVersion) {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public NodeState getNodeState() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public List<Job> getJobs() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+}

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/NodeState.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server;
+package org.apache.ambari.server.state.live;
 
 public enum NodeState {
   /**

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

@@ -0,0 +1,58 @@
+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;
+
+
+public interface ServiceComponentNode {
+
+  /**
+   * Get the ServiceComponent this object maps to
+   * @return Name of the ServiceComponent
+   */
+  public String getServiceComponentName();
+  
+  /**
+   * Get the Node this object maps to
+   * @return Node's hostname
+   */
+  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
+   * @return List of Jobs
+   */
+  public List<Job> getJobs();
+  
+  
+  /**
+   * Get ServiceComponent-Node State
+   * @return ServiceComponentNodeState
+   */
+  public ServiceComponentNodeState getState();
+
+  /**
+   * Set the State for this ServiceComponent-Node
+   * @param state ServiceComponentNodeState to set to
+   */
+  public void setState(ServiceComponentNodeState state);
+
+  /**
+   * Send a ServiceComponentNodeState event to the StateMachine
+   * @param event Event to handle
+   * @throws InvalidStateTransitonException
+   */
+  public void handleEvent(ServiceComponentNodeEvent event)
+      throws InvalidStateTransitonException;
+
+}

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeEvent.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
 import org.apache.ambari.server.fsm.event.AbstractEvent;
 

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeEventType.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
 public enum ServiceComponentNodeEventType {
   /**

+ 37 - 9
ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeFSMImpl.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java

@@ -1,15 +1,19 @@
-package org.apache.ambari.server.fsm;
+package org.apache.ambari.server.state.live;
 
-import org.apache.ambari.server.ServiceComponentNodeState;
-import org.apache.ambari.server.fsm.StateMachineFactory;
+import java.util.List;
 
-public class ServiceComponentNodeFSMImpl implements ServiceComponentNodeFSM {
+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;
+
+public class ServiceComponentNodeImpl implements ServiceComponentNode {
 
   private static final StateMachineFactory
-  <ServiceComponentNodeFSMImpl, ServiceComponentNodeState,
+  <ServiceComponentNodeImpl, ServiceComponentNodeState,
   ServiceComponentNodeEventType, ServiceComponentNodeEvent>
     daemonStateMachineFactory
-      = new StateMachineFactory<ServiceComponentNodeFSMImpl,
+      = new StateMachineFactory<ServiceComponentNodeImpl,
           ServiceComponentNodeState, ServiceComponentNodeEventType,
           ServiceComponentNodeEvent>
           (ServiceComponentNodeState.INIT)
@@ -101,10 +105,10 @@ public class ServiceComponentNodeFSMImpl implements ServiceComponentNodeFSM {
      .installTopology();
 
   private static final StateMachineFactory
-  <ServiceComponentNodeFSMImpl, ServiceComponentNodeState,
+  <ServiceComponentNodeImpl, ServiceComponentNodeState,
   ServiceComponentNodeEventType, ServiceComponentNodeEvent>
     clientStateMachineFactory
-      = new StateMachineFactory<ServiceComponentNodeFSMImpl,
+      = new StateMachineFactory<ServiceComponentNodeImpl,
           ServiceComponentNodeState, ServiceComponentNodeEventType,
           ServiceComponentNodeEvent>
           (ServiceComponentNodeState.INIT)
@@ -164,7 +168,7 @@ public class ServiceComponentNodeFSMImpl implements ServiceComponentNodeFSM {
   private final StateMachine<ServiceComponentNodeState,
       ServiceComponentNodeEventType, ServiceComponentNodeEvent> stateMachine;
 
-  public ServiceComponentNodeFSMImpl(boolean isClient) {
+  public ServiceComponentNodeImpl(boolean isClient) {
     super();
     if (isClient) {
       this.stateMachine = clientStateMachineFactory.make(this);
@@ -191,4 +195,28 @@ public class ServiceComponentNodeFSMImpl implements ServiceComponentNodeFSM {
     stateMachine.doTransition(event.getType(), event);
   }
 
+  @Override
+  public ConfigVersion getConfigVersion() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public List<Job> getJobs() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public String getServiceComponentName() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public String getNodeName() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
 }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNodeState.java → ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java

@@ -1,4 +1,4 @@
-package org.apache.ambari.server;
+package org.apache.ambari.server.state.live;
 
 public enum ServiceComponentNodeState {
   /**