ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-17796 - Ranger Admin Fails To Stop Or Start During Downgrade From HDP 2.5 to HDP 2.4 (jonathanhurley)
Date Tue, 19 Jul 2016 21:14:30 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 b855963da -> c30054463


AMBARI-17796 - Ranger Admin Fails To Stop Or Start During Downgrade From HDP 2.5 to HDP 2.4
(jonathanhurley)


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

Branch: refs/heads/branch-2.4
Commit: c30054463495a5d11ea615fc6b0a4ea357c8b16a
Parents: b855963
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Tue Jul 19 14:33:41 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Jul 19 17:12:43 2016 -0400

----------------------------------------------------------------------
 .../libraries/functions/stack_features.py       | 115 +++++++++++
 .../ATLAS/0.1.0.2.3/package/scripts/params.py   |   4 +-
 .../0.96.0.2.0/package/scripts/params_linux.py  |   5 +-
 .../2.1.0.2.0/package/scripts/params_linux.py   |   7 +-
 .../0.12.0.2.0/package/scripts/params_linux.py  |   6 +-
 .../KAFKA/0.8.1/package/scripts/params.py       |   6 +-
 .../0.5.0.2.2/package/scripts/params_linux.py   |   7 +-
 .../RANGER/0.4.0/package/scripts/params.py      |   4 +-
 .../0.5.0.2.3/package/scripts/params.py         |   4 +-
 .../STORM/0.9.1/package/scripts/params_linux.py |   7 +-
 .../2.1.0.2.0/package/scripts/params_linux.py   |   5 +-
 .../src/test/python/TestStackFeature.py         | 198 +++++++++++++++++++
 12 files changed, 350 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py
b/ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py
index 5db1718..2b3df5f 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py
@@ -22,6 +22,14 @@ limitations under the License.
 import ambari_simplejson as json
 from resource_management.core.exceptions import Fail
 from resource_management.core.logger import Logger
+from resource_management.libraries.functions.constants import Direction
+
+# executionCommand for STOP
+_ROLE_COMMAND_STOP = 'STOP'
+
+# executionCommand for a custom command (which could be STOP)
+_ROLE_COMMAND_CUSTOM = 'CUSTOM_COMMAND'
+
 
 def check_stack_feature(stack_feature, stack_version):
   """
@@ -57,3 +65,110 @@ def check_stack_feature(stack_feature, stack_version):
     raise Fail("Stack features not defined by stack")
         
   return False
+
+
+def get_stack_feature_version(config):
+  """
+  Uses the specified ConfigDictionary to determine which version to use for stack
+  feature checks.
+
+  Normally, the commandParams/version is the correct value to use as it represent the 4-digit
+  exact stack version/build being upgrade to or downgraded to. However, there are cases where
the
+  commands being sent are to stop running services which are on a different stack version
from the
+  version being upgraded/downgraded to. As a result, the configurations sent for these specific
+  stop commands do not match commandParams/version.
+  :param config:  a ConfigDictionary instance to extra the hostLevelParams
+                  and commandParams from.
+  :return: the version to use when checking stack features.
+  """
+  from resource_management.libraries.functions.default import default
+
+  if "hostLevelParams" not in config or "commandParams" not in config:
+    raise Fail("Unable to determine the correct version since hostLevelParams and commandParams
were not present in the configuration dictionary")
+
+  # should always be there
+  stack_version = config['hostLevelParams']['stack_version']
+
+  # something like 2.4.0.0-1234; represents the version for the command
+  # (or None if this is a cluster install and it hasn't been calculated yet)
+  version = default("/commandParams/version", None)
+
+  # something like 2.4.0.0-1234
+  # (or None if this is a cluster install and it hasn't been calculated yet)
+  current_cluster_version = default("/hostLevelParams/current_version", None)
+
+  # UPGRADE or DOWNGRADE (or None)
+  upgrade_direction = default("/commandParams/upgrade_direction", None)
+
+  # start out with the value that's right 99% of the time
+  version_for_stack_feature_checks = version if version is not None else stack_version
+
+  # if this is not an upgrade, then we take the simple path
+  if upgrade_direction is None:
+    Logger.info(
+      "Stack Feature Version Info: stack_version={0}, version={1}, current_cluster_version={2}
-> {3}".format(
+        stack_version, version, current_cluster_version, version_for_stack_feature_checks))
+
+    return version_for_stack_feature_checks
+
+  # STOP commands are the trouble maker as they are intended to stop a service not on the
+  # version of the stack being upgrade/downgraded to
+  is_stop_command = _is_stop_command(config)
+  if not is_stop_command:
+    Logger.info(
+      "Stack Feature Version Info: stack_version={0}, version={1}, current_cluster_version={2},
upgrade_direction={3} -> {4}".format(
+        stack_version, version, current_cluster_version, upgrade_direction,
+        version_for_stack_feature_checks))
+
+    return version_for_stack_feature_checks
+
+  original_stack = default("/commandParams/original_stack", None)
+  target_stack = default("/commandParams/target_stack", None)
+
+  # something like 2.5.0.0-5678 (or None)
+  downgrade_from_version = default("/commandParams/downgrade_from_version", None)
+
+  # guaranteed to have a STOP command now during an UPGRADE/DOWNGRADE, check direction
+  if upgrade_direction.lower() == Direction.DOWNGRADE.lower():
+    if downgrade_from_version is None:
+      Logger.warning(
+        "Unable to determine the version being downgraded when stopping services, using {0}".format(
+          version_for_stack_feature_checks))
+    else:
+      version_for_stack_feature_checks = downgrade_from_version
+  else:
+    # UPGRADE
+    if current_cluster_version is not None:
+      version_for_stack_feature_checks = current_cluster_version
+    elif original_stack is not None:
+      version_for_stack_feature_checks = original_stack
+    else:
+      version_for_stack_feature_checks = version if version is not None else stack_version
+
+  Logger.info(
+    "Stack Feature Version Info: stack_version={0}, version={1}, current_cluster_version={2},
upgrade_direction={3}, original_stack={4}, target_stack={5}, downgrade_from_version={6}, stop_command={7}
-> {8}".format(
+      stack_version, version, current_cluster_version, upgrade_direction, original_stack,
+      target_stack, downgrade_from_version, is_stop_command, version_for_stack_feature_checks))
+
+  return version_for_stack_feature_checks
+
+
+def _is_stop_command(config):
+  """
+  Gets whether this is a STOP command
+  :param config:
+  :return:
+  """
+  from resource_management.libraries.functions.default import default
+
+  # STOP commands are the trouble maker as they are intended to stop a service not on the
+  # version of the stack being upgrade/downgraded to
+  role_command = config["roleCommand"]
+  if role_command == _ROLE_COMMAND_STOP:
+    return True
+
+  custom_command = default("/hostLevelParams/custom_command", None)
+  if role_command == _ROLE_COMMAND_CUSTOM and custom_command == _ROLE_COMMAND_STOP:
+    return True
+
+  return False
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/params.py
b/ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/params.py
index 17b5796..02a0cbc 100644
--- a/ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/params.py
@@ -27,6 +27,7 @@ from resource_management import format_stack_version, Script
 from resource_management.libraries.functions import format
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.is_empty import is_empty
 from resource_management.libraries.functions.expect import expect
@@ -90,7 +91,8 @@ version = default("/commandParams/version", None)
 stack_version_unformatted = config['hostLevelParams']['stack_version']
 stack_version_formatted = format_stack_version(stack_version_unformatted)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
 
 metadata_home = os.environ['METADATA_HOME_DIR'] if 'METADATA_HOME_DIR' in os.environ else
format('{stack_root}/current/atlas-server')
 metadata_bin = format("{metadata_home}/bin")

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py
b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py
index 95814f4..f235ba8 100644
--- a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py
@@ -31,6 +31,7 @@ from resource_management.libraries.functions import stack_select
 from resource_management.libraries.functions import format
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions import get_kinit_path
 from resource_management.libraries.functions import is_empty
@@ -55,7 +56,9 @@ stack_version_unformatted = status_params.stack_version_unformatted
 stack_version_formatted = status_params.stack_version_formatted
 stack_root = status_params.stack_root
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
+
 stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT,
version_for_stack_feature_checks)
 stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT,
version_for_stack_feature_checks)
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/params_linux.py
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/params_linux.py
index 93987be..d3a6acb 100644
--- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/params_linux.py
@@ -29,6 +29,7 @@ from resource_management.libraries.functions import conf_select
 from resource_management.libraries.functions import stack_select
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions import format
 from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions.default import default
@@ -40,8 +41,6 @@ from resource_management.libraries.script.script import Script
 from resource_management.libraries.resources.hdfs_resource import HdfsResource
 from resource_management.libraries.functions.format_jvm_option import format_jvm_option
 from resource_management.libraries.functions.get_lzo_packages import get_lzo_packages
-from resource_management.libraries.functions.is_empty import is_empty
-from resource_management.libraries.functions.expect import expect
 from resource_management.libraries.functions.hdfs_utils import is_https_enabled_in_hdfs
 
 
@@ -68,7 +67,9 @@ version = default("/commandParams/version", None)
 # are started using different commands.
 desired_namenode_role = default("/commandParams/desired_namenode_role", None)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
+
 stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT,
version_for_stack_feature_checks)
 stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT,
version_for_stack_feature_checks)
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
index 8f95bf3..49527dc 100644
--- a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
@@ -37,6 +37,7 @@ from resource_management.libraries.functions.get_not_managed_resources import
ge
 from resource_management.libraries.script.script import Script
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions.get_port_from_url import get_port_from_url
 from resource_management.libraries.functions.expect import expect
 from resource_management.libraries import functions
@@ -80,9 +81,8 @@ current_version = default("/hostLevelParams/current_version", None)
 # downgrade_from_version provides the source-version the downgrade is happening from
 downgrade_from_version = default("/commandParams/downgrade_from_version", None)
 
-# determine which version to use for checking stack features; version is the most accurate
but
-# may not always be available (especially on first install of the cluster)
-version_for_stack_feature_checks = version if version is not None else stack_version_unformatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
 
 # Upgrade direction
 upgrade_direction = default("/commandParams/upgrade_direction", None)

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/params.py
b/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/params.py
index 9068b0c..dcd6f73 100644
--- a/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/params.py
@@ -23,12 +23,12 @@ from resource_management.libraries.script.script import Script
 from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions.default import default
 from utils import get_bare_principal
 from resource_management.libraries.functions.get_stack_version import get_stack_version
 from resource_management.libraries.functions.is_empty import is_empty
 import status_params
-from resource_management.core.logger import Logger
 from resource_management.libraries.resources.hdfs_resource import HdfsResource
 from resource_management.libraries.functions import stack_select
 from resource_management.libraries.functions import conf_select
@@ -54,7 +54,9 @@ stack_version_unformatted = config['hostLevelParams']['stack_version']
 stack_version_formatted = format_stack_version(stack_version_unformatted)
 upgrade_direction = default("/commandParams/upgrade_direction", None)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
+
 stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT,
version_for_stack_feature_checks)
 stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT,
version_for_stack_feature_checks)
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/params_linux.py
b/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/params_linux.py
index 6baaab6..e7ae8ba 100644
--- a/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/params_linux.py
@@ -36,7 +36,8 @@ from resource_management.libraries.functions import stack_select
 from resource_management.libraries.functions import conf_select
 from resource_management.libraries.functions.get_not_managed_resources import get_not_managed_resources
 from resource_management.libraries.functions.stack_features import check_stack_feature
-from resource_management.libraries.functions import StackFeature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
+from resource_management.libraries.functions.constants import StackFeature
 
 # server configurations
 config = Script.get_config()
@@ -53,7 +54,9 @@ version_formatted = format_stack_version(version)
 stack_version_unformatted = config['hostLevelParams']['stack_version']
 stack_version_formatted = format_stack_version(stack_version_unformatted)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
+
 stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT,
version_for_stack_feature_checks)
 stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT,
version_for_stack_feature_checks)
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py
b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py
index 6ff833b..ea79ae1 100644
--- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py
@@ -26,6 +26,7 @@ from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.is_empty import is_empty
 from resource_management.libraries.functions.constants import Direction
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.get_bare_principal import get_bare_principal
 
@@ -56,7 +57,8 @@ xml_configurations_supported = config['configurations']['ranger-env']['xml_confi
 
 create_db_dbuser = config['configurations']['ranger-env']['create_db_dbuser']
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
 
 stack_supports_rolling_upgrade = check_stack_feature(StackFeature.ROLLING_UPGRADE, version_for_stack_feature_checks)
 stack_supports_config_versioning = check_stack_feature(StackFeature.CONFIG_VERSIONING, version_for_stack_feature_checks)

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py
b/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py
index 6814ca2..5059595 100755
--- a/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py
@@ -24,6 +24,7 @@ from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions.format import format
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.get_bare_principal import get_bare_principal
 from resource_management.libraries.functions.is_empty import is_empty
@@ -38,7 +39,8 @@ version = default("/commandParams/version", None)
 stack_version_unformatted = config['hostLevelParams']['stack_version']
 stack_version_formatted = format_stack_version(stack_version_unformatted)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
 
 stack_supports_config_versioning = check_stack_feature(StackFeature.CONFIG_VERSIONING, version_for_stack_feature_checks)
 stack_support_kms_hsm = check_stack_feature(StackFeature.RANGER_KMS_HSM_SUPPORT, version_for_stack_feature_checks)

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/STORM/0.9.1/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/STORM/0.9.1/package/scripts/params_linux.py
b/ambari-server/src/main/resources/common-services/STORM/0.9.1/package/scripts/params_linux.py
index e2cf6a5..21a70e6 100644
--- a/ambari-server/src/main/resources/common-services/STORM/0.9.1/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/STORM/0.9.1/package/scripts/params_linux.py
@@ -24,9 +24,7 @@ import ambari_simplejson as json # simplejson is much faster comparing to
Python
 import status_params
 
 from ambari_commons.constants import AMBARI_SUDO_BINARY
-from resource_management.libraries.functions.constants import Direction
 from resource_management.libraries.functions import format
-from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.get_bare_principal import get_bare_principal
 from resource_management.libraries.script import Script
@@ -36,6 +34,7 @@ from resource_management.libraries.functions import conf_select
 from resource_management.libraries.functions import get_kinit_path
 from resource_management.libraries.functions.get_not_managed_resources import get_not_managed_resources
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.expect import expect
 from resource_management.libraries.functions.setup_atlas_hook import has_atlas_in_cluster
@@ -65,7 +64,9 @@ stack_supports_ru = stack_version_formatted and check_stack_feature(StackFeature
 stack_supports_storm_kerberos = stack_version_formatted and check_stack_feature(StackFeature.STORM_KERBEROS,
stack_version_formatted)
 stack_supports_storm_ams = stack_version_formatted and check_stack_feature(StackFeature.STORM_AMS,
stack_version_formatted)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
+
 stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT,
version_for_stack_feature_checks)
 stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT,
version_for_stack_feature_checks)
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/package/scripts/params_linux.py
b/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/package/scripts/params_linux.py
index b5a4c99..fefc659 100644
--- a/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/package/scripts/params_linux.py
@@ -28,6 +28,7 @@ from resource_management.libraries.functions import stack_select
 from resource_management.libraries.functions import format
 from resource_management.libraries.functions import StackFeature
 from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
 from resource_management.libraries.functions import get_kinit_path
 from resource_management.libraries.functions.get_not_managed_resources import get_not_managed_resources
 from resource_management.libraries.functions.version import format_stack_version
@@ -73,7 +74,9 @@ stack_supports_timeline_state_store = stack_version_formatted_major and
check_st
 # It cannot be used during the initial Cluser Install because the version is not yet known.
 version = default("/commandParams/version", None)
 
-version_for_stack_feature_checks = version if version is not None else stack_version_formatted_major
+# get the correct version to use for checking stack features
+version_for_stack_feature_checks = get_stack_feature_version(config)
+
 stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT,
version_for_stack_feature_checks)
 stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT,
version_for_stack_feature_checks)
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c3005446/ambari-server/src/test/python/TestStackFeature.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestStackFeature.py b/ambari-server/src/test/python/TestStackFeature.py
new file mode 100644
index 0000000..0116a7a
--- /dev/null
+++ b/ambari-server/src/test/python/TestStackFeature.py
@@ -0,0 +1,198 @@
+# !/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+
+from resource_management.core.logger import Logger
+from resource_management.libraries.functions.stack_features import get_stack_feature_version
+from resource_management.libraries.script import Script
+from resource_management.core.exceptions import Fail
+from unittest import TestCase
+
+Logger.initialize_logger()
+
+class TestStackFeature(TestCase):
+  def test_get_stack_feature_version_missing_params(self):
+    try:
+      stack_feature_version = get_stack_feature_version({})
+      self.assertEqual("2.3.0.0-1234", stack_feature_version)
+      self.fail("Expected an exception when there are required parameters missing from the
dictionary")
+    except Fail:
+      pass
+
+  def test_get_stack_feature_version_for_install_command(self):
+    """
+    Tests the stack feature version calculated during an install command on a new cluster
+    :return:
+    """
+    command_json = TestStackFeature._get_cluster_install_command_json()
+    Script.config = command_json
+
+    stack_feature_version = get_stack_feature_version(command_json)
+    self.assertEqual("2.4", stack_feature_version)
+
+
+  def test_get_stack_feature_version_for_upgrade_restart(self):
+    """
+    Tests the stack feature version calculated during a restart command in an upgrade.
+    :return:
+    """
+    command_json = TestStackFeature._get_cluster_upgrade_restart_json()
+    Script.config = command_json
+
+    stack_feature_version = get_stack_feature_version(command_json)
+    self.assertEqual("2.5.9.9-9999", stack_feature_version)
+
+
+  def test_get_stack_feature_version_for_downgrade_restart(self):
+    """
+    Tests the stack feature version calculated during a restart command in a downgrade.
+    :return:
+    """
+    command_json = TestStackFeature._get_cluster_downgrade_restart_json()
+    Script.config = command_json
+
+    stack_feature_version = get_stack_feature_version(command_json)
+    self.assertEqual("2.4.0.0-1234", stack_feature_version)
+
+
+  def test_get_stack_feature_version_for_downgrade_stop(self):
+    """
+    Tests the stack feature version calculated during a STOP command in a downgrade.
+    :return:
+    """
+    command_json = TestStackFeature._get_cluster_downgrade_stop_json()
+    Script.config = command_json
+
+    stack_feature_version = get_stack_feature_version(command_json)
+    self.assertEqual("2.5.9.9-9999", stack_feature_version)
+
+    command_json = TestStackFeature._get_cluster_downgrade_stop_custom_command_json()
+    Script.config = command_json
+
+    stack_feature_version = get_stack_feature_version(command_json)
+    self.assertEqual("2.5.9.9-9999", stack_feature_version)
+
+  @staticmethod
+  def _get_cluster_install_command_json():
+    """
+    Install command JSON with no upgrade and no version information.
+    :return:
+    """
+    return {
+      "roleCommand": "ACTIONEXECUTE",
+      "hostLevelParams": {
+        "stack_name": "HDP",
+        "stack_version": "2.4",
+      },
+      "commandParams": {
+        "command_timeout": "1800",
+        "script_type": "PYTHON",
+        "script": "install_packages.py"
+      }
+    }
+
+  @staticmethod
+  def _get_cluster_upgrade_restart_json():
+    """
+    A restart command during an upgrade.
+    :return:
+    """
+    return {
+      "roleCommand":"ACTIONEXECUTE",
+      "hostLevelParams": {
+        "stack_name": "HDP",
+        "stack_version": "2.4",
+        "current_version":  "2.4.0.0-1234"
+      },
+      "commandParams": {
+        "original_stack": "2.4",
+        "target_stack": "2.5",
+        "upgrade_direction": "upgrade",
+        "version": "2.5.9.9-9999"
+      }
+    }
+
+  @staticmethod
+  def _get_cluster_downgrade_restart_json():
+    """
+    A restart command during a downgrade.
+    :return:
+    """
+    return {
+      "roleCommand":"ACTIONEXECUTE",
+      "hostLevelParams":{
+        "stack_name":"HDP",
+        "stack_version":"2.4",
+        "current_version":"2.4.0.0-1234"
+      },
+      "commandParams":{
+        "original_stack":"2.4",
+        "target_stack":"2.5",
+        "upgrade_direction":"downgrade",
+        "version":"2.4.0.0-1234",
+        "downgrade_from_version": "2.5.9.9-9999"
+      }
+    }
+
+
+  @staticmethod
+  def _get_cluster_downgrade_stop_json():
+    """
+    A STOP command during a downgrade.
+    :return:
+    """
+    return {
+      "roleCommand":"STOP",
+      "hostLevelParams":{
+        "stack_name":"HDP",
+        "stack_version":"2.5",
+        "current_version":"2.4.0.0-1234"
+      },
+      "commandParams":{
+        "original_stack":"2.4",
+        "target_stack":"2.5",
+        "upgrade_direction":"downgrade",
+        "version":"2.4.0.0-1234",
+        "downgrade_from_version":"2.5.9.9-9999"
+      }
+    }
+
+  @staticmethod
+  def _get_cluster_downgrade_stop_custom_command_json():
+    """
+    A STOP command during a downgrade.
+    :return:
+    """
+    return {
+      "roleCommand":"CUSTOM_COMMAND",
+      "hostLevelParams":{
+        "stack_name":"HDP",
+        "stack_version":"2.5",
+        "current_version":"2.4.0.0-1234",
+        "custom_command":"STOP"
+      },
+      "commandParams":{
+        "original_stack":"2.4",
+        "target_stack":"2.5",
+        "upgrade_direction":"downgrade",
+        "version":"2.4.0.0-1234",
+        "downgrade_from_version":"2.5.9.9-9999"
+      }
+    }
\ No newline at end of file


Mime
View raw message