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
15class EmrError(Exception):
16
17    """
18    The base exception class for Emr exceptions.
19
20    :ivar msg: The descriptive message associated with the error.
21    """
22    fmt = 'An unspecified error occurred'
23
24    def __init__(self, **kwargs):
25        msg = self.fmt.format(**kwargs)
26        Exception.__init__(self, msg)
27        self.kwargs = kwargs
28
29
30class MissingParametersError(EmrError):
31
32    """
33    One or more required parameters were not supplied.
34
35    :ivar object_name: The object that has missing parameters.
36        This can be an operation or a parameter (in the
37        case of inner params).  The str() of this object
38        will be used so it doesn't need to implement anything
39        other than str().
40    :ivar missing: The names of the missing parameters.
41    """
42    fmt = ('aws: error: The following required parameters are missing for '
43           '{object_name}: {missing}.')
44
45
46class EmptyListError(EmrError):
47
48    """
49    The provided list is empty.
50
51    :ivar param: The provided list parameter
52    """
53    fmt = ('aws: error: The prameter {param} cannot be an empty list.')
54
55
56class MissingRequiredInstanceGroupsError(EmrError):
57
58    """
59    In create-cluster command, none of --instance-group,
60    --instance-count nor --instance-type were not supplied.
61    """
62    fmt = ('aws: error: Must specify either --instance-groups or '
63           '--instance-type with --instance-count(optional) to '
64           'configure instance groups.')
65
66
67class InstanceGroupsValidationError(EmrError):
68
69    """
70    --instance-type and --instance-count are shortcut option
71    for --instance-groups and they cannot be specified
72    together with --instance-groups
73    """
74    fmt = ('aws: error: You may not specify --instance-type '
75           'or --instance-count with --instance-groups, '
76           'because --instance-type and --instance-count are '
77           'shortcut options for --instance-groups.')
78
79
80class InvalidAmiVersionError(EmrError):
81
82    """
83    The supplied ami-version is invalid.
84    :ivar ami_version: The provided ami_version.
85    """
86    fmt = ('aws: error: The supplied AMI version "{ami_version}" is invalid.'
87           ' Please see AMI Versions Supported in Amazon EMR in '
88           'Amazon Elastic MapReduce Developer Guide: '
89           'http://docs.aws.amazon.com/ElasticMapReduce/'
90           'latest/DeveloperGuide/ami-versions-supported.html')
91
92
93class MissingBooleanOptionsError(EmrError):
94
95    """
96    Required boolean options are not supplied.
97
98    :ivar true_option
99    :ivar false_option
100    """
101    fmt = ('aws: error: Must specify one of the following boolean options: '
102           '{true_option}|{false_option}.')
103
104
105class UnknownStepTypeError(EmrError):
106
107    """
108    The provided step type is not supported.
109
110    :ivar step_type: the step_type provided.
111    """
112    fmt = ('aws: error: The step type {step_type} is not supported.')
113
114
115class UnknownIamEndpointError(EmrError):
116
117    """
118    The IAM endpoint is not known for the specified region.
119
120    :ivar region: The region specified.
121    """
122    fmt = 'IAM endpoint not known for region: {region}.' +\
123          ' Specify the iam-endpoint using the --iam-endpoint option.'
124
125
126class ResolveServicePrincipalError(EmrError):
127
128    """
129    The service principal could not be resolved from the region or the
130    endpoint.
131    """
132    fmt = 'Could not resolve the service principal from' +\
133          ' the region or the endpoint.'
134
135
136class LogUriError(EmrError):
137
138    """
139    The LogUri is not specified and debugging is enabled for the cluster.
140    """
141    fmt = ('aws: error: LogUri not specified. You must specify a logUri '
142           'if you enable debugging when creating a cluster.')
143
144
145class MasterDNSNotAvailableError(EmrError):
146
147    """
148    Cannot get dns of master node on the cluster.
149    """
150    fmt = 'Cannot get DNS of master node on the cluster. '\
151          ' Please try again after some time.'
152
153
154class WrongPuttyKeyError(EmrError):
155
156    """
157    A wrong key has been used with a compatible program.
158    """
159    fmt = 'Key file file format is incorrect. Putty expects a ppk file. '\
160          'Please refer to documentation at http://docs.aws.amazon.com/'\
161          'ElasticMapReduce/latest/DeveloperGuide/EMR_SetUp_SSH.html. '
162
163
164class SSHNotFoundError(EmrError):
165
166    """
167    SSH or Putty not available.
168    """
169    fmt = 'SSH or Putty not available. Please refer to the documentation '\
170          'at http://docs.aws.amazon.com/ElasticMapReduce/latest/'\
171          'DeveloperGuide/EMR_SetUp_SSH.html.'
172
173
174class SCPNotFoundError(EmrError):
175
176    """
177    SCP or Pscp not available.
178    """
179    fmt = 'SCP or Pscp not available. Please refer to the documentation '\
180          'at http://docs.aws.amazon.com/ElasticMapReduce/latest/'\
181          'DeveloperGuide/EMR_SetUp_SSH.html. '
182
183
184class SubnetAndAzValidationError(EmrError):
185
186    """
187    SubnetId and AvailabilityZone are mutual exclusive in --ec2-attributes.
188    """
189    fmt = ('aws: error: You may not specify both a SubnetId and an Availabili'
190           'tyZone (placement) because ec2SubnetId implies a placement.')
191
192
193class RequiredOptionsError(EmrError):
194
195    """
196    Either of option1 or option2 is required.
197    """
198
199    fmt = ('aws: error: Either {option1} or {option2} is required.')
200
201
202class MutualExclusiveOptionError(EmrError):
203
204    """
205    The provided option1 and option2 are mutually exclusive.
206
207    :ivar option1
208    :ivar option2
209    :ivar message (optional)
210    """
211
212    def __init__(self, **kwargs):
213        msg = ('aws: error: You cannot specify both ' +
214               kwargs.get('option1', '') + ' and ' +
215               kwargs.get('option2', '') + ' options together.' +
216               kwargs.get('message', ''))
217        Exception.__init__(self, msg)
218
219
220class MissingApplicationsError(EmrError):
221
222    """
223    The application required for a step is not installed when creating a
224    cluster.
225
226    :ivar applications
227    """
228
229    def __init__(self, **kwargs):
230        msg = ('aws: error: Some of the steps require the following'
231               ' applications to be installed: ' +
232               ', '.join(kwargs['applications']) + '. Please install the'
233               ' applications using --applications.')
234        Exception.__init__(self, msg)
235
236
237class ClusterTerminatedError(EmrError):
238
239    """
240    The cluster is terminating or has already terminated.
241    """
242    fmt = 'aws: error: Cluster terminating or already terminated.'
243
244
245class ClusterStatesFilterValidationError(EmrError):
246
247    """
248    In the list-clusters command, customers can specify only one
249    of the following states filters:
250    --cluster-states, --active, --terminated, --failed
251
252    """
253    fmt = ('aws: error: You can specify only one of the cluster state '
254           'filters: --cluster-states, --active, --terminated, --failed.')
255
256
257class MissingClusterAttributesError(EmrError):
258
259    """
260    In the modify-cluster-attributes command, customers need to provide
261    at least one of the following cluster attributes: --visible-to-all-users,
262    --no-visible-to-all-users, --termination-protected
263    and --no-termination-protected
264    """
265    fmt = ('aws: error: Must specify one of the following boolean options: '
266           '--visible-to-all-users|--no-visible-to-all-users, '
267           '--termination-protected|--no-termination-protected.')
268
269
270class InvalidEmrFsArgumentsError(EmrError):
271
272    """
273    The provided EMRFS parameters are invalid as parent feature e.g.,
274    Consistent View, CSE, SSE is not configured
275
276    :ivar invalid: Invalid parameters
277    :ivar parent_object_name: Parent feature name
278    """
279
280    fmt = ('aws: error: {parent_object_name} is not specified. Thus, '
281           ' following parameters are invalid: {invalid}')
282
283
284class DuplicateEmrFsConfigurationError(EmrError):
285
286    fmt = ('aws: error: EMRFS should be configured either using '
287           '--configuration or --emrfs but not both')
288
289
290class UnknownCseProviderTypeError(EmrError):
291
292    """
293    The provided EMRFS client-side encryption provider type is not supported.
294
295    :ivar provider_type: the provider_type provided.
296    """
297    fmt = ('aws: error: The client side encryption type "{provider_type}" is '
298           'not supported. You must specify either KMS or Custom')
299
300
301class UnknownEncryptionTypeError(EmrError):
302
303    """
304    The provided encryption type is not supported.
305
306    :ivar provider_type: the provider_type provided.
307    """
308    fmt = ('aws: error: The encryption type "{encryption}" is invalid. '
309           'You must specify either ServerSide or ClientSide')
310
311
312class BothSseAndEncryptionConfiguredError(EmrError):
313
314    """
315    Only one of SSE or Encryption can be configured.
316
317    :ivar sse: Value for SSE
318    :ivar encryption: Value for encryption
319    """
320
321    fmt = ('aws: error: Both SSE={sse} and Encryption={encryption} are '
322           'configured for --emrfs. You must specify only one of the two.')
323
324
325class InvalidBooleanConfigError(EmrError):
326
327    fmt = ("aws: error: {config_value} for {config_key} in the config file is "
328           "invalid. The value should be either 'True' or 'False'. Use "
329           "'aws configure set {profile_var_name}.emr.{config_key} <value>' "
330           "command to set a valid value.")
331
332
333class UnsupportedCommandWithReleaseError(EmrError):
334
335    fmt = ("aws: error: {command} is not supported with "
336           "'{release_label}' release.")
337
338class MissingAutoScalingRoleError(EmrError):
339
340    fmt = ("aws: error: Must specify --auto-scaling-role when configuring an "
341           "AutoScaling policy for an instance group.")
342
343