impala_flags.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. LOG = logging.getLogger(__name__)
  21. _IMPALA_FLAGS = None
  22. _WEBSERVER_CERTIFICATE_FILE = '-webserver_certificate_file'
  23. _SSL_SERVER_CERTIFICATE = '-ssl_server_certificate'
  24. _MAX_RESULT_CACHE_SIZE = '-max_result_cache_size'
  25. _AUTHORIZED_PROXY_USER_CONFIG = '-authorized_proxy_user_config'
  26. def reset():
  27. global _IMPALA_FLAGS
  28. _IMPALA_FLAGS = None
  29. def get_conf():
  30. if _IMPALA_FLAGS is None:
  31. _parse_impala_flags()
  32. return _IMPALA_FLAGS
  33. def get_webserver_certificate_file():
  34. return get_conf().get(_WEBSERVER_CERTIFICATE_FILE)
  35. def get_ssl_server_certificate():
  36. """
  37. The path to the TLS/SSL file containing the server certificate key used for TLS/SSL. Used when Catalog
  38. Server Webserver is acting as a TLS/SSL server. The certificate file must be in PEM format.
  39. """
  40. return get_conf().get(_SSL_SERVER_CERTIFICATE)
  41. def get_max_result_cache_size():
  42. """
  43. Maximum number of query results a client may request to be cached on a per-query basis to support restarting
  44. fetches. This option guards against unreasonably large result caches requested by clients. Requests exceeding
  45. this maximum will be rejected.
  46. """
  47. result_size = get_conf().get(_MAX_RESULT_CACHE_SIZE)
  48. return int(result_size) if result_size else 50000
  49. def get_authorized_proxy_user_config():
  50. """
  51. Specifies the set of authorized proxy users (users who can impersonate other users during authorization) and whom
  52. they are allowed to impersonate. Input is a semicolon-separated list of key=value pairs of authorized proxy users
  53. to the user(s) they can impersonate. These users are specified as a comma separated list of short usernames, or '*'
  54. to indicate all users. For example: joe=alice,bob;hue=*;admin=*. Only valid when Sentry is enabled.
  55. """
  56. return get_conf().get(_AUTHORIZED_PROXY_USER_CONFIG)
  57. def is_impersonation_enabled():
  58. """
  59. Returns True if user_config config contains 'hue='
  60. """
  61. user_config = get_conf().get(_AUTHORIZED_PROXY_USER_CONFIG)
  62. return True if user_config and 'hue=' in user_config else False
  63. def _parse_impala_flags():
  64. from impala import conf # Cyclic dependency
  65. global _IMPALA_FLAGS
  66. try:
  67. impala_flags_path = os.path.join(conf.IMPALA_CONF_DIR.get(), 'impalad_flags')
  68. _IMPALA_FLAGS = dict(line.strip().split('=', 1) for line in open(impala_flags_path) if '=' in line)
  69. except IOError, err:
  70. if err.errno != errno.ENOENT:
  71. LOG.error('Cannot read from "%s": %s' % (impala_flags_path, err))
  72. _IMPALA_FLAGS = {}
  73. except Exception, ex:
  74. LOG.error('Failed to parse Impala config from "%s": %s' % (impala_flags_path, ex))
  75. _IMPALA_FLAGS = {}