conf.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 sys
  19. from django.utils.translation import ugettext as _, ugettext_lazy as _t
  20. from desktop.conf import default_ssl_validate
  21. from desktop.lib.conf import Config, coerce_bool, validate_path
  22. LOG = logging.getLogger(__name__)
  23. OOZIE_URL = Config(
  24. key='oozie_url',
  25. help=_t('URL of Oozie server. This is required for job submission. Empty value disables the config check.'),
  26. default='http://localhost:11000/oozie',
  27. type=str)
  28. SECURITY_ENABLED = Config(
  29. key="security_enabled",
  30. help=_t("Whether Oozie requires client to perform Kerberos authentication."),
  31. default=False,
  32. type=coerce_bool)
  33. REMOTE_DEPLOYMENT_DIR = Config(
  34. key="remote_deployement_dir",
  35. default="/user/hue/oozie/deployments/_$USER_-oozie-$JOBID-$TIME",
  36. help=_t("Location on HDFS where the workflows/coordinators are deployed when submitted by a non-owner."
  37. " Parameters are $TIME, $USER and $JOBID, e.g. /user/$USER/hue/deployments/$JOBID-$TIME"))
  38. SSL_CERT_CA_VERIFY=Config(
  39. key="ssl_cert_ca_verify",
  40. help="In secure mode (HTTPS), if SSL certificates from Oozie Rest APIs have to be verified against certificate authority",
  41. dynamic_default=default_ssl_validate,
  42. type=coerce_bool)
  43. USE_LIBPATH_FOR_JARS = Config(
  44. key="use_libpath_for_jars",
  45. help=_t("Whether Hue append jar paths to the oozie.libpath instead of copying them into the workspace."
  46. " This makes submissions faster and less prone to HDFS permission errors"),
  47. default=False,
  48. type=coerce_bool)
  49. def get_oozie_status(user):
  50. from liboozie.oozie_api import get_oozie
  51. status = 'down'
  52. try:
  53. if not 'test' in sys.argv: # Avoid tests hanging
  54. status = str(get_oozie(user).get_oozie_status())
  55. except:
  56. LOG.exception('failed to get oozie status')
  57. return status
  58. def config_validator(user):
  59. """
  60. config_validator() -> [ (config_variable, error_message) ]
  61. Called by core check_config() view.
  62. """
  63. from desktop.lib.fsmanager import get_filesystem
  64. from hadoop.cluster import get_all_hdfs
  65. from hadoop.fs.hadoopfs import Hdfs
  66. from liboozie.oozie_api import get_oozie
  67. from oozie.conf import REMOTE_SAMPLE_DIR
  68. res = []
  69. if OOZIE_URL.get():
  70. status = get_oozie_status(user)
  71. if 'NORMAL' not in status:
  72. res.append((status, _('The Oozie server is not available')))
  73. fs = get_filesystem()
  74. NICE_NAME = 'Oozie'
  75. if fs.exists(REMOTE_SAMPLE_DIR.get()):
  76. stats = fs.stats(REMOTE_SAMPLE_DIR.get())
  77. mode = oct(stats.mode)
  78. # if neither group nor others have write permission
  79. group_has_write = int(mode[-2]) & 2
  80. others_has_write = int(mode[-1]) & 2
  81. if not group_has_write and not others_has_write:
  82. res.append((NICE_NAME, "The permissions of workspace '%s' are too restrictive" % REMOTE_SAMPLE_DIR.get()))
  83. api = get_oozie(user, api_version="v2")
  84. configuration = api.get_configuration()
  85. if 'org.apache.oozie.service.MetricsInstrumentationService' in [c.strip() for c in configuration.get('oozie.services.ext', '').split(',')]:
  86. metrics = api.get_metrics()
  87. sharelib_url = 'gauges' in metrics and 'libs.sharelib.system.libpath' in metrics['gauges'] and [metrics['gauges']['libs.sharelib.system.libpath']['value']] or []
  88. else:
  89. intrumentation = api.get_instrumentation()
  90. sharelib_url = [param['value'] for group in intrumentation['variables'] for param in group['data'] if param['name'] == 'sharelib.system.libpath']
  91. if sharelib_url:
  92. sharelib_url = Hdfs.urlsplit(sharelib_url[0])[2]
  93. if not sharelib_url:
  94. res.append((status, _('Oozie Share Lib path is not available')))
  95. class ConfigMock:
  96. def __init__(self, value): self.value = value
  97. def get(self): return self.value
  98. def get_fully_qualifying_key(self): return self.value
  99. for cluster in get_all_hdfs().values():
  100. res.extend(validate_path(ConfigMock(sharelib_url), is_dir=True, fs=cluster,
  101. message=_('Oozie Share Lib not installed in default location.')))
  102. return res