Ver código fonte

AMBARI-725. Add commandstatus/result/error objects into the rest API between server and agent. (mahadev)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1384161 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 12 anos atrás
pai
commit
be60c7ca2f
26 arquivos alterados com 375 adições e 122 exclusões
  1. 3 0
      AMBARI-666-CHANGES.txt
  2. 57 15
      ambari-agent/src/main/python/ambari_agent/Controller.py
  3. 6 10
      ambari-agent/src/main/python/ambari_agent/Heartbeat.py
  4. 51 0
      ambari-agent/src/main/python/ambari_agent/Register.py
  5. 7 2
      ambari-project/pom.xml
  6. 4 0
      ambari-server/pom.xml
  7. 19 1
      ambari-server/src/main/java/org/apache/ambari/server/agent/AgentCommand.java
  8. 46 0
      ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java
  9. 36 0
      ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java
  10. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/agent/DiskInfo.java
  11. 18 0
      ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
  12. 10 42
      ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeat.java
  13. 16 5
      ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
  14. 15 9
      ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatResponse.java
  15. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/agent/HostInfo.java
  16. 41 0
      ambari-server/src/main/java/org/apache/ambari/server/agent/HostStatus.java
  17. 7 7
      ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java
  18. 6 6
      ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
  19. 7 7
      ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationStatus.java
  20. 10 7
      ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
  21. 2 1
      ambari-server/src/main/java/org/apache/ambari/server/api/rest/HealthCheck.java
  22. 1 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
  23. 3 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
  24. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeImpl.java
  25. 3 3
      ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeRegistrationRequestEvent.java
  26. 3 3
      ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java

+ 3 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-725. Add commandstatus/result/error objects into the rest API between
+  server and agent. (mahadev)
+
   AMBARI-723. Implement Installer Welcome page and Install Options page
  (Jaimin Jetly via yusaku)
 

+ 57 - 15
ambari-agent/src/main/python/ambari_agent/Controller.py

@@ -29,7 +29,9 @@ import threading
 import urllib2
 from urllib2 import Request, urlopen, URLError
 import AmbariConfig
+import pprint
 from Heartbeat import Heartbeat
+from Register import Register
 from ActionQueue import ActionQueue
 from optparse import OptionParser
 from wsgiref.simple_server import ServerHandler
@@ -50,48 +52,88 @@ class Controller(threading.Thread):
     #  self.credential = { 'user' : config.get('controller', 'user'),
     #                      'password' : config.get('controller', 'password')
     #  }
-    self.url = config.get('server', 'url') + '/agent/register/' + socket.gethostname()
-
+    self.hostname = socket.gethostname()
+    self.registerUrl = config.get('server', 'url') + \
+      '/agent/register/' + self.hostname
+    self.heartbeatUrl = config.get('server', 'url') + \
+       '/agent/heartbeat/' + self.hostname
+     
   def start(self):
     self.actionQueue = ActionQueue(self.config)
     self.actionQueue.start()
+    self.register = Register()
     self.heartbeat = Heartbeat(self.actionQueue)
-
+    pass
+  
   def __del__(self):
     logger.info("Server connection disconnected.")
-
-  def run(self):
-    id='-1'
-    opener = urllib2.build_opener()
-    urllib2.install_opener(opener)
+    pass
+  
+  def registerWithServer(self):
     retry=False
     firstTime=True
+    registered=False
+    id = -1
+    ret = {}
+    while registered == False:
+      try:
+        data = json.dumps(self.register.build(id))
+        req = urllib2.Request(self.registerUrl, data, {'Content-Type': 
+                                                      'application/json'})
+        stream = urllib2.urlopen(req)
+        response = stream.read()
+        stream.close()
+        ret = json.loads(response)
+        logger.info("Registered with the server with " + pprint.pformat(ret))
+        registered = True
+        pass
+      except Exception, err:
+        logger.info("Unable to connect to: " + self.registerUrl, exc_info = True)
+        """ sleep for 30 seconds and then retry again """
+        time.sleep(30)
+        pass
+      pass  
+    return ret
+  
+  def heartbeatWithServer(self):
+    retry = False
+    #TODO make sure the response id is monotonically increasing
+    id = 0
     while True:
       try:
         if retry==False:
           data = json.dumps(self.heartbeat.build(id))
-        req = urllib2.Request(self.url, data, {'Content-Type': 'application/json'})
+        req = urllib2.Request(self.heartbeatUrl, data, {'Content-Type': 'application/json'})
         f = urllib2.urlopen(req)
         response = f.read()
         f.close()
         data = json.loads(response)
         id=int(data['responseId'])
-        self.actionQueue.put(data)
-        if retry==True or firstTime==True:
-          logger.info("Controller connection established")
-          firstTime=False
+        logger.info("HeartBeat Response from Server: \n" + pprint.pformat(data))
         retry=False
       except Exception, err:
         retry=True
         if "code" in err:
           logger.error(err.code)
         else:
-          logger.error("Unable to connect to: "+self.url,exc_info=True)
+          logger.error("Unable to connect to: "+self.heartbeatUrl,exc_info=True)
       if self.actionQueue.isIdle():
         time.sleep(30)
       else:
-        time.sleep(1)
+        time.sleep(1) 
+    pass
+  
 
+  def run(self):
+    opener = urllib2.build_opener()
+    urllib2.install_opener(opener)
+    
+    registerResponse = self.registerWithServer()
+    message = registerResponse['response']
+    logger.info("Response from server = " + message)
+    self.heartbeatWithServer()
+    pass
+    
 def main(argv=None):
   # Allow Ctrl-C
   signal.signal(signal.SIGINT, signal.SIG_DFL)

+ 6 - 10
ambari-agent/src/main/python/ambari_agent/Heartbeat.py

@@ -30,7 +30,8 @@ class Heartbeat:
 
   def __init__(self, actionQueue):
     self.actionQueue = actionQueue
-    self.hardware = Hardware()
+    self.reports = []
+    self.componentStatus = []
 
   def build(self, id='-1'):
     global clusterId, clusterDefinitionRevision, firstContact
@@ -41,16 +42,11 @@ class Heartbeat:
     heartbeat = { 'responseId'        : int(id),
                   'timestamp'         : timestamp,
                   'hostname'          : socket.gethostname(),
-                  'hardwareProfile'   : self.hardware.get(),
-                  'idle'              : self.actionQueue.isIdle(),
-                  'installScriptHash' : self.actionQueue.getInstallScriptHash(),
-                  'firstContact'      : firstContact
+                  'reports'           : self.reports,
+                  'componentStatus'   : self.componentStatus
                 }
-    if len(queueResult)!=0:
-      heartbeat['actionResults'] = queueResult
-    if len(installedRoleStates)!=0:
-      heartbeat['installedRoleStates'] = installedRoleStates
-    firstContact = False
+  
+    
     return heartbeat
 
 def main(argv=None):

+ 51 - 0
ambari-agent/src/main/python/ambari_agent/Register.py

@@ -0,0 +1,51 @@
+#!/usr/bin/env python2.6
+
+'''
+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.
+'''
+
+import json
+from Hardware import Hardware
+from ActionQueue import ActionQueue
+from ServerStatus import ServerStatus
+import socket
+import time
+
+
+firstContact = True
+class Register:
+  """ Registering with the server. Get the hardware profile and 
+  declare success for now """
+  def __init__(self):
+    self.hardware = Hardware()
+
+  def build(self, id='-1'):
+    global clusterId, clusterDefinitionRevision, firstContact
+    timestamp = int(time.time()*1000)
+    register = { 'responseId'        : int(id),
+                  'timestamp'         : timestamp,
+                  'hostname'          : socket.gethostname(),
+                  'hardwareProfile'   : self.hardware.get(),
+                }
+    return register
+  
+def main(argv=None):
+  register = Register()
+  print json.dumps(register.build())
+
+if __name__ == '__main__':
+  main()

+ 7 - 2
ambari-project/pom.xml

@@ -78,7 +78,7 @@
               </execution>
             </executions>
           </plugin>
-       </plugins>
+        </plugins>
       </build>
     </profile>
   </profiles>
@@ -114,7 +114,7 @@
         <artifactId>postgresql</artifactId>
         <version>9.1-901.jdbc4</version>
       </dependency>
-      <dependency>
+     <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</artifactId>
         <version>1.8.5</version>
@@ -174,6 +174,11 @@
         <artifactId>jersey-test-framework-external</artifactId>
         <version>1.8</version>
       </dependency>
+      <dependency>
+        <groupId>com.sun.jersey.contribs</groupId>
+        <artifactId>jersey-guice</artifactId>
+        <version>1.8</version>
+      </dependency>
       <dependency>
         <groupId>log4j</groupId>
         <artifactId>log4j</artifactId>

+ 4 - 0
ambari-server/pom.xml

@@ -124,6 +124,10 @@
     <dependency>
       <groupId>com.sun.jersey.contribs</groupId>
       <artifactId>jersey-multipart</artifactId>
+    </dependency>
+     <dependency>
+      <groupId>com.sun.jersey.contribs</groupId>
+      <artifactId>jersey-guice</artifactId>
     </dependency>
     <dependency>
       <groupId>com.sun.jersey.jersey-test-framework</groupId>

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

@@ -17,6 +17,24 @@
  */
 package org.apache.ambari.server.agent;
 
-public class AgentCommand {
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
+public abstract class AgentCommand {
+  @XmlElement
   private String commandId;
+  
+  public String getCommandId() {
+    return this.commandId;
+  }
+  
+  public void setCommandId(String commandId) {
+    this.commandId = commandId;
+  }
 }

+ 46 - 0
ambari-server/src/main/java/org/apache/ambari/server/agent/CommandReport.java

@@ -17,10 +17,56 @@
  */
 package org.apache.ambari.server.agent;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
 public class CommandReport {
+  @XmlElement
   String actionId;
+  @XmlElement
   String stdout;
+  @XmlElement
   String stderr;
+  @XmlElement
   String status;
+  @XmlElement
   int exitCode;
+ 
+  public String getActionId() {
+    return this.actionId;
+  }
+ 
+  public void setActionId(String actionId) {
+    this.actionId = actionId;
+  }
+  
+  public String getStdErr() {
+    return this.stderr;
+  }
+  
+  public void setStdErr(String stderr) {
+    this.stderr = stderr;
+  }
+  
+  public int getExitCode() {
+    return this.exitCode;
+  }
+  
+  public void setExitCode(int exitCode) {
+    this.exitCode = exitCode;
+  }
+  
+  public String getStdOut() {
+    return this.stdout;
+  }
+  
+  public void setStdOut(String stdout) {
+    this.stdout = stdout;
+  }
 }

+ 36 - 0
ambari-server/src/main/java/org/apache/ambari/server/agent/ComponentStatus.java

@@ -17,8 +17,44 @@
  */
 package org.apache.ambari.server.agent;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
 public class ComponentStatus {
+  @XmlElement
   String componentName;
+  @XmlElement
   String msg;
+  @XmlElement
   String status;
+
+  public String getComponentName() {
+    return this.componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+  
+  public String getMessage() {
+    return this.msg;
+  }
+  
+  public void setMessage(String msg) {
+    this.msg = msg;
+  }
+  
+  public String getStatus() {
+    return this.status;
+  }
+  
+  public void setStatus(String status) {
+    this.status = status;
+  }
 }

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

@@ -65,7 +65,7 @@ public class DiskInfo {
   }
 
   /**
-   * Needed for JAXB
+   * Needed for Serialization
    */
   public DiskInfo() {}
 

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java

@@ -17,6 +17,24 @@
  */
 package org.apache.ambari.server.agent;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
 public class ExecutionCommand extends AgentCommand {
+  @XmlElement
   String manifest;
+  
+  public String getManifest() {
+    return this.manifest;
+  }
+  
+  public void setManifest(String manifest) {
+    this.manifest = manifest;
+  }
 }

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

@@ -1,4 +1,4 @@
-/*
+/**
  * 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
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.agent;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
@@ -34,35 +35,26 @@ import javax.xml.bind.annotation.XmlType;
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "", propOrder = {"responseId","timestamp",
-    "hostname", "hardwareProfile", "installedRoleStates", "installScriptHash",
-    "actionResults", "firstContact", "idle"})
+@XmlType(name = "", propOrder = {})
 public class HeartBeat {
-  //TODO add serialization
-  List<CommandReport> reports;
-  //TODO add serialization
-  List<ComponentStatus> componentStatus;
-  //TODO add serialization
-  NodeStatus nodeStatus;
-
   @XmlElement
-  private short responseId = -1;
+  private long responseId = -1;
   @XmlElement
   private long timestamp;
   @XmlElement
   private String hostname;
   @XmlElement
-  private int installScriptHash;
+  List<CommandReport> reports = new ArrayList<CommandReport>();
   @XmlElement
-  private boolean firstContact;
+  List<ComponentStatus> componentStatus = new ArrayList<ComponentStatus>();
   @XmlElement
-  private boolean idle;
-
-  public short getResponseId() {
+  HostStatus nodeStatus;
+  
+  public long getResponseId() {
     return responseId;
   }
 
-  public void setResponseId(short responseId) {
+  public void setResponseId(long responseId) {
     this.responseId=responseId;
   }
 
@@ -74,18 +66,6 @@ public class HeartBeat {
     return hostname;
   }
 
-  public boolean getFirstContact() {
-    return firstContact;
-  }
-
-  public boolean getIdle() {
-    return idle;
-  }
-
-  public int getInstallScriptHash() {
-    return installScriptHash;
-  }
-
   public void setTimestamp(long timestamp) {
     this.timestamp = timestamp;
   }
@@ -93,16 +73,4 @@ public class HeartBeat {
   public void setHostname(String hostname) {
     this.hostname = hostname;
   }
-
-  public void setFirstContact(boolean firstContact) {
-    this.firstContact = firstContact;
-  }
-
-  public void setIdle(boolean idle) {
-    this.idle = idle;
-  }
-
-  public void setInstallScriptHash(int hash) {
-    this.installScriptHash = hash;
-  }
 }

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

@@ -17,17 +17,28 @@
  */
 package org.apache.ambari.server.agent;
 
-import org.apache.ambari.server.agent.rest.HeartBeatResponse;
+import java.util.ArrayList;
+
+import com.google.inject.Singleton;
+
 
 /**
  * This class handles the heartbeats coming from the agent, passes on the information
  * to other modules and processes the queue to send heartbeat response.
  */
+@Singleton
 public class HeartBeatHandler {
-  private String lastCompletedActionId;
-
   public HeartBeatResponse handleHeartBeat(HeartBeat heartbeat) {
-    System.out.println(heartbeat.toString());
-    return null;
+    HeartBeatResponse response = new HeartBeatResponse();
+    response.setAgentCommands(new ArrayList<AgentCommand>());
+    response.setClusterId("test");
+    response.setResponseId(999L);
+    return response;    
+  }
+  
+  public RegistrationResponse handleRegistration(Register register) {
+    RegistrationResponse registrationResponse = new RegistrationResponse();
+    registrationResponse.setResponseStatus(RegistrationStatus.OK);
+    return registrationResponse;
   }
 }

+ 15 - 9
ambari-server/src/main/java/org/apache/ambari/server/agent/rest/HeartBeatResponse.java → ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatResponse.java

@@ -16,8 +16,9 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.server.agent.rest;
+package org.apache.ambari.server.agent;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
@@ -26,7 +27,6 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
-import org.apache.ambari.server.agent.AgentCommand;
 
 
 /**
@@ -39,19 +39,18 @@ import org.apache.ambari.server.agent.AgentCommand;
 @XmlType(name = "", propOrder = {})
 public class HeartBeatResponse {
 
-  String lastCompletedActionId;
   @XmlElement
-  public short responseId;
+  private long responseId;
   @XmlElement
-  public String clusterId;
-
-  List<AgentCommand> cmds = null;
+  private String clusterId;
+  @XmlElement
+  List<AgentCommand> cmds = new ArrayList<AgentCommand>();
 
-  public short getResponseId() {
+  public long getResponseId() {
     return responseId;
   }
 
-  public void setResponseId(short responseId) {
+  public void setResponseId(long responseId) {
     this.responseId=responseId;
   }
 
@@ -63,4 +62,11 @@ public class HeartBeatResponse {
     this.clusterId = clusterId;
   }
 
+  public List<AgentCommand> getAgentCommands() {
+    return this.cmds;
+  }
+  
+  public void setAgentCommands(List<AgentCommand> cmds) {
+    this.cmds = cmds;
+  }
 }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/agent/NodeInfo.java → ambari-server/src/main/java/org/apache/ambari/server/agent/HostInfo.java

@@ -35,7 +35,7 @@ import javax.xml.bind.annotation.XmlType;
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {})
-public class NodeInfo {
+public class HostInfo {
   @XmlElement
   private String architecture;
   @XmlElement

+ 41 - 0
ambari-server/src/main/java/org/apache/ambari/server/agent/HostStatus.java

@@ -0,0 +1,41 @@
+/**
+ * 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.agent;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
+public class HostStatus {
+  @XmlType
+  @XmlEnum
+  public enum Status {
+    HEALTHY,
+    UNHEALTHY
+  }
+  @XmlElement
+  Status status;
+  @XmlElement
+  String cause;
+}

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

@@ -43,8 +43,8 @@ public class Register {
   @XmlElement
   private String hostname;
   @XmlElement
-  private NodeInfo hardwareProfile;
-
+  private HostInfo hardwareProfile;
+  
   public short getResponseId() {
     return responseId;
   }
@@ -60,8 +60,8 @@ public class Register {
   public String getHostname() {
     return hostname;
   }
-
-  public NodeInfo getHardwareProfile() {
+ 
+  public HostInfo 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;
+ 
+  public void setHardwareProfile(HostInfo hardwareProfile) {
+    this.hardwareProfile = hardwareProfile;    
   }
 
   @Override

+ 6 - 6
ambari-server/src/main/java/org/apache/ambari/server/agent/rest/RegistrationResponse.java → ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java

@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.server.agent.rest;
+package org.apache.ambari.server.agent;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -34,14 +34,14 @@ import javax.xml.bind.annotation.XmlType;
 @XmlType(name = "", propOrder = {})
 public class RegistrationResponse {
   @XmlElement
-  public short responseId;
+  public RegistrationStatus response;
 
 
-  public short getResponseId() {
-    return responseId;
+  public RegistrationStatus getResponseStatus() {
+    return response;
   }
 
-  public void setResponseId(short responseId) {
-    this.responseId=responseId;
+  public void setResponseStatus(RegistrationStatus response) {
+    this.response = response;
   }
 }

+ 7 - 7
ambari-server/src/main/java/org/apache/ambari/server/agent/NodeStatus.java → ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationStatus.java

@@ -17,12 +17,12 @@
  */
 package org.apache.ambari.server.agent;
 
-public class NodeStatus {
-  public enum Status {
-    HEALTHY,
-    UNHEALTHY
-  }
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlType;
 
-  Status status;
-  String cause;
+@XmlType(name="registrationstatus")
+@XmlEnum
+public enum RegistrationStatus {
+  OK,
+  FAILED
 }

+ 10 - 7
ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java

@@ -29,7 +29,9 @@ import javax.ws.rs.core.MediaType;
 
 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.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -47,10 +49,10 @@ public class AgentResource {
   private static Log LOG = LogFactory.getLog(AgentResource.class);
 
   @Inject
-  static void setHandler(HeartBeatHandler handler) {
-    hh = handler;
+  static void init(HeartBeatHandler instance) {
+    hh = instance;
   }
-
+  
   /**
    * Register information about the host (Internal API to be used for
    * Ambari Agent)
@@ -69,9 +71,9 @@ public class AgentResource {
   public RegistrationResponse register(Register message,
       @Context HttpServletRequest req)
       throws WebApplicationException {
-    LOG.info("Post input = " + req.toString());
-    RegistrationResponse response = new RegistrationResponse();
     LOG.info("Received message from agent " + message.toString());
+    /* Call into the heartbeat handler */
+    RegistrationResponse response = hh.handleRegistration(message);
     return response;
   }
 
@@ -86,15 +88,16 @@ public class AgentResource {
    * @param message Heartbeat message
    * @throws Exception
    */
-  @Path("heartbeat/{hostname}")
+  @Path("heartbeat/{hostName}")
   @POST
   @Consumes(MediaType.APPLICATION_JSON)
   @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
   public HeartBeatResponse heartbeat(HeartBeat message)
       throws WebApplicationException {
+    LOG.info("Received Heartbeat message " + message);
     HeartBeatResponse heartBeatResponse = new HeartBeatResponse();
     try {
-      heartBeatResponse = new HeartBeatResponse();
+      heartBeatResponse = hh.handleHeartBeat(message);
     } catch (Exception e) {
       LOG.info("Error in HeartBeat", e);
       throw new WebApplicationException(500);

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/api/rest/HealthCheck.java

@@ -30,8 +30,9 @@ import javax.ws.rs.core.MediaType;
 
 @Path("/check")
 public class HealthCheck {
-  private static final String status = "RUNNING";
+  private  final String status = "RUNNING";
   // This method is called if TEXT_PLAIN is request
+ 
   @GET
   @Produces(MediaType.TEXT_PLAIN)
   public String plainTextCheck() {

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

@@ -21,6 +21,7 @@ package org.apache.ambari.server.controller;
 
 import java.io.IOException;
 
+import org.apache.ambari.server.agent.HeartBeatHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.mortbay.jetty.Server;

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java

@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 package org.apache.ambari.server.controller;
+import org.apache.ambari.server.agent.rest.AgentResource;
+
 import com.google.inject.AbstractModule;
 
 /**
@@ -26,5 +28,6 @@ public class ControllerModule extends AbstractModule {
 
   @Override
   protected void configure() {
+    requestStaticInjection(AgentResource.class);
   }
 }

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

@@ -27,7 +27,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.ambari.server.agent.DiskInfo;
-import org.apache.ambari.server.agent.NodeInfo;
+import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.fsm.SingleArcTransition;
 import org.apache.ambari.server.state.fsm.StateMachine;
@@ -299,7 +299,7 @@ public class NodeImpl implements Node {
     }
   }
 
-  void importNodeInfo(NodeInfo nodeInfo) {
+  void importNodeInfo(HostInfo nodeInfo) {
     try {
       writeLock.lock();
       this.hostName = nodeInfo.getHostName();

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeRegistrationRequestEvent.java

@@ -18,19 +18,19 @@
 
 package org.apache.ambari.server.state.live.node;
 
-import org.apache.ambari.server.agent.NodeInfo;
+import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.state.live.AgentVersion;
 
 public class NodeRegistrationRequestEvent extends NodeEvent {
 
   final long registrationTime;
 
-  final NodeInfo nodeInfo;
+  final HostInfo nodeInfo;
 
   final AgentVersion agentVersion;
 
   public NodeRegistrationRequestEvent(String nodeName,
-      AgentVersion agentVersion, long registrationTime, NodeInfo nodeInfo) {
+      AgentVersion agentVersion, long registrationTime, HostInfo nodeInfo) {
     super(nodeName, NodeEventType.NODE_REGISTRATION_REQUEST);
     this.registrationTime = registrationTime;
     this.nodeInfo = nodeInfo;

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

@@ -24,7 +24,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.ambari.server.agent.DiskInfo;
-import org.apache.ambari.server.agent.NodeInfo;
+import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.state.live.AgentVersion;
 import org.apache.ambari.server.state.live.node.NodeHealthStatus.HealthStatus;
 import org.junit.Assert;
@@ -34,7 +34,7 @@ public class TestNodeImpl {
 
   @Test
   public void testNodeInfoImport() {
-    NodeInfo info = new NodeInfo();
+    HostInfo info = new HostInfo();
     info.setMemorySize(100);
     info.setProcessorCount(10);
     List<DiskInfo> mounts = new ArrayList<DiskInfo>();
@@ -61,7 +61,7 @@ public class TestNodeImpl {
   }
 
   private void registerNode(NodeImpl node) throws Exception {
-    NodeInfo info = new NodeInfo();
+    HostInfo info = new HostInfo();
     info.setMemorySize(100);
     info.setProcessorCount(10);
     List<DiskInfo> mounts = new ArrayList<DiskInfo>();