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
|
#!.venv/bin/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.
"""
Common implementation for all hooks.
"""
import os
import jujuresources
from charmhelpers.core import hookenv
from charmhelpers.core import unitdata
from charmhelpers.core import charmframework
# ensure that the venv is used for installing resources
# (venv is used to ensure library versions needed by plugin
# don't conflict with the charm the plugin is supporting)
os.environ['PATH'] = os.pathsep.join([
os.path.join(hookenv.charm_dir(), '.venv/bin'),
os.environ['PATH']])
def bootstrap_resources():
"""
Install required resources defined in resources.yaml
"""
if unitdata.kv().get('charm.bootstrapped', False):
return True
hookenv.status_set('maintenance', 'Installing base resources')
mirror_url = jujuresources.config_get('resources_mirror')
if not jujuresources.fetch(mirror_url=mirror_url):
missing = jujuresources.invalid()
hookenv.status_set('blocked', 'Unable to fetch required resource%s: %s' % (
's' if len(missing) > 1 else '',
', '.join(missing),
))
return False
jujuresources.install(['pathlib', 'jujubigdata', 'charm-benchmark'])
unitdata.kv().set('charm.bootstrapped', True)
return True
def manage():
if not bootstrap_resources():
# defer until resources are available, since jujubigdata, and thus the
# classes needed for the requires blocks, (will be) managed by jujuresources
return
import jujubigdata
import callbacks
# list of keys required to be in the dist.yaml
client_reqs = ['vendor', 'hadoop_version', 'packages', 'groups', 'users',
'dirs']
dist_config = jujubigdata.utils.DistConfig(filename='dist.yaml',
required_keys=client_reqs)
hadoop = jujubigdata.handlers.HadoopBase(dist_config)
hdfs = jujubigdata.handlers.HDFS(hadoop)
yarn = jujubigdata.handlers.YARN(hadoop)
hdfs_relation = jujubigdata.relations.NameNode(spec=hadoop.client_spec)
yarn_relation = jujubigdata.relations.ResourceManager(spec=hadoop.client_spec)
manager = charmframework.Manager([
{
'name': 'hadoop-base',
'requires': [
hadoop.verify_conditional_resources,
],
'callbacks': [
hadoop.install,
callbacks.update_blocked_status,
],
},
{
'name': 'hdfs',
'provides': [
jujubigdata.relations.HadoopPlugin(),
],
'requires': [
hadoop.is_installed,
hdfs_relation,
],
'callbacks': [
callbacks.update_working_status,
hdfs_relation.register_provided_hosts,
jujubigdata.utils.manage_etc_hosts,
hdfs.configure_client,
callbacks.update_active_status,
],
'cleanup': [
callbacks.clear_active_flag,
callbacks.update_blocked_status,
],
},
{
'name': 'yarn',
'provides': [],
'requires': [
hadoop.is_installed,
yarn_relation,
],
'callbacks': [
callbacks.update_working_status,
yarn_relation.register_provided_hosts,
jujubigdata.utils.manage_etc_hosts,
yarn.install_demo,
yarn.configure_client,
callbacks.update_active_status,
],
'cleanup': [
callbacks.update_blocked_status,
],
},
])
manager.manage()
if __name__ == '__main__':
manage()
|