params.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/python
  2. """
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. """
  17. from resource_management.libraries.functions.version import format_hdp_stack_version, compare_versions
  18. from resource_management.libraries.functions.default import default
  19. from resource_management import *
  20. from setup_spark import *
  21. import status_params
  22. config = Script.get_config()
  23. tmp_dir = Script.get_tmp_dir()
  24. stack_name = default("/hostLevelParams/stack_name", None)
  25. stack_version_unformatted = str(config['hostLevelParams']['stack_version'])
  26. hdp_stack_version = format_hdp_stack_version(stack_version_unformatted)
  27. host_sys_prepped = default("/hostLevelParams/host_sys_prepped", False)
  28. # New Cluster Stack Version that is defined during the RESTART of a Rolling Upgrade
  29. version = default("/commandParams/version", None)
  30. # TODO! FIXME! Version check is not working as of today :
  31. # $ yum list installed | grep hdp-select
  32. # hdp-select.noarch 2.2.1.0-2340.el6 @HDP-2.2
  33. # And hdp_stack_version returned from hostLevelParams/stack_version is : 2.2.0.0
  34. # Commenting out for time being
  35. #stack_is_hdp22_or_further = hdp_stack_version != "" and compare_versions(hdp_stack_version, '2.2.1.0') >= 0
  36. stack_is_hdp22_or_further = hdp_stack_version != "" and compare_versions(hdp_stack_version, '2.2') >= 0
  37. if stack_is_hdp22_or_further:
  38. hadoop_home = "/usr/hdp/current/hadoop-client"
  39. hadoop_bin_dir = "/usr/hdp/current/hadoop-client/bin"
  40. spark_conf = '/etc/spark/conf'
  41. spark_log_dir = config['configurations']['spark-env']['spark_log_dir']
  42. spark_pid_dir = status_params.spark_pid_dir
  43. spark_role_root = "spark-client"
  44. command_role = default("/role", "")
  45. if command_role == "SPARK_CLIENT":
  46. spark_role_root = "spark-client"
  47. elif command_role == "SPARK_JOBHISTORYSERVER":
  48. spark_role_root = "spark-historyserver"
  49. spark_home = format("/usr/hdp/current/{spark_role_root}")
  50. else:
  51. pass
  52. java_home = config['hostLevelParams']['java_home']
  53. hadoop_conf_dir = "/etc/hadoop/conf"
  54. hdfs_user = config['configurations']['hadoop-env']['hdfs_user']
  55. hdfs_principal_name = config['configurations']['hadoop-env']['hdfs_principal_name']
  56. hdfs_user_keytab = config['configurations']['hadoop-env']['hdfs_user_keytab']
  57. spark_user = status_params.spark_user
  58. spark_group = status_params.spark_group
  59. user_group = status_params.user_group
  60. spark_hdfs_user_dir = format("/user/{spark_user}")
  61. spark_history_server_pid_file = status_params.spark_history_server_pid_file
  62. spark_history_server_start = format("{spark_home}/sbin/start-history-server.sh")
  63. spark_history_server_stop = format("{spark_home}/sbin/stop-history-server.sh")
  64. spark_submit_cmd = format("{spark_home}/bin/spark-submit")
  65. spark_smoke_example = "org.apache.spark.examples.SparkPi"
  66. spark_service_check_cmd = format(
  67. "{spark_submit_cmd} --class {spark_smoke_example} --master yarn-cluster --num-executors 1 --driver-memory 256m --executor-memory 256m --executor-cores 1 {spark_home}/lib/spark-examples*.jar 1")
  68. spark_jobhistoryserver_hosts = default("/clusterHostInfo/spark_jobhistoryserver_hosts", [])
  69. if len(spark_jobhistoryserver_hosts) > 0:
  70. spark_history_server_host = spark_jobhistoryserver_hosts[0]
  71. else:
  72. spark_history_server_host = "localhost"
  73. # spark-defaults params
  74. spark_hive_sec_authorization_enabled = "false"
  75. spark_yarn_historyServer_address = default(spark_history_server_host, "localhost")
  76. spark_history_ui_port = config['configurations']['spark-defaults']['spark.history.ui.port']
  77. spark_env_sh = config['configurations']['spark-env']['content']
  78. spark_log4j_properties = config['configurations']['spark-log4j-properties']['content']
  79. spark_metrics_properties = config['configurations']['spark-metrics-properties']['content']
  80. spark_javaopts_properties = config['configurations']['spark-javaopts-properties']['content']
  81. hive_server_host = default("/clusterHostInfo/hive_server_host", [])
  82. is_hive_installed = not len(hive_server_host) == 0
  83. hdp_full_version = functions.get_hdp_version('spark-client')
  84. spark_driver_extraJavaOptions = str(config['configurations']['spark-defaults']['spark.driver.extraJavaOptions'])
  85. if spark_driver_extraJavaOptions.find('-Dhdp.version') == -1:
  86. spark_driver_extraJavaOptions = spark_driver_extraJavaOptions + ' -Dhdp.version=' + str(hdp_full_version)
  87. spark_yarn_am_extraJavaOptions = str(config['configurations']['spark-defaults']['spark.yarn.am.extraJavaOptions'])
  88. if spark_yarn_am_extraJavaOptions.find('-Dhdp.version') == -1:
  89. spark_yarn_am_extraJavaOptions = spark_yarn_am_extraJavaOptions + ' -Dhdp.version=' + str(hdp_full_version)
  90. spark_javaopts_properties = str(spark_javaopts_properties)
  91. if spark_javaopts_properties.find('-Dhdp.version') == -1:
  92. spark_javaopts_properties = spark_javaopts_properties+ ' -Dhdp.version=' + str(hdp_full_version)
  93. security_enabled = config['configurations']['cluster-env']['security_enabled']
  94. kinit_path_local = functions.get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None))
  95. spark_kerberos_keytab = config['configurations']['spark-defaults']['spark.history.kerberos.keytab']
  96. spark_kerberos_principal = config['configurations']['spark-defaults']['spark.history.kerberos.principal']
  97. spark_hive_properties = {
  98. 'hive.metastore.uris': config['configurations']['hive-site']['hive.metastore.uris']
  99. }
  100. if security_enabled:
  101. spark_principal = spark_kerberos_principal.replace('_HOST',spark_history_server_host.lower())
  102. if is_hive_installed:
  103. spark_hive_properties += {
  104. 'hive.metastore.sasl.enabled': str(config['configurations']['hive-site']['hive.metastore.sasl.enabled']).lower(),
  105. 'hive.metastore.kerberos.keytab.file': config['configurations']['hive-site']['hive.metastore.kerberos.keytab.file'],
  106. 'hive.server2.authentication.spnego.principal': config['configurations']['hive-site']['hive.server2.authentication.spnego.principal'],
  107. 'hive.server2.authentication.spnego.keytab': config['configurations']['hive-site']['hive.server2.authentication.spnego.keytab'],
  108. 'hive.metastore.kerberos.principal': config['configurations']['hive-site']['hive.metastore.kerberos.principal'],
  109. 'hive.server2.authentication.kerberos.principal': config['configurations']['hive-site']['hive.server2.authentication.kerberos.principal'],
  110. 'hive.server2.authentication.kerberos.keytab': config['configurations']['hive-site']['hive.server2.authentication.kerberos.keytab'],
  111. 'hive.security.authorization.enabled': spark_hive_sec_authorization_enabled,
  112. 'hive.server2.enable.doAs': str(config['configurations']['hive-site']['hive.server2.enable.doAs']).lower()
  113. }
  114. import functools
  115. #create partial functions with common arguments for every HdfsDirectory call
  116. #to create hdfs directory we need to call params.HdfsDirectory in code
  117. HdfsDirectory = functools.partial(
  118. HdfsDirectory,
  119. conf_dir=hadoop_conf_dir,
  120. hdfs_user=hdfs_user,
  121. security_enabled = security_enabled,
  122. keytab = hdfs_user_keytab,
  123. kinit_path_local = kinit_path_local,
  124. bin_dir = hadoop_bin_dir
  125. )