hbase.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/usr/bin/env 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. import os
  18. from resource_management import *
  19. import sys
  20. from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
  21. from ambari_commons import OSConst
  22. @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
  23. def hbase(name=None):
  24. import params
  25. XmlConfig("hbase-site.xml",
  26. conf_dir = params.hbase_conf_dir,
  27. configurations = params.config['configurations']['hbase-site'],
  28. configuration_attributes=params.config['configuration_attributes']['hbase-site']
  29. )
  30. if params.service_map.has_key(name):
  31. # Manually overriding service logon user & password set by the installation package
  32. service_name = params.service_map[name]
  33. ServiceConfig(service_name,
  34. action="change_user",
  35. username = params.hbase_user,
  36. password = Script.get_password(params.hbase_user))
  37. # name is 'master' or 'regionserver' or 'queryserver' or 'client'
  38. @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
  39. def hbase(name=None):
  40. import params
  41. Directory( params.etc_prefix_dir,
  42. mode=0755
  43. )
  44. Directory( params.hbase_conf_dir,
  45. owner = params.hbase_user,
  46. group = params.user_group,
  47. create_parents = True
  48. )
  49. Directory(params.java_io_tmpdir,
  50. owner = params.hbase_user,
  51. group = params.user_group,
  52. create_parents = True,
  53. mode=0777
  54. )
  55. parent_dir = os.path.dirname(params.tmp_dir)
  56. # In case if we have several placeholders in path
  57. while ("${" in parent_dir):
  58. parent_dir = os.path.dirname(parent_dir)
  59. if parent_dir != os.path.abspath(os.sep) :
  60. Directory (parent_dir,
  61. create_parents = True,
  62. cd_access="a",
  63. )
  64. Execute(("chmod", "1777", parent_dir), sudo=True)
  65. XmlConfig( "hbase-site.xml",
  66. conf_dir = params.hbase_conf_dir,
  67. configurations = params.config['configurations']['hbase-site'],
  68. configuration_attributes=params.config['configuration_attributes']['hbase-site'],
  69. owner = params.hbase_user,
  70. group = params.user_group
  71. )
  72. XmlConfig( "core-site.xml",
  73. conf_dir = params.hbase_conf_dir,
  74. configurations = params.config['configurations']['core-site'],
  75. configuration_attributes=params.config['configuration_attributes']['core-site'],
  76. owner = params.hbase_user,
  77. group = params.user_group
  78. )
  79. if 'hdfs-site' in params.config['configurations']:
  80. XmlConfig( "hdfs-site.xml",
  81. conf_dir = params.hbase_conf_dir,
  82. configurations = params.config['configurations']['hdfs-site'],
  83. configuration_attributes=params.config['configuration_attributes']['hdfs-site'],
  84. owner = params.hbase_user,
  85. group = params.user_group
  86. )
  87. XmlConfig("hdfs-site.xml",
  88. conf_dir=params.hadoop_conf_dir,
  89. configurations=params.config['configurations']['hdfs-site'],
  90. configuration_attributes=params.config['configuration_attributes']['hdfs-site'],
  91. owner=params.hdfs_user,
  92. group=params.user_group
  93. )
  94. if 'hbase-policy' in params.config['configurations']:
  95. XmlConfig( "hbase-policy.xml",
  96. conf_dir = params.hbase_conf_dir,
  97. configurations = params.config['configurations']['hbase-policy'],
  98. configuration_attributes=params.config['configuration_attributes']['hbase-policy'],
  99. owner = params.hbase_user,
  100. group = params.user_group
  101. )
  102. # Manually overriding ownership of file installed by hadoop package
  103. else:
  104. File( format("{params.hbase_conf_dir}/hbase-policy.xml"),
  105. owner = params.hbase_user,
  106. group = params.user_group
  107. )
  108. File(format("{hbase_conf_dir}/hbase-env.sh"),
  109. owner = params.hbase_user,
  110. content=InlineTemplate(params.hbase_env_sh_template),
  111. group = params.user_group,
  112. )
  113. # On some OS this folder could be not exists, so we will create it before pushing there files
  114. Directory(params.limits_conf_dir,
  115. create_parents = True,
  116. owner='root',
  117. group='root'
  118. )
  119. File(os.path.join(params.limits_conf_dir, 'hbase.conf'),
  120. owner='root',
  121. group='root',
  122. mode=0644,
  123. content=Template("hbase.conf.j2")
  124. )
  125. hbase_TemplateConfig( params.metric_prop_file_name,
  126. tag = 'GANGLIA-MASTER' if name == 'master' else 'GANGLIA-RS'
  127. )
  128. hbase_TemplateConfig( 'regionservers')
  129. if params.security_enabled:
  130. hbase_TemplateConfig( format("hbase_{name}_jaas.conf"))
  131. if name != "client":
  132. Directory( params.pid_dir,
  133. owner = params.hbase_user,
  134. create_parents = True,
  135. cd_access = "a",
  136. mode = 0755,
  137. )
  138. Directory (params.log_dir,
  139. owner = params.hbase_user,
  140. create_parents = True,
  141. cd_access = "a",
  142. mode = 0755,
  143. )
  144. if (params.log4j_props != None):
  145. File(format("{params.hbase_conf_dir}/log4j.properties"),
  146. mode=0644,
  147. group=params.user_group,
  148. owner=params.hbase_user,
  149. content=params.log4j_props
  150. )
  151. elif (os.path.exists(format("{params.hbase_conf_dir}/log4j.properties"))):
  152. File(format("{params.hbase_conf_dir}/log4j.properties"),
  153. mode=0644,
  154. group=params.user_group,
  155. owner=params.hbase_user
  156. )
  157. if name == "master":
  158. params.HdfsResource(params.hbase_hdfs_root_dir,
  159. type="directory",
  160. action="create_on_execute",
  161. owner=params.hbase_user
  162. )
  163. params.HdfsResource(params.hbase_staging_dir,
  164. type="directory",
  165. action="create_on_execute",
  166. owner=params.hbase_user,
  167. mode=0711
  168. )
  169. params.HdfsResource(None, action="execute")
  170. if params.phoenix_enabled:
  171. Package(params.phoenix_package)
  172. def hbase_TemplateConfig(name, tag=None):
  173. import params
  174. TemplateConfig( format("{hbase_conf_dir}/{name}"),
  175. owner = params.hbase_user,
  176. template_tag = tag
  177. )