hbase_site.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env python
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import errno
  18. import logging
  19. import os.path
  20. from hadoop import confparse
  21. from desktop.lib.security_util import get_components
  22. LOG = logging.getLogger(__name__)
  23. SITE_PATH = None
  24. SITE_DICT = None
  25. _CNF_HBASE_THRIFT_KERBEROS_PRINCIPAL = 'hbase.thrift.kerberos.principal'
  26. _CNF_HBASE_AUTHENTICATION = 'hbase.security.authentication'
  27. _CNF_HBASE_REGIONSERVER_THRIFT_FRAMED = 'hbase.regionserver.thrift.framed'
  28. _CNF_HBASE_IMPERSONATION_ENABLED = 'hbase.thrift.support.proxyuser'
  29. _CNF_HBASE_USE_THRIFT_HTTP = 'hbase.regionserver.thrift.http'
  30. _CNF_HBASE_USE_THRIFT_SSL = 'hbase.thrift.ssl.enabled'
  31. def reset():
  32. global SITE_DICT
  33. SITE_DICT = None
  34. def get_conf():
  35. if SITE_DICT is None:
  36. _parse_site()
  37. return SITE_DICT
  38. def get_server_principal():
  39. principal = get_conf().get(_CNF_HBASE_THRIFT_KERBEROS_PRINCIPAL, None)
  40. components = get_components(principal)
  41. if components is not None:
  42. return components[0]
  43. def get_server_authentication():
  44. return get_conf().get(_CNF_HBASE_AUTHENTICATION, 'NOSASL').upper()
  45. def get_thrift_transport():
  46. use_framed = get_conf().get(_CNF_HBASE_REGIONSERVER_THRIFT_FRAMED)
  47. if use_framed is not None:
  48. if use_framed.upper() == "TRUE":
  49. return "framed"
  50. else:
  51. return "buffered"
  52. else:
  53. #Avoid circular import
  54. from hbase.conf import THRIFT_TRANSPORT
  55. return THRIFT_TRANSPORT.get()
  56. def is_impersonation_enabled():
  57. #Avoid circular import
  58. from hbase.conf import USE_DOAS
  59. return get_conf().get(_CNF_HBASE_IMPERSONATION_ENABLED, 'FALSE').upper() == 'TRUE' or USE_DOAS.get()
  60. def is_using_thrift_http():
  61. #Avoid circular import
  62. from hbase.conf import USE_DOAS
  63. return get_conf().get(_CNF_HBASE_USE_THRIFT_HTTP, 'FALSE').upper() == 'TRUE' or USE_DOAS.get()
  64. def is_using_thrift_ssl():
  65. return get_conf().get(_CNF_HBASE_USE_THRIFT_SSL, 'FALSE').upper() == 'TRUE'
  66. def _parse_site():
  67. global SITE_DICT
  68. global SITE_PATH
  69. #Avoid circular import
  70. from hbase.conf import HBASE_CONF_DIR
  71. SITE_PATH = os.path.join(HBASE_CONF_DIR.get(), 'hbase-site.xml')
  72. try:
  73. data = file(SITE_PATH, 'r').read()
  74. except IOError as err:
  75. if err.errno != errno.ENOENT:
  76. LOG.error('Cannot read from "%s": %s' % (SITE_PATH, err))
  77. return
  78. data = ""
  79. SITE_DICT = confparse.ConfParse(data)