params.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 os
  17. import functools
  18. from hawq_constants import PXF_PORT, pxf_hdfs_test_dir
  19. from resource_management import Script
  20. from resource_management.libraries.functions.default import default
  21. from resource_management.libraries.resources.hdfs_resource import HdfsResource
  22. from resource_management.libraries.functions import get_kinit_path
  23. config = Script.get_config()
  24. def __get_component_host(component):
  25. """
  26. Returns the first host where the given component is deployed, None if the component is not deployed
  27. """
  28. component_host = None
  29. if component in config['clusterHostInfo'] and len(config['clusterHostInfo'][component]) > 0:
  30. component_host = config['clusterHostInfo'][component][0]
  31. return component_host
  32. hostname = config['hostname']
  33. # Users and Groups
  34. hdfs_superuser = config['configurations']['hadoop-env']['hdfs_user']
  35. user_group = config['configurations']['cluster-env']['user_group']
  36. # Convert hawq_password to unicode for crypt() function in case user enters a numeric password
  37. hawq_password = unicode(config['configurations']['hawq-env']['hawq_password'])
  38. # HAWQ Hostnames
  39. hawqmaster_host = __get_component_host('hawqmaster_hosts')
  40. hawqstandby_host = __get_component_host('hawqstandby_hosts')
  41. hawqsegment_hosts = default('/clusterHostInfo/hawqsegment_hosts', [])
  42. hawq_master_hosts = [host for host in hawqmaster_host, hawqstandby_host if host]
  43. hawq_all_hosts = set(hawq_master_hosts + hawqsegment_hosts)
  44. # HDFS
  45. hdfs_site = config['configurations']['hdfs-site']
  46. default_fs = config['configurations']['core-site']['fs.defaultFS']
  47. security_enabled = config['configurations']['cluster-env']['security_enabled']
  48. hdfs_user_keytab = config['configurations']['hadoop-env']['hdfs_user_keytab']
  49. kinit_path_local = get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None))
  50. hdfs_principal_name = config['configurations']['hadoop-env']['hdfs_principal_name']
  51. dfs_nameservice = default('/configurations/hdfs-site/dfs.nameservices', None)
  52. # HDFSResource partial function
  53. HdfsResource = functools.partial(HdfsResource,
  54. user=hdfs_superuser,
  55. security_enabled=security_enabled,
  56. keytab=hdfs_user_keytab,
  57. kinit_path_local=kinit_path_local,
  58. principal_name=hdfs_principal_name,
  59. hdfs_site=hdfs_site,
  60. default_fs=default_fs)
  61. # For service Check
  62. is_pxf_installed = __get_component_host("pxf_hosts") is not None
  63. namenode_path = "{0}:{1}".format(__get_component_host("namenode_host"), PXF_PORT) if dfs_nameservice is None else dfs_nameservice
  64. table_definition = {
  65. "HAWQ": {
  66. "name": "ambari_hawq_test",
  67. "create_type": "",
  68. "drop_type": "",
  69. "description": "(col1 int) DISTRIBUTED RANDOMLY"
  70. },
  71. "EXTERNAL_HDFS_READABLE": {
  72. "name": "ambari_hawq_pxf_hdfs_readable_test",
  73. "create_type": "READABLE EXTERNAL",
  74. "drop_type": "EXTERNAL",
  75. "description": "(col1 int) LOCATION ('pxf://{0}{1}?PROFILE=HdfsTextSimple') FORMAT 'TEXT'".format(namenode_path, pxf_hdfs_test_dir)
  76. },
  77. "EXTERNAL_HDFS_WRITABLE": {
  78. "name": "ambari_hawq_pxf_hdfs_writable_test",
  79. "create_type": "WRITABLE EXTERNAL",
  80. "drop_type": "EXTERNAL",
  81. "description": "(col1 int) LOCATION ('pxf://{0}{1}?PROFILE=HdfsTextSimple') FORMAT 'TEXT'".format(namenode_path, pxf_hdfs_test_dir)
  82. }
  83. }
  84. # YARN
  85. # Note: YARN is not mandatory for HAWQ. It is required only when the users set HAWQ to use YARN as resource manager
  86. rm_host = __get_component_host('rm_host')
  87. yarn_ha_enabled = default('/configurations/yarn-site/yarn.resourcemanager.ha.enabled', False)
  88. # Config files
  89. gpcheck_content = config['configurations']['gpcheck-env']['content']
  90. # database user limits
  91. hawq_limits = config['configurations']['hawq-limits-env']
  92. # sysctl parameters
  93. hawq_sysctl = config['configurations']['hawq-sysctl-env']
  94. # hawq config
  95. hawq_site = config['configurations']['hawq-site']
  96. # hdfs-client for enabling HAWQ to work with HDFS namenode HA
  97. hdfs_client = config['configurations']['hdfs-client']
  98. # yarn-client for enabling HAWQ to work with YARN resource manager HA
  99. yarn_client = config['configurations']['yarn-client']
  100. # Directories and ports
  101. hawq_master_dir = hawq_site.get('hawq_master_directory')
  102. hawq_segment_dir = hawq_site.get('hawq_segment_directory')
  103. hawq_master_temp_dir = hawq_site.get('hawq_master_temp_directory')
  104. hawq_segment_temp_dir = hawq_site.get('hawq_segment_temp_directory')
  105. # Extract hawq hdfs directory from hdfs url. Ex: /hawq/hawq_default from
  106. # host:8080/hawq/hawq_default
  107. hawq_hdfs_data_dir = "/{0}".format(hawq_site.get('hawq_dfs_url').split('/', 1)[1])
  108. hawq_master_address_port = hawq_site.get('hawq_master_address_port')
  109. hawq_segment_address_port = hawq_site.get('hawq_segment_address_port')