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
|
#!/usr/bin/env python
# Licensed 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 subprocess import check_call
import jujuresources
from jujuresources import resource_path
def bootstrap_resources():
"""
Attempt to load and install resources.
"""
if not jujuresources.verify_resources():
base_url = jujuresources.config_get('resources_mirror')
jujuresources.fetch_resources(base_url=base_url)
if not jujuresources.verify_resources():
check_call(['juju-log', '-l', 'ERROR',
'Resources unavailable; manual intervention required'])
return False
check_call(['pip', 'install', resource_path('pathlib')])
check_call(['pip', 'install', resource_path('charmhelpers')])
return True
def manage():
if not bootstrap_resources():
# defer until resources are available, since charmhelpers, and thus
# the framework, (will be) managed by jujuresources
return
from charmhelpers.core import ch_framework
from charmhelpers.contrib import bigdata
hadoop = bigdata.handlers.apache.HadoopBase()
yarn = bigdata.handlers.apache.YARN(hadoop)
hdfs = bigdata.handlers.apache.HDFS(hadoop)
manager = ch_framework.Manager([
{
'name': 'hadoop-base',
'requires': [
hadoop.verify_conditional_resources,
],
'callbacks': [
hadoop.install,
],
},
{
'name': 'yarn-master',
'provides': [bigdata.relations.YARNMaster(spec=hadoop.spec)],
'requires': [
hadoop.is_installed,
bigdata.relations.HDFSMaster(spec=hadoop.spec),
],
'callbacks': [
yarn.configure_resourcemanager,
yarn.configure_jobhistory,
hdfs.configure_client,
ch_framework.helpers.open_ports(yarn.master_ports),
],
'cleanup': [
ch_framework.helpers.close_ports(yarn.master_ports),
yarn.stop_resourcemanager,
yarn.stop_jobhistory,
],
},
])
manager.manage()
if __name__ == '__main__':
manage()
|