Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emr/hbase.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 hbaseutils
17
from awscli.customizations.emr import helptext
18
from awscli.customizations.emr.command import Command
19
20
21
class RestoreFromHBaseBackup(Command):
22
NAME = 'restore-from-hbase-backup'
23
DESCRIPTION = ('Restores HBase from S3. ' +
24
helptext.AVAILABLE_ONLY_FOR_AMI_VERSIONS)
25
ARG_TABLE = [
26
{'name': 'cluster-id', 'required': True,
27
'help_text': helptext.CLUSTER_ID},
28
{'name': 'dir', 'required': True,
29
'help_text': helptext.HBASE_BACKUP_DIR},
30
{'name': 'backup-version',
31
'help_text': helptext.HBASE_BACKUP_VERSION}
32
]
33
34
def _run_main_command(self, parsed_args, parsed_globals):
35
steps = []
36
args = hbaseutils.build_hbase_restore_from_backup_args(
37
parsed_args.dir, parsed_args.backup_version)
38
39
step_config = emrutils.build_step(
40
jar=constants.HBASE_JAR_PATH,
41
name=constants.HBASE_RESTORE_STEP_NAME,
42
action_on_failure=constants.CANCEL_AND_WAIT,
43
args=args)
44
45
steps.append(step_config)
46
parameters = {'JobFlowId': parsed_args.cluster_id,
47
'Steps': steps}
48
emrutils.call_and_display_response(self._session, 'AddJobFlowSteps',
49
parameters, parsed_globals)
50
return 0
51
52
53
class ScheduleHBaseBackup(Command):
54
NAME = 'schedule-hbase-backup'
55
DESCRIPTION = ('Adds a step to schedule automated HBase backup. ' +
56
helptext.AVAILABLE_ONLY_FOR_AMI_VERSIONS)
57
ARG_TABLE = [
58
{'name': 'cluster-id', 'required': True,
59
'help_text': helptext.CLUSTER_ID},
60
{'name': 'type', 'required': True,
61
'help_text': "<p>Backup type. You can specify 'incremental' or "
62
"'full'.</p>"},
63
{'name': 'dir', 'required': True,
64
'help_text': helptext.HBASE_BACKUP_DIR},
65
{'name': 'interval', 'required': True,
66
'help_text': '<p>The time between backups.</p>'},
67
{'name': 'unit', 'required': True,
68
'help_text': "<p>The time unit for backup's time-interval. "
69
"You can specify one of the following values:"
70
" 'minutes', 'hours', or 'days'.</p>"},
71
{'name': 'start-time',
72
'help_text': '<p>The time of the first backup in ISO format.</p>'
73
' e.g. 2014-04-21T05:26:10Z. Default is now.'},
74
{'name': 'consistent', 'action': 'store_true',
75
'help_text': '<p>Performs a consistent backup.'
76
' Pauses all write operations to the HBase cluster'
77
' during the backup process.</p>'}
78
]
79
80
def _run_main_command(self, parsed_args, parsed_globals):
81
steps = []
82
self._check_type(parsed_args.type)
83
self._check_unit(parsed_args.unit)
84
args = self._build_hbase_schedule_backup_args(parsed_args)
85
86
step_config = emrutils.build_step(
87
jar=constants.HBASE_JAR_PATH,
88
name=constants.HBASE_SCHEDULE_BACKUP_STEP_NAME,
89
action_on_failure=constants.CANCEL_AND_WAIT,
90
args=args)
91
92
steps.append(step_config)
93
parameters = {'JobFlowId': parsed_args.cluster_id,
94
'Steps': steps}
95
emrutils.call_and_display_response(self._session, 'AddJobFlowSteps',
96
parameters, parsed_globals)
97
return 0
98
99
def _check_type(self, type):
100
type = type.lower()
101
if type != constants.FULL and type != constants.INCREMENTAL:
102
raise ValueError('aws: error: invalid type. '
103
'type should be either ' +
104
constants.FULL + ' or ' + constants.INCREMENTAL +
105
'.')
106
107
def _check_unit(self, unit):
108
unit = unit.lower()
109
if (unit != constants.MINUTES and
110
unit != constants.HOURS and
111
unit != constants.DAYS):
112
raise ValueError('aws: error: invalid unit. unit should be one of'
113
' the following values: ' + constants.MINUTES +
114
', ' + constants.HOURS + ' or ' + constants.DAYS +
115
'.')
116
117
def _build_hbase_schedule_backup_args(self, parsed_args):
118
args = [constants.HBASE_MAIN, constants.HBASE_SCHEDULED_BACKUP,
119
constants.TRUE, constants.HBASE_BACKUP_DIR, parsed_args.dir]
120
121
type = parsed_args.type.lower()
122
unit = parsed_args.unit.lower()
123
124
if parsed_args.consistent is True:
125
args.append(constants.HBASE_BACKUP_CONSISTENT)
126
127
if type == constants.FULL:
128
args.append(constants.HBASE_FULL_BACKUP_INTERVAL)
129
else:
130
args.append(constants.HBASE_INCREMENTAL_BACKUP_INTERVAL)
131
132
args.append(parsed_args.interval)
133
134
if type == constants.FULL:
135
args.append(constants.HBASE_FULL_BACKUP_INTERVAL_UNIT)
136
else:
137
args.append(constants.HBASE_INCREMENTAL_BACKUP_INTERVAL_UNIT)
138
139
args.append(unit)
140
args.append(constants.HBASE_BACKUP_STARTTIME)
141
142
if parsed_args.start_time is not None:
143
args.append(parsed_args.start_time)
144
else:
145
args.append(constants.NOW)
146
147
return args
148
149
150
class CreateHBaseBackup(Command):
151
NAME = 'create-hbase-backup'
152
DESCRIPTION = ('Creates a HBase backup in S3. ' +
153
helptext.AVAILABLE_ONLY_FOR_AMI_VERSIONS)
154
ARG_TABLE = [
155
{'name': 'cluster-id', 'required': True,
156
'help_text': helptext.CLUSTER_ID},
157
{'name': 'dir', 'required': True,
158
'help_text': helptext.HBASE_BACKUP_DIR},
159
{'name': 'consistent', 'action': 'store_true',
160
'help_text': '<p>Performs a consistent backup. Pauses all write'
161
' operations to the HBase cluster during the backup'
162
' process.</p>'}
163
]
164
165
def _run_main_command(self, parsed_args, parsed_globals):
166
steps = []
167
args = self._build_hbase_backup_args(parsed_args)
168
169
step_config = emrutils.build_step(
170
jar=constants.HBASE_JAR_PATH,
171
name=constants.HBASE_BACKUP_STEP_NAME,
172
action_on_failure=constants.CANCEL_AND_WAIT,
173
args=args)
174
175
steps.append(step_config)
176
parameters = {'JobFlowId': parsed_args.cluster_id,
177
'Steps': steps}
178
emrutils.call_and_display_response(self._session, 'AddJobFlowSteps',
179
parameters, parsed_globals)
180
return 0
181
182
def _build_hbase_backup_args(self, parsed_args):
183
args = [constants.HBASE_MAIN,
184
constants.HBASE_BACKUP,
185
constants.HBASE_BACKUP_DIR, parsed_args.dir]
186
187
if parsed_args.consistent is True:
188
args.append(constants.HBASE_BACKUP_CONSISTENT)
189
190
return args
191
192
193
class DisableHBaseBackups(Command):
194
NAME = 'disable-hbase-backups'
195
DESCRIPTION = ('Add a step to disable automated HBase backups. ' +
196
helptext.AVAILABLE_ONLY_FOR_AMI_VERSIONS)
197
ARG_TABLE = [
198
{'name': 'cluster-id', 'required': True,
199
'help_text': helptext.CLUSTER_ID},
200
{'name': 'full', 'action': 'store_true',
201
'help_text': 'Disables full backup.'},
202
{'name': 'incremental', 'action': 'store_true',
203
'help_text': 'Disables incremental backup.'}
204
]
205
206
def _run_main_command(self, parsed_args, parsed_globals):
207
steps = []
208
209
args = self._build_hbase_disable_backups_args(parsed_args)
210
211
step_config = emrutils.build_step(
212
constants.HBASE_JAR_PATH,
213
constants.HBASE_SCHEDULE_BACKUP_STEP_NAME,
214
constants.CANCEL_AND_WAIT,
215
args)
216
217
steps.append(step_config)
218
parameters = {'JobFlowId': parsed_args.cluster_id,
219
'Steps': steps}
220
emrutils.call_and_display_response(self._session, 'AddJobFlowSteps',
221
parameters, parsed_globals)
222
return 0
223
224
def _build_hbase_disable_backups_args(self, parsed_args):
225
args = [constants.HBASE_MAIN, constants.HBASE_SCHEDULED_BACKUP,
226
constants.FALSE]
227
if parsed_args.full is False and parsed_args.incremental is False:
228
error_message = 'Should specify at least one of --' +\
229
constants.FULL + ' and --' +\
230
constants.INCREMENTAL + '.'
231
raise ValueError(error_message)
232
if parsed_args.full is True:
233
args.append(constants.HBASE_DISABLE_FULL_BACKUP)
234
if parsed_args.incremental is True:
235
args.append(constants.HBASE_DISABLE_INCREMENTAL_BACKUP)
236
237
return args
238
239