ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject git commit: AMBARI-3770. Need better error log message when agent unable to reach server (Dmytro Shkvyra via dlysnichenko)
Date Fri, 15 Nov 2013 18:45:14 GMT
Updated Branches:
  refs/heads/trunk 16d4306a6 -> 6ccdcc836


AMBARI-3770. Need better error log message when agent unable to reach server (Dmytro Shkvyra
via dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/6ccdcc83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/6ccdcc83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/6ccdcc83

Branch: refs/heads/trunk
Commit: 6ccdcc836fb240fb99e0729dd1fdaa0b451dd8fb
Parents: 16d4306
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Fri Nov 15 20:44:02 2013 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Fri Nov 15 20:44:53 2013 +0200

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/Controller.py  |  8 ++++++-
 ambari-agent/src/test/python/TestController.py  | 22 ++++++++++----------
 .../server/agent/RegistrationResponse.java      |  7 +++++++
 .../ambari/server/agent/rest/AgentResource.java | 16 +++++++++++---
 4 files changed, 38 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6ccdcc83/ambari-agent/src/main/python/ambari_agent/Controller.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Controller.py b/ambari-agent/src/main/python/ambari_agent/Controller.py
index 7c51b5f..fbaf0c7 100644
--- a/ambari-agent/src/main/python/ambari_agent/Controller.py
+++ b/ambari-agent/src/main/python/ambari_agent/Controller.py
@@ -84,7 +84,13 @@ class Controller(threading.Thread):
         logger.info("Registering with the server " + pprint.pformat(data))
         response = self.sendRequest(self.registerUrl, data)
         ret = json.loads(response)
-
+        errors = None
+        if 'errors' in ret.keys():
+          errors = ret['errors']
+        print str(errors)
+        if not (errors == None or errors == ""):
+          logger.error(ret['errors'])
+          return ret
         logger.info("Registered with the server with " + pprint.pformat(ret))
         print("Registered with the server")
         self.responseId= int(ret['responseId'])

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6ccdcc83/ambari-agent/src/test/python/TestController.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/TestController.py b/ambari-agent/src/test/python/TestController.py
index 2b0e614..6a36115 100644
--- a/ambari-agent/src/test/python/TestController.py
+++ b/ambari-agent/src/test/python/TestController.py
@@ -55,12 +55,11 @@ class TestController(unittest.TestCase):
 
 
   @patch("json.dumps")
-  @patch("json.loads")
   @patch("time.sleep")
   @patch("pprint.pformat")
   @patch.object(Controller, "randint")
   def test_registerWithServer(self, randintMock, pformatMock, sleepMock,
-                              loadsMock, dumpsMock):
+                              dumpsMock):
 
     out = StringIO.StringIO()
     sys.stdout = out
@@ -68,19 +67,20 @@ class TestController(unittest.TestCase):
     register = MagicMock()
     self.controller.register = register
 
-    sendRequest = MagicMock()
-    self.controller.sendRequest = sendRequest
+    self.controller.sendRequest = MagicMock()
 
     dumpsMock.return_value = "request"
-    response = {"responseId":1,}
-    loadsMock.return_value = response
+    self.controller.sendRequest.return_value = '{"errors":"Error text"}'
+
+    self.assertEqual({'errors': 'Error text'}, self.controller.registerWithServer())
 
-    self.assertEqual(response, self.controller.registerWithServer())
+    self.controller.sendRequest.return_value = '{"responseId":1}'
+    self.assertEqual({"responseId":1}, self.controller.registerWithServer())
 
-    response["statusCommands"] = "commands"
+    self.controller.sendRequest.return_value = '{"responseId":1, "statusCommands": "commands"}'
     self.controller.addToQueue = MagicMock(name="addToQueue")
 
-    self.assertEqual(response, self.controller.registerWithServer())
+    self.assertEqual({"responseId":1, "statusCommands": "commands"}, self.controller.registerWithServer())
     self.controller.addToQueue.assert_called_with("commands")
 
     calls = []
@@ -91,10 +91,10 @@ class TestController(unittest.TestCase):
         raise Exception("test")
       return "request"
 
-    del response["statusCommands"]
+    self.controller.sendRequest.return_value = '{"responseId":1}'
 
     dumpsMock.side_effect = side_effect
-    self.assertEqual(response, self.controller.registerWithServer())
+    self.assertEqual({"responseId":1}, self.controller.registerWithServer())
     self.assertTrue(randintMock.called)
     self.assertTrue(sleepMock.called)
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6ccdcc83/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
b/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
index 5e466aa..6c4fd69 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/RegistrationResponse.java
@@ -30,6 +30,9 @@ import org.codehaus.jackson.annotate.JsonProperty;
 public class RegistrationResponse {
   @JsonProperty("response")
   private RegistrationStatus response;
+
+  @JsonProperty("errors")
+  private String errors;
   
   //Response id to start with, usually zero.
   @JsonProperty("responseId")
@@ -62,6 +65,10 @@ public class RegistrationResponse {
     this.responseId = responseId;
   }
 
+  public void setErrors(String errors) {
+    this.errors = errors;
+  }  
+  
   @Override
   public String toString() {
     return "RegistrationResponse{" +

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6ccdcc83/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
b/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
index 1aac28e..0fa24fd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
@@ -38,6 +38,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import com.google.inject.Inject;
+import org.apache.ambari.server.agent.RegistrationStatus;
 
 /**
  * Agent Resource represents Ambari agent controller.
@@ -75,11 +76,20 @@ public class AgentResource {
   @Produces({MediaType.APPLICATION_JSON})
   public RegistrationResponse register(Register message,
       @Context HttpServletRequest req)
-      throws WebApplicationException, AmbariException, InvalidStateTransitionException {
+      throws WebApplicationException, InvalidStateTransitionException {
     /* Call into the heartbeat handler */
 
-    RegistrationResponse response = hh.handleRegistration(message);
-    LOG.debug("Sending registration response " + response);
+    RegistrationResponse response = null;
+    try {
+      response = hh.handleRegistration(message);
+      LOG.debug("Sending registration response " + response);
+    } catch (AmbariException ex) {
+      response = new RegistrationResponse();
+      response.setResponseId(-1);
+      response.setResponseStatus(RegistrationStatus.FAILED);
+      response.setErrors(ex.getMessage());
+      return response;
+    }
     return response;
   }
 


Mime
View raw message