ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-20822 Ambari Agent needs to handle custom version number like 1.2.3.4_Company in its Controller code (dili)
Date Tue, 25 Apr 2017 16:01:29 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 26484a8f7 -> 04a539279


AMBARI-20822 Ambari Agent needs to handle custom version number like 1.2.3.4_Company in its
Controller code (dili)


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

Branch: refs/heads/trunk
Commit: 04a5392791548a5341b705f869094adc0b5f58fa
Parents: 26484a8
Author: Di Li <dili@apache.org>
Authored: Tue Apr 25 12:01:01 2017 -0400
Committer: Di Li <dili@apache.org>
Committed: Tue Apr 25 12:01:01 2017 -0400

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/Controller.py    | 18 ++++++++++++++----
 .../test/python/ambari_agent/TestController.py    | 14 ++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/04a53927/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 78b5c0c..0297f74 100644
--- a/ambari-agent/src/main/python/ambari_agent/Controller.py
+++ b/ambari-agent/src/main/python/ambari_agent/Controller.py
@@ -29,6 +29,7 @@ import threading
 import urllib2
 import pprint
 from random import randint
+import re
 import subprocess
 import functools
 
@@ -587,7 +588,9 @@ class Controller(threading.Thread):
     Stack Upgrade.
     """
     try:
-      if compare_versions(self.version, "2.1.2") >= 0:
+      version = self.get_version()
+      logger.debug("Ambari Agent version {0}".format(version))
+      if compare_versions(version, "2.1.2") >= 0:
         source_file = "/etc/hadoop/conf/dfs_data_dir_mount.hist"
         destination_file = "/var/lib/ambari-agent/data/datanode/dfs_data_dir_mount.hist"
         if os.path.exists(source_file) and not os.path.exists(destination_file):
@@ -601,9 +604,16 @@ class Controller(threading.Thread):
           return_code = subprocess.call(command, shell=True)
           logger.info("Return code: %d" % return_code)
     except Exception, e:
-      logger.info("Exception in move_data_dir_mount_file(). Error: {0}".format(str(e)))
-
-
+      logger.error("Exception in move_data_dir_mount_file(). Error: {0}".format(str(e)))
+
+  def get_version(self):
+    version = self.version
+    matches = re.findall(r"[\d+.]+",version)
+    if not matches:
+      logger.warning("No version match result, use original version {0}".format(version))
+      return version
+    else:
+      return matches[0]
 
 def main(argv=None):
   # Allow Ctrl-C

http://git-wip-us.apache.org/repos/asf/ambari/blob/04a53927/ambari-agent/src/test/python/ambari_agent/TestController.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestController.py b/ambari-agent/src/test/python/ambari_agent/TestController.py
index 7f5d451..20da81f 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestController.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestController.py
@@ -416,6 +416,20 @@ class TestController(unittest.TestCase):
                         exceptionMessage, str(e))
 
 
+  def test_getVersion(self):
+    self.controller.version = "1.2.3.4_MyAgent"
+    version = self.controller.get_version()
+    self.assertEquals('1.2.3.4', version)
+    self.controller.version = "1.2.3-MyAgent"
+    version = self.controller.get_version()
+    self.assertEquals('1.2.3', version)
+    self.controller.version = "11.2.3-MyAgent"
+    version = self.controller.get_version()
+    self.assertEquals('11.2.3', version)
+    self.controller.version = "11.2.13.10_MyAgent"
+    version = self.controller.get_version()
+    self.assertEquals('11.2.13.10', version)
+
   @patch.object(ExitHelper, "exit")
   @patch.object(threading._Event, "wait")
   @patch("time.sleep")


Mime
View raw message