Repository: ambari Updated Branches: refs/heads/trunk 492954e42 -> 0300a6aee
Revert "AMBARI-15674: Remove hdp specific logic from custom_actions scripts (jluniya)" This reverts commit 492954e42e631604fc02c7086d6036568b2a7fd7. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0300a6ae Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0300a6ae Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0300a6ae Branch: refs/heads/trunk Commit: 0300a6aee863274fc5fcb67a04d24bda78dc3847 Parents: 492954e Author: Jayush Luniya <jlun...@hortonworks.com> Authored: Mon Apr 4 15:05:26 2016 -0700 Committer: Jayush Luniya <jlun...@hortonworks.com> Committed: Mon Apr 4 15:05:26 2016 -0700 ---------------------------------------------------------------------- .../custom_actions/scripts/install_packages.py | 34 +++++++++------- .../custom_actions/scripts/ru_set_all.py | 42 +++++++++++--------- 2 files changed, 43 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0300a6ae/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py b/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py index c01dbb3..2e5cffc 100644 --- a/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py +++ b/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py @@ -36,13 +36,11 @@ from resource_management.libraries.functions.packages_analyzer import allInstall from resource_management.libraries.functions import conf_select from resource_management.libraries.functions import stack_tools from resource_management.libraries.functions.stack_select import get_stack_versions -from resource_management.libraries.functions.version import format_stack_version +from resource_management.libraries.functions.version import compare_versions, format_stack_version from resource_management.libraries.functions.repo_version_history \ import read_actual_version_from_history_file, write_actual_version_to_history_file, REPO_VERSION_HISTORY_FILE from resource_management.libraries.script.script import Script from resource_management.core.resources.system import Execute -from resource_management.libraries.functions.stack_features import check_stack_feature -from resource_management.libraries.functions import StackFeature from resource_management.core.logger import Logger @@ -56,6 +54,8 @@ class InstallPackages(Script): """ UBUNTU_REPO_COMPONENTS_POSTFIX = ["main"] + REPO_FILE_NAME_PREFIX = 'HDP-' + STACK_TO_ROOT_FOLDER = {"HDP": "/usr/hdp"} def actionexecute(self, env): num_errors = 0 @@ -91,12 +91,16 @@ class InstallPackages(Script): self.current_stack_version_formatted = format_stack_version(current_stack_version_unformatted) - self.stack_name = Script.get_stack_name() - if self.stack_name is None: - raise Fail("Cannot determine the stack name") - self.stack_root_folder = Script.get_stack_root() + stack_name = None + self.stack_root_folder = None + if stack_id and "-" in stack_id: + stack_split = stack_id.split("-") + if len(stack_split) == 2: + stack_name = stack_split[0].upper() + if stack_name in self.STACK_TO_ROOT_FOLDER: + self.stack_root_folder = self.STACK_TO_ROOT_FOLDER[stack_name] if self.stack_root_folder is None: - raise Fail("Cannot determine the stack's root directory") + raise Fail("Cannot determine the stack's root directory by parsing the stack_id property, {0}".format(str(stack_id))) if self.repository_version is None: raise Fail("Cannot determine the repository version to install") @@ -184,19 +188,21 @@ class InstallPackages(Script): Logger.info("Unrecognized stack id {0}, cannot create config links".format(stack_id)) return - target_stack_version = args[1] - if not (target_stack_version and check_stack_feature(StackFeature.CONFIG_VERSIONING, target_stack_version)): - Logger.info("Configuration symlinks are not needed for {0}".format(stack_version)) + if args[0] != "HDP": + Logger.info("Unrecognized stack name {0}, cannot create config links".format(args[0])) + + if compare_versions(format_stack_version(args[1]), "2.3.0.0") < 0: + Logger.info("Configuration symlinks are not needed for {0}, only HDP-2.3+".format(stack_version)) return for package_name, directories in conf_select.get_package_dirs().iteritems(): # if already on HDP 2.3, then we should skip making conf.backup folders - if self.current_stack_version_formatted and check_stack_feature(StackFeature.CONFIG_VERSIONING, self.current_stack_version_formatted): + if self.current_stack_version_formatted and compare_versions(self.current_stack_version_formatted, '2.3') >= 0: conf_selector_name = stack_tools.get_stack_tool_name(stack_tools.CONF_SELECTOR_NAME) Logger.info("The current cluster stack of {0} does not require backing up configurations; " "only {1} versioned config directories will be created.".format(stack_version, conf_selector_name)) # only link configs for all known packages - conf_select.select(self.stack_name, package_name, stack_version, ignore_errors = True) + conf_select.select("HDP", package_name, stack_version, ignore_errors = True) else: # link configs and create conf.backup folders for all known packages # this will also call conf-select select @@ -407,7 +413,7 @@ class InstallPackages(Script): repo['mirrorsList'] = url_info['mirrorsList'] ubuntu_components = [url_info['name']] + self.UBUNTU_REPO_COMPONENTS_POSTFIX - file_name = self.stack_name + "-" + self.repository_version + file_name = self.REPO_FILE_NAME_PREFIX + self.repository_version Repository(repo['repoName'], action = "create", http://git-wip-us.apache.org/repos/asf/ambari/blob/0300a6ae/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py b/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py index d70e87f..bcb08c4 100644 --- a/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py +++ b/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py @@ -28,13 +28,12 @@ from resource_management.libraries.functions import conf_select from resource_management.libraries.functions import stack_tools from resource_management.libraries.functions.constants import Direction from resource_management.libraries.functions.default import default +from resource_management.libraries.functions.version import compare_versions from resource_management.libraries.functions.version import format_stack_version from resource_management.core import shell from resource_management.core.exceptions import Fail from resource_management.core.logger import Logger from resource_management.core.resources.system import Execute, Link, Directory -from resource_management.libraries.functions.stack_features import check_stack_feature -from resource_management.libraries.functions import StackFeature class UpgradeSetAll(Script): """ @@ -56,17 +55,19 @@ class UpgradeSetAll(Script): cmd = ('/usr/bin/yum', 'clean', 'all') code, out = shell.call(cmd, sudo=True) + min_ver = format_stack_version("2.2") real_ver = format_stack_version(version) - if real_ver and check_stack_feature(StackFeature.ROLLING_UPGRADE, real_ver): - stack_selector_path = stack_tools.get_stack_tool_path(stack_tools.STACK_SELECTOR_NAME) - cmd = ('ambari-python-wrap', stack_selector_path, 'set', 'all', version) - code, out = shell.call(cmd, sudo=True) + if stack_name == "HDP": + if compare_versions(real_ver, min_ver) >= 0: + stack_selector_path = stack_tools.get_stack_tool_path(stack_tools.STACK_SELECTOR_NAME) + cmd = ('ambari-python-wrap', stack_selector_path, 'set', 'all', version) + code, out = shell.call(cmd, sudo=True) - if real_ver and check_stack_feature(StackFeature.CONFIG_VERSIONING, real_ver): - # backup the old and symlink /etc/[component]/conf to <stack-root>/current/[component] - for k, v in conf_select.get_package_dirs().iteritems(): - for dir_def in v: - link_config(dir_def['conf_dir'], dir_def['current_dir']) + if compare_versions(real_ver, format_stack_version("2.3")) >= 0: + # backup the old and symlink /etc/[component]/conf to <stack-root>/current/[component] + for k, v in conf_select.get_package_dirs().iteritems(): + for dir_def in v: + link_config(dir_def['conf_dir'], dir_def['current_dir']) def unlink_all_configs(self, env): @@ -84,27 +85,30 @@ class UpgradeSetAll(Script): Logger.warning("Unlinking configurations should only be performed on a downgrade.") return + # HDP only + if stack_name != "HDP": + Logger.warning("Unlinking configurations should only be performed on the HDP stack.") + return + if downgrade_to_version is None or downgrade_from_version is None: Logger.warning("Both 'commandParams/version' and 'commandParams/downgrade_from_version' must be specified to unlink configs on downgrade.") return - Logger.info("Unlinking all configs when downgrading from {0} {1} to {2}".format( - stack_name, downgrade_from_version, downgrade_to_version)) + Logger.info("Unlinking all configs when downgrading from HDP 2.3 to 2.2") # normalize the versions + stack_23 = format_stack_version("2.3") downgrade_to_version = format_stack_version(downgrade_to_version) downgrade_from_version = format_stack_version(downgrade_from_version) # downgrade-to-version must be 2.2 (less than 2.3) - if downgrade_to_version and check_stack_feature(StackFeature.CONFIG_VERSIONING, downgrade_to_version): - Logger.warning("Unlinking configurations should not be performed when downgrading {0} {1} to {2}".format( - stack_name, downgrade_from_version, downgrade_to_version)) + if compare_versions(downgrade_to_version, stack_23) >= 0: + Logger.warning("Unlinking configurations should only be performed when downgrading to HDP 2.2") return # downgrade-from-version must be 2.3+ - if not( downgrade_from_version and check_stack_feature(StackFeature.CONFIG_VERSIONING, downgrade_from_version) ): - Logger.warning("Unlinking configurations should not be performed when downgrading {0} {1} to {2}".format( - stack_name, downgrade_from_version, downgrade_to_version)) + if compare_versions(downgrade_from_version, stack_23) < 0: + Logger.warning("Unlinking configurations should only be performed when downgrading from HDP 2.3 or later") return # iterate through all directory conf mappings and undo the symlinks