conf.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 logging
  18. import os
  19. import sys
  20. from django.utils.translation import ugettext_lazy as _t, ugettext as _
  21. from desktop.lib.conf import Config, validate_thrift_transport, coerce_bool
  22. from desktop.lib.exceptions import StructuredThriftTransportException
  23. LOG = logging.getLogger(__name__)
  24. HBASE_CLUSTERS = Config(
  25. key="hbase_clusters",
  26. default="(Cluster|localhost:9090)",
  27. help=_t("Comma-separated list of HBase Thrift servers for clusters in the format of '(name|host:port)'. Use full hostname with security."
  28. "Prefix hostname with https:// if using SSL and http mode with impersonation."),
  29. type=str
  30. )
  31. TRUNCATE_LIMIT = Config(
  32. key="truncate_limit",
  33. default="500",
  34. help=_t("Hard limit of rows or columns per row fetched before truncating."),
  35. type=int
  36. )
  37. THRIFT_TRANSPORT = Config(
  38. key="thrift_transport",
  39. default="buffered",
  40. help=_t("'buffered' is the default of the HBase Thrift Server and supports security. " +
  41. "'framed' can be used to chunk up responses, " +
  42. "which is useful when used in conjunction with the nonblocking server in Thrift."),
  43. type=str
  44. )
  45. HBASE_CONF_DIR = Config(
  46. key='hbase_conf_dir',
  47. help=_t('HBase configuration directory, where hbase-site.xml is located.'),
  48. default=os.environ.get("HBASE_CONF_DIR", '/etc/hbase/conf')
  49. )
  50. # Hidden, just for making patching of older version of Hue easier. To remove in Hue 4.
  51. USE_DOAS = Config(
  52. key='use_doas',
  53. help=_t('Force Hue to use Http Thrift mode with doas impersonation, regarless of hbase-site.xml properties.'),
  54. default=False,
  55. type=coerce_bool
  56. )
  57. def config_validator(user):
  58. res = []
  59. from hbase.api import HbaseApi
  60. from hbase.settings import NICE_NAME
  61. try:
  62. if not 'test' in sys.argv: # Avoid tests hanging
  63. api = HbaseApi(user=user)
  64. cluster_name = api.getClusters()[0]['name'] # Currently pick first configured cluster
  65. # Check connectivity
  66. api.connectCluster(cluster_name)
  67. api.getTableList(cluster_name)
  68. except Exception, e:
  69. print e
  70. if 'Could not connect' in str(e):
  71. msg = "The application won't work without a running HBase Thrift Server v1."
  72. else:
  73. msg = 'Failed to authenticate to HBase Thrift Server, check authentication configurations.'
  74. LOG.exception(msg)
  75. res.append((NICE_NAME, _(msg)))
  76. res.extend(validate_thrift_transport(THRIFT_TRANSPORT))
  77. return res