瀏覽代碼

AMBARI-15528: Stack Featurize RANGER and RANGER_KMS service (jluniya)

Jayush Luniya 9 年之前
父節點
當前提交
63f8d74f80
共有 15 個文件被更改,包括 56 次插入33 次删除
  1. 1 0
      ambari-common/src/main/python/resource_management/libraries/functions/constants.py
  2. 1 1
      ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py
  3. 1 0
      ambari-common/src/main/python/resource_management/libraries/functions/setup_ranger_plugin_xml.py
  4. 5 0
      ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py
  5. 19 13
      ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py
  6. 2 1
      ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py
  7. 1 1
      ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_service.py
  8. 2 1
      ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py
  9. 4 5
      ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/setup_ranger_xml.py
  10. 1 1
      ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py
  11. 3 3
      ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py
  12. 2 1
      ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms_server.py
  13. 8 5
      ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py
  14. 1 1
      ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/upgrade.py
  15. 5 0
      ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json

+ 1 - 0
ambari-common/src/main/python/resource_management/libraries/functions/constants.py

@@ -59,3 +59,4 @@ class StackFeature:
   KAFKA_LISTENERS = "kafka_listeners"
   KAFKA_LISTENERS = "kafka_listeners"
   KAFKA_KERBEROS = "kafka_kerberos"
   KAFKA_KERBEROS = "kafka_kerberos"
   PIG_ON_TEZ = "pig_on_tez"
   PIG_ON_TEZ = "pig_on_tez"
+  RANGER_USERSYNC_NON_ROOT = "ranger_usersync_non_root"

+ 1 - 1
ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py

@@ -65,7 +65,7 @@ def get_stack_version(package_name):
   @param package_name, name of the package, from which, function will try to get stack version
   @param package_name, name of the package, from which, function will try to get stack version
   """
   """
 
 
-  stack_selector_path = stack_tools.get_stack_tool_name(stack_tools.STACK_SELECTOR_NAME)
+  stack_selector_path = stack_tools.get_stack_tool_path(stack_tools.STACK_SELECTOR_NAME)
 
 
   if not os.path.exists(stack_selector_path):
   if not os.path.exists(stack_selector_path):
     Logger.info('Skipping get_stack_version since " + stack_selector_tool + " is not yet available')
     Logger.info('Skipping get_stack_version since " + stack_selector_tool + " is not yet available')

+ 1 - 0
ambari-common/src/main/python/resource_management/libraries/functions/setup_ranger_plugin_xml.py

@@ -163,6 +163,7 @@ def setup_ranger_plugin_jar_symblink(stack_version, service_name, component_list
 def setup_ranger_plugin_keystore(service_name, audit_db_is_enabled, stack_version, credential_file, xa_audit_db_password,
 def setup_ranger_plugin_keystore(service_name, audit_db_is_enabled, stack_version, credential_file, xa_audit_db_password,
                                 ssl_truststore_password, ssl_keystore_password, component_user, component_group, java_home):
                                 ssl_truststore_password, ssl_keystore_password, component_user, component_group, java_home):
 
 
+  stack_root = Script.get_stack_root()
   cred_lib_path = format('{stack_root}/{stack_version}/ranger-{service_name}-plugin/install/lib/*')
   cred_lib_path = format('{stack_root}/{stack_version}/ranger-{service_name}-plugin/install/lib/*')
   cred_setup_prefix = (format('{stack_root}/{stack_version}/ranger-{service_name}-plugin/ranger_credential_helper.py'), '-l', cred_lib_path)
   cred_setup_prefix = (format('{stack_root}/{stack_version}/ranger-{service_name}-plugin/ranger_credential_helper.py'), '-l', cred_lib_path)
 
 

+ 5 - 0
ambari-common/src/main/python/resource_management/libraries/functions/stack_features.py

@@ -128,6 +128,11 @@ _DEFAULT_STACK_FEATURES = {
       "name": "pig_on_tez",
       "name": "pig_on_tez",
       "description": "Pig on Tez support (AMBARI-7863)",
       "description": "Pig on Tez support (AMBARI-7863)",
       "min_version": "2.2.0.0"
       "min_version": "2.2.0.0"
+    },
+    {
+      "name": "ranger_usersync_non_root",
+      "description": "Ranger Usersync as non-root user (AMBARI-10416)",
+      "min_version": "2.3.0.0"
     }
     }
   ]
   ]
 }
 }

+ 19 - 13
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py

@@ -23,8 +23,9 @@ from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions.format import format
 from resource_management.libraries.functions.format import format
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.is_empty import is_empty
 from resource_management.libraries.functions.is_empty import is_empty
-from resource_management.libraries.functions.version import compare_versions
 from resource_management.libraries.functions.constants import Direction
 from resource_management.libraries.functions.constants import Direction
+from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions import StackFeature
 
 
 # a map of the Ambari role to the component name
 # a map of the Ambari role to the component name
 # for use with <stack-root>/current/<component>
 # for use with <stack-root>/current/<component>
@@ -37,6 +38,7 @@ component_directory = Script.get_component_from_role(SERVER_ROLE_DIRECTORY_MAP,
 
 
 config  = Script.get_config()
 config  = Script.get_config()
 tmp_dir = Script.get_tmp_dir()
 tmp_dir = Script.get_tmp_dir()
+stack_root = Script.get_stack_root()
 
 
 stack_name = default("/hostLevelParams/stack_name", None)
 stack_name = default("/hostLevelParams/stack_name", None)
 version = default("/commandParams/version", None)
 version = default("/commandParams/version", None)
@@ -51,8 +53,9 @@ xml_configurations_supported = config['configurations']['ranger-env']['xml_confi
 
 
 create_db_dbuser = config['configurations']['ranger-env']['create_db_dbuser']
 create_db_dbuser = config['configurations']['ranger-env']['create_db_dbuser']
 
 
-stack_is_hdp22_or_further = Script.is_stack_greater_or_equal("2.2")
-stack_is_hdp23_or_further = Script.is_stack_greater_or_equal("2.3")
+stack_supports_rolling_upgrade = stack_version_formatted and check_stack_feature(StackFeature.ROLLING_UPGRADE, stack_version_formatted)
+stack_supports_config_versioning =  stack_version_formatted and check_stack_feature(StackFeature.CONFIG_VERSIONING, stack_version_formatted)
+stack_supports_usersync_non_root =  stack_version_formatted and check_stack_feature(StackFeature.RANGER_USERSYNC_NON_ROOT, stack_version_formatted)
 
 
 downgrade_from_version = default("/commandParams/downgrade_from_version", None)
 downgrade_from_version = default("/commandParams/downgrade_from_version", None)
 upgrade_direction = default("/commandParams/upgrade_direction", None)
 upgrade_direction = default("/commandParams/upgrade_direction", None)
@@ -60,25 +63,28 @@ upgrade_direction = default("/commandParams/upgrade_direction", None)
 ranger_conf    = '/etc/ranger/admin/conf'
 ranger_conf    = '/etc/ranger/admin/conf'
 ranger_ugsync_conf = '/etc/ranger/usersync/conf'
 ranger_ugsync_conf = '/etc/ranger/usersync/conf'
 
 
-if upgrade_direction == Direction.DOWNGRADE and compare_versions(format_stack_version(version),'2.3' ) < 0:
-  stack_is_hdp22_or_further = True
-  stack_is_hdp23_or_further = False
+if upgrade_direction == Direction.DOWNGRADE and version and not check_stack_feature(StackFeature.CONFIG_VERSIONING, version):
+  stack_supports_rolling_upgrade = True
+  stack_supports_config_versioning = False
 
 
-if stack_is_hdp22_or_further:
-  ranger_home    = '/usr/hdp/current/ranger-admin'
+if upgrade_direction == Direction.DOWNGRADE and version and not check_stack_feature(StackFeature.RANGER_USERSYNC_NON_ROOT, version):
+  stack_supports_usersync_non_root = False
+
+if stack_supports_rolling_upgrade:
+  ranger_home    = format('{stack_root}/current/ranger-admin')
   ranger_conf    = '/etc/ranger/admin/conf'
   ranger_conf    = '/etc/ranger/admin/conf'
   ranger_stop    = '/usr/bin/ranger-admin-stop'
   ranger_stop    = '/usr/bin/ranger-admin-stop'
   ranger_start   = '/usr/bin/ranger-admin-start'
   ranger_start   = '/usr/bin/ranger-admin-start'
-  usersync_home  = '/usr/hdp/current/ranger-usersync'
+  usersync_home  = format('{stack_root}/current/ranger-usersync')
   usersync_start = '/usr/bin/ranger-usersync-start'
   usersync_start = '/usr/bin/ranger-usersync-start'
   usersync_stop  = '/usr/bin/ranger-usersync-stop'
   usersync_stop  = '/usr/bin/ranger-usersync-stop'
   ranger_ugsync_conf = '/etc/ranger/usersync/conf'
   ranger_ugsync_conf = '/etc/ranger/usersync/conf'
 
 
-if stack_is_hdp23_or_further:
-  ranger_conf = '/usr/hdp/current/ranger-admin/conf'
-  ranger_ugsync_conf = '/usr/hdp/current/ranger-usersync/conf'
+if stack_supports_config_versioning:
+  ranger_conf = format('{stack_root}/current/ranger-admin/conf')
+  ranger_ugsync_conf = format('{stack_root}/current/ranger-usersync/conf')
 
 
-usersync_services_file = "/usr/hdp/current/ranger-usersync/ranger-usersync-services.sh"
+usersync_services_file = format('{stack_root}/current/ranger-usersync/ranger-usersync-services.sh')
 
 
 java_home = config['hostLevelParams']['java_home']
 java_home = config['hostLevelParams']['java_home']
 unix_user  = config['configurations']['ranger-env']['ranger_user']
 unix_user  = config['configurations']['ranger-env']['ranger_user']

+ 2 - 1
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py

@@ -31,7 +31,8 @@ import os, errno
 class RangerAdmin(Script):
 class RangerAdmin(Script):
 
 
   def get_stack_to_component(self):
   def get_stack_to_component(self):
-    return {"HDP": "ranger-admin"}
+    import params
+    return {params.stack_name: "ranger-admin"}
 
 
   def install(self, env):
   def install(self, env):
     self.install_packages(env)
     self.install_packages(env)

+ 1 - 1
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_service.py

@@ -33,7 +33,7 @@ def ranger_service(name, action=None):
     no_op_test = format('ps -ef | grep proc_rangerusersync | grep -v grep')
     no_op_test = format('ps -ef | grep proc_rangerusersync | grep -v grep')
 
 
 
 
-    if params.stack_is_hdp23_or_further:
+    if params.stack_supports_usersync_non_root:
       Execute(params.usersync_start,
       Execute(params.usersync_start,
               environment=env_dict,
               environment=env_dict,
               not_if=no_op_test,
               not_if=no_op_test,

+ 2 - 1
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py

@@ -71,7 +71,8 @@ class RangerUsersync(Script):
     upgrade.prestart(env, "ranger-usersync")
     upgrade.prestart(env, "ranger-usersync")
 
 
   def get_stack_to_component(self):
   def get_stack_to_component(self):
-    return {"HDP": "ranger-usersync"}
+    import params
+    return {params.stack_name: "ranger-usersync"}
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":

+ 4 - 5
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/setup_ranger_xml.py

@@ -133,8 +133,7 @@ def setup_ranger_admin(upgrade_type=None):
     Execute(('cp', '-f', src_file, dst_file), sudo=True)
     Execute(('cp', '-f', src_file, dst_file), sudo=True)
     File(params.security_app_context_file, owner=params.unix_user, group=params.unix_group)
     File(params.security_app_context_file, owner=params.unix_user, group=params.unix_group)
 
 
-  if upgrade_type is not None and params.stack_is_hdp23_or_further:
-
+  if upgrade_type is not None and params.stack_supports_config_versioning:
     if os.path.islink('/usr/bin/ranger-admin'):
     if os.path.islink('/usr/bin/ranger-admin'):
       Link('/usr/bin/ranger-admin', action="delete")
       Link('/usr/bin/ranger-admin', action="delete")
 
 
@@ -169,7 +168,7 @@ def setup_ranger_db(stack_version=None):
   ranger_home = params.ranger_home
   ranger_home = params.ranger_home
   version = params.version
   version = params.version
   if stack_version is not None:
   if stack_version is not None:
-    ranger_home = format("/usr/hdp/{stack_version}/ranger-admin")
+    ranger_home = format("{stack_root}/{stack_version}/ranger-admin")
     version = stack_version
     version = stack_version
 
 
   copy_jdbc_connector(stack_version=version)
   copy_jdbc_connector(stack_version=version)
@@ -208,7 +207,7 @@ def setup_java_patch(stack_version=None):
 
 
   ranger_home = params.ranger_home
   ranger_home = params.ranger_home
   if stack_version is not None:
   if stack_version is not None:
-    ranger_home = format("/usr/hdp/{stack_version}/ranger-admin")
+    ranger_home = format("{stack_root}/{stack_version}/ranger-admin")
 
 
   env_dict = {'RANGER_ADMIN_HOME':ranger_home, 'JAVA_HOME':params.java_home}
   env_dict = {'RANGER_ADMIN_HOME':ranger_home, 'JAVA_HOME':params.java_home}
   if params.db_flavor.lower() == 'sqla':
   if params.db_flavor.lower() == 'sqla':
@@ -291,7 +290,7 @@ def copy_jdbc_connector(stack_version=None):
 
 
   ranger_home = params.ranger_home
   ranger_home = params.ranger_home
   if stack_version is not None:
   if stack_version is not None:
-    ranger_home = format("/usr/hdp/{stack_version}/ranger-admin")
+    ranger_home = format("{stack_root}/{stack_version}/ranger-admin")
 
 
   if params.db_flavor.lower() == 'sqla':
   if params.db_flavor.lower() == 'sqla':
     Execute(('tar', '-xvf', params.downloaded_custom_connector, '-C', params.tmp_dir), sudo = True)
     Execute(('tar', '-xvf', params.downloaded_custom_connector, '-C', params.tmp_dir), sudo = True)

+ 1 - 1
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py

@@ -26,6 +26,6 @@ from resource_management.libraries.functions.format import format
 def prestart(env, stack_component):
 def prestart(env, stack_component):
   import params
   import params
 
 
-  if params.version and params.stack_is_hdp22_or_further:
+  if params.version and params.stack_supports_rolling_upgrade:
     conf_select.select(params.stack_name, stack_component, params.version)
     conf_select.select(params.stack_name, stack_component, params.version)
     stack_select.select(stack_component, params.version)
     stack_select.select(stack_component, params.version)

+ 3 - 3
ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py

@@ -56,7 +56,7 @@ def setup_kms_db(stack_version=None):
     kms_home = params.kms_home
     kms_home = params.kms_home
     version = params.version
     version = params.version
     if stack_version is not None:
     if stack_version is not None:
-      kms_home = format("/usr/hdp/{stack_version}/ranger-kms")
+      kms_home = format("{stack_root}/{stack_version}/ranger-kms")
       version = stack_version
       version = stack_version
 
 
     password_validation(params.kms_master_key_password, 'KMS master key')
     password_validation(params.kms_master_key_password, 'KMS master key')
@@ -266,7 +266,7 @@ def kms(upgrade_type=None):
       content=params.kms_log4j,
       content=params.kms_log4j,
       mode=0644
       mode=0644
     )
     )
-    if params.stack_is_hdp23_or_further and params.security_enabled:
+    if params.security_enabled:
       # core-site.xml linking required by setup for HDFS encryption
       # core-site.xml linking required by setup for HDFS encryption
       XmlConfig("core-site.xml",
       XmlConfig("core-site.xml",
         conf_dir=params.kms_conf_dir,
         conf_dir=params.kms_conf_dir,
@@ -282,7 +282,7 @@ def copy_jdbc_connector(stack_version=None):
 
 
   kms_home = params.kms_home
   kms_home = params.kms_home
   if stack_version is not None:
   if stack_version is not None:
-    kms_home = format("/usr/hdp/{stack_version}/ranger-kms")
+    kms_home = format("{stack_root}/{stack_version}/ranger-kms")
 
 
   File(params.downloaded_custom_connector,
   File(params.downloaded_custom_connector,
     content = DownloadSource(params.driver_curl_source),
     content = DownloadSource(params.driver_curl_source),

+ 2 - 1
ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms_server.py

@@ -31,7 +31,8 @@ import upgrade
 class KmsServer(Script):
 class KmsServer(Script):
 
 
   def get_stack_to_component(self):
   def get_stack_to_component(self):
-    return {"HDP": "ranger-kms"}
+    import params
+    return {params.stack_name: "ranger-kms"}
 
 
   def install(self, env):
   def install(self, env):
     self.install_packages(env)
     self.install_packages(env)

+ 8 - 5
ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/params.py

@@ -20,12 +20,15 @@ limitations under the License.
 import os
 import os
 from resource_management.libraries.functions import conf_select
 from resource_management.libraries.functions import conf_select
 from resource_management.libraries.script import Script
 from resource_management.libraries.script import Script
-from resource_management.libraries.functions.version import format_stack_version, compare_versions
+from resource_management.libraries.functions.version import format_stack_version
 from resource_management.libraries.functions.format import format
 from resource_management.libraries.functions.format import format
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.default import default
+from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions import StackFeature
 
 
 config  = Script.get_config()
 config  = Script.get_config()
 tmp_dir = Script.get_tmp_dir()
 tmp_dir = Script.get_tmp_dir()
+stack_root = Script.get_stack_root()
 
 
 stack_name = default("/hostLevelParams/stack_name", None)
 stack_name = default("/hostLevelParams/stack_name", None)
 version = default("/commandParams/version", None)
 version = default("/commandParams/version", None)
@@ -33,13 +36,13 @@ version = default("/commandParams/version", None)
 stack_version_unformatted = config['hostLevelParams']['stack_version']
 stack_version_unformatted = config['hostLevelParams']['stack_version']
 stack_version_formatted = format_stack_version(stack_version_unformatted)
 stack_version_formatted = format_stack_version(stack_version_unformatted)
 
 
-stack_is_hdp23_or_further = Script.is_stack_greater_or_equal("2.3")
+stack_supports_config_versioning =  stack_version_formatted and check_stack_feature(StackFeature.CONFIG_VERSIONING, stack_version_formatted)
 hadoop_conf_dir = conf_select.get_hadoop_conf_dir()
 hadoop_conf_dir = conf_select.get_hadoop_conf_dir()
 security_enabled = config['configurations']['cluster-env']['security_enabled']
 security_enabled = config['configurations']['cluster-env']['security_enabled']
 
 
-if stack_is_hdp23_or_further:
-  kms_home = '/usr/hdp/current/ranger-kms'
-  kms_conf_dir = '/usr/hdp/current/ranger-kms/conf'
+if stack_supports_config_versioning:
+  kms_home = format('{stack_root}/current/ranger-kms')
+  kms_conf_dir = format('{stack_root}/current/ranger-kms/conf')
 
 
 kms_log_dir = default("/configurations/kms-env/kms_log_dir", "/var/log/ranger/kms")
 kms_log_dir = default("/configurations/kms-env/kms_log_dir", "/var/log/ranger/kms")
 java_home = config['hostLevelParams']['java_home']
 java_home = config['hostLevelParams']['java_home']

+ 1 - 1
ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/upgrade.py

@@ -25,6 +25,6 @@ from resource_management.libraries.functions.format import format
 def prestart(env, stack_component):
 def prestart(env, stack_component):
   import params
   import params
 
 
-  if params.version and params.stack_is_hdp23_or_further:
+  if params.version and params.stack_supports_config_versioning:
     conf_select.select(params.stack_name, stack_component, params.version)
     conf_select.select(params.stack_name, stack_component, params.version)
     stack_select.select(stack_component, params.version)
     stack_select.select(stack_component, params.version)

+ 5 - 0
ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json

@@ -102,6 +102,11 @@
       "name": "pig_on_tez",
       "name": "pig_on_tez",
       "description": "Pig on Tez support (AMBARI-7863)",
       "description": "Pig on Tez support (AMBARI-7863)",
       "min_version": "2.2.0.0"
       "min_version": "2.2.0.0"
+    },
+    {
+      "name": "ranger_usersync_non_root",
+      "description": "Ranger Usersync as non-root user (AMBARI-10416)",
+      "min_version": "2.3.0.0"
     }
     }
   ]
   ]
 }
 }