conf.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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, coerce_bool
  22. from spark.settings import NICE_NAME
  23. LOG = logging.getLogger(__name__)
  24. LIVY_ASSEMBLY_JAR = Config(
  25. key="livy_assembly_jar",
  26. help=_t("Path to livy-assembly.jar"),
  27. private=True,
  28. default=os.path.join(os.path.dirname(__file__), "..", "..", "java-lib", "livy-assembly.jar"))
  29. LIVY_SERVER_HOST = Config(
  30. key="livy_server_host",
  31. help=_t("Host address of the Livy Server."),
  32. default="localhost")
  33. LIVY_SERVER_PORT = Config(
  34. key="livy_server_port",
  35. help=_t("Port of the Livy Server."),
  36. default="8998")
  37. LIVY_SERVER_SESSION_KIND = Config(
  38. key="livy_server_session_kind",
  39. help=_t("Configure livy to start in local 'process' mode, or 'yarn' workers."),
  40. default="process")
  41. LIVY_YARN_JAR = Config(
  42. key="livy_yarn_jar",
  43. help=_t("Path to livy-assembly.jar inside HDFS"),
  44. private=True)
  45. LIVY_IMPERSONATION_ENABLED = Config(
  46. key="livy_impersonation_enabled",
  47. help=_t("Use impersonation when submitting livy jobs"),
  48. default=True,
  49. type=coerce_bool)
  50. START_LIVY_SERVER = Config(
  51. key="start_livy_server",
  52. help=_t("Experimental option to launch livy"),
  53. default=False,
  54. type=coerce_bool,
  55. private=True)
  56. SQL_SERVER_HOST = Config(
  57. key="sql_server_host",
  58. help=_t("Host where SparkSQL server is running."),
  59. default="localhost")
  60. SQL_SERVER_PORT = Config(
  61. key="sql_server_port",
  62. help=_t("Port the SparkSQL server runs on."),
  63. default=10000,
  64. type=int)
  65. def get_livy_server_url():
  66. return 'http://%s:%s' % (LIVY_SERVER_HOST.get(), LIVY_SERVER_PORT.get())
  67. def get_spark_status(user):
  68. from spark.job_server_api import get_api
  69. status = None
  70. try:
  71. if not 'test' in sys.argv: # Avoid tests hanging
  72. get_api(user).get_status()
  73. status = 'OK'
  74. except:
  75. LOG.exception('failed to get spark status')
  76. return status
  77. def config_validator(user):
  78. res = []
  79. status = get_spark_status(user)
  80. if status != 'OK':
  81. res.append((NICE_NAME, _("The app won't work without a running Livy Spark Server")))
  82. return res