journalnode.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. from resource_management import *
  17. from resource_management.libraries.functions import conf_select
  18. from resource_management.libraries.functions import stack_select
  19. from resource_management.libraries.functions.version import compare_versions, \
  20. format_stack_version
  21. from resource_management.libraries.functions.format import format
  22. from resource_management.libraries.functions.security_commons import build_expectations, \
  23. cached_kinit_executor, get_params_from_filesystem, validate_security_config_properties, \
  24. FILE_TYPE_XML
  25. from utils import service
  26. from hdfs import hdfs
  27. import journalnode_upgrade
  28. from ambari_commons.os_family_impl import OsFamilyImpl
  29. from ambari_commons import OSConst
  30. class JournalNode(Script):
  31. def install(self, env):
  32. import params
  33. env.set_params(params)
  34. self.install_packages(env)
  35. @OsFamilyImpl(os_family=OsFamilyImpl.DEFAULT)
  36. class JournalNodeDefault(JournalNode):
  37. def get_stack_to_component(self):
  38. return {"HDP": "hadoop-hdfs-journalnode"}
  39. def pre_upgrade_restart(self, env, upgrade_type=None):
  40. Logger.info("Executing Stack Upgrade pre-restart")
  41. import params
  42. env.set_params(params)
  43. if params.version and compare_versions(format_stack_version(params.version), '2.2.0.0') >= 0:
  44. conf_select.select(params.stack_name, "hadoop", params.version)
  45. stack_select.select("hadoop-hdfs-journalnode", params.version)
  46. def start(self, env, upgrade_type=None):
  47. import params
  48. env.set_params(params)
  49. self.configure(env)
  50. service(
  51. action="start", name="journalnode", user=params.hdfs_user,
  52. create_pid_dir=True,
  53. create_log_dir=True
  54. )
  55. def post_upgrade_restart(self, env, upgrade_type=None):
  56. if upgrade_type == "nonrolling":
  57. return
  58. Logger.info("Executing Stack Upgrade post-restart")
  59. import params
  60. env.set_params(params)
  61. journalnode_upgrade.post_upgrade_check()
  62. def stop(self, env, upgrade_type=None):
  63. import params
  64. env.set_params(params)
  65. service(
  66. action="stop", name="journalnode", user=params.hdfs_user,
  67. create_pid_dir=True,
  68. create_log_dir=True
  69. )
  70. def configure(self, env):
  71. import params
  72. Directory(params.jn_edits_dir,
  73. create_parents = True,
  74. cd_access="a",
  75. owner=params.hdfs_user,
  76. group=params.user_group
  77. )
  78. env.set_params(params)
  79. hdfs()
  80. pass
  81. def status(self, env):
  82. import status_params
  83. env.set_params(status_params)
  84. check_process_status(status_params.journalnode_pid_file)
  85. def security_status(self, env):
  86. import status_params
  87. env.set_params(status_params)
  88. props_value_check = {"hadoop.security.authentication": "kerberos",
  89. "hadoop.security.authorization": "true"}
  90. props_empty_check = ["hadoop.security.auth_to_local"]
  91. props_read_check = None
  92. core_site_expectations = build_expectations('core-site', props_value_check, props_empty_check,
  93. props_read_check)
  94. props_value_check = None
  95. props_empty_check = ['dfs.journalnode.keytab.file',
  96. 'dfs.journalnode.kerberos.principal']
  97. props_read_check = ['dfs.journalnode.keytab.file']
  98. hdfs_site_expectations = build_expectations('hdfs-site', props_value_check, props_empty_check,
  99. props_read_check)
  100. hdfs_expectations = {}
  101. hdfs_expectations.update(hdfs_site_expectations)
  102. hdfs_expectations.update(core_site_expectations)
  103. security_params = get_params_from_filesystem(status_params.hadoop_conf_dir,
  104. {'core-site.xml': FILE_TYPE_XML})
  105. if 'core-site' in security_params and 'hadoop.security.authentication' in security_params['core-site'] and \
  106. security_params['core-site']['hadoop.security.authentication'].lower() == 'kerberos':
  107. result_issues = validate_security_config_properties(security_params, hdfs_expectations)
  108. if not result_issues: # If all validations passed successfully
  109. try:
  110. # Double check the dict before calling execute
  111. if ('hdfs-site' not in security_params or
  112. 'dfs.journalnode.kerberos.keytab.file' not in security_params['hdfs-site'] or
  113. 'dfs.journalnode.kerberos.principal' not in security_params['hdfs-site']):
  114. self.put_structured_out({"securityState": "UNSECURED"})
  115. self.put_structured_out(
  116. {"securityIssuesFound": "Keytab file or principal are not set property."})
  117. return
  118. cached_kinit_executor(status_params.kinit_path_local,
  119. status_params.hdfs_user,
  120. security_params['hdfs-site']['dfs.journalnode.kerberos.keytab.file'],
  121. security_params['hdfs-site']['dfs.journalnode.kerberos.principal'],
  122. status_params.hostname,
  123. status_params.tmp_dir)
  124. self.put_structured_out({"securityState": "SECURED_KERBEROS"})
  125. except Exception as e:
  126. self.put_structured_out({"securityState": "ERROR"})
  127. self.put_structured_out({"securityStateErrorInfo": str(e)})
  128. else:
  129. issues = []
  130. for cf in result_issues:
  131. issues.append("Configuration file %s did not pass the validation. Reason: %s" % (cf, result_issues[cf]))
  132. self.put_structured_out({"securityIssuesFound": ". ".join(issues)})
  133. self.put_structured_out({"securityState": "UNSECURED"})
  134. else:
  135. self.put_structured_out({"securityState": "UNSECURED"})
  136. @OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY)
  137. class JournalNodeWindows(JournalNode):
  138. def install(self, env):
  139. import install_params
  140. self.install_packages(env)
  141. def start(self, env):
  142. import params
  143. self.configure(env)
  144. Service(params.journalnode_win_service_name, action="start")
  145. def stop(self, env):
  146. import params
  147. Service(params.journalnode_win_service_name, action="stop")
  148. def configure(self, env):
  149. import params
  150. env.set_params(params)
  151. hdfs("journalnode")
  152. pass
  153. def status(self, env):
  154. import status_params
  155. env.set_params(status_params)
  156. check_windows_service_status(status_params.journalnode_win_service_name)
  157. if __name__ == "__main__":
  158. JournalNode().execute()