Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emr/applicationutils.py
1567 views
1
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
from awscli.customizations.emr import constants
15
from awscli.customizations.emr import emrutils
16
from awscli.customizations.emr import exceptions
17
18
19
def build_applications(region,
20
parsed_applications, ami_version=None):
21
app_list = []
22
step_list = []
23
ba_list = []
24
25
for app_config in parsed_applications:
26
app_name = app_config['Name'].lower()
27
28
if app_name == constants.HIVE:
29
hive_version = constants.LATEST
30
step_list.append(
31
_build_install_hive_step(region=region))
32
args = app_config.get('Args')
33
if args is not None:
34
hive_site_path = _find_matching_arg(
35
key=constants.HIVE_SITE_KEY, args_list=args)
36
if hive_site_path is not None:
37
step_list.append(
38
_build_install_hive_site_step(
39
region=region,
40
hive_site_path=hive_site_path))
41
elif app_name == constants.PIG:
42
pig_version = constants.LATEST
43
step_list.append(
44
_build_pig_install_step(
45
region=region))
46
elif app_name == constants.GANGLIA:
47
ba_list.append(
48
_build_ganglia_install_bootstrap_action(
49
region=region))
50
elif app_name == constants.HBASE:
51
ba_list.append(
52
_build_hbase_install_bootstrap_action(
53
region=region))
54
if ami_version >= '3.0':
55
step_list.append(
56
_build_hbase_install_step(
57
constants.HBASE_PATH_HADOOP2_INSTALL_JAR))
58
elif ami_version >= '2.1':
59
step_list.append(
60
_build_hbase_install_step(
61
constants.HBASE_PATH_HADOOP1_INSTALL_JAR))
62
else:
63
raise ValueError('aws: error: AMI version ' + ami_version +
64
'is not compatible with HBase.')
65
elif app_name == constants.IMPALA:
66
ba_list.append(
67
_build_impala_install_bootstrap_action(
68
region=region,
69
args=app_config.get('Args')))
70
else:
71
app_list.append(
72
_build_supported_product(
73
app_config['Name'], app_config.get('Args')))
74
75
return app_list, ba_list, step_list
76
77
78
def _build_supported_product(name, args):
79
if args is None:
80
args = []
81
config = {'Name': name.lower(), 'Args': args}
82
return config
83
84
85
def _build_ganglia_install_bootstrap_action(region):
86
return emrutils.build_bootstrap_action(
87
name=constants.INSTALL_GANGLIA_NAME,
88
path=emrutils.build_s3_link(
89
relative_path=constants.GANGLIA_INSTALL_BA_PATH,
90
region=region))
91
92
93
def _build_hbase_install_bootstrap_action(region):
94
return emrutils.build_bootstrap_action(
95
name=constants.INSTALL_HBASE_NAME,
96
path=emrutils.build_s3_link(
97
relative_path=constants.HBASE_INSTALL_BA_PATH,
98
region=region))
99
100
101
def _build_hbase_install_step(jar):
102
return emrutils.build_step(
103
jar=jar,
104
name=constants.START_HBASE_NAME,
105
action_on_failure=constants.TERMINATE_CLUSTER,
106
args=constants.HBASE_INSTALL_ARG)
107
108
109
def _build_impala_install_bootstrap_action(region, args=None):
110
args_list = [
111
constants.BASE_PATH_ARG,
112
emrutils.build_s3_link(region=region),
113
constants.IMPALA_VERSION,
114
constants.LATEST]
115
if args is not None:
116
args_list.append(constants.IMPALA_CONF)
117
args_list.append(','.join(args))
118
return emrutils.build_bootstrap_action(
119
name=constants.INSTALL_IMPALA_NAME,
120
path=emrutils.build_s3_link(
121
relative_path=constants.IMPALA_INSTALL_PATH,
122
region=region),
123
args=args_list)
124
125
126
def _build_install_hive_step(region,
127
action_on_failure=constants.TERMINATE_CLUSTER):
128
step_args = [
129
emrutils.build_s3_link(constants.HIVE_SCRIPT_PATH, region),
130
constants.INSTALL_HIVE_ARG,
131
constants.BASE_PATH_ARG,
132
emrutils.build_s3_link(constants.HIVE_BASE_PATH, region),
133
constants.HIVE_VERSIONS,
134
constants.LATEST]
135
step = emrutils.build_step(
136
name=constants.INSTALL_HIVE_NAME,
137
action_on_failure=action_on_failure,
138
jar=emrutils.build_s3_link(constants.SCRIPT_RUNNER_PATH, region),
139
args=step_args)
140
return step
141
142
143
def _build_install_hive_site_step(region, hive_site_path,
144
action_on_failure=constants.CANCEL_AND_WAIT):
145
step_args = [
146
emrutils.build_s3_link(constants.HIVE_SCRIPT_PATH, region),
147
constants.BASE_PATH_ARG,
148
emrutils.build_s3_link(constants.HIVE_BASE_PATH),
149
constants.INSTALL_HIVE_SITE_ARG,
150
hive_site_path,
151
constants.HIVE_VERSIONS,
152
constants.LATEST]
153
step = emrutils.build_step(
154
name=constants.INSTALL_HIVE_SITE_NAME,
155
action_on_failure=action_on_failure,
156
jar=emrutils.build_s3_link(constants.SCRIPT_RUNNER_PATH, region),
157
args=step_args)
158
return step
159
160
161
def _build_pig_install_step(region,
162
action_on_failure=constants.TERMINATE_CLUSTER):
163
step_args = [
164
emrutils.build_s3_link(constants.PIG_SCRIPT_PATH, region),
165
constants.INSTALL_PIG_ARG,
166
constants.BASE_PATH_ARG,
167
emrutils.build_s3_link(constants.PIG_BASE_PATH, region),
168
constants.PIG_VERSIONS,
169
constants.LATEST]
170
step = emrutils.build_step(
171
name=constants.INSTALL_PIG_NAME,
172
action_on_failure=action_on_failure,
173
jar=emrutils.build_s3_link(constants.SCRIPT_RUNNER_PATH, region),
174
args=step_args)
175
return step
176
177
178
def _find_matching_arg(key, args_list):
179
for arg in args_list:
180
if key in arg:
181
return arg
182
183
return None
184
185