AMBARI-21581 - Replace Hard Coded conf-select Structures (jonathanhurley)
[ambari.git] / ambari-server / src / main / resources / common-services / DRUID / 0.9.2 / package / scripts / druid_node.py
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
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 """
19 import os
20 from resource_management.core import sudo
21 from resource_management import Script
22 from resource_management.core.logger import Logger
23 from resource_management.core.resources.system import Execute
24 from resource_management.libraries.functions.format import format
25 from resource_management.libraries.functions import stack_select
26 from resource_management.libraries.functions import StackFeature
27 from resource_management.libraries.functions.stack_features import check_stack_feature
28 from resource_management.libraries.functions.check_process_status import check_process_status
29 from resource_management.libraries.functions.show_logs import show_logs
30 from druid import druid, get_daemon_cmd, getPid
31
32
33 class DruidBase(Script):
34 def __init__(self, nodeType=None):
35 self.nodeType = nodeType
36
37 def install(self, env):
38 self.install_packages(env)
39
40 def configure(self, env, upgrade_type=None):
41 import params
42 env.set_params(params)
43 druid(upgrade_type=upgrade_type, nodeType=self.nodeType)
44
45 def pre_upgrade_restart(self, env, upgrade_type=None):
46 node_type_lower = self.nodeType.lower()
47 Logger.info(format("Executing druid-{node_type_lower} Upgrade pre-restart"))
48 import params
49
50 env.set_params(params)
51
52 if params.stack_version and check_stack_feature(StackFeature.ROLLING_UPGRADE, params.stack_version):
53 stack_select.select_packages(params.stack_version)
54
55 def start(self, env, upgrade_type=None):
56 import params
57 env.set_params(params)
58 self.configure(env, upgrade_type=upgrade_type)
59 daemon_cmd = get_daemon_cmd(params, self.nodeType, "start")
60 # Verify Database connection on Druid start
61 if params.metadata_storage_type == 'mysql':
62 if not params.jdbc_driver_jar or not os.path.isfile(params.connector_download_dir + os.path.sep + params.jdbc_driver_jar):
63 path_to_jdbc = params.connector_download_dir + os.path.sep + "*"
64 error_message = "Error! Sorry, but we can't find jdbc driver for mysql.So, db connection check can fail." + \
65 "Please run 'ambari-server setup --jdbc-db=mysql --jdbc-driver={path_to_jdbc} on server host.'"
66 Logger.error(error_message)
67 else:
68 path_to_jdbc = params.connector_download_dir + os.path.sep + params.jdbc_driver_jar
69 db_connection_check_command = format("{params.java8_home}/bin/java -cp {params.check_db_connection_jar}:{path_to_jdbc} org.apache.ambari.server.DBConnectionVerification '{params.metadata_storage_url}' {params.metadata_storage_user} {params.metadata_storage_password!p} com.mysql.jdbc.Driver")
70 else:
71 db_connection_check_command = None
72
73 if db_connection_check_command:
74 sudo.chmod(params.check_db_connection_jar, 0755)
75 Execute( db_connection_check_command,
76 tries=5,
77 try_sleep=10,
78 user=params.druid_user
79 )
80
81 try:
82 Execute(daemon_cmd,
83 user=params.druid_user
84 )
85 except:
86 show_logs(params.druid_log_dir, params.druid_user)
87 raise
88
89 def stop(self, env, upgrade_type=None):
90 import params
91 env.set_params(params)
92
93 daemon_cmd = get_daemon_cmd(params, self.nodeType, "stop")
94 try:
95 Execute(daemon_cmd,
96 user=params.druid_user
97 )
98 except:
99 show_logs(params.druid_log_dir, params.druid_user)
100 raise
101
102 def status(self, env):
103 import status_params
104 env.set_params(status_params)
105 pid_file = getPid(status_params, self.nodeType)
106 check_process_status(pid_file)
107
108 def get_log_folder(self):
109 import params
110 return params.druid_log_dir
111
112 def get_user(self):
113 import params
114 return params.druid_user