def configure(self, env, upgrade_type=None): import params # The configure command doesn't actually receive the upgrade_type from Script.py, so get it from the config dictionary if upgrade_type is None: upgrade_type = Script.get_upgrade_type( default("/commandParams/upgrade_type", "")) if upgrade_type is not None and params.upgrade_direction == Direction.UPGRADE and params.version is not None: Logger.info( format( "Configuring Oozie during upgrade type: {upgrade_type}, direction: {params.upgrade_direction}, and version {params.version}" )) if params.version and check_stack_feature( StackFeature.ROLLING_UPGRADE, params.version): # In order for the "<stack-root>/current/oozie-<client/server>" point to the new version of # oozie, we need to create the symlinks both for server and client. # This is required as both need to be pointing to new installed oozie version. # Sets the symlink : eg: <stack-root>/current/oozie-client -> <stack-root>/a.b.c.d-<version>/oozie stack_select.select("oozie-client", params.version) # Sets the symlink : eg: <stack-root>/current/oozie-server -> <stack-root>/a.b.c.d-<version>/oozie stack_select.select("oozie-server", params.version) if params.version and check_stack_feature( StackFeature.CONFIG_VERSIONING, params.version): conf_select.select(params.stack_name, "oozie", params.version) env.set_params(params) oozie(is_server=True, upgrade_type=upgrade_type)
def setup_atlas_jar_symlinks(hook_name, jar_source_dir): """ In HDP 2.3, 2.4, and 2.5.0.0, Sqoop and Storm still relied on the following method to setup Atlas hooks because the RPM for Sqoop and Storm did not bring in any dependencies. /usr/hdp/current/storm-*/libext/ should contain symlinks for every jar in /usr/hdp/current/atlas-server/hooks/storm/somejavafile.jar /usr/hdp/current/sqoop-*/lib/ should contain symlinks for every jar in /usr/hdp/current/atlas-server/hooks/sqoop/somejavafile.jar In HDP 2.5.x.y, we plan to have the Sqoop and Storm rpms have additional dependencies on some sqoop-atlas-hook and storm-atlas-hook rpms, respectively, that will bring in the necessary jars and create the symlinks. If atlas is present on this host, then link the jars from {stack_root}/current/{hook_name}/lib/name_version.jar -> {jar_source_dir}/name_version.jar @param hook_name: one of sqoop, storm @param jar_source_dir: directory of where the symlinks need to be created from. """ import params stack_root = Script.get_stack_root() atlas_home_dir = os.path.join(stack_root, "current", "atlas-server") # if this is an upgrade/downagrade, then we must link in the correct version # which may not be "current", so change the home directory location upgrade_type = Script.get_upgrade_type( default("/commandParams/upgrade_type", "")) if upgrade_type is not None: version_dir_segment = stack_features.get_stack_feature_version( Script.get_config()) atlas_home_dir = os.path.join(stack_root, version_dir_segment, "atlas") # Will only exist if this host contains Atlas Server atlas_hook_dir = os.path.join(atlas_home_dir, "hook", hook_name) if os.path.exists(atlas_hook_dir): Logger.info( "Atlas Server is present on this host, will symlink jars inside of %s to %s if not already done." % (jar_source_dir, atlas_hook_dir)) src_files = os.listdir(atlas_hook_dir) for file_name in src_files: atlas_hook_file_name = os.path.join(atlas_hook_dir, file_name) source_lib_file_name = os.path.join(jar_source_dir, file_name) if os.path.isfile(atlas_hook_file_name): Link(source_lib_file_name, to=atlas_hook_file_name) else: Logger.info("Atlas hook directory path {0} doesn't exist".format( atlas_hook_dir))
def configure(self, env, upgrade_type=None): import params # The configure command doesn't actually receive the upgrade_type from Script.py, so get it from the config dictionary if upgrade_type is None: upgrade_type = Script.get_upgrade_type( default("/commandParams/upgrade_type", "")) if upgrade_type is not None and params.upgrade_direction == Direction.UPGRADE and params.version is not None: Logger.info( format( "Configuring Oozie during upgrade type: {upgrade_type}, direction: {params.upgrade_direction}, and version {params.version}" )) if params.version and check_stack_feature( StackFeature.ROLLING_UPGRADE, params.version): stack_select.select_packages(params.version) env.set_params(params) oozie(is_server=True, upgrade_type=upgrade_type)
jdk_name = default("/ambariLevelParams/jdk_name", None) java_home = config['ambariLevelParams']['java_home'] java_version = expect("/ambariLevelParams/java_version", int) jdk_location = config['ambariLevelParams']['jdk_location'] hadoop_custom_extensions_enabled = default( "/configurations/core-site/hadoop.custom-extensions.enabled", False) sudo = AMBARI_SUDO_BINARY ambari_server_hostname = config['ambariLevelParams']['ambari_server_host'] stack_version_unformatted = config['clusterLevelParams']['stack_version'] stack_version_formatted = format_stack_version(stack_version_unformatted) upgrade_type = Script.get_upgrade_type( default("/commandParams/upgrade_type", "")) version = default("/commandParams/version", None) # Handle upgrade and downgrade if (upgrade_type is not None) and version: stack_version_formatted = format_stack_version(version) ambari_java_home = default("/commandParams/ambari_java_home", None) ambari_jdk_name = default("/commandParams/ambari_jdk_name", None) security_enabled = config['configurations']['cluster-env']['security_enabled'] hdfs_user = config['configurations']['hadoop-env']['hdfs_user'] # Some datanode settings dfs_dn_addr = default('/configurations/hdfs-site/dfs.datanode.address', None) dfs_dn_http_addr = default( '/configurations/hdfs-site/dfs.datanode.http.address', None) dfs_dn_https_addr = default(
def setup_ranger_admin(upgrade_type=None): import params if upgrade_type is None: upgrade_type = Script.get_upgrade_type( default("/commandParams/upgrade_type", "")) ranger_home = params.ranger_home ranger_conf = params.ranger_conf Directory(ranger_conf, owner=params.unix_user, group=params.unix_group, create_parents=True) copy_jdbc_connector() File( format("/usr/lib/ambari-agent/{check_db_connection_jar_name}"), content=DownloadSource( format("{jdk_location}{check_db_connection_jar_name}")), mode=0644, ) cp = format("{check_db_connection_jar}") if params.db_flavor.lower() == 'sqla': cp = cp + os.pathsep + format("{ranger_home}/ews/lib/sajdbc4.jar") else: cp = cp + os.pathsep + format("{driver_curl_target}") cp = cp + os.pathsep + format("{ranger_home}/ews/lib/*") db_connection_check_command = format( "{java_home}/bin/java -cp {cp} org.apache.ambari.server.DBConnectionVerification '{ranger_jdbc_connection_url}' {ranger_db_user} {ranger_db_password!p} {ranger_jdbc_driver}" ) env_dict = {} if params.db_flavor.lower() == 'sqla': env_dict = {'LD_LIBRARY_PATH': params.ld_lib_path} Execute(db_connection_check_command, path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin', tries=5, try_sleep=10, environment=env_dict) Execute( ('ln', '-sf', format('{ranger_home}/ews/webapp/WEB-INF/classes/conf'), format('{ranger_home}/conf')), not_if=format("ls {ranger_home}/conf"), only_if=format("ls {ranger_home}/ews/webapp/WEB-INF/classes/conf"), sudo=True) if upgrade_type is not None: src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/ranger-admin-default-site.xml' ) dst_file = format('{ranger_home}/conf/ranger-admin-default-site.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/security-applicationContext.xml' ) dst_file = format('{ranger_home}/conf/security-applicationContext.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) Directory( format('{ranger_home}/'), owner=params.unix_user, group=params.unix_group, recursive_ownership=True, ) Directory(params.ranger_pid_dir, mode=0755, owner=params.unix_user, group=params.user_group, cd_access="a", create_parents=True) if params.stack_supports_pid: File( format('{ranger_conf}/ranger-admin-env-piddir.sh'), content=format( "export RANGER_PID_DIR_PATH={ranger_pid_dir}\nexport RANGER_USER={unix_user}" ), owner=params.unix_user, group=params.unix_group, mode=0755) Directory(params.admin_log_dir, owner=params.unix_user, group=params.unix_group, create_parents=True, cd_access='a', mode=0755) File(format('{ranger_conf}/ranger-admin-env-logdir.sh'), content=format("export RANGER_ADMIN_LOG_DIR={admin_log_dir}"), owner=params.unix_user, group=params.unix_group, mode=0755) if os.path.isfile(params.ranger_admin_default_file): File(params.ranger_admin_default_file, owner=params.unix_user, group=params.unix_group) else: Logger.warning( 'Required file {0} does not exist, copying the file to {1} path'. format(params.ranger_admin_default_file, ranger_conf)) src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/ranger-admin-default-site.xml' ) dst_file = format('{ranger_home}/conf/ranger-admin-default-site.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) File(params.ranger_admin_default_file, owner=params.unix_user, group=params.unix_group) if os.path.isfile(params.security_app_context_file): File(params.security_app_context_file, owner=params.unix_user, group=params.unix_group) else: Logger.warning( 'Required file {0} does not exist, copying the file to {1} path'. format(params.security_app_context_file, ranger_conf)) src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/security-applicationContext.xml' ) dst_file = format('{ranger_home}/conf/security-applicationContext.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) File(params.security_app_context_file, owner=params.unix_user, group=params.unix_group) if upgrade_type is not None and params.stack_supports_config_versioning: if os.path.islink('/usr/bin/ranger-admin'): Link('/usr/bin/ranger-admin', action="delete") Link('/usr/bin/ranger-admin', to=format('{ranger_home}/ews/ranger-admin-services.sh')) Execute(('ln', '-sf', format('{ranger_home}/ews/ranger-admin-services.sh'), '/usr/bin/ranger-admin'), not_if=format("ls /usr/bin/ranger-admin"), only_if=format("ls {ranger_home}/ews/ranger-admin-services.sh"), sudo=True) # remove plain-text password from xml configs ranger_admin_site_copy = {} ranger_admin_site_copy.update( params.config['configurations']['ranger-admin-site']) for prop in params.ranger_admin_password_properties: if prop in ranger_admin_site_copy: ranger_admin_site_copy[prop] = "_" XmlConfig( "ranger-admin-site.xml", conf_dir=ranger_conf, configurations=ranger_admin_site_copy, configuration_attributes=params.config['configuration_attributes'] ['ranger-admin-site'], owner=params.unix_user, group=params.unix_group, mode=0644) Directory( os.path.join(ranger_conf, 'ranger_jaas'), mode=0700, owner=params.unix_user, group=params.unix_group, ) if params.stack_supports_ranger_log4j: File(format('{ranger_home}/ews/webapp/WEB-INF/log4j.properties'), owner=params.unix_user, group=params.unix_group, content=InlineTemplate(params.admin_log4j), mode=0644) do_keystore_setup(upgrade_type=upgrade_type) create_core_site_xml(ranger_conf) if params.stack_supports_ranger_kerberos and params.security_enabled: if params.is_hbase_ha_enabled and params.ranger_hbase_plugin_enabled: XmlConfig( "hbase-site.xml", conf_dir=ranger_conf, configurations=params.config['configurations']['hbase-site'], configuration_attributes=params. config['configuration_attributes']['hbase-site'], owner=params.unix_user, group=params.unix_group, mode=0644) if params.is_namenode_ha_enabled and params.ranger_hdfs_plugin_enabled: XmlConfig( "hdfs-site.xml", conf_dir=ranger_conf, configurations=params.config['configurations']['hdfs-site'], configuration_attributes=params. config['configuration_attributes']['hdfs-site'], owner=params.unix_user, group=params.unix_group, mode=0644)
def setup_ranger_admin(upgrade_type=None): import params if upgrade_type is None: upgrade_type = Script.get_upgrade_type( default("/commandParams/upgrade_type", "")) ranger_home = params.ranger_home ranger_conf = params.ranger_conf Directory(ranger_conf, owner=params.unix_user, group=params.unix_group, create_parents=True) copy_jdbc_connector(ranger_home) File( format("/usr/lib/ambari-agent/{check_db_connection_jar_name}"), content=DownloadSource( format("{jdk_location}/{check_db_connection_jar_name}")), mode=0644, ) generate_logfeeder_input_config( 'ranger', Template("input.config-ranger.json.j2", extra_imports=[default])) cp = format("{check_db_connection_jar}") if params.db_flavor.lower() == 'sqla': cp = cp + os.pathsep + format("{ranger_home}/ews/lib/sajdbc4.jar") else: cp = cp + os.pathsep + format("{driver_curl_target}") cp = cp + os.pathsep + format("{ranger_home}/ews/lib/*") db_connection_check_command = format( "{java_home}/bin/java -cp {cp} org.apache.ambari.server.DBConnectionVerification '{ranger_jdbc_connection_url}' {ranger_db_user} {ranger_db_password!p} {ranger_jdbc_driver}" ) env_dict = {} if params.db_flavor.lower() == 'sqla': env_dict = {'LD_LIBRARY_PATH': params.ld_lib_path} Execute(db_connection_check_command, path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin', tries=5, try_sleep=10, environment=env_dict) Execute( ('ln', '-sf', format('{ranger_home}/ews/webapp/WEB-INF/classes/conf'), format('{ranger_home}/conf')), not_if=format("ls {ranger_home}/conf"), only_if=format("ls {ranger_home}/ews/webapp/WEB-INF/classes/conf"), sudo=True) if upgrade_type is not None: src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/ranger-admin-default-site.xml' ) dst_file = format('{ranger_home}/conf/ranger-admin-default-site.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/security-applicationContext.xml' ) dst_file = format('{ranger_home}/conf/security-applicationContext.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) Directory( format('{ranger_home}/'), owner=params.unix_user, group=params.unix_group, recursive_ownership=True, ) Directory(params.ranger_pid_dir, mode=0755, owner=params.unix_user, group=params.user_group, cd_access="a", create_parents=True) Directory(params.admin_log_dir, owner=params.unix_user, group=params.unix_group, create_parents=True, cd_access='a', mode=0755) if os.path.isfile(params.ranger_admin_default_file): File(params.ranger_admin_default_file, owner=params.unix_user, group=params.unix_group) else: Logger.warning( 'Required file {0} does not exist, copying the file to {1} path'. format(params.ranger_admin_default_file, ranger_conf)) src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/ranger-admin-default-site.xml' ) dst_file = format('{ranger_home}/conf/ranger-admin-default-site.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) File(params.ranger_admin_default_file, owner=params.unix_user, group=params.unix_group) if os.path.isfile(params.security_app_context_file): File(params.security_app_context_file, owner=params.unix_user, group=params.unix_group) else: Logger.warning( 'Required file {0} does not exist, copying the file to {1} path'. format(params.security_app_context_file, ranger_conf)) src_file = format( '{ranger_home}/ews/webapp/WEB-INF/classes/conf.dist/security-applicationContext.xml' ) dst_file = format('{ranger_home}/conf/security-applicationContext.xml') Execute(('cp', '-f', src_file, dst_file), sudo=True) File(params.security_app_context_file, owner=params.unix_user, group=params.unix_group) if default( "/configurations/ranger-admin-site/ranger.authentication.method", "") == 'PAM': d = '/etc/pam.d' if os.path.isdir(d): if os.path.isfile(os.path.join(d, 'ranger-admin')): Logger.info('ranger-admin PAM file already exists.') else: File(format('{d}/ranger-admin'), content=Template('ranger_admin_pam.j2'), owner=params.unix_user, group=params.unix_group, mode=0644) if os.path.isfile(os.path.join(d, 'ranger-remote')): Logger.info('ranger-remote PAM file already exists.') else: File(format('{d}/ranger-remote'), content=Template('ranger_remote_pam.j2'), owner=params.unix_user, group=params.unix_group, mode=0644) else: Logger.error( "Unable to use PAM authentication, /etc/pam.d/ directory does not exist." ) # remove plain-text password from xml configs ranger_admin_site_copy = {} ranger_admin_site_copy.update( params.config['configurations']['ranger-admin-site']) for prop in params.ranger_admin_password_properties: if prop in ranger_admin_site_copy: ranger_admin_site_copy[prop] = "_" if 'ranger.ha.spnego.kerberos.keytab' in ranger_admin_site_copy: ranger_admin_site_copy[ 'ranger.spnego.kerberos.keytab'] = ranger_admin_site_copy[ 'ranger.ha.spnego.kerberos.keytab'] XmlConfig("ranger-admin-site.xml", conf_dir=ranger_conf, configurations=ranger_admin_site_copy, configuration_attributes=params.config['configurationAttributes'] ['ranger-admin-site'], owner=params.unix_user, group=params.unix_group, mode=0644) Directory( os.path.join(ranger_conf, 'ranger_jaas'), mode=0700, owner=params.unix_user, group=params.unix_group, ) if params.stack_supports_ranger_log4j: File(format('{ranger_home}/ews/webapp/WEB-INF/log4j.properties'), owner=params.unix_user, group=params.unix_group, content=InlineTemplate(params.admin_log4j), mode=0644) do_keystore_setup(upgrade_type=upgrade_type) create_core_site_xml(ranger_conf) if params.stack_supports_ranger_kerberos: if params.is_hbase_ha_enabled and params.ranger_hbase_plugin_enabled: XmlConfig( "hbase-site.xml", conf_dir=ranger_conf, configurations=params.config['configurations']['hbase-site'], configuration_attributes=params. config['configurationAttributes']['hbase-site'], owner=params.unix_user, group=params.unix_group, mode=0644) if params.is_namenode_ha_enabled and params.ranger_hdfs_plugin_enabled: XmlConfig( "hdfs-site.xml", conf_dir=ranger_conf, configurations=params.config['configurations']['hdfs-site'], configuration_attributes=params. config['configurationAttributes']['hdfs-site'], owner=params.unix_user, group=params.unix_group, mode=0644) File(format("{ranger_conf}/ranger-admin-env.sh"), content=InlineTemplate(params.ranger_env_content), owner=params.unix_user, group=params.unix_group, mode=0755)