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