ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlun...@apache.org
Subject [37/50] [abbrv] ambari git commit: AMBARI-22007 - Addition of service component after patching a service still keeps the component at base version (part2) (jonathanhurley)
Date Tue, 26 Sep 2017 05:20:28 GMT
AMBARI-22007 - Addition of service component after patching a service still keeps the component
at base version (part2) (jonathanhurley)


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

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 311c7bbd8ee94b8964a7f1769b41efc40ecdcdc6
Parents: eb5bcef
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Sep 25 08:45:58 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Mon Sep 25 08:51:38 2017 -0400

----------------------------------------------------------------------
 .../libraries/functions/version_select_util.py  |  7 ++--
 .../libraries/script/script.py                  | 36 ++++++++++++++++----
 .../src/test/python/TestVersionSelectUtil.py    |  4 +--
 3 files changed, 35 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/311c7bbd/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
b/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
index 9fbb42b..73b5dc1 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
@@ -28,10 +28,11 @@ from resource_management.core import shell
 from resource_management.libraries.functions import stack_tools
 
 
-def get_component_version(stack_name, component_name):
+def get_component_version_from_symlink(stack_name, component_name):
   """
-  For any stack name, returns the version currently installed for a given component.
-  Because each stack name may have different logic, the input is a generic dictionary.
+  Gets the version of the specified component by invoking the stack-select tool to query
for the
+  version which is referenced by the symlink.
+
   :param stack_name: one of HDP, HDPWIN, BIGTOP, PHD, etc. usually retrieved from
   the command-#.json file's ["hostLevelParams"]["stack_name"]
   :param component_name: Component name as a string necessary to get the version

http://git-wip-us.apache.org/repos/asf/ambari/blob/311c7bbd/ambari-common/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/script/script.py
b/ambari-common/src/main/python/resource_management/libraries/script/script.py
index 303b640..e612638 100644
--- a/ambari-common/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-common/src/main/python/resource_management/libraries/script/script.py
@@ -47,7 +47,7 @@ from resource_management.core.environment import Environment
 from resource_management.core.logger import Logger
 from resource_management.core.exceptions import Fail, ClientComponentHasNoStatus, ComponentIsNotRunning
 from resource_management.core.resources.packaging import Package
-from resource_management.libraries.functions.version_select_util import get_component_version
+from resource_management.libraries.functions.version_select_util import get_component_version_from_symlink
 from resource_management.libraries.functions.version import compare_versions
 from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions import stack_tools
@@ -207,18 +207,40 @@ class Script(object):
       return os.path.realpath(config_path)
     return None
 
-  def save_component_version_to_structured_out(self):
+  def save_component_version_to_structured_out(self, command_name):
     """
-    :param stack_name: One of HDP, HDPWIN, PHD, BIGTOP.
-    :return: Append the version number to the structured out.
+    Saves the version of the component for this command to the structured out file. If the
+    command is an install command and the repository is trusted, then it will use the version
of
+    the repository. Otherwise, it will consult the stack-select tool to read the symlink
version.
+    :param command_name: command name
+    :return: None
     """
+    from resource_management.libraries.functions.default import default
     from resource_management.libraries.functions import stack_select
 
+    repository_resolved = default("repositoryFile/resolved", False)
+    repository_version = default("repositoryFile/repoVersion", None)
+    is_install_command = command_name is not None and command_name.lower() == "install"
+
+    # start out with no version
+    component_version = None
+
+    # install command + trusted repo means use the repo version and don't consult stack-select
+    # this is needed in cases where an existing symlink is on the system and stack-select
can't
+    # change it on installation (because it's scared to in order to support parallel installs)
+    if is_install_command and repository_resolved and repository_version is not None:
+      Logger.info("The repository with version {0} for this command has been marked as resolved."\
+        " It will be used to report the version of the component which was installed".format(repository_version))
+
+      component_version = repository_version
+
     stack_name = Script.get_stack_name()
     stack_select_package_name = stack_select.get_package_name()
 
     if stack_select_package_name and stack_name:
-      component_version = get_component_version(stack_name, stack_select_package_name)
+      # only query for the component version from stack-select if we can't trust the repository
yet
+      if component_version is None:
+        component_version = get_component_version_from_symlink(stack_name, stack_select_package_name)
 
       if component_version:
         self.put_structured_out({"version": component_version})
@@ -336,7 +358,7 @@ class Script(object):
       raise
     finally:
       if self.should_expose_component_version(self.command_name):
-        self.save_component_version_to_structured_out()
+        self.save_component_version_to_structured_out(self.command_name)
 
   def execute_prefix_function(self, command_name, afix, env):
     """
@@ -938,7 +960,7 @@ class Script(object):
           self.post_rolling_restart(env)
 
     if self.should_expose_component_version("restart"):
-      self.save_component_version_to_structured_out()
+      self.save_component_version_to_structured_out("restart")
 
 
   # TODO, remove after all services have switched to post_upgrade_restart

http://git-wip-us.apache.org/repos/asf/ambari/blob/311c7bbd/ambari-server/src/test/python/TestVersionSelectUtil.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestVersionSelectUtil.py b/ambari-server/src/test/python/TestVersionSelectUtil.py
index 5195dca..82985fa 100644
--- a/ambari-server/src/test/python/TestVersionSelectUtil.py
+++ b/ambari-server/src/test/python/TestVersionSelectUtil.py
@@ -133,7 +133,7 @@ class TestVersionSelectUtil(TestCase):
     call_mock.side_effect = [(0, "value will come from MagicFile"), ] * 2
 
     # Pass
-    version = self.module.get_component_version("HDP", "hive-server2")
+    version = self.module.get_component_version_from_symlink("HDP", "hive-server2")
     self.assertEquals(version, stack_expected_version)
-    version = self.module.get_component_version("HDP", "zookeeper-server")
+    version = self.module.get_component_version_from_symlink("HDP", "zookeeper-server")
     self.assertEquals(version, stack_expected_version)


Mime
View raw message