1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 try:
18 import json
19 except ImportError:
20 import simplejson as json
21
22 from cm_api.endpoints.types import *
23 from cm_api.endpoints import roles, role_config_groups
24
25 __docformat__ = "epytext"
26
27 SERVICES_PATH = "/clusters/%s/services"
28 SERVICE_PATH = "/clusters/%s/services/%s"
29 ROLETYPES_CFG_KEY = 'roleTypeConfigs'
30
31 -def create_service(resource_root, name, service_type,
32 cluster_name="default"):
33 """
34 Create a service
35 @param resource_root: The root Resource object.
36 @param name: Service name
37 @param service_type: Service type
38 @param cluster_name: Cluster name
39 @return: An ApiService object
40 """
41 apiservice = ApiService(resource_root, name, service_type)
42 return call(resource_root.post,
43 SERVICES_PATH % (cluster_name,),
44 ApiService, True, data=[apiservice])[0]
45
46 -def get_service(resource_root, name, cluster_name="default"):
47 """
48 Lookup a service by name
49 @param resource_root: The root Resource object.
50 @param name: Service name
51 @param cluster_name: Cluster name
52 @return: An ApiService object
53 """
54 return _get_service(resource_root, "%s/%s" % (SERVICES_PATH % (cluster_name,), name))
55
58
60 """
61 Get all services
62 @param resource_root: The root Resource object.
63 @param cluster_name: Cluster name
64 @return: A list of ApiService objects.
65 """
66 return call(resource_root.get,
67 SERVICES_PATH % (cluster_name,),
68 ApiService, True, params=view and dict(view=view) or None)
69
71 """
72 Delete a service by name
73 @param resource_root: The root Resource object.
74 @param name: Service name
75 @param cluster_name: Cluster name
76 @return: The deleted ApiService object
77 """
78 return call(resource_root.delete,
79 "%s/%s" % (SERVICES_PATH % (cluster_name,), name),
80 ApiService)
81
82
84 _ATTRIBUTES = {
85 'name' : None,
86 'type' : None,
87 'displayName' : None,
88 'serviceState' : ROAttr(),
89 'healthSummary' : ROAttr(),
90 'healthChecks' : ROAttr(),
91 'clusterRef' : ROAttr(ApiClusterRef),
92 'configStale' : ROAttr(),
93 'configStalenessStatus' : ROAttr(),
94 'clientConfigStalenessStatus' : ROAttr(),
95 'serviceUrl' : ROAttr(),
96 'roleInstancesUrl' : ROAttr(),
97 'maintenanceMode' : ROAttr(),
98 'maintenanceOwners' : ROAttr(),
99 'entityStatus' : ROAttr(),
100 }
101
102 - def __init__(self, resource_root, name=None, type=None):
104
106 return "<ApiService>: %s (cluster: %s)" % (
107 self.name, self._get_cluster_name())
108
110 if hasattr(self, 'clusterRef') and self.clusterRef:
111 return self.clusterRef.clusterName
112 return None
113
115 """
116 Return the API path for this service.
117
118 This method assumes that lack of a cluster reference means that the
119 object refers to the Cloudera Management Services instance.
120 """
121 if self._get_cluster_name():
122 return SERVICE_PATH % (self._get_cluster_name(), self.name)
123 else:
124 return '/cm/service'
125
126 - def _role_cmd(self, cmd, roles, api_version=1):
129
131 """
132 Parse a json-decoded ApiServiceConfig dictionary into a 2-tuple.
133
134 @param json_dic: The json dictionary with the config data.
135 @param view: View to materialize.
136 @return: 2-tuple (service config dictionary, role type configurations)
137 """
138 svc_config = json_to_config(json_dic, view == 'full')
139 rt_configs = { }
140 if json_dic.has_key(ROLETYPES_CFG_KEY):
141 for rt_config in json_dic[ROLETYPES_CFG_KEY]:
142 rt_configs[rt_config['roleType']] = \
143 json_to_config(rt_config, view == 'full')
144
145 return (svc_config, rt_configs)
146
148 """
149 Retrieve a list of running commands for this service.
150
151 @param view: View to materialize ('full' or 'summary')
152 @return: A list of running commands.
153 """
154 return self._get("commands", ApiCommand, True,
155 params = view and dict(view=view) or None)
156
159
161 return self._get("activities", ApiActivity, True,
162 params=query_str and dict(query=query_str) or dict())
163
166
167 - def get_impala_queries(self, start_time, end_time, filter_str="", limit=100,
168 offset=0):
169 """
170 Returns a list of queries that satisfy the filter
171
172 @type start_time: datetime.datetime. Note that the datetime must either be
173 time zone aware or specified in the server time zone. See
174 the python datetime documentation for more details about
175 python's time zone handling.
176 @param start_time: Queries must have ended after this time
177 @type end_time: datetime.datetime. Note that the datetime must either be
178 time zone aware or specified in the server time zone. See
179 the python datetime documentation for more details about
180 python's time zone handling.
181 @param end_time: Queries must have started before this time
182 @param filter_str: A filter to apply to the queries. For example:
183 'user = root and queryDuration > 5s'
184 @param limit: The maximum number of results to return
185 @param offset: The offset into the return list
186 @since: API v4
187 """
188 params = {
189 'from': start_time.isoformat(),
190 'to': end_time.isoformat(),
191 'filter': filter_str,
192 'limit': limit,
193 'offset': offset,
194 }
195 return self._get("impalaQueries", ApiImpalaQueryResponse,
196 params=params, api_version=4)
197
199 """
200 Cancel the query.
201
202 @param query_id: The query ID
203 @return: The warning message, if any.
204 @since: API v4
205 """
206 return self._post("impalaQueries/%s/cancel" % query_id,
207 ApiImpalaCancelResponse, api_version=4)
208
210 """
211 Get the query details
212
213 @param query_id: The query ID
214 @param format: The format of the response ('text' or 'thrift_encoded')
215 @return: The details text
216 @since: API v4
217 """
218 return self._get("impalaQueries/" + query_id, ApiImpalaQueryDetailsResponse,
219 params=dict(format=format), api_version=4)
220
222 """
223 Returns the list of all attributes that the Service Monitor can associate
224 with Impala queries.
225
226 Examples of attributes include the user who issued the query and the
227 number of HDFS bytes read by the query.
228
229 These attributes can be used to search for specific Impala queries through
230 the get_impala_queries API. For example the 'user' attribute could be used
231 in the search 'user = root'. If the attribute is numeric it can also be used
232 as a metric in a tsquery (ie, 'select hdfs_bytes_read from IMPALA_QUERIES').
233
234 Note that this response is identical for all Impala services.
235
236 @return: A list of the Impala query attributes
237 @since API v6
238 """
239 return self._get("impalaQueries/attributes", ApiImpalaQueryAttribute,
240 ret_is_list=True, api_version=6)
241
243 """
244 Create the Impala Catalog Database. Only works with embedded postgresql
245 database. This command should usually be followed by a call to
246 create_impala_catalog_database_tables.
247
248 @return: Reference to the submitted command.
249 @since: API v6
250 """
251 return self._cmd('impalaCreateCatalogDatabase', api_version=6)
252
254 """
255 Creates the Impala Catalog Database tables in the configured database.
256 Will do nothing if tables already exist. Will not perform an upgrade.
257
258 @return: Reference to the submitted command.
259 @since: API v6
260 """
261 return self._cmd('impalaCreateCatalogDatabaseTables', api_version=6)
262
264 """
265 Create the Impala user directory
266
267 @return: Reference to submitted command.
268 @since: API v6
269 """
270 return self._cmd('impalaCreateUserDir', api_version=6)
271
272 - def enable_llama_rm(self, llama1_host_id, llama1_role_name=None,
273 llama2_host_id=None, llama2_role_name=None,
274 zk_service_name=None, skip_restart=False):
275 """
276 Enable Llama-based resource management for Impala.
277
278 This command only applies to CDH 5.1+ Impala services.
279
280 This command configures YARN and Impala for Llama resource management,
281 and then creates one or two Llama roles, as specified by the parameters.
282 When two Llama roles are created, they are configured as an active-standby
283 pair. Auto-failover from active to standby Llama will be enabled using
284 ZooKeeper.
285
286 If optional role name(s) are specified, the new Llama role(s) will be
287 named accordingly; otherwise, role name(s) will be automatically generated.
288
289 By default, YARN, Impala, and any dependent services will be restarted,
290 and client configuration will be re-deployed across the cluster. These
291 default actions may be suppressed.
292
293 In order to enable Llama resource management, a YARN service must be
294 present in the cluster, and Cgroup-based resource management must be
295 enabled for all hosts with NodeManager roles. If these preconditions
296 are not met, the command will fail.
297
298 @param llama1_host_id: id of the host where the first Llama role will
299 be created.
300 @param llama1_role_name: Name of the first Llama role. If omitted, a
301 name will be generated automatically.
302 @param llama2_host_id: id of the host where the second Llama role will
303 be created. If omitted, only one Llama role will
304 be created (i.e., high availability will not be
305 enabled).
306 @param llama2_role_name: Name of the second Llama role. If omitted, a
307 name will be generated automatically.
308 @param zk_service_name: Name of the ZooKeeper service to use for
309 auto-failover. Only relevant when enabling
310 Llama RM in HA mode (i.e., when creating two
311 Llama roles). If Impala's ZooKeeper dependency
312 is already set, then that ZooKeeper service will
313 be used for auto-failover, and this parameter
314 may be omitted.
315 @param skip_restart: true to skip the restart of Yarn, Impala, and
316 their dependent services, and to skip deployment
317 of client configuration. Default is False (i.e.,
318 by default dependent services are restarted and
319 client configuration is deployed).
320 @return: Reference to the submitted command.
321 @since: API v8
322 """
323 args = dict(
324 llama1HostId = llama1_host_id,
325 llama1RoleName = llama1_role_name,
326 llama2HostId = llama2_host_id,
327 llama2RoleName = llama2_role_name,
328 zkServiceName = zk_service_name,
329 skipRestart = skip_restart
330 )
331 return self._cmd('impalaEnableLlamaRm', data=args, api_version=8)
332
334 """
335 Disable Llama-based resource management for Impala.
336
337 This command only applies to CDH 5.1+ Impala services.
338
339 This command disables resource management for Impala by removing all
340 Llama roles present in the Impala service. Any services that depend
341 on the Impala service being modified are restarted by the command,
342 and client configuration is deployed for all services of the cluster.
343
344 @return: Reference to the submitted command.
345 @since: API v8
346 """
347 return self._cmd('impalaDisableLlamaRm', api_version=8)
348
349 - def enable_llama_ha(self, new_llama_host_id, zk_service_name=None,
350 new_llama_role_name=None):
351 """
352 Enable high availability for an Impala Llama ApplicationMaster.
353
354 This command only applies to CDH 5.1+ Impala services.
355
356 @param new_llama_host_id: id of the host where the second Llama role
357 will be added.
358 @param zk_service_name: Name of the ZooKeeper service to use for
359 auto-failover. If Impala's ZooKeeper dependency
360 is already set, then that ZooKeeper service will
361 be used for auto-failover, and this parameter
362 may be omitted.
363 @param new_llama_role_name: Name of the new Llama role. If omitted, a
364 name will be generated automatically.
365 @return: Reference to the submitted command.
366 @since: API v8
367 """
368 args = dict(
369 newLlamaHostId = new_llama_host_id,
370 zkServiceName = zk_service_name,
371 newLlamaRoleName = new_llama_role_name
372 )
373 return self._cmd('impalaEnableLlamaHa', data=args, api_version=8)
374
376 """
377 Disable high availability for an Impala Llama active-standby pair.
378
379 This command only applies to CDH 5.1+ Impala services.
380
381 @param active_name: name of the Llama role that will be active after
382 the disable operation. The other Llama role will
383 be removed.
384
385 @return: Reference to the submitted command.
386 @since: API v8
387 """
388 args = dict(
389 activeName = active_name
390 )
391 return self._cmd('impalaDisableLlamaHa', data=args, api_version=8)
392
395 """
396 Returns a list of YARN applications that satisfy the filter
397 @type start_time: datetime.datetime. Note that the datetime must either be
398 time zone aware or specified in the server time zone. See
399 the python datetime documentation for more details about
400 python's time zone handling.
401 @param start_time: Applications must have ended after this time
402 @type end_time: datetime.datetime. Note that the datetime must either be
403 time zone aware or specified in the server time zone. See
404 the python datetime documentation for more details about
405 python's time zone handling.
406 @param filter_str: A filter to apply to the applications. For example:
407 'user = root and applicationDuration > 5s'
408 @param limit: The maximum number of results to return
409 @param offset: The offset into the return list
410 @since: API v6
411 """
412 params = {
413 'from': start_time.isoformat(),
414 'to': end_time.isoformat(),
415 'filter': filter_str,
416 'limit': limit,
417 'offset': offset
418 }
419 return self._get("yarnApplications", ApiYarnApplicationResponse,
420 params=params, api_version=6)
421
423 """
424 Kills the application.
425
426 @return: The warning message, if any.
427 @since: API v6
428 """
429 return self._post("yarnApplications/%s/kill" % (application_id, ),
430 ApiYarnKillResponse, api_version=6)
431
433 """
434 Returns the list of all attributes that the Service Monitor can associate
435 with YARN applications.
436
437 Examples of attributes include the user who ran the application and the
438 number of maps completed by the application.
439
440 These attributes can be used to search for specific YARN applications through
441 the get_yarn_applications API. For example the 'user' attribute could be used
442 in the search 'user = root'. If the attribute is numeric it can also be used
443 as a metric in a tsquery (ie, 'select maps_completed from YARN_APPLICATIONS').
444
445 Note that this response is identical for all YARN services.
446
447 @return: A list of the YARN application attributes
448 @since API v6
449 """
450 return self._get("yarnApplications/attributes", ApiYarnApplicationAttribute,
451 ret_is_list=True, api_version=6)
452
454 """
455 Create the Yarn job history directory.
456
457 @return: Reference to submitted command.
458 @since: API v6
459 """
460 return self._cmd('yarnCreateJobHistoryDirCommand', api_version=6)
461
463 """
464 Create the Yarn NodeManager remote application log directory.
465
466 @return: Reference to submitted command.
467 @since: API v6
468 """
469 return self._cmd('yarnNodeManagerRemoteAppLogDirCommand', api_version=6)
470
472 """
473 DEPRECATED: use create_yarn_application_diagnostics_bundle on the Yarn service. Deprecated since v10.
474
475 Collects the Diagnostics data for Yarn applications.
476
477 @param application_ids: An array of strings containing the ids of the
478 yarn applications.
479 @return: Reference to the submitted command.
480 @since: API v8
481 """
482 args = dict(applicationIds = application_ids)
483 return self._cmd('yarnApplicationDiagnosticsCollection', api_version=8, data=args)
484
486 """
487 Collects the Diagnostics data for Yarn applications.
488
489 @param application_ids: An array of strings containing the ids of the
490 yarn applications.
491 @param ticket_number: If applicable, the support ticket number of the issue
492 being experienced on the cluster.
493 @param comments: Additional comments
494 @return: Reference to the submitted command.
495 @since: API v10
496 """
497 args = dict(applicationIds = application_ids,
498 ticketNumber = ticket_number,
499 comments = comments)
500
501 return self._cmd('yarnApplicationDiagnosticsCollection', api_version=10, data=args)
502
504 """
505 Retrieve the service's configuration.
506
507 Retrieves both the service configuration and role type configuration
508 for each of the service's supported role types. The role type
509 configurations are returned as a dictionary, whose keys are the
510 role type name, and values are the respective configuration dictionaries.
511
512 The 'summary' view contains strings as the dictionary values. The full
513 view contains ApiConfig instances as the values.
514
515 @param view: View to materialize ('full' or 'summary')
516 @return: 2-tuple (service config dictionary, role type configurations)
517 """
518 path = self._path() + '/config'
519 resp = self._get_resource_root().get(path,
520 params = view and dict(view=view) or None)
521 return self._parse_svc_config(resp, view)
522
524 """
525 Update the service's configuration.
526
527 @param svc_config: Dictionary with service configuration to update.
528 @param rt_configs: Dict of role type configurations to update.
529 @return: 2-tuple (service config dictionary, role type configurations)
530 """
531 path = self._path() + '/config'
532
533 if svc_config:
534 data = config_to_api_list(svc_config)
535 else:
536 data = { }
537 if rt_configs:
538 rt_list = [ ]
539 for rt, cfg in rt_configs.iteritems():
540 rt_data = config_to_api_list(cfg)
541 rt_data['roleType'] = rt
542 rt_list.append(rt_data)
543 data[ROLETYPES_CFG_KEY] = rt_list
544
545 resp = self._get_resource_root().put(path, data = json.dumps(data))
546 return self._parse_svc_config(resp)
547
549 """
550 Create a role.
551
552 @param role_name: Role name
553 @param role_type: Role type
554 @param host_id: ID of the host to assign the role to
555 @return: An ApiRole object
556 """
557 return roles.create_role(self._get_resource_root(), self.name, role_type,
558 role_name, host_id, self._get_cluster_name())
559
569
579
589
591 """
592 Get all roles of a certain type in a service.
593
594 @param role_type: Role type
595 @param view: View to materialize ('full' or 'summary')
596 @return: A list of ApiRole objects.
597 """
598 return roles.get_roles_by_type(self._get_resource_root(), self.name,
599 role_type, self._get_cluster_name(), view)
600
602 """
603 Get a list of role types in a service.
604
605 @return: A list of role types (strings)
606 """
607 resp = self._get_resource_root().get(self._path() + '/roleTypes')
608 return resp[ApiList.LIST_KEY]
609
619
630
632 """
633 Create a role config group.
634
635 @param name: The name of the new group.
636 @param display_name: The display name of the new group.
637 @param role_type: The role type of the new group.
638 @return: New ApiRoleConfigGroup object.
639 @since: API v3
640 """
641 return role_config_groups.create_role_config_group(
642 self._get_resource_root(), self.name, name, display_name, role_type,
643 self._get_cluster_name())
644
657
668
669 - def get_metrics(self, from_time=None, to_time=None, metrics=None, view=None):
670 """
671 This endpoint is not supported as of v6. Use the timeseries API
672 instead. To get all metrics for a service with the timeseries API use
673 the query:
674
675 'select * where serviceName = $SERVICE_NAME'.
676
677 To get specific metrics for a service use a comma-separated list of
678 the metric names as follows:
679
680 'select $METRIC_NAME1, $METRIC_NAME2 where serviceName = $SERVICE_NAME'.
681
682 For more information see http://tiny.cloudera.com/tsquery_doc
683
684 Retrieve metric readings for the service.
685 @param from_time: A datetime; start of the period to query (optional).
686 @param to_time: A datetime; end of the period to query (default = now).
687 @param metrics: List of metrics to query (default = all).
688 @param view: View to materialize ('full' or 'summary')
689 @return: List of metrics and their readings.
690 """
691 return self._get_resource_root().get_metrics(self._path() + '/metrics',
692 from_time, to_time, metrics, view)
693
695 """
696 Start a service.
697
698 @return: Reference to the submitted command.
699 """
700 return self._cmd('start')
701
703 """
704 Stop a service.
705
706 @return: Reference to the submitted command.
707 """
708 return self._cmd('stop')
709
711 """
712 Restart a service.
713
714 @return: Reference to the submitted command.
715 """
716 return self._cmd('restart')
717
719 """
720 Start a list of roles.
721
722 @param role_names: names of the roles to start.
723 @return: List of submitted commands.
724 """
725 return self._role_cmd('start', role_names)
726
728 """
729 Stop a list of roles.
730
731 @param role_names: names of the roles to stop.
732 @return: List of submitted commands.
733 """
734 return self._role_cmd('stop', role_names)
735
737 """
738 Restart a list of roles.
739
740 @param role_names: names of the roles to restart.
741 @return: List of submitted commands.
742 """
743 return self._role_cmd('restart', role_names)
744
746 """
747 Bootstrap HDFS stand-by NameNodes.
748
749 Initialize their state by syncing it with the respective HA partner.
750
751 @param role_names: NameNodes to bootstrap.
752 @return: List of submitted commands.
753 """
754 return self._role_cmd('hdfsBootstrapStandBy', role_names)
755
766
768 """
769 DEPRECATED: use create_hive_warehouse on the Hive service. Deprecated since v3.
770
771 Create the Beeswax role's warehouse for a Hue service.
772
773 @return: Reference to the submitted command.
774 """
775 return self._cmd('hueCreateHiveWarehouse')
776
778 """
779 Create the root directory of an HBase service.
780
781 @return: Reference to the submitted command.
782 """
783 return self._cmd('hbaseCreateRoot')
784
786 """
787 Create the /tmp directory in HDFS with appropriate ownership and permissions.
788
789 @return: Reference to the submitted command
790 @since: API v2
791 """
792 return self._cmd('hdfsCreateTmpDir')
793
795 """
796 Execute the "refresh" command on a set of roles.
797
798 @param role_names: Names of the roles to refresh.
799 @return: Reference to the submitted command.
800 """
801 return self._role_cmd('refresh', role_names)
802
804 """
805 Decommission roles in a service.
806
807 @param role_names: Names of the roles to decommission.
808 @return: Reference to the submitted command.
809 """
810 return self._cmd('decommission', data=role_names)
811
813 """
814 Recommission roles in a service.
815
816 @param role_names: Names of the roles to recommission.
817 @return: Reference to the submitted command.
818 @since: API v2
819 """
820 return self._cmd('recommission', data=role_names)
821
823 """
824 Deploys client configuration to the hosts where roles are running.
825
826 @param role_names: Names of the roles to decommission.
827 @return: Reference to the submitted command.
828 """
829 return self._cmd('deployClientConfig', data=role_names)
830
832 """
833 Disable auto-failover for a highly available HDFS nameservice.
834 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead.
835
836 @param nameservice: Affected nameservice.
837 @return: Reference to the submitted command.
838 """
839 return self._cmd('hdfsDisableAutoFailover', data=nameservice)
840
841 - def disable_hdfs_ha(self, active_name, secondary_name,
842 start_dependent_services=True, deploy_client_configs=True,
843 disable_quorum_storage=False):
844 """
845 Disable high availability for an HDFS NameNode.
846 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead.
847
848 @param active_name: Name of the NameNode to keep.
849 @param secondary_name: Name of (existing) SecondaryNameNode to link to
850 remaining NameNode.
851 @param start_dependent_services: whether to re-start dependent services.
852 @param deploy_client_configs: whether to re-deploy client configurations.
853 @param disable_quorum_storage: whether to disable Quorum-based Storage. Available since API v2.
854 Quorum-based Storage will be disabled for all
855 nameservices that have Quorum-based Storage
856 enabled.
857 @return: Reference to the submitted command.
858 """
859 args = dict(
860 activeName = active_name,
861 secondaryName = secondary_name,
862 startDependentServices = start_dependent_services,
863 deployClientConfigs = deploy_client_configs,
864 )
865
866 version = self._get_resource_root().version
867 if version < 2:
868 if disable_quorum_storage:
869 raise AttributeError("Quorum-based Storage requires at least API version 2 available in Cloudera Manager 4.1.")
870 else:
871 args['disableQuorumStorage'] = disable_quorum_storage
872
873 return self._cmd('hdfsDisableHa', data=args)
874
877 """
878 Enable auto-failover for an HDFS nameservice.
879 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead.
880
881 @param nameservice: Nameservice for which to enable auto-failover.
882 @param active_fc_name: Name of failover controller to create for active node.
883 @param standby_fc_name: Name of failover controller to create for stand-by node.
884 @param zk_service: ZooKeeper service to use.
885 @return: Reference to the submitted command.
886 """
887 version = self._get_resource_root().version
888
889 args = dict(
890 nameservice = nameservice,
891 activeFCName = active_fc_name,
892 standByFCName = standby_fc_name,
893 zooKeeperService = dict(
894 clusterName = zk_service.clusterRef.clusterName,
895 serviceName = zk_service.name,
896 ),
897 )
898 return self._cmd('hdfsEnableAutoFailover', data=args)
899
900 - def enable_hdfs_ha(self, active_name, active_shared_path, standby_name,
901 standby_shared_path, nameservice, start_dependent_services=True,
902 deploy_client_configs=True, enable_quorum_storage=False):
903 """
904 Enable high availability for an HDFS NameNode.
905 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead.
906
907 @param active_name: name of active NameNode.
908 @param active_shared_path: shared edits path for active NameNode.
909 Ignored if Quorum-based Storage is being enabled.
910 @param standby_name: name of stand-by NameNode.
911 @param standby_shared_path: shared edits path for stand-by NameNode.
912 Ignored if Quourm Journal is being enabled.
913 @param nameservice: nameservice for the HA pair.
914 @param start_dependent_services: whether to re-start dependent services.
915 @param deploy_client_configs: whether to re-deploy client configurations.
916 @param enable_quorum_storage: whether to enable Quorum-based Storage. Available since API v2.
917 Quorum-based Storage will be enabled for all
918 nameservices except those configured with NFS High
919 Availability.
920 @return: Reference to the submitted command.
921 """
922 version = self._get_resource_root().version
923
924 args = dict(
925 activeName = active_name,
926 standByName = standby_name,
927 nameservice = nameservice,
928 startDependentServices = start_dependent_services,
929 deployClientConfigs = deploy_client_configs,
930 )
931
932 if enable_quorum_storage:
933 if version < 2:
934 raise AttributeError("Quorum-based Storage is not supported prior to Cloudera Manager 4.1.")
935 else:
936 args['enableQuorumStorage'] = enable_quorum_storage
937 else:
938 if active_shared_path is None or standby_shared_path is None:
939 raise AttributeError("Active and standby shared paths must be specified if not enabling Quorum-based Storage")
940 args['activeSharedEditsPath'] = active_shared_path
941 args['standBySharedEditsPath'] = standby_shared_path
942
943 return self._cmd('hdfsEnableHa', data=args)
944
945 - def enable_nn_ha(self, active_name, standby_host_id, nameservice, jns,
946 standby_name_dir_list=None, qj_name=None, standby_name=None,
947 active_fc_name=None, standby_fc_name=None, zk_service_name=None,
948 force_init_znode=True, clear_existing_standby_name_dirs=True, clear_existing_jn_edits_dir=True):
949 """
950 Enable High Availability (HA) with Auto-Failover for an HDFS NameNode.
951 @param active_name: Name of Active NameNode.
952 @param standby_host_id: ID of host where Standby NameNode will be created.
953 @param nameservice: Nameservice to be used while enabling HA.
954 Optional if Active NameNode already has this config set.
955 @param jns: List of Journal Nodes to be created during the command.
956 Each element of the list must be a dict containing the following keys:
957 - B{jnHostId}: ID of the host where the new JournalNode will be created.
958 - B{jnName}: Name of the JournalNode role (optional)
959 - B{jnEditsDir}: Edits dir of the JournalNode. Can be omitted if the config
960 is already set at RCG level.
961 @param standby_name_dir_list: List of directories for the new Standby NameNode.
962 If not provided then it will use same dirs as Active NameNode.
963 @param qj_name: Name of the journal located on each JournalNodes' filesystem.
964 This can be optionally provided if the config hasn't been already set for the Active NameNode.
965 If this isn't provided and Active NameNode doesn't also have the config,
966 then nameservice is used by default.
967 @param standby_name: Name of the Standby NameNode role to be created (Optional).
968 @param active_fc_name: Name of the Active Failover Controller role to be created (Optional).
969 @param standby_fc_name: Name of the Standby Failover Controller role to be created (Optional).
970 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover.
971 If HDFS service already depends on a ZooKeeper service then that ZooKeeper
972 service will be used for auto-failover and in that case this parameter
973 can either be omitted or should be the same ZooKeeper service.
974 @param force_init_znode: Indicates if the ZNode should be force initialized if it is
975 already present. Useful while re-enabling High Availability. (Default: TRUE)
976 @param clear_existing_standby_name_dirs: Indicates if the existing name directories for Standby NameNode
977 should be cleared during the workflow.
978 Useful while re-enabling High Availability. (Default: TRUE)
979 @param clear_existing_jn_edits_dir: Indicates if the existing edits directories for the JournalNodes
980 for the specified nameservice should be cleared during the workflow.
981 Useful while re-enabling High Availability. (Default: TRUE)
982 @return: Reference to the submitted command.
983 @since: API v6
984 """
985 args = dict (
986 activeNnName = active_name,
987 standbyNnName = standby_name,
988 standbyNnHostId = standby_host_id,
989 standbyNameDirList = standby_name_dir_list,
990 nameservice = nameservice,
991 qjName = qj_name,
992 activeFcName = active_fc_name,
993 standbyFcName = standby_fc_name,
994 zkServiceName = zk_service_name,
995 forceInitZNode = force_init_znode,
996 clearExistingStandbyNameDirs = clear_existing_standby_name_dirs,
997 clearExistingJnEditsDir = clear_existing_jn_edits_dir,
998 jns = jns
999 )
1000 return self._cmd('hdfsEnableNnHa', data=args, api_version=6)
1001
1002 - def disable_nn_ha(self, active_name, snn_host_id, snn_check_point_dir_list,
1003 snn_name=None):
1004 """
1005 Disable high availability with automatic failover for an HDFS NameNode.
1006
1007 @param active_name: Name of the NamdeNode role that is going to be active after
1008 High Availability is disabled.
1009 @param snn_host_id: Id of the host where the new SecondaryNameNode will be created.
1010 @param snn_check_point_dir_list : List of directories used for checkpointing
1011 by the new SecondaryNameNode.
1012 @param snn_name: Name of the new SecondaryNameNode role (Optional).
1013 @return: Reference to the submitted command.
1014 @since: API v6
1015 """
1016 args = dict(
1017 activeNnName = active_name,
1018 snnHostId = snn_host_id,
1019 snnCheckpointDirList = snn_check_point_dir_list,
1020 snnName = snn_name
1021 )
1022 return self._cmd('hdfsDisableNnHa', data=args, api_version=6)
1023
1024 - def enable_jt_ha(self, new_jt_host_id, force_init_znode=True, zk_service_name=None,
1025 new_jt_name=None, fc1_name=None, fc2_name=None):
1026 """
1027 Enable high availability for a MR JobTracker.
1028
1029 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover.
1030 If MapReduce service depends on a ZooKeeper service then that ZooKeeper
1031 service will be used for auto-failover and in that case this parameter
1032 can be omitted.
1033 @param new_jt_host_id: id of the host where the second JobTracker
1034 will be added.
1035 @param force_init_znode: Initialize the ZNode used for auto-failover even if
1036 it already exists. This can happen if JobTracker HA
1037 was enabled before and then disabled. Disable operation
1038 doesn't delete this ZNode. Defaults to true.
1039 @param new_jt_name: Name of the second JobTracker role to be created.
1040 @param fc1_name: Name of the Failover Controller role that is co-located with
1041 the existing JobTracker.
1042 @param fc2_name: Name of the Failover Controller role that is co-located with
1043 the new JobTracker.
1044 @return: Reference to the submitted command.
1045 @since: API v5
1046 """
1047 args = dict(
1048 newJtHostId = new_jt_host_id,
1049 forceInitZNode = force_init_znode,
1050 zkServiceName = zk_service_name,
1051 newJtRoleName = new_jt_name,
1052 fc1RoleName = fc1_name,
1053 fc2RoleName = fc2_name
1054 )
1055 return self._cmd('enableJtHa', data=args)
1056
1058 """
1059 Disable high availability for a MR JobTracker active-standby pair.
1060
1061 @param active_name: name of the JobTracker that will be active after
1062 the disable operation. The other JobTracker and
1063 Failover Controllers will be removed.
1064 @return: Reference to the submitted command.
1065 """
1066 args = dict(
1067 activeName = active_name,
1068 )
1069 return self._cmd('disableJtHa', data=args)
1070
1071 - def enable_rm_ha(self, new_rm_host_id, zk_service_name=None):
1072 """
1073 Enable high availability for a YARN ResourceManager.
1074
1075 @param new_rm_host_id: id of the host where the second ResourceManager
1076 will be added.
1077 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover.
1078 If YARN service depends on a ZooKeeper service then that ZooKeeper
1079 service will be used for auto-failover and in that case this parameter
1080 can be omitted.
1081 @return: Reference to the submitted command.
1082 @since: API v6
1083 """
1084 args = dict(
1085 newRmHostId = new_rm_host_id,
1086 zkServiceName = zk_service_name
1087 )
1088 return self._cmd('enableRmHa', data=args)
1089
1091 """
1092 Disable high availability for a YARN ResourceManager active-standby pair.
1093
1094 @param active_name: name of the ResourceManager that will be active after
1095 the disable operation. The other ResourceManager
1096 will be removed.
1097 @return: Reference to the submitted command.
1098 @since: API v6
1099 """
1100 args = dict(
1101 activeName = active_name
1102 )
1103 return self._cmd('disableRmHa', data=args)
1104
1105 - def enable_oozie_ha(self, new_oozie_server_host_ids, new_oozie_server_role_names=None,
1106 zk_service_name=None, load_balancer_host_port=None):
1107 """
1108 Enable high availability for Oozie.
1109
1110 @param new_oozie_server_host_ids: List of IDs of the hosts on which new Oozie Servers
1111 will be added.
1112 @param new_oozie_server_role_names: List of names of the new Oozie Servers. This is an
1113 optional argument, but if provided, it should
1114 match the length of host IDs provided.
1115 @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA.
1116 This is an optional parameter if the Oozie to ZooKeeper
1117 dependency is already set.
1118 @param load_balancer_host_port: Address and port of the load balancer used for Oozie HA.
1119 This is an optional parameter if this config is already set.
1120 @return: Reference to the submitted command.
1121 @since: API v6
1122 """
1123 args = dict(
1124 newOozieServerHostIds = new_oozie_server_host_ids,
1125 newOozieServerRoleNames = new_oozie_server_role_names,
1126 zkServiceName = zk_service_name,
1127 loadBalancerHostPort = load_balancer_host_port
1128 )
1129 return self._cmd('oozieEnableHa', data=args, api_version=6)
1130
1132 """
1133 Disable high availability for Oozie
1134
1135 @param active_name: Name of the Oozie Server that will be active after
1136 High Availability is disabled.
1137 @return: Reference to the submitted command.
1138 @since: API v6
1139 """
1140 args = dict(
1141 activeName = active_name
1142 )
1143 return self._cmd('oozieDisableHa', data=args, api_version=6)
1144
1145 - def failover_hdfs(self, active_name, standby_name, force=False):
1146 """
1147 Initiate a failover of an HDFS NameNode HA pair.
1148
1149 This will make the given stand-by NameNode active, and vice-versa.
1150
1151 @param active_name: name of currently active NameNode.
1152 @param standby_name: name of NameNode currently in stand-by.
1153 @param force: whether to force failover.
1154 @return: Reference to the submitted command.
1155 """
1156 params = { "force" : "true" and force or "false" }
1157 args = { ApiList.LIST_KEY : [ active_name, standby_name ] }
1158 return self._cmd('hdfsFailover', data=[ active_name, standby_name ],
1159 params = { "force" : "true" and force or "false" })
1160
1169
1171 """
1172 Initialize HDFS failover controller metadata.
1173
1174 Only one controller per nameservice needs to be initialized.
1175
1176 @param controllers: Name of failover controller instances to initialize.
1177 @return: List of submitted commands.
1178 """
1179 return self._role_cmd('hdfsInitializeAutoFailover', controllers)
1180
1182 """
1183 Initialize a NameNode's shared edits directory.
1184
1185 @param namenodes: Name of NameNode instances.
1186 @return: List of submitted commands.
1187 """
1188 return self._role_cmd('hdfsInitializeSharedDir', namenodes)
1189
1191 """
1192 Roll the edits of an HDFS NameNode or Nameservice.
1193
1194 @param nameservice: Nameservice whose edits should be rolled.
1195 Required only with a federated HDFS.
1196 @return: Reference to the submitted command.
1197 @since: API v3
1198 """
1199 args = dict()
1200 if nameservice:
1201 args['nameservice'] = nameservice
1202
1203 return self._cmd('hdfsRollEdits', data=args)
1204
1213
1215 """
1216 Upgrade HBase data in HDFS and ZooKeeper as part of upgrade from CDH4 to CDH5.
1217
1218 @return: Reference to the submitted command.
1219 @since: API v6
1220 """
1221 return self._cmd('hbaseUpgrade', api_version=6)
1222
1224 """
1225 Creates the user directory of a Sqoop service in HDFS.
1226
1227 @return: Reference to the submitted command.
1228 @since: API v4
1229 """
1230 return self._cmd('createSqoopUserDir', api_version=4)
1231
1233 """
1234 Creates the Sqoop2 Server database tables in the configured database.
1235 Will do nothing if tables already exist. Will not perform an upgrade.
1236
1237 @return: Reference to the submitted command.
1238 @since: API v10
1239 """
1240 return self._cmd('sqoopCreateDatabaseTables', api_version=10)
1241
1243 """
1244 Upgrade Sqoop Database schema as part of a major version upgrade.
1245
1246 @return: Reference to the submitted command.
1247 @since: API v6
1248 """
1249 return self._cmd('sqoopUpgradeDb', api_version=6)
1250
1259
1261 """
1262 Cleanup a ZooKeeper service or roles.
1263
1264 If no server role names are provided, the command applies to the whole
1265 service, and cleans up all the server roles that are currently running.
1266
1267 @param servers: ZK server role names (optional).
1268 @return: Command reference (for service command) or list of command
1269 references (for role commands).
1270 """
1271 if servers:
1272 return self._role_cmd('zooKeeperCleanup', servers)
1273 else:
1274 return self._cmd('zooKeeperCleanup')
1275
1277 """
1278 Initialize a ZooKeeper service or roles.
1279
1280 If no server role names are provided, the command applies to the whole
1281 service, and initializes all the configured server roles.
1282
1283 @param servers: ZK server role names (optional).
1284 @return: Command reference (for service command) or list of command
1285 references (for role commands).
1286 """
1287 if servers:
1288 return self._role_cmd('zooKeeperInit', servers)
1289 else:
1290 return self._cmd('zooKeeperInit')
1291
1293 """
1294 Synchronize the Hue server's database.
1295
1296 @param servers: Name of Hue Server roles to synchronize. Not required starting with API v10.
1297 @return: List of submitted commands.
1298 """
1299
1300 actual_version = self._get_resource_root().version
1301 if actual_version < 10:
1302 return self._role_cmd('hueSyncDb', servers)
1303
1304 return self._cmd('hueSyncDb', api_version=10)
1305
1306
1308 """
1309 Dump the Hue server's database; it can be loaded later.
1310
1311 @return: List of submitted commands.
1312 """
1313 return self._cmd('hueDumpDb', api_version=10)
1314
1316 """
1317 Load data into Hue server's database from a previous data dump.
1318
1319 @return: List of submitted commands.
1320 """
1321 return self._cmd('hueLoadDb', api_version=10)
1322
1323 - def lsof(self, *rolenames):
1324 """
1325 Run the lsof diagnostic command. This command runs the lsof utility to list
1326 a role's open files.
1327
1328 @param rolenames: Name of the role instances
1329 @return: List of submitted commands.
1330 @since: API v8
1331 """
1332 return self._role_cmd('lsof', rolenames)
1333
1334 - def jstack(self, *rolenames):
1335 """
1336 Run the jstack diagnostic command. The command runs the jstack utility to
1337 capture a role's java thread stacks.
1338
1339 @param rolenames: Name of the role instances
1340 @return: List of submitted commands.
1341 @since: API v8
1342 """
1343 return self._role_cmd('jstack', rolenames)
1344
1346 """
1347 Run the jmapHisto diagnostic command. The command runs the jmap utility to
1348 capture a histogram of the objects on the role's java heap.
1349
1350 @param rolenames: Name of the role instances
1351 @return: List of submitted commands.
1352 @since: API v8
1353 """
1354 return self._role_cmd('jmapHisto', rolenames)
1355
1357 """
1358 Run the jmapDump diagnostic command. The command runs the jmap utility to
1359 capture a dump of the role's java heap.
1360
1361 @param rolenames: Name of the role instances
1362 @return: List of submitted commands.
1363 @since: API v8
1364 """
1365 return self._role_cmd('jmapDump', rolenames)
1366
1368 """
1369 Put the service in maintenance mode.
1370
1371 @return: Reference to the completed command.
1372 @since: API v2
1373 """
1374 cmd = self._cmd('enterMaintenanceMode')
1375 if cmd.success:
1376 self._update(_get_service(self._get_resource_root(), self._path()))
1377 return cmd
1378
1380 """
1381 Take the service out of maintenance mode.
1382
1383 @return: Reference to the completed command.
1384 @since: API v2
1385 """
1386 cmd = self._cmd('exitMaintenanceMode')
1387 if cmd.success:
1388 self._update(_get_service(self._get_resource_root(), self._path()))
1389 return cmd
1390
1391 - def rolling_restart(self, slave_batch_size=None,
1392 slave_fail_count_threshold=None,
1393 sleep_seconds=None,
1394 stale_configs_only=None,
1395 unupgraded_only=None,
1396 restart_role_types=None,
1397 restart_role_names=None):
1398 """
1399 Rolling restart the roles of a service. The sequence is:
1400 1. Restart all the non-slave roles
1401 2. If slaves are present restart them in batches of size specified
1402 3. Perform any post-command needed after rolling restart
1403
1404 @param slave_batch_size: Number of slave roles to restart at a time
1405 Must be greater than 0. Default is 1.
1406 For HDFS, this number should be less than the replication factor (default 3)
1407 to ensure data availability during rolling restart.
1408 @param slave_fail_count_threshold: The threshold for number of slave batches that
1409 are allowed to fail to restart before the entire command is considered failed.
1410 Must be >= 0. Default is 0.
1411 @param sleep_seconds: Number of seconds to sleep between restarts of slave role batches.
1412 Must be >=0. Default is 0.
1413 @param stale_configs_only: Restart roles with stale configs only. Default is false.
1414 @param unupgraded_only: Restart roles that haven't been upgraded yet. Default is false.
1415 @param restart_role_types: Role types to restart. If not specified, all startable roles are restarted.
1416 @param restart_role_names: List of specific roles to restart.
1417 If none are specified, then all roles of specified role types are restarted.
1418 @return: Reference to the submitted command.
1419 @since: API v3
1420 """
1421 args = dict()
1422 if slave_batch_size:
1423 args['slaveBatchSize'] = slave_batch_size
1424 if slave_fail_count_threshold:
1425 args['slaveFailCountThreshold'] = slave_fail_count_threshold
1426 if sleep_seconds:
1427 args['sleepSeconds'] = sleep_seconds
1428 if stale_configs_only:
1429 args['staleConfigsOnly'] = stale_configs_only
1430 if unupgraded_only:
1431 args['unUpgradedOnly'] = unupgraded_only
1432 if restart_role_types:
1433 args['restartRoleTypes'] = restart_role_types
1434 if restart_role_names:
1435 args['restartRoleNames'] = restart_role_names
1436
1437 return self._cmd('rollingRestart', data=args)
1438
1439 - def create_replication_schedule(self,
1440 start_time, end_time, interval_unit, interval, paused, arguments,
1441 alert_on_start=False, alert_on_success=False, alert_on_fail=False,
1442 alert_on_abort=False):
1443 """
1444 Create a new replication schedule for this service.
1445
1446 The replication argument type varies per service type. The following types
1447 are recognized:
1448 - HDFS: ApiHdfsReplicationArguments
1449 - Hive: ApiHiveReplicationArguments
1450
1451 @type start_time: datetime.datetime
1452 @param start_time: The time at which the schedule becomes active and first executes.
1453 @type end_time: datetime.datetime
1454 @param end_time: The time at which the schedule will expire.
1455 @type interval_unit: str
1456 @param interval_unit: The unit of time the `interval` represents. Ex. MINUTE, HOUR,
1457 DAY. See the server documentation for a full list of values.
1458 @type interval: int
1459 @param interval: The number of time units to wait until triggering the next replication.
1460 @type paused: bool
1461 @param paused: Should the schedule be paused? Useful for on-demand replication.
1462 @param arguments: service type-specific arguments for the replication job.
1463 @param alert_on_start: whether to generate alerts when the job is started.
1464 @param alert_on_success: whether to generate alerts when the job succeeds.
1465 @param alert_on_fail: whether to generate alerts when the job fails.
1466 @param alert_on_abort: whether to generate alerts when the job is aborted.
1467 @return: The newly created schedule.
1468 @since: API v3
1469 """
1470 schedule = ApiReplicationSchedule(self._get_resource_root(),
1471 startTime=start_time, endTime=end_time, intervalUnit=interval_unit, interval=interval,
1472 paused=paused, alertOnStart=alert_on_start, alertOnSuccess=alert_on_success,
1473 alertOnFail=alert_on_fail, alertOnAbort=alert_on_abort)
1474
1475 if self.type == 'HDFS':
1476 if not isinstance(arguments, ApiHdfsReplicationArguments):
1477 raise TypeError, 'Unexpected type for HDFS replication argument.'
1478 schedule.hdfsArguments = arguments
1479 elif self.type == 'HIVE':
1480 if not isinstance(arguments, ApiHiveReplicationArguments):
1481 raise TypeError, 'Unexpected type for Hive replication argument.'
1482 schedule.hiveArguments = arguments
1483 else:
1484 raise TypeError, 'Replication is not supported for service type ' + self.type
1485
1486 return self._post("replications", ApiReplicationSchedule, True, [schedule],
1487 api_version=3)[0]
1488
1490 """
1491 Retrieve a list of replication schedules.
1492
1493 @return: A list of replication schedules.
1494 @since: API v3
1495 """
1496 return self._get("replications", ApiReplicationSchedule, True,
1497 api_version=3)
1498
1500 """
1501 Retrieve a single replication schedule.
1502
1503 @param schedule_id: The id of the schedule to retrieve.
1504 @return: The requested schedule.
1505 @since: API v3
1506 """
1507 return self._get("replications/%d" % schedule_id, ApiReplicationSchedule,
1508 api_version=3)
1509
1511 """
1512 Delete a replication schedule.
1513
1514 @param schedule_id: The id of the schedule to delete.
1515 @return: The deleted replication schedule.
1516 @since: API v3
1517 """
1518 return self._delete("replications/%s" % schedule_id, ApiReplicationSchedule,
1519 api_version=3)
1520
1522 """
1523 Update a replication schedule.
1524
1525 @param schedule_id: The id of the schedule to update.
1526 @param schedule: The modified schedule.
1527 @return: The updated replication schedule.
1528 @since: API v3
1529 """
1530 return self._put("replications/%s" % schedule_id, ApiReplicationSchedule,
1531 data=schedule, api_version=3)
1532
1533 - def get_replication_command_history(self, schedule_id, limit=20, offset=0,
1534 view=None):
1535 """
1536 Retrieve a list of commands for a replication schedule.
1537
1538 @param schedule_id: The id of the replication schedule.
1539 @param limit: Maximum number of commands to retrieve.
1540 @param offset: Index of first command to retrieve.
1541 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'.
1542 @return: List of commands executed for a replication schedule.
1543 @since: API v4
1544 """
1545 params = {
1546 'limit': limit,
1547 'offset': offset,
1548 }
1549 if view:
1550 params['view'] = view
1551
1552 return self._get("replications/%s/history" % schedule_id,
1553 ApiReplicationCommand, True, params=params, api_version=4)
1554
1556 """
1557 Trigger replication immediately. Start and end dates on the schedule will be
1558 ignored.
1559
1560 @param schedule_id: The id of the schedule to trigger.
1561 @param dry_run: Whether to execute a dry run.
1562 @return: The command corresponding to the replication job.
1563 @since: API v3
1564 """
1565 return self._post("replications/%s/run" % schedule_id, ApiCommand,
1566 params=dict(dryRun=dry_run),
1567 api_version=3)
1568
1570 """
1571 Create a new snapshot policy for this service.
1572 @param policy: The snapshot policy to create
1573 @return: The newly created policy.
1574 @since: API v6
1575 """
1576 return self._post("snapshots/policies", ApiSnapshotPolicy, True, [policy],
1577 api_version=6)[0]
1578
1580 """
1581 Retrieve a list of snapshot policies.
1582
1583 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'.
1584 @return: A list of snapshot policies.
1585 @since: API v6
1586 """
1587 return self._get("snapshots/policies", ApiSnapshotPolicy, True,
1588 params=view and dict(view=view) or None, api_version=6)
1589
1591 """
1592 Retrieve a single snapshot policy.
1593
1594 @param name: The name of the snapshot policy to retrieve.
1595 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'.
1596 @return: The requested snapshot policy.
1597 @since: API v6
1598 """
1599 return self._get("snapshots/policies/%s" % name, ApiSnapshotPolicy,
1600 params=view and dict(view=view) or None, api_version=6)
1601
1603 """
1604 Delete a snapshot policy.
1605
1606 @param name: The name of the snapshot policy to delete.
1607 @return: The deleted snapshot policy.
1608 @since: API v6
1609 """
1610 return self._delete("snapshots/policies/%s" % name, ApiSnapshotPolicy, api_version=6)
1611
1613 """
1614 Update a snapshot policy.
1615
1616 @param name: The name of the snapshot policy to update.
1617 @param policy: The modified snapshot policy.
1618 @return: The updated snapshot policy.
1619 @since: API v6
1620 """
1621 return self._put("snapshots/policies/%s" % name, ApiSnapshotPolicy, data=policy,
1622 api_version=6)
1623
1624 - def get_snapshot_command_history(self, name, limit=20, offset=0, view=None):
1625 """
1626 Retrieve a list of commands triggered by a snapshot policy.
1627
1628 @param name: The name of the snapshot policy.
1629 @param limit: Maximum number of commands to retrieve.
1630 @param offset: Index of first command to retrieve.
1631 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'.
1632 @return: List of commands triggered by a snapshot policy.
1633 @since: API v6
1634 """
1635 params = {
1636 'limit': limit,
1637 'offset': offset,
1638 }
1639 if view:
1640 params['view'] = view
1641
1642 return self._get("snapshots/policies/%s/history" % name, ApiSnapshotCommand, True,
1643 params=params, api_version=6)
1644
1645
1647 """
1648 Installs the Oozie ShareLib. Oozie must be stopped before running this
1649 command.
1650
1651 @return: Reference to the submitted command.
1652 @since: API v3
1653 """
1654 return self._cmd('installOozieShareLib', api_version=3)
1655
1657 """
1658 Create the Oozie Server Database. Only works with embedded postgresql
1659 database. This command should usually be followed by a call to
1660 create_oozie_db.
1661
1662 @return: Reference to the submitted command.
1663 @since: API v10
1664 """
1665 return self._cmd('oozieCreateEmbeddedDatabase', api_version=10)
1666
1668 """
1669 Creates the Oozie Database Schema in the configured database.
1670 This command does not create database. This command creates only tables
1671 required by Oozie. To create database, please refer to create_oozie_embedded_database.
1672
1673 @return: Reference to the submitted command.
1674 @since: API v2
1675 """
1676 return self._cmd('createOozieDb', api_version=2)
1677
1679 """
1680 Upgrade Oozie Database schema as part of a major version upgrade.
1681
1682 @return: Reference to the submitted command.
1683 @since: API v6
1684 """
1685 return self._cmd('oozieUpgradeDb', api_version=6)
1686
1688 """
1689 Initializes the Solr service in Zookeeper.
1690
1691 @return: Reference to the submitted command.
1692 @since: API v4
1693 """
1694 return self._cmd('initSolr', api_version=4)
1695
1697 """
1698 Creates the home directory of a Solr service in HDFS.
1699
1700 @return: Reference to the submitted command.
1701 @since: API v4
1702 """
1703 return self._cmd('createSolrHdfsHomeDir', api_version=4)
1704
1714
1716 """
1717 Creates the Hive warehouse directory in HDFS.
1718
1719 @return: Reference to the submitted command.
1720 @since: API v3
1721 """
1722 return self._cmd('hiveCreateHiveWarehouse')
1723
1725 """
1726 Creates the Hive user directory in HDFS.
1727
1728 @return: Reference to the submitted command.
1729 @since: API v4
1730 """
1731 return self._cmd('hiveCreateHiveUserDir')
1732
1743
1745 """
1746 Create the Sentry Server Database. Only works with embedded postgresql
1747 database. This command should usually be followed by a call to
1748 create_sentry_database_tables.
1749
1750 @return: Reference to the submitted command.
1751 @since: API v7
1752 """
1753 return self._cmd('sentryCreateDatabase', api_version=7)
1754
1756 """
1757 Creates the Sentry Server database tables in the configured database.
1758 Will do nothing if tables already exist. Will not perform an upgrade.
1759
1760 @return: Reference to the submitted command.
1761 @since: API v7
1762 """
1763 return self._cmd('sentryCreateDatabaseTables', api_version=7)
1764
1766 """
1767 Upgrades the Sentry Server database tables in the configured database.
1768
1769 @return: Reference to the submitted command.
1770 @since: API v8
1771 """
1772 return self._cmd('sentryUpgradeDatabaseTables', api_version=8)
1773
1786
1788 """
1789 Import MapReduce configuration into Yarn, overwriting Yarn configuration.
1790
1791 You will lose existing Yarn configuration. Read all MapReduce
1792 configuration, role assignments, and role configuration groups and update
1793 Yarn with corresponding values. MR1 configuration will be converted into
1794 the equivalent MR2 configuration.
1795
1796 Before running this command, Yarn must be stopped and MapReduce must exist
1797 with valid configuration.
1798
1799 @return: Reference to the submitted command.
1800 @since: API v6
1801 """
1802 return self._cmd('importMrConfigsIntoYarn', api_version=6)
1803
1805 """
1806 Change the cluster to use MR2 instead of MR1. Services will be restarted.
1807
1808 Will perform the following steps:
1809 * Update all services that depend on MapReduce to instead depend on Yarn.
1810 * Stop MapReduce
1811 * Start Yarn (includes MR2)
1812 * Deploy Yarn (MR2) Client Configuration
1813
1814 Available since API v6.
1815
1816 @return: Reference to the submitted command.
1817 @since: API v6
1818 """
1819 return self._cmd('switchToMr2', api_version=6)
1820
1822 """
1823 Finalizes the rolling upgrade for HDFS by updating the NameNode
1824 metadata permanently to the next version. Should be done after
1825 doing a rolling upgrade to a CDH version >= 5.2.0.
1826
1827 @return: Reference to the submitted command.
1828 @since: API v8
1829 """
1830 return self._cmd('hdfsFinalizeRollingUpgrade', api_version=8)
1831
1833 """
1834 Executes a role command by name on the specified
1835 roles
1836
1837 @param command_name: The name of the command.
1838 @param role_names: The role names to execute this command on.
1839 @return: Reference to the submitted command.
1840 @since: API v6
1841 """
1842 return self._role_cmd(command_name, role_names, api_version=6)
1843
1845 """
1846 Executes a command on the service specified
1847 by name.
1848
1849 @param command_name: The name of the command.
1850 @return: Reference to the submitted command.
1851 @since: API v6
1852 """
1853 return self._cmd(command_name, api_version=6)
1854
1856 """
1857 Lists all the commands that can be executed by name
1858 on the provided service.
1859
1860 @return: A list of command metadata objects
1861 @since: API v6
1862 """
1863 return self._get("commandsByName", ApiCommandMetadata, True,
1864 api_version=6)
1865
1867 _ATTRIBUTES = {
1868 'name' : None,
1869 'type' : None,
1870 'config' : Attr(ApiConfig),
1871 'roles' : Attr(roles.ApiRole),
1872 }
1873
1874 - def __init__(self, name=None, type=None,
1875 config=None, roles=None):
1876
1877 resource_root = None
1878
1879
1880 BaseApiObject.init(self, None, locals())
1881
1883 """
1884 Set the service configuration.
1885
1886 @param config: A dictionary of config key/value
1887 """
1888 if self.config is None:
1889 self.config = { }
1890 self.config.update(config_to_api_list(config))
1891
1893 """
1894 Add a role type setup info.
1895
1896 @param role_type: Role type
1897 @param config: A dictionary of role type configuration
1898 """
1899 rt_config = config_to_api_list(config)
1900 rt_config['roleType'] = role_type
1901
1902 if self.config is None:
1903 self.config = { }
1904 if not self.config.has_key(ROLETYPES_CFG_KEY):
1905 self.config[ROLETYPES_CFG_KEY] = [ ]
1906 self.config[ROLETYPES_CFG_KEY].append(rt_config)
1907
1908 - def add_role_info(self, role_name, role_type, host_id, config=None):
1909 """
1910 Add a role info. The role will be created along with the service setup.
1911
1912 @param role_name: Role name
1913 @param role_type: Role type
1914 @param host_id: The host where the role should run
1915 @param config: (Optional) A dictionary of role config values
1916 """
1917 if self.roles is None:
1918 self.roles = [ ]
1919 api_config_list = config is not None and config_to_api_list(config) or None
1920 self.roles.append({
1921 'name' : role_name,
1922 'type' : role_type,
1923 'hostRef' : { 'hostId' : host_id },
1924 'config' : api_config_list })
1925
1927 """
1928 Prepare and start this service.
1929 Perform all the steps needed to prepare and start this service.
1930
1931 @return: Reference to the submitted command.
1932 @since: API v7
1933 """
1934 return self._cmd('firstRun', None, api_version=7)
1935