forked from apache/ambari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
livy_server.py
148 lines (113 loc) · 5.61 KB
/
livy_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/python
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from resource_management.libraries.script.script import Script
from resource_management.libraries.functions.check_process_status import check_process_status
from resource_management.libraries.functions.stack_features import check_stack_feature
from resource_management.libraries.functions.constants import StackFeature
from resource_management.core.exceptions import Fail
from resource_management.core.resources.system import Execute
from resource_management.libraries.providers.hdfs_resource import WebHDFSUtil
from resource_management.libraries.providers.hdfs_resource import HdfsResourceProvider
from resource_management import is_empty
from resource_management import shell
from resource_management.libraries.functions.decorator import retry
from resource_management.core.logger import Logger
from resource_management.libraries.functions.format import format
from resource_management.libraries.functions import stack_select
from resource_management.libraries.functions import namenode_ha_utils
from livy_service import livy_service
from setup_livy import setup_livy
class LivyServer(Script):
def install(self, env):
import params
env.set_params(params)
self.install_packages(env)
def configure(self, env, upgrade_type=None):
import params
env.set_params(params)
setup_livy(env, 'server', upgrade_type=upgrade_type, action = 'config')
def start(self, env, upgrade_type=None):
import params
env.set_params(params)
if params.has_ats and params.has_livyserver:
Logger.info("Verifying DFS directories where ATS stores time line data for active and completed applications.")
self.wait_for_dfs_directories_created([params.entity_groupfs_store_dir, params.entity_groupfs_active_dir])
self.configure(env)
livy_service('server', upgrade_type=upgrade_type, action='start')
def stop(self, env, upgrade_type=None):
import params
env.set_params(params)
livy_service('server', upgrade_type=upgrade_type, action='stop')
def status(self, env):
import status_params
env.set_params(status_params)
check_process_status(status_params.livy_server_pid_file)
# TODO move out and compose with similar method in resourcemanager.py
def wait_for_dfs_directories_created(self, dirs):
import params
ignored_dfs_dirs = HdfsResourceProvider.get_ignored_resources_list(params.hdfs_resource_ignore_file)
if params.security_enabled:
Execute(format("{kinit_path_local} -kt {livy_kerberos_keytab} {livy_principal}"),
user=params.livy_user
)
Execute(format("{kinit_path_local} -kt {hdfs_user_keytab} {hdfs_principal_name}"),
user=params.hdfs_user
)
for dir_path in dirs:
self.wait_for_dfs_directory_created(dir_path, ignored_dfs_dirs)
def get_pid_files(self):
import status_params
return [status_params.livy_server_pid_file]
@retry(times=8, sleep_time=20, backoff_factor=1, err_class=Fail)
def wait_for_dfs_directory_created(self, dir_path, ignored_dfs_dirs):
import params
if not is_empty(dir_path):
dir_path = HdfsResourceProvider.parse_path(dir_path)
if dir_path in ignored_dfs_dirs:
Logger.info("Skipping DFS directory '" + dir_path + "' as it's marked to be ignored.")
return
Logger.info("Verifying if DFS directory '" + dir_path + "' exists.")
dir_exists = None
nameservices = namenode_ha_utils.get_nameservices(params.hdfs_site)
nameservice = None if not nameservices else nameservices[-1]
if WebHDFSUtil.is_webhdfs_available(params.is_webhdfs_enabled, params.dfs_type):
# check with webhdfs is much faster than executing hdfs dfs -test
util = WebHDFSUtil(params.hdfs_site, nameservice, params.hdfs_user, params.security_enabled)
list_status = util.run_command(dir_path, 'GETFILESTATUS', method='GET', ignore_status_codes=['404'], assertable_result=False)
dir_exists = ('FileStatus' in list_status)
else:
# have to do time expensive hdfs dfs -d check.
dfs_ret_code = shell.call(format("hdfs --config {hadoop_conf_dir} dfs -test -d " + dir_path), user=params.livy_user)[0]
dir_exists = not dfs_ret_code #dfs -test -d returns 0 in case the dir exists
if not dir_exists:
raise Fail("DFS directory '" + dir_path + "' does not exist !")
else:
Logger.info("DFS directory '" + dir_path + "' exists.")
def pre_upgrade_restart(self, env, upgrade_type=None):
import params
env.set_params(params)
if params.version and check_stack_feature(StackFeature.ROLLING_UPGRADE, params.version):
Logger.info("Executing Livy Server Stack Upgrade pre-restart")
stack_select.select_packages(params.version)
def get_log_folder(self):
import params
return params.livy_log_dir
def get_user(self):
import params
return params.livy_user
if __name__ == "__main__":
LivyServer().execute()