conf.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. from django.utils.translation import ugettext as _, ugettext_lazy as _t
  18. from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_bool
  19. from desktop.appmanager import get_apps_dict
  20. from notebook.conf import get_ordered_interpreters
  21. def is_enabled():
  22. """Automatic when search is enabled."""
  23. apps = get_apps_dict()
  24. return 'search' in apps or HAS_SQL_ENABLED.get()
  25. IS_ENABLED = Config(
  26. key="is_enabled",
  27. help=_t("Activate the Dashboard link in the menu."),
  28. dynamic_default=is_enabled,
  29. type=coerce_bool
  30. )
  31. HAS_SQL_ENABLED = Config(
  32. key="has_sql_enabled",
  33. help=_t("Activate the SQL Dashboard (beta)."),
  34. default=False,
  35. type=coerce_bool
  36. )
  37. HAS_REPORT_ENABLED = Config(
  38. key="has_report_enabled",
  39. help=_t("Activate the static report layout (beta)."),
  40. default=False,
  41. type=coerce_bool
  42. )
  43. USE_GRIDSTER = Config(
  44. key="use_gridster",
  45. help=_t("Activate the new grid layout system."),
  46. default=True,
  47. type=coerce_bool
  48. )
  49. USE_NEW_ADD_METHOD = Config(
  50. key="use_new_add_method",
  51. help=_t("Activate the simplified drag in the dashboard."),
  52. default=False,
  53. type=coerce_bool
  54. )
  55. HAS_WIDGET_FILTER = Config(
  56. key="has_widget_filter",
  57. help=_t("Activate the widget filter and comparison (beta)."),
  58. default=False,
  59. type=coerce_bool
  60. )
  61. HAS_TREE_WIDGET = Config(
  62. key="has_tree_widget",
  63. help=_t("Activate the tree widget (to drill down fields as dimensions, alpha)."),
  64. default=False,
  65. type=coerce_bool
  66. )
  67. def get_properties():
  68. if ENGINES.get():
  69. engines = ENGINES.get()
  70. return dict([
  71. (i, {
  72. 'analytics': engines[i].ANALYTICS.get(),
  73. 'nesting': engines[i].NESTING.get()
  74. }) for i in engines]
  75. )
  76. else:
  77. return {
  78. 'solr': {
  79. 'analytics': False,
  80. 'nesting': False,
  81. },
  82. 'sql': {
  83. 'analytics': True,
  84. 'nesting': False,
  85. },
  86. }
  87. def get_engines(user):
  88. engines = []
  89. apps = get_apps_dict(user=user)
  90. settings = get_properties()
  91. if 'search' in apps:
  92. engines.append({
  93. 'name': _('Index (Solr)'),
  94. 'type': 'solr',
  95. 'analytics': settings.get('solr') and settings['solr'].get('analytics'),
  96. 'nesting': settings.get('solr') and settings['solr'].get('nesting'),
  97. })
  98. if HAS_SQL_ENABLED.get() and ('beeswax' in apps or 'rdbms' in apps):
  99. engines += [{
  100. 'name': _('Table (%s)') % interpreter['name'],
  101. 'type': interpreter['type'],
  102. 'async': interpreter['interface'] == 'hiveserver2',
  103. 'analytics': settings.get('sql') and settings['sql'].get('analytics'),
  104. 'nesting': settings.get('sql') and settings['sql'].get('nesting'),
  105. }
  106. for interpreter in get_ordered_interpreters(user) if interpreter['interface'] in ('hiveserver2', 'jdbc', 'rdbms')
  107. ]
  108. return engines
  109. ENGINES = UnspecifiedConfigSection(
  110. "engines",
  111. help="One entry for each type of snippet.",
  112. each=ConfigSection(
  113. help=_t("Name of the interface to use as query engine for the dashboard, e.g. solr, sql."),
  114. members=dict(
  115. ANALYTICS=Config(
  116. "analytics",
  117. help=_t("Support analytics facets or not."),
  118. default=False,
  119. type=coerce_bool,
  120. ),
  121. NESTING=Config(
  122. "nesting",
  123. help=_t("Support nested documents or not."),
  124. default=False,
  125. type=coerce_bool,
  126. ),
  127. )
  128. )
  129. )