<s> """<STR_LIT>""" <EOL> import errno <EOL> import logging <EOL> import os . path <EOL> import re <EOL> import socket <EOL> from desktop . lib import security_util <EOL> from hadoop import confparse <EOL> import beeswax . conf <EOL> LOG = logging . getLogger ( __name__ ) <EOL> _HIVE_SITE_PATH = None <EOL> _HIVE_SITE_DICT = None <EOL> _METASTORE_LOC_CACHE = None <EOL> _CNF_METASTORE_SASL = '<STR_LIT>' <EOL> _CNF_METASTORE_URIS = '<STR_LIT>' <EOL> _CNF_METASTORE_KERBEROS_PRINCIPAL = '<STR_LIT>' <EOL> _CNF_METASTORE_WAREHOUSE_DIR = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_KERBEROS_PRINCIPAL = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_AUTHENTICATION = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_IMPERSONATION = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_USE_SSL = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_TRANSPORT_MODE = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_THRIFT_HTTP_PORT = '<STR_LIT>' <EOL> _CNF_HIVESERVER2_THRIFT_HTTP_PATH = '<STR_LIT>' <EOL> _THRIFT_URI_RE = re . compile ( "<STR_LIT>" ) <EOL> class MalformedHiveSiteException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def reset ( ) : <EOL> """<STR_LIT>""" <EOL> global _HIVE_SITE_DICT <EOL> global _METASTORE_LOC_CACHE <EOL> _HIVE_SITE_DICT = None <EOL> _METASTORE_LOC_CACHE = None <EOL> def get_conf ( ) : <EOL> """<STR_LIT>""" <EOL> if _HIVE_SITE_DICT is None : <EOL> _parse_hive_site ( ) <EOL> return _HIVE_SITE_DICT <EOL> def get_metastore ( ) : <EOL> """<STR_LIT>""" <EOL> global _METASTORE_LOC_CACHE <EOL> if not _METASTORE_LOC_CACHE : <EOL> thrift_uris = get_conf ( ) . get ( _CNF_METASTORE_URIS ) <EOL> is_local = thrift_uris is None or thrift_uris == '<STR_LIT>' <EOL> if not is_local : <EOL> use_sasl = str ( get_conf ( ) . get ( _CNF_METASTORE_SASL , '<STR_LIT:false>' ) ) . lower ( ) == '<STR_LIT:true>' <EOL> thrift_uri = thrift_uris . split ( "<STR_LIT:U+002C>" ) [ <NUM_LIT:0> ] <EOL> host = socket . getfqdn ( ) <EOL> match = _THRIFT_URI_RE . match ( thrift_uri ) <EOL> if not match : <EOL> LOG . error ( '<STR_LIT>' % thrift_uri ) <EOL> else : <EOL> host , port = match . groups ( ) <EOL> kerberos_principal = security_util . get_kerberos_principal ( get_conf ( ) . get ( _CNF_METASTORE_KERBEROS_PRINCIPAL , None ) , host ) <EOL> _METASTORE_LOC_CACHE = { <EOL> '<STR_LIT>' : use_sasl , <EOL> '<STR_LIT>' : thrift_uri , <EOL> '<STR_LIT>' : kerberos_principal <EOL> } <EOL> else : <EOL> LOG . error ( '<STR_LIT>' ) <EOL> return _METASTORE_LOC_CACHE <EOL> def get_hiveserver2_kerberos_principal ( hostname_or_ip ) : <EOL> """<STR_LIT>""" <EOL> fqdn = security_util . get_fqdn ( hostname_or_ip ) <EOL> principal = get_conf ( ) . get ( _CNF_HIVESERVER2_KERBEROS_PRINCIPAL , None ) <EOL> if principal : <EOL> return security_util . get_kerberos_principal ( principal , fqdn ) <EOL> else : <EOL> return None <EOL> def get_metastore_warehouse_dir ( ) : <EOL> return get_conf ( ) . get ( _CNF_METASTORE_WAREHOUSE_DIR , '<STR_LIT>' ) <EOL> def get_hiveserver2_authentication ( ) : <EOL> return get_conf ( ) . get ( _CNF_HIVESERVER2_AUTHENTICATION , '<STR_LIT>' ) . upper ( ) <EOL> def hiveserver2_impersonation_enabled ( ) : <EOL> return get_conf ( ) . get ( _CNF_HIVESERVER2_IMPERSONATION , '<STR_LIT>' ) . upper ( ) == '<STR_LIT>' <EOL> def hiveserver2_jdbc_url ( ) : <EOL> return '<STR_LIT>' % ( beeswax . conf . HIVE_SERVER_HOST . get ( ) , beeswax . conf . HIVE_SERVER_PORT . get ( ) ) <EOL> def hiveserver2_use_ssl ( ) : <EOL> return get_conf ( ) . get ( _CNF_HIVESERVER2_USE_SSL , '<STR_LIT>' ) . upper ( ) == '<STR_LIT>' <EOL> def hiveserver2_transport_mode ( ) : <EOL> return get_conf ( ) . get ( _CNF_HIVESERVER2_TRANSPORT_MODE , '<STR_LIT>' ) . upper ( ) <EOL> def hiveserver2_thrift_http_port ( ) : <EOL> return get_conf ( ) . get ( _CNF_HIVESERVER2_THRIFT_HTTP_PORT , '<STR_LIT>' ) <EOL> def hiveserver2_thrift_http_path ( ) : <EOL> return get_conf ( ) . get ( _CNF_HIVESERVER2_THRIFT_HTTP_PATH , '<STR_LIT>' ) <EOL> def _parse_hive_site ( ) : <EOL> """<STR_LIT>""" <EOL> global _HIVE_SITE_DICT <EOL> global _HIVE_SITE_PATH <EOL> _HIVE_SITE_PATH = os . path . join ( beeswax . conf . HIVE_CONF_DIR . get ( ) , '<STR_LIT>' ) <EOL> try : <EOL> data = file ( _HIVE_SITE_PATH , '<STR_LIT:r>' ) . read ( ) <EOL> except IOError , err : <EOL> if err . errno != errno . ENOENT : <EOL> LOG . error ( '<STR_LIT>' % ( _HIVE_SITE_PATH , err ) ) <EOL> return <EOL> data = "<STR_LIT>" <EOL> _HIVE_SITE_DICT = confparse . ConfParse ( data ) </s>
