You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2013/09/20 16:58:50 UTC

git commit: AMBARI-3297. Fix agent config handler to log parsing errors (ncole)

Updated Branches:
  refs/heads/branch-1.4.1 53ca7bd46 -> 6a99f1efe


AMBARI-3297. Fix agent config handler to log parsing errors (ncole)


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

Branch: refs/heads/branch-1.4.1
Commit: 6a99f1efe8a71823db24c614126d6186ec13f82f
Parents: 53ca7bd
Author: Nate Cole <nc...@hortonworks.com>
Authored: Fri Sep 20 10:14:42 2013 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Fri Sep 20 10:14:42 2013 -0400

----------------------------------------------------------------------
 .../main/python/ambari_agent/ActualConfigHandler.py  | 11 ++++++++++-
 .../src/test/python/TestActualConfigHandler.py       | 15 +++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6a99f1ef/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py b/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
index ff7220b..3adaf9a 100644
--- a/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
+++ b/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
@@ -56,9 +56,18 @@ class ActualConfigHandler:
     runDir = self.findRunDir()
     fullname = os.path.join(runDir, filename)
     if os.path.isfile(fullname):
+      res = None
       conf_file = open(os.path.join(runDir, filename), 'r')
-      res = json.load(conf_file)
+      try:
+        res = json.load(conf_file)
+        if (0 == len(res)):
+          res = None
+      except Exception, e:
+        logger.error("Error parsing " + filename + ": " + repr(e))
+        res = None
+        pass
       conf_file.close()
+
       return res
     return None
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6a99f1ef/ambari-agent/src/test/python/TestActualConfigHandler.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/TestActualConfigHandler.py b/ambari-agent/src/test/python/TestActualConfigHandler.py
index 4824dd0..2461499 100644
--- a/ambari-agent/src/test/python/TestActualConfigHandler.py
+++ b/ambari-agent/src/test/python/TestActualConfigHandler.py
@@ -41,6 +41,20 @@ class TestActualConfigHandler(TestCase):
     self.assertEquals(tags, output)
     os.remove(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME))
 
+  def test_read_empty(self):
+    config = AmbariConfig().getConfig()
+    tmpdir = tempfile.gettempdir()
+    config.set('agent', 'prefix', tmpdir)
+    handler = ActualConfigHandler(config)
+
+    conf_file = open(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME), 'w')
+    conf_file.write("")
+    conf_file.close()
+    
+    output = handler.read_actual()
+    self.assertEquals(None, output)
+    os.remove(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME))
+
   def test_read_write_component(self):
     config = AmbariConfig().getConfig()
     tmpdir = tempfile.gettempdir()
@@ -65,3 +79,4 @@ class TestActualConfigHandler(TestCase):
     self.assertEquals(tags2, output3)
     self.assertEquals(tags1, output4)
     os.remove(os.path.join(tmpdir, "FOO_" + ActualConfigHandler.CONFIG_NAME))
+    os.remove(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME))