You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ji...@apache.org on 2012/10/03 01:36:26 UTC

svn commit: r1393238 - in /incubator/ambari/branches/AMBARI-666: AMBARI-666-CHANGES.txt ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java

Author: jitendra
Date: Tue Oct  2 23:36:26 2012
New Revision: 1393238

URL: http://svn.apache.org/viewvc?rev=1393238&view=rev
Log:
AMBARI-787. Registration throws HostNotFoundException for new hosts.

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/HeartBeatHandler.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.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=1393238&r1=1393237&r2=1393238&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Tue Oct  2 23:36:26 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-787. Registration throws HostNotFoundException for new hosts. (jitendra)
+
   AMBARI-788. Fix server and agent startup for end to end testing. (mahadev)
 
   AMBARI-785. Action response unit test. (jitendra)

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=1393238&r1=1393237&r2=1393238&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 Tue Oct  2 23:36:26 2012
@@ -122,6 +122,10 @@ public class HeartBeatHandler {
       throws InvalidStateTransitonException, AmbariException {
     String hostname = register.getHostname();
     long now = System.currentTimeMillis();
+    if (clusterFsm.getHost(hostname) == null) {
+      clusterFsm.addHost(hostname);
+    }
+    Host hostObject = clusterFsm.getHost(hostname);
     List<StatusCommand> cmds = new ArrayList<StatusCommand>();
     for (Cluster cl : clusterFsm.getClustersForHost(hostname)) {
       List<ServiceComponentHost> roleList = cl
@@ -134,7 +138,7 @@ public class HeartBeatHandler {
       statusCmd.setRoles(roles);
       cmds.add(statusCmd);
     }
-    Host hostObject = clusterFsm.getHost(hostname);
+    
     hostObject.handleEvent(new HostRegistrationRequestEvent(hostname,
         new AgentVersion("v1"), now, register.getHardwareProfile()));
     RegistrationResponse response = new RegistrationResponse();

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java?rev=1393238&r1=1393237&r2=1393238&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java Tue Oct  2 23:36:26 2012
@@ -26,6 +26,7 @@ import org.apache.ambari.server.actionma
 import org.apache.ambari.server.agent.HostStatus.Status;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.live.Clusters;
+import org.apache.ambari.server.state.live.ClustersImpl;
 import org.apache.ambari.server.state.live.host.Host;
 import org.apache.ambari.server.state.live.host.HostImpl;
 import org.apache.ambari.server.state.live.host.HostState;
@@ -76,5 +77,22 @@ public class TestHeartbeatHandler {
     assertEquals(hostObject.getState(), HostState.HEALTHY);
     assertEquals("MegaOperatingSystem", hostObject.getOsType());
   }
-
+  
+  @Test
+  public void testRegisterNewNode() throws AmbariException, InvalidStateTransitonException {
+    ActionManager am = new ActionManager(0, 0, null, null,
+        new ActionDBInMemoryImpl());
+    Clusters fsm = new ClustersImpl();
+    String hostname = "host1";
+    HeartBeatHandler handler = new HeartBeatHandler(fsm, new ActionQueue(), am);
+    Register reg = new Register();
+    HostInfo hi = new HostInfo();
+    hi.setOS("MegaOperatingSystem");
+    reg.setHostname(hostname);
+    reg.setHardwareProfile(hi);
+    handler.handleRegistration(reg);
+    Host hostObject = fsm.getHost(hostname);
+    assertEquals(hostObject.getState(), HostState.HEALTHY);
+    assertEquals("MegaOperatingSystem", hostObject.getOsType());
+  }
 }