params.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. """
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF 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. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. """
  16. import functools
  17. import hawq_constants
  18. from resource_management import Script
  19. from resource_management.libraries.functions.default import default
  20. from resource_management.libraries.resources.hdfs_resource import HdfsResource
  21. from resource_management.libraries.resources.xml_config import XmlConfig
  22. from resource_management.libraries.functions import get_kinit_path
  23. config = Script.get_config()
  24. config_attrs = config['configuration_attributes']
  25. def __get_component_host(component):
  26. """
  27. Returns the first host where the given component is deployed, None if the component is not deployed
  28. """
  29. component_host = None
  30. if component in config['clusterHostInfo'] and len(config['clusterHostInfo'][component]) > 0:
  31. component_host = config['clusterHostInfo'][component][0]
  32. return component_host
  33. hostname = config['hostname']
  34. # Users and Groups
  35. hdfs_superuser = config['configurations']['hadoop-env']['hdfs_user']
  36. user_group = config['configurations']['cluster-env']['user_group']
  37. # Convert hawq_password to unicode for crypt() function in case user enters a numeric password
  38. hawq_password = unicode(config['configurations']['hawq-env']['hawq_password'])
  39. # HAWQ Hostnames
  40. hawqmaster_host = __get_component_host('hawqmaster_hosts')
  41. hawqstandby_host = __get_component_host('hawqstandby_hosts')
  42. hawqsegment_hosts = default('/clusterHostInfo/hawqsegment_hosts', [])
  43. hawq_master_hosts = [host for host in hawqmaster_host, hawqstandby_host if host]
  44. hawq_all_hosts = set(hawq_master_hosts + hawqsegment_hosts)
  45. # HDFS
  46. hdfs_site = config['configurations']['hdfs-site']
  47. default_fs = config['configurations']['core-site']['fs.defaultFS']
  48. security_enabled = config['configurations']['cluster-env']['security_enabled']
  49. hdfs_user_keytab = config['configurations']['hadoop-env']['hdfs_user_keytab']
  50. kinit_path_local = get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None))
  51. hdfs_principal_name = config['configurations']['hadoop-env']['hdfs_principal_name']
  52. dfs_nameservice = default('/configurations/hdfs-site/dfs.nameservices', None)
  53. # HDFSResource partial function
  54. HdfsResource = functools.partial(HdfsResource,
  55. user=hdfs_superuser,
  56. security_enabled=security_enabled,
  57. keytab=hdfs_user_keytab,
  58. kinit_path_local=kinit_path_local,
  59. principal_name=hdfs_principal_name,
  60. hdfs_site=hdfs_site,
  61. default_fs=default_fs)
  62. # XMLConfig partial function
  63. XmlConfig = functools.partial(XmlConfig,
  64. conf_dir=hawq_constants.hawq_config_dir,
  65. owner=hawq_constants.hawq_user,
  66. group=hawq_constants.hawq_group,
  67. mode=0644)
  68. # For service Check
  69. is_pxf_installed = __get_component_host("pxf_hosts") is not None
  70. namenode_path = "{0}:{1}".format(__get_component_host("namenode_host"), hawq_constants.PXF_PORT) if dfs_nameservice is None else dfs_nameservice
  71. table_definition = {
  72. "HAWQ": {
  73. "name": "ambari_hawq_test",
  74. "create_type": "",
  75. "drop_type": "",
  76. "description": "(col1 int) DISTRIBUTED RANDOMLY"
  77. },
  78. "EXTERNAL_HDFS_READABLE": {
  79. "name": "ambari_hawq_pxf_hdfs_readable_test",
  80. "create_type": "READABLE EXTERNAL",
  81. "drop_type": "EXTERNAL",
  82. "description": "(col1 int) LOCATION ('pxf://{0}{1}?PROFILE=HdfsTextSimple') FORMAT 'TEXT'".format(namenode_path, hawq_constants.pxf_hdfs_test_dir)
  83. },
  84. "EXTERNAL_HDFS_WRITABLE": {
  85. "name": "ambari_hawq_pxf_hdfs_writable_test",
  86. "create_type": "WRITABLE EXTERNAL",
  87. "drop_type": "EXTERNAL",
  88. "description": "(col1 int) LOCATION ('pxf://{0}{1}?PROFILE=HdfsTextSimple') FORMAT 'TEXT'".format(namenode_path, hawq_constants.pxf_hdfs_test_dir)
  89. }
  90. }
  91. # YARN
  92. # Note: YARN is not mandatory for HAWQ. It is required only when the users set HAWQ to use YARN as resource manager
  93. rm_host = __get_component_host('rm_host')
  94. yarn_ha_enabled = default('/configurations/yarn-site/yarn.resourcemanager.ha.enabled', False)
  95. # Config files
  96. hawq_check_content = config['configurations']['hawq-check-env']['content']
  97. # database user limits
  98. hawq_limits = config['configurations']['hawq-limits-env']
  99. # sysctl parameters
  100. hawq_sysctl = config['configurations']['hawq-sysctl-env']
  101. # hawq config
  102. hawq_site = config['configurations']['hawq-site']
  103. # hdfs-client for enabling HAWQ to work with HDFS namenode HA
  104. hdfs_client = config['configurations']['hdfs-client']
  105. # yarn-client for enabling HAWQ to work with YARN resource manager HA
  106. yarn_client = config['configurations']['yarn-client']
  107. # Directories and ports
  108. hawq_master_dir = hawq_site.get('hawq_master_directory')
  109. hawq_segment_dir = hawq_site.get('hawq_segment_directory')
  110. hawq_master_temp_dir = hawq_site.get('hawq_master_temp_directory')
  111. hawq_segment_temp_dir = hawq_site.get('hawq_segment_temp_directory')
  112. # Extract hawq hdfs directory from hdfs url. Ex: /hawq/hawq_default from
  113. # host:8080/hawq/hawq_default
  114. hawq_hdfs_data_dir = "/{0}".format(hawq_site.get('hawq_dfs_url').split('/', 1)[1])
  115. hawq_master_address_port = hawq_site.get('hawq_master_address_port')
  116. hawq_segment_address_port = hawq_site.get('hawq_segment_address_port')