falcon.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.path
  17. import traceback
  18. # Local Imports
  19. from resource_management.core.environment import Environment
  20. from resource_management.core.source import InlineTemplate
  21. from resource_management.core.source import Template
  22. from resource_management.core.source import DownloadSource
  23. from resource_management.core.resources import Execute
  24. from resource_management.core.resources.service import Service
  25. from resource_management.core.resources.service import ServiceConfig
  26. from resource_management.core.resources.system import Directory
  27. from resource_management.core.resources.system import File
  28. from resource_management.libraries.script import Script
  29. from resource_management.libraries.resources import PropertiesFile
  30. from resource_management.libraries.functions import format
  31. from resource_management.libraries.functions.show_logs import show_logs
  32. from resource_management.libraries.functions.setup_atlas_hook import has_atlas_in_cluster, setup_atlas_hook, install_atlas_hook_packages, setup_atlas_jar_symlinks
  33. from resource_management.libraries.functions.stack_features import check_stack_feature
  34. from resource_management.libraries.functions import get_user_call_output
  35. from resource_management.libraries.functions import StackFeature
  36. from ambari_commons.constants import SERVICE
  37. from resource_management.core.logger import Logger
  38. from ambari_commons import OSConst
  39. from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
  40. @OsFamilyFuncImpl(os_family = OsFamilyImpl.DEFAULT)
  41. def falcon(type, action = None, upgrade_type=None):
  42. import params
  43. if action == 'config':
  44. Directory(params.falcon_pid_dir,
  45. owner = params.falcon_user,
  46. create_parents = True,
  47. mode = 0755,
  48. cd_access = "a",
  49. )
  50. Directory(params.falcon_log_dir,
  51. owner = params.falcon_user,
  52. create_parents = True,
  53. mode = 0755,
  54. cd_access = "a",
  55. )
  56. Directory(params.falcon_webapp_dir,
  57. owner = params.falcon_user,
  58. create_parents = True)
  59. Directory(params.falcon_home,
  60. owner = params.falcon_user,
  61. create_parents = True)
  62. Directory(params.etc_prefix_dir,
  63. mode = 0755,
  64. create_parents = True)
  65. Directory(params.falcon_conf_dir,
  66. owner = params.falcon_user,
  67. create_parents = True)
  68. File(params.falcon_conf_dir + '/falcon-env.sh',
  69. content = InlineTemplate(params.falcon_env_sh_template),
  70. owner = params.falcon_user,
  71. group=params.user_group,
  72. )
  73. PropertiesFile(params.falcon_conf_dir + '/client.properties',
  74. properties = params.falcon_client_properties,
  75. mode = 0644,
  76. owner = params.falcon_user)
  77. PropertiesFile(params.falcon_conf_dir + '/runtime.properties',
  78. properties = params.falcon_runtime_properties,
  79. mode = 0644,
  80. owner = params.falcon_user)
  81. PropertiesFile(params.falcon_conf_dir + '/startup.properties',
  82. properties = params.falcon_startup_properties,
  83. mode = 0644,
  84. owner = params.falcon_user)
  85. if params.falcon_graph_storage_directory:
  86. Directory(params.falcon_graph_storage_directory,
  87. owner = params.falcon_user,
  88. group = params.user_group,
  89. mode = 0775,
  90. create_parents = True,
  91. cd_access = "a")
  92. if params.falcon_graph_serialize_path:
  93. Directory(params.falcon_graph_serialize_path,
  94. owner = params.falcon_user,
  95. group = params.user_group,
  96. mode = 0775,
  97. create_parents = True,
  98. cd_access = "a")
  99. # Generate atlas-application.properties.xml file
  100. if params.falcon_atlas_support:
  101. # If Atlas is added later than Falcon, this package will be absent.
  102. install_atlas_hook_packages()
  103. atlas_hook_filepath = os.path.join(params.falcon_conf_dir, params.atlas_hook_filename)
  104. setup_atlas_hook(SERVICE.FALCON, params.falcon_atlas_application_properties, atlas_hook_filepath, params.falcon_user, params.user_group)
  105. # Falcon 0.10 uses FALCON_EXTRA_CLASS_PATH.
  106. # Setup symlinks for older versions.
  107. if params.current_version_formatted and check_stack_feature(StackFeature.FALCON_ATLAS_SUPPORT_2_3, params.current_version_formatted):
  108. setup_atlas_jar_symlinks("falcon", params.falcon_webinf_lib)
  109. if type == 'server':
  110. if action == 'config':
  111. if params.store_uri[0:4] == "hdfs":
  112. params.HdfsResource(params.store_uri,
  113. type = "directory",
  114. action = "create_on_execute",
  115. owner = params.falcon_user,
  116. mode = 0755)
  117. elif params.store_uri[0:4] == "file":
  118. Directory(params.store_uri[7:],
  119. owner = params.falcon_user,
  120. create_parents = True)
  121. # TODO change to proper mode
  122. params.HdfsResource(params.falcon_apps_dir,
  123. type = "directory",
  124. action = "create_on_execute",
  125. owner = params.falcon_user,
  126. mode = 0777)
  127. # In HDP 2.4 and earlier, the data-mirroring directory was copied to HDFS.
  128. if params.supports_data_mirroring:
  129. params.HdfsResource(params.dfs_data_mirroring_dir,
  130. type = "directory",
  131. action = "create_on_execute",
  132. owner = params.falcon_user,
  133. group = params.proxyuser_group,
  134. recursive_chown = True,
  135. recursive_chmod = True,
  136. mode = 0770,
  137. source = params.local_data_mirroring_dir)
  138. if params.supports_falcon_extensions:
  139. params.HdfsResource(params.falcon_extensions_dest_dir,
  140. type = "directory",
  141. action = "create_on_execute",
  142. owner = params.falcon_user,
  143. group = params.proxyuser_group,
  144. recursive_chown = True,
  145. recursive_chmod = True,
  146. mode = 0755,
  147. source = params.falcon_extensions_source_dir)
  148. # Create the extensons HiveDR store
  149. params.HdfsResource(os.path.join(params.falcon_extensions_dest_dir, "mirroring"),
  150. type = "directory",
  151. action = "create_on_execute",
  152. owner = params.falcon_user,
  153. group = params.proxyuser_group,
  154. mode = 0770)
  155. # At least one HDFS Dir should be created, so execute the change now.
  156. params.HdfsResource(None, action = "execute")
  157. Directory(params.falcon_local_dir,
  158. owner = params.falcon_user,
  159. create_parents = True,
  160. cd_access = "a")
  161. if params.falcon_embeddedmq_enabled == True:
  162. Directory(
  163. os.path.abspath(os.path.join(params.falcon_embeddedmq_data, "..")),
  164. owner = params.falcon_user,
  165. create_parents = True)
  166. Directory(params.falcon_embeddedmq_data,
  167. owner = params.falcon_user,
  168. create_parents = True)
  169. # although Falcon's falcon-config.sh will use 'which hadoop' to figure
  170. # this out, in an upgraded cluster, it's possible that 'which hadoop'
  171. # still points to older binaries; it's safer to just pass in the
  172. # hadoop home directory to use
  173. environment_dictionary = { "HADOOP_HOME" : params.hadoop_home_dir }
  174. pid = get_user_call_output.get_user_call_output(format("cat {server_pid_file}"), user=params.falcon_user, is_checked_call=False)[1]
  175. process_exists = format("ls {server_pid_file} && ps -p {pid}")
  176. if action == 'start':
  177. if not os.path.exists(params.target_jar_file):
  178. try :
  179. File(params.target_jar_file,
  180. content = DownloadSource(params.bdb_resource_name))
  181. except :
  182. exc_msg = traceback.format_exc()
  183. exception_message = format("Caught Exception while downloading {bdb_resource_name}:\n{exc_msg}")
  184. Logger.error(exception_message)
  185. if not os.path.isfile(params.target_jar_file) :
  186. error_message = """
  187. If you are using bdb as the Falcon graph db store, please run
  188. ambari-server setup --jdbc-db=bdb --jdbc-driver=<path to je5.0.73.jar
  189. on the ambari server host. Otherwise falcon startup will fail.
  190. Otherwise please configure Falcon to use HBase as the backend as described
  191. in the Falcon documentation.
  192. """
  193. Logger.error(error_message)
  194. try:
  195. Execute(format('{falcon_home}/bin/falcon-start -port {falcon_port}'),
  196. user = params.falcon_user,
  197. path = params.hadoop_bin_dir,
  198. environment=environment_dictionary,
  199. not_if = process_exists,
  200. )
  201. except:
  202. show_logs(params.falcon_log_dir, params.falcon_user)
  203. raise
  204. if action == 'stop':
  205. try:
  206. Execute(format('{falcon_home}/bin/falcon-stop'),
  207. user = params.falcon_user,
  208. path = params.hadoop_bin_dir,
  209. environment=environment_dictionary)
  210. except:
  211. show_logs(params.falcon_log_dir, params.falcon_user)
  212. raise
  213. File(params.server_pid_file, action = 'delete')
  214. @OsFamilyFuncImpl(os_family = OSConst.WINSRV_FAMILY)
  215. def falcon(type, action = None, upgrade_type=None):
  216. import params
  217. if action == 'config':
  218. env = Environment.get_instance()
  219. # These 2 parameters are used in ../templates/client.properties.j2
  220. env.config.params["falcon_host"] = params.falcon_host
  221. env.config.params["falcon_port"] = params.falcon_port
  222. File(os.path.join(params.falcon_conf_dir, 'falcon-env.sh'),
  223. content = InlineTemplate(params.falcon_env_sh_template))
  224. PropertiesFile(os.path.join(params.falcon_conf_dir, 'runtime.properties'),
  225. properties = params.falcon_runtime_properties)
  226. PropertiesFile(os.path.join(params.falcon_conf_dir, 'startup.properties'),
  227. properties = params.falcon_startup_properties)
  228. PropertiesFile(os.path.join(params.falcon_conf_dir, 'client.properties'),
  229. properties = params.falcon_client_properties)
  230. if type == 'server':
  231. ServiceConfig(params.falcon_win_service_name,
  232. action = "change_user",
  233. username = params.falcon_user,
  234. password = Script.get_password(params.falcon_user))
  235. if action == 'start':
  236. Service(params.falcon_win_service_name, action = "start")
  237. if action == 'stop':
  238. Service(params.falcon_win_service_name, action = "stop")