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