incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jiten...@apache.org
Subject svn commit: r1392493 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/agent/ ambari-server/src/main/java/org/apache/ambari/server/agent/rest/ ambari-server/src/main/java/org/apache/ambari/server/state/...
Date Mon, 01 Oct 2012 18:16:29 GMT
Author: jitendra
Date: Mon Oct  1 18:16:28 2012
New Revision: 1392493

URL: http://svn.apache.org/viewvc?rev=1392493&view=rev
Log:
AMBARI-755. Heartbeat handler: Update state as reported in heartbeat.

Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/Host.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Mon Oct  1 18:16:28 2012
@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-755. Heartbeat handler: Update state as reported in heartbeat.
+  (jitendra)
+
   AMBARI-777. Add NOTICE file for copyright of stdlib from puppetlabs.
   (mahadev)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java
Mon Oct  1 18:16:28 2012
@@ -37,6 +37,9 @@ public class CommandReport {
   String status;
   @XmlElement
   int exitCode;
+  
+  @XmlElement
+  private String clusterName;
  
   public String getActionId() {
     return this.actionId;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java
Mon Oct  1 18:16:28 2012
@@ -33,7 +33,11 @@ public class ComponentStatus {
   String msg;
   @XmlElement
   String status;
-
+  @XmlElement
+  String serviceName;
+  @XmlElement
+  String clusterName;
+  
   public String getComponentName() {
     return this.componentName;
   }
@@ -57,4 +61,28 @@ public class ComponentStatus {
   public void setStatus(String status) {
     this.status = status;
   }
+
+  public String getMsg() {
+    return msg;
+  }
+
+  public void setMsg(String msg) {
+    this.msg = msg;
+  }
+
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
Mon Oct  1 18:16:28 2012
@@ -46,6 +46,9 @@ public class ExecutionCommand extends Ag
   }
   
   @XmlElement
+  private String clusterName;
+  
+  @XmlElement
   private String commandId;
   
   @XmlElement

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
Mon Oct  1 18:16:28 2012
@@ -20,8 +20,18 @@ package org.apache.ambari.server.agent;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionManager;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.live.Cluster;
 import org.apache.ambari.server.state.live.Clusters;
+import org.apache.ambari.server.state.live.host.Host;
+import org.apache.ambari.server.state.live.host.HostEvent;
+import org.apache.ambari.server.state.live.host.HostEventType;
+import org.apache.ambari.server.state.live.host.HostState;
+import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
+import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostLiveState;
+import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostState;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -51,19 +61,18 @@ public class HeartBeatHandler {
     heartbeatMonitor.start();
   }
   
-  public HeartBeatResponse handleHeartBeat(HeartBeat heartbeat) {
+  public HeartBeatResponse handleHeartBeat(HeartBeat heartbeat) throws AmbariException {
 
     HeartBeatResponse response = new HeartBeatResponse();
-    response.setClusterId("test");
     response.setResponseId(0L);
-    List<String> clusterNames = clusterFsm.getClusters(heartbeat.getHostname()); 
+    String hostname = heartbeat.getHostname();
+    Host hostObject = clusterFsm.getHost(hostname);
     try {
-      clusterFsm.handleHeartbeat(heartbeat.getHostname(),
-          heartbeat.getTimestamp());
-    } catch (Exception ex) {
-      // Unexpected heartbeat, reset to init state
-      // send registration command
-      clusterFsm.updateStatus(heartbeat.getHostname(), "GO_TO_INIT");
+      // TODO: handle unhealthy heartbeat as well
+      hostObject.handleEvent(new HostEvent(hostname,
+          HostEventType.HOST_HEARTBEAT_HEALTHY));
+    } catch (InvalidStateTransitonException ex) {
+      hostObject.setState(HostState.INIT);
       RegistrationCommand regCmd = new RegistrationCommand();
       List<AgentCommand> cmds = new ArrayList<AgentCommand>();
       cmds.add(regCmd);
@@ -71,34 +80,46 @@ public class HeartBeatHandler {
       return response;
     }
 
-    // Examine heartbeat for command reports
+    //Examine heartbeat for command reports
     List<CommandReport> reports = heartbeat.getCommandReports();
-    actionManager.actionResponse(heartbeat.getHostname(), reports);
+    actionManager.actionResponse(hostname, reports);
 
     // Examine heartbeart for component status
-    for (ComponentStatus status : heartbeat.componentStatus) {
-      clusterFsm.updateStatus(heartbeat.getHostname(), status.status);
+    List<Cluster> clusters = clusterFsm.getClusters(hostname);
+    for (Cluster cl : clusters) {
+      for (ComponentStatus status : heartbeat.componentStatus) {
+        if (status.getClusterName() == cl.getClusterName()) {
+          ServiceComponentHost scHost = cl.getServiceComponentHost(
+              status.getServiceName(), status.getComponentName(), hostname);
+          ServiceComponentHostState currentState = scHost.getState();
+          ServiceComponentHostLiveState liveState = ServiceComponentHostLiveState
+              .valueOf(ServiceComponentHostLiveState.class, status.getStatus());
+          // Hack
+          scHost.setState(new ServiceComponentHostState(currentState
+              .getConfigVersion(), currentState.getStackVersion(), liveState));
+        }
+      }
     }
-    
-    //TODO: Check if heartbeat is unhealthy
 
-    //Send commands if node is active
-    if (clusterFsm.isNodeActive(heartbeat.getHostname())) {
+    // Send commands if node is active
+    if (hostObject.getState().equals(HostState.HEALTHY)) {
       List<AgentCommand> cmds = actionQueue.dequeueAll(heartbeat.getHostname());
       response.setAgentCommands(cmds);
     }
     return response;
   }
   
-  public RegistrationResponse handleRegistration(Register register) {
-    List<String> roles = clusterFsm.getHostComponents(register.getHostname());
-    try {
-      clusterFsm.handleRegistration(register.getHostname());
-    } catch (Exception ex) {
-      //Go to status check state
-      clusterFsm.updateStatus(register.getHostname(), "GO TO STATUS CHECK");
-    }
+  public RegistrationResponse handleRegistration(Register register)
+      throws InvalidStateTransitonException, AmbariException {
+    String hostname = register.getHostname();
+    List<String> roles = clusterFsm.getHostComponents(hostname);
+    Host hostObject = clusterFsm.getHost(hostname);
     RegistrationResponse response = new RegistrationResponse();
+    StatusCommand statusCmd = new StatusCommand();
+    statusCmd.setRoles(roles);
+    response.setCommand(statusCmd);
+    hostObject.handleEvent(new HostEvent(hostname,
+        HostEventType.HOST_REGISTRATION_REQUEST));
     return response;
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
Mon Oct  1 18:16:28 2012
@@ -19,8 +19,13 @@ package org.apache.ambari.server.agent;
 
 import java.util.List;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionManager;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.live.Clusters;
+import org.apache.ambari.server.state.live.host.Host;
+import org.apache.ambari.server.state.live.host.HostEvent;
+import org.apache.ambari.server.state.live.host.HostEventType;
 import org.apache.ambari.server.state.live.host.HostState;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -48,7 +53,6 @@ public class HeartbeatMonitor implements
   public void shutdown() {
     shouldRun = false;
   }
-  
 
   public void start() {
     monitorThread = new Thread(this);
@@ -73,28 +77,35 @@ public class HeartbeatMonitor implements
   //Go through all the nodes, check for last heartbeat or any waiting state
   //If heartbeat is lost, update node fsm state, purge the action queue
   //notify action manager for node failure.
-  private void doWork() {
-    List<String> allHosts = fsm.getAllHosts();
+  private void doWork() throws InvalidStateTransitonException {
+    List<Host> allHosts = fsm.getAllHosts();
     long now = System.currentTimeMillis();
-    for (String host : allHosts) {
-      HostState hostState = fsm.getHostState(host);
-      long lastHeartbeat = hostState.getLastHeartbeat();
+    for (Host hostObj : allHosts) {
+      String host = hostObj.getHostName();
+      HostState hostState = hostObj.getState();
+      
+      long lastHeartbeat = 0;
+      try {
+        lastHeartbeat = fsm.getHost(host).getLastHeartbeatTime();
+      } catch (AmbariException e) {
+        LOG.warn("Exception in getting host object; Is it fatal?", e);
+      }
       if (lastHeartbeat + 5*threadWakeupInterval < now) {
+        LOG.warn("Hearbeat lost from host "+host);
         //Heartbeat is expired
-        fsm.updateStatus(host, "HEARTBEAT_EXPIRED");
+        hostObj.handleEvent(new HostEvent(host, HostEventType.HOST_HEARTBEAT_LOST));
         //Purge action queue
         actionQueue.dequeueAll(host);
         //notify action manager
         actionManager.handleLostHost(host);
       }
       if (hostState == HostState.WAITING_FOR_HOST_STATUS_UPDATES) {
-        long timeSpentInState = hostState.getTimeInState();
+        long timeSpentInState = hostObj.getTimeInState();
         if (timeSpentInState + 5*threadWakeupInterval < now) {
-          //Ask to register again
-          fsm.updateStatus(host, "GO_BACK_TO_INIT");
+          //Go back to init, the agent will be asked to register again in the next heartbeat
+          hostObj.setState(HostState.INIT);
         }
       }
     }
   }
-
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
Mon Oct  1 18:16:28 2012
@@ -45,4 +45,12 @@ public class RegistrationResponse {
   public void setResponseStatus(RegistrationStatus response) {
     this.response = response;
   }
+
+  public AgentCommand getCommand() {
+    return command;
+  }
+
+  public void setCommand(AgentCommand command) {
+    this.command = command;
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
Mon Oct  1 18:16:28 2012
@@ -42,6 +42,8 @@ public class StatusCommand extends Agent
   @XmlElement
   List<String> roles;
 
+  @XmlElement
+  private String clusterName;
   
   public List<String> getRoles() {
     return roles;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
Mon Oct  1 18:16:28 2012
@@ -27,11 +27,13 @@ import javax.ws.rs.WebApplicationExcepti
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.agent.HeartBeat;
 import org.apache.ambari.server.agent.HeartBeatHandler;
 import org.apache.ambari.server.agent.HeartBeatResponse;
 import org.apache.ambari.server.agent.Register;
 import org.apache.ambari.server.agent.RegistrationResponse;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import com.google.inject.Inject;
@@ -61,6 +63,8 @@ public class AgentResource {
    * @response.representation.406.doc Error in register message format
    * @response.representation.408.doc Request Timed out
    * @param message Register message
+   * @throws InvalidStateTransitonException 
+   * @throws AmbariException 
    * @throws Exception
    */
   @Path("register/{hostName}")
@@ -69,7 +73,7 @@ public class AgentResource {
   @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
   public RegistrationResponse register(Register message,
       @Context HttpServletRequest req)
-      throws WebApplicationException {
+      throws WebApplicationException, AmbariException, InvalidStateTransitonException {
     LOG.info("Received message from agent " + message.toString());
     /* Call into the heartbeat handler */
     RegistrationResponse response = hh.handleRegistration(message);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
Mon Oct  1 18:16:28 2012
@@ -22,6 +22,7 @@ import org.apache.ambari.server.AmbariEx
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.live.host.HostEvent;
 import org.apache.ambari.server.state.live.host.HostState;
+import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostEvent;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostState;
 
@@ -37,7 +38,7 @@ public interface Cluster {
    * @throws AmbariException
    */
   public void addHost(String host) throws AmbariException;
-
+  
   /**
    * Add a new ServiceComponentHost to the cluster
    * @param serviceName
@@ -105,4 +106,7 @@ public interface Cluster {
       ServiceComponentHostEvent event)
           throws AmbariException, InvalidStateTransitonException;
 
+  public ServiceComponentHost getServiceComponentHost(String serviceName,
+      String componentName, String hostname) throws AmbariException;
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
Mon Oct  1 18:16:28 2012
@@ -55,7 +55,7 @@ public class ClusterImpl implements Clus
     return hosts.get(hostName);
   }
 
-  private ServiceComponentHost getServiceComponentHost(String serviceName,
+  public ServiceComponentHost getServiceComponentHost(String serviceName,
       String serviceComponentName, String hostName) throws AmbariException {
     if (!serviceComponentHosts.containsKey(serviceName)
         || !serviceComponentHosts.get(serviceName)

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
Mon Oct  1 18:16:28 2012
@@ -21,6 +21,7 @@ package org.apache.ambari.server.state.l
 import java.util.List;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.state.live.host.Host;
 import org.apache.ambari.server.state.live.host.HostState;
 
 public interface Clusters {
@@ -42,16 +43,22 @@ public interface Clusters {
 
   public void updateStatus(String hostname, String status);
 
-  public HostState getHostState(String host);
-
-  public List<String> getAllHosts();
-
-  public boolean isNodeActive(String hostname);
+  public List<Host> getAllHosts();
 
   public List<String> getHostComponents(String hostname);
 
   public void handleRegistration(String hostname);
 
-  public List<String> getClusters(String hostname);
+  /**
+   * Returns all the cluster names for this hostname.
+   * @param hostname
+   * @return List of cluster names
+   */
+  public List<Cluster> getClusters(String hostname);
+
+  /**
+   * Get a Host object
+   */
+  public Host getHost(String host) throws AmbariException;
 
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
Mon Oct  1 18:16:28 2012
@@ -24,7 +24,7 @@ import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
-import org.apache.ambari.server.state.live.host.HostState;
+import org.apache.ambari.server.state.live.host.Host;
 
 public class ClustersImpl implements Clusters {
 
@@ -68,37 +68,31 @@ public class ClustersImpl implements Clu
   }
 
   @Override
-  public HostState getHostState(String host) {
+  public List<Host> getAllHosts() {
     // TODO Auto-generated method stub
     return null;
   }
 
   @Override
-  public List<String> getAllHosts() {
+  public List<String> getHostComponents(String hostname) {
     // TODO Auto-generated method stub
     return null;
   }
 
   @Override
-  public boolean isNodeActive(String hostname) {
+  public void handleRegistration(String hostname) {
     // TODO Auto-generated method stub
-    return false;
+    
   }
 
   @Override
-  public List<String> getHostComponents(String hostname) {
+  public List<Cluster> getClusters(String hostname) {
     // TODO Auto-generated method stub
     return null;
   }
 
   @Override
-  public void handleRegistration(String hostname) {
-    // TODO Auto-generated method stub
-    
-  }
-
-  @Override
-  public List<String> getClusters(String hostname) {
+  public Host getHost(String host) throws AmbariException {
     // TODO Auto-generated method stub
     return null;
   }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/Host.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/Host.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/Host.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/Host.java
Mon Oct  1 18:16:28 2012
@@ -236,4 +236,10 @@ public interface Host {
    */
   public void handleEvent(HostEvent event)
       throws InvalidStateTransitonException;
+
+  /**
+   * Get time spent in the current state i.e. the time since last state change.
+   * @return Time spent in current state.
+   */
+  public long getTimeInState();
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
Mon Oct  1 18:16:28 2012
@@ -742,4 +742,10 @@ public class HostImpl implements Host {
     return null;
   }
 
+  @Override
+  public long getTimeInState() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java
Mon Oct  1 18:16:28 2012
@@ -43,14 +43,4 @@ public enum HostState {
    * any other additional means ( monitoring layer )
    */
   UNHEALTHY;
-
-  public long getTimeInState() {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  public long getLastHeartbeat() {
-    // TODO Auto-generated method stub
-    return 0;
-  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
Mon Oct  1 18:16:28 2012
@@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
 
 import junit.framework.Assert;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.agent.rest.AgentResource;
 import org.apache.ambari.server.state.live.Clusters;
@@ -66,9 +67,14 @@ public class AgentResourceTest extends J
       handler = mock(HeartBeatHandler.class);
       response.setResponseStatus(RegistrationStatus.OK);
       hresponse.setResponseId(0L);
-      when(handler.handleRegistration(any(Register.class))).thenReturn(
-          response);
-      when(handler.handleHeartBeat(any(HeartBeat.class))).thenReturn(hresponse);
+      try {
+        when(handler.handleRegistration(any(Register.class))).thenReturn(
+            response);
+        when(handler.handleHeartBeat(any(HeartBeat.class))).thenReturn(
+            hresponse);
+      } catch (Exception ex) {
+        // The test will fail anyway
+      }
       requestStaticInjection(AgentResource.class);
       bind(Clusters.class).to(ClustersImpl.class);
       actionManager = mock(ActionManager.class);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java?rev=1392493&r1=1392492&r2=1392493&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
Mon Oct  1 18:16:28 2012
@@ -25,6 +25,8 @@ import java.util.List;
 
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.state.live.Clusters;
+import org.apache.ambari.server.state.live.host.Host;
+import org.apache.ambari.server.state.live.host.HostEvent;
 import org.apache.ambari.server.state.live.host.HostState;
 import org.junit.Test;
 
@@ -36,10 +38,13 @@ public class TestHeartbeatMonitor {
     ActionQueue aq = new ActionQueue();
     ActionManager am = mock(ActionManager.class);
     HostState hs = HostState.WAITING_FOR_HOST_STATUS_UPDATES;
-    List<String> allHosts = new ArrayList<String>();
-    allHosts.add("host1");
+    List<Host> allHosts = new ArrayList<Host>();
+    Host hostObj = mock(Host.class);
+    allHosts.add(hostObj);
     when(fsm.getAllHosts()).thenReturn(allHosts);
-    when(fsm.getHostState("host1")).thenReturn(hs);
+    when(fsm.getHost("host1")).thenReturn(hostObj);
+    when(hostObj.getState()).thenReturn(hs);
+    when(hostObj.getHostName()).thenReturn("host1");
     aq.enqueue("host1", new ExecutionCommand());
     HeartbeatMonitor hm = new HeartbeatMonitor(fsm, aq, am, 100);
     hm.start();
@@ -47,7 +52,8 @@ public class TestHeartbeatMonitor {
     //Heartbeat must have expired for host1, action queue must be flushed
     assertEquals(0, aq.dequeueAll("host1").size());
     verify(am, times(1)).handleLostHost("host1");
-    verify(fsm, times(2)).updateStatus(eq("host1"), anyString());
+    verify(hostObj, times(1)).handleEvent(any(HostEvent.class));
+    verify(hostObj, times(1)).setState(HostState.INIT);
     hm.shutdown();
   }
 



Mime
View raw message