Package cm_api :: Package endpoints :: Module services
[hide private]
[frames] | no frames]

Source Code for Module cm_api.endpoints.services

   1  # Licensed to Cloudera, Inc. under one 
   2  # or more contributor license agreements.  See the NOTICE file 
   3  # distributed with this work for additional information 
   4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
   5  # to you under the Apache License, Version 2.0 (the 
   6  # "License"); you may not use this file except in compliance 
   7  # with the License.  You may obtain a copy of the License at 
   8  # 
   9  #     http://www.apache.org/licenses/LICENSE-2.0 
  10  # 
  11  # Unless required by applicable law or agreed to in writing, software 
  12  # distributed under the License is distributed on an "AS IS" BASIS, 
  13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  14  # See the License for the specific language governing permissions and 
  15  # limitations under the License. 
  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
56 -def _get_service(resource_root, path):
57 return call(resource_root.get, path, ApiService)
58
59 -def get_all_services(resource_root, cluster_name="default", view=None):
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
70 -def delete_service(resource_root, name, cluster_name="default"):
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
83 -class ApiService(BaseApiResource):
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):
101 BaseApiObject.init(self, resource_root, locals())
102
103 - def __str__(self):
104 return "<ApiService>: %s (cluster: %s)" % ( 105 self.name, self._get_cluster_name())
106
107 - def _get_cluster_name(self):
108 if hasattr(self, 'clusterRef') and self.clusterRef: 109 return self.clusterRef.clusterName 110 return None
111
112 - def _path(self):
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):
125 return self._post("roleCommands/" + cmd, ApiBulkCommandList, 126 data=roles, api_version=api_version)
127
128 - def _parse_svc_config(self, json_dic, view = None):
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
145 - def get_commands(self, view=None):
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
155 - def get_running_activities(self):
156 return self.query_activities()
157
158 - def query_activities(self, query_str=None):
159 return self._get("activities", ApiActivity, True, 160 params=query_str and dict(query=query_str) or dict())
161
162 - def get_activity(self, job_id):
163 return self._get("activities/" + job_id, ApiActivity)
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
196 - def cancel_impala_query(self, query_id):
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
207 - def get_query_details(self, query_id, format='text'):
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
261 - def create_impala_user_dir(self):
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 get_yarn_applications(self, start_time, end_time, filter_str="", limit=100, 271 offset=0):
272 """ 273 Returns a list of YARN applications that satisfy the filter 274 @type start_time: datetime.datetime. Note that the datetime must either be 275 time zone aware or specified in the server time zone. See 276 the python datetime documentation for more details about 277 python's time zone handling. 278 @param start_time: Applications must have ended after this time 279 @type end_time: datetime.datetime. Note that the datetime must either be 280 time zone aware or specified in the server time zone. See 281 the python datetime documentation for more details about 282 python's time zone handling. 283 @param filter_str: A filter to apply to the applications. For example: 284 'user = root and applicationDuration > 5s' 285 @param limit: The maximum number of results to return 286 @param offset: The offset into the return list 287 @since: API v6 288 """ 289 params = { 290 'from': start_time.isoformat(), 291 'to': end_time.isoformat(), 292 'filter': filter_str, 293 'limit': limit, 294 'offset': offset 295 } 296 return self._get("yarnApplications", ApiYarnApplicationResponse, 297 params=params, api_version=6)
298
299 - def kill_yarn_application(self, application_id):
300 """ 301 Kills the application. 302 303 @return: The warning message, if any. 304 @since: API v6 305 """ 306 return self._post("yarnApplications/%s/kill" % (application_id, ), 307 ApiYarnKillResponse, api_version=6)
308
310 """ 311 Returns the list of all attributes that the Service Monitor can associate 312 with YARN applications. 313 314 Examples of attributes include the user who ran the application and the 315 number of maps completed by the application. 316 317 These attributes can be used to search for specific YARN applications through 318 the get_yarn_applications API. For example the 'user' attribute could be used 319 in the search 'user = root'. If the attribute is numeric it can also be used 320 as a metric in a tsquery (ie, 'select maps_completed from YARN_APPLICATIONS'). 321 322 Note that this response is identical for all YARN services. 323 324 @return: A list of the YARN application attributes 325 @since API v6 326 """ 327 return self._get("yarnApplications/attributes", ApiYarnApplicationAttribute, 328 api_version=6)
329
331 """ 332 Create the Yarn job history directory. 333 334 @return: Reference to submitted command. 335 @since: API v6 336 """ 337 return self._cmd('yarnCreateJobHistoryDirCommand', api_version=6)
338
340 """ 341 Create the Yarn NodeManager remote application log directory. 342 343 @return: Reference to submitted command. 344 @since: API v6 345 """ 346 return self._cmd('yarnNodeManagerRemoteAppLogDirCommand', api_version=6)
347
348 - def get_config(self, view = None):
349 """ 350 Retrieve the service's configuration. 351 352 Retrieves both the service configuration and role type configuration 353 for each of the service's supported role types. The role type 354 configurations are returned as a dictionary, whose keys are the 355 role type name, and values are the respective configuration dictionaries. 356 357 The 'summary' view contains strings as the dictionary values. The full 358 view contains ApiConfig instances as the values. 359 360 @param view: View to materialize ('full' or 'summary') 361 @return: 2-tuple (service config dictionary, role type configurations) 362 """ 363 path = self._path() + '/config' 364 resp = self._get_resource_root().get(path, 365 params = view and dict(view=view) or None) 366 return self._parse_svc_config(resp, view)
367
368 - def update_config(self, svc_config, **rt_configs):
369 """ 370 Update the service's configuration. 371 372 @param svc_config: Dictionary with service configuration to update. 373 @param rt_configs: Dict of role type configurations to update. 374 @return: 2-tuple (service config dictionary, role type configurations) 375 """ 376 path = self._path() + '/config' 377 378 if svc_config: 379 data = config_to_api_list(svc_config) 380 else: 381 data = { } 382 if rt_configs: 383 rt_list = [ ] 384 for rt, cfg in rt_configs.iteritems(): 385 rt_data = config_to_api_list(cfg) 386 rt_data['roleType'] = rt 387 rt_list.append(rt_data) 388 data[ROLETYPES_CFG_KEY] = rt_list 389 390 resp = self._get_resource_root().put(path, data = json.dumps(data)) 391 return self._parse_svc_config(resp)
392
393 - def create_role(self, role_name, role_type, host_id):
394 """ 395 Create a role. 396 397 @param role_name: Role name 398 @param role_type: Role type 399 @param host_id: ID of the host to assign the role to 400 @return: An ApiRole object 401 """ 402 return roles.create_role(self._get_resource_root(), self.name, role_type, 403 role_name, host_id, self._get_cluster_name())
404
405 - def delete_role(self, name):
406 """ 407 Delete a role by name. 408 409 @param name: Role name 410 @return: The deleted ApiRole object 411 """ 412 return roles.delete_role(self._get_resource_root(), self.name, name, 413 self._get_cluster_name())
414
415 - def get_role(self, name):
416 """ 417 Lookup a role by name. 418 419 @param name: Role name 420 @return: An ApiRole object 421 """ 422 return roles.get_role(self._get_resource_root(), self.name, name, 423 self._get_cluster_name())
424
425 - def get_all_roles(self, view = None):
426 """ 427 Get all roles in the service. 428 429 @param view: View to materialize ('full' or 'summary') 430 @return: A list of ApiRole objects. 431 """ 432 return roles.get_all_roles(self._get_resource_root(), self.name, 433 self._get_cluster_name(), view)
434
435 - def get_roles_by_type(self, role_type, view = None):
436 """ 437 Get all roles of a certain type in a service. 438 439 @param role_type: Role type 440 @param view: View to materialize ('full' or 'summary') 441 @return: A list of ApiRole objects. 442 """ 443 return roles.get_roles_by_type(self._get_resource_root(), self.name, 444 role_type, self._get_cluster_name(), view)
445
446 - def get_role_types(self):
447 """ 448 Get a list of role types in a service. 449 450 @return: A list of role types (strings) 451 """ 452 resp = self._get_resource_root().get(self._path() + '/roleTypes') 453 return resp[ApiList.LIST_KEY]
454
455 - def get_all_role_config_groups(self):
456 """ 457 Get a list of role configuration groups in the service. 458 459 @return: A list of ApiRoleConfigGroup objects. 460 @since: API v3 461 """ 462 return role_config_groups.get_all_role_config_groups( 463 self._get_resource_root(), self.name, self._get_cluster_name())
464
465 - def get_role_config_group(self, name):
466 """ 467 Get a role configuration group in the service by name. 468 469 @param name: The name of the role config group. 470 @return: An ApiRoleConfigGroup object. 471 @since: API v3 472 """ 473 return role_config_groups.get_role_config_group( 474 self._get_resource_root(), self.name, name, self._get_cluster_name())
475
476 - def create_role_config_group(self, name, display_name, role_type):
477 """ 478 Create a role config group. 479 480 @param name: The name of the new group. 481 @param display_name: The display name of the new group. 482 @param role_type: The role type of the new group. 483 @return: New ApiRoleConfigGroup object. 484 @since: API v3 485 """ 486 return role_config_groups.create_role_config_group( 487 self._get_resource_root(), self.name, name, display_name, role_type, 488 self._get_cluster_name())
489
490 - def update_role_config_group(self, name, apigroup):
491 """ 492 Update a role config group. 493 494 @param name: Role config group name. 495 @param apigroup: The updated role config group. 496 @return: The updated ApiRoleConfigGroup object. 497 @since: API v3 498 """ 499 return role_config_groups.update_role_config_group( 500 self._get_resource_root(), self.name, name, apigroup, 501 self._get_cluster_name())
502
503 - def delete_role_config_group(self, name):
504 """ 505 Delete a role config group by name. 506 507 @param name: Role config group name. 508 @return: The deleted ApiRoleConfigGroup object. 509 @since: API v3 510 """ 511 return role_config_groups.delete_role_config_group( 512 self._get_resource_root(), self.name, name, self._get_cluster_name())
513
514 - def get_metrics(self, from_time=None, to_time=None, metrics=None, view=None):
515 """ 516 This endpoint is not supported as of v6. Use the timeseries API 517 instead. To get all metrics for a service with the timeseries API use 518 the query: 519 520 'select * where serviceName = $SERVICE_NAME'. 521 522 To get specific metrics for a service use a comma-separated list of 523 the metric names as follows: 524 525 'select $METRIC_NAME1, $METRIC_NAME2 where serviceName = $SERVICE_NAME'. 526 527 For more information see http://tiny.cloudera.com/tsquery_doc 528 529 Retrieve metric readings for the service. 530 @param from_time: A datetime; start of the period to query (optional). 531 @param to_time: A datetime; end of the period to query (default = now). 532 @param metrics: List of metrics to query (default = all). 533 @param view: View to materialize ('full' or 'summary') 534 @return: List of metrics and their readings. 535 """ 536 return self._get_resource_root().get_metrics(self._path() + '/metrics', 537 from_time, to_time, metrics, view)
538
539 - def start(self):
540 """ 541 Start a service. 542 543 @return: Reference to the submitted command. 544 """ 545 return self._cmd('start')
546
547 - def stop(self):
548 """ 549 Stop a service. 550 551 @return: Reference to the submitted command. 552 """ 553 return self._cmd('stop')
554
555 - def restart(self):
556 """ 557 Restart a service. 558 559 @return: Reference to the submitted command. 560 """ 561 return self._cmd('restart')
562
563 - def start_roles(self, *role_names):
564 """ 565 Start a list of roles. 566 567 @param role_names: names of the roles to start. 568 @return: List of submitted commands. 569 """ 570 return self._role_cmd('start', role_names)
571
572 - def stop_roles(self, *role_names):
573 """ 574 Stop a list of roles. 575 576 @param role_names: names of the roles to stop. 577 @return: List of submitted commands. 578 """ 579 return self._role_cmd('stop', role_names)
580
581 - def restart_roles(self, *role_names):
582 """ 583 Restart a list of roles. 584 585 @param role_names: names of the roles to restart. 586 @return: List of submitted commands. 587 """ 588 return self._role_cmd('restart', role_names)
589
590 - def bootstrap_hdfs_stand_by(self, *role_names):
591 """ 592 Bootstrap HDFS stand-by NameNodes. 593 594 Initialize their state by syncing it with the respective HA partner. 595 596 @param role_names: NameNodes to bootstrap. 597 @return: List of submitted commands. 598 """ 599 return self._role_cmd('hdfsBootstrapStandBy', role_names)
600
601 - def create_beeswax_warehouse(self):
602 """ 603 DEPRECATED: use create_hive_warehouse on the Hive service. Deprecated since v3. 604 605 Create the Beeswax role's warehouse for a Hue service. 606 607 @return: Reference to the submitted command. 608 """ 609 return self._cmd('hueCreateHiveWarehouse')
610
611 - def create_hbase_root(self):
612 """ 613 Create the root directory of an HBase service. 614 615 @return: Reference to the submitted command. 616 """ 617 return self._cmd('hbaseCreateRoot')
618
619 - def create_hdfs_tmp(self):
620 """ 621 Create the /tmp directory in HDFS with appropriate ownership and permissions. 622 623 @return: Reference to the submitted command 624 @since: API v2 625 """ 626 return self._cmd('hdfsCreateTmpDir')
627
628 - def refresh(self, *role_names):
629 """ 630 Execute the "refresh" command on a set of roles. 631 632 @param role_names: Names of the roles to refresh. 633 @return: Reference to the submitted command. 634 """ 635 return self._role_cmd('refresh', role_names)
636
637 - def decommission(self, *role_names):
638 """ 639 Decommission roles in a service. 640 641 @param role_names: Names of the roles to decommission. 642 @return: Reference to the submitted command. 643 """ 644 return self._cmd('decommission', data=role_names)
645
646 - def recommission(self, *role_names):
647 """ 648 Recommission roles in a service. 649 650 @param role_names: Names of the roles to recommission. 651 @return: Reference to the submitted command. 652 @since: API v2 653 """ 654 return self._cmd('recommission', data=role_names)
655
656 - def deploy_client_config(self, *role_names):
657 """ 658 Deploys client configuration to the hosts where roles are running. 659 660 @param role_names: Names of the roles to decommission. 661 @return: Reference to the submitted command. 662 """ 663 return self._cmd('deployClientConfig', data=role_names)
664
665 - def disable_hdfs_auto_failover(self, nameservice):
666 """ 667 Disable auto-failover for a highly available HDFS nameservice. 668 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 669 670 @param nameservice: Affected nameservice. 671 @return: Reference to the submitted command. 672 """ 673 return self._cmd('hdfsDisableAutoFailover', data=nameservice)
674
675 - def disable_hdfs_ha(self, active_name, secondary_name, 676 start_dependent_services=True, deploy_client_configs=True, 677 disable_quorum_storage=False):
678 """ 679 Disable high availability for an HDFS NameNode. 680 This command is no longer supported with API v6 onwards. Use disable_nn_ha instead. 681 682 @param active_name: Name of the NameNode to keep. 683 @param secondary_name: Name of (existing) SecondaryNameNode to link to 684 remaining NameNode. 685 @param start_dependent_services: whether to re-start dependent services. 686 @param deploy_client_configs: whether to re-deploy client configurations. 687 @param disable_quorum_storage: whether to disable Quorum-based Storage. Available since API v2. 688 Quorum-based Storage will be disabled for all 689 nameservices that have Quorum-based Storage 690 enabled. 691 @return: Reference to the submitted command. 692 """ 693 args = dict( 694 activeName = active_name, 695 secondaryName = secondary_name, 696 startDependentServices = start_dependent_services, 697 deployClientConfigs = deploy_client_configs, 698 ) 699 700 version = self._get_resource_root().version 701 if version < 2: 702 if disable_quorum_storage: 703 raise AttributeError("Quorum-based Storage requires at least API version 2 available in Cloudera Manager 4.1.") 704 else: 705 args['disableQuorumStorage'] = disable_quorum_storage 706 707 return self._cmd('hdfsDisableHa', data=args)
708
709 - def enable_hdfs_auto_failover(self, nameservice, active_fc_name, 710 standby_fc_name, zk_service):
711 """ 712 Enable auto-failover for an HDFS nameservice. 713 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 714 715 @param nameservice: Nameservice for which to enable auto-failover. 716 @param active_fc_name: Name of failover controller to create for active node. 717 @param standby_fc_name: Name of failover controller to create for stand-by node. 718 @param zk_service: ZooKeeper service to use. 719 @return: Reference to the submitted command. 720 """ 721 version = self._get_resource_root().version 722 723 args = dict( 724 nameservice = nameservice, 725 activeFCName = active_fc_name, 726 standByFCName = standby_fc_name, 727 zooKeeperService = dict( 728 clusterName = zk_service.clusterRef.clusterName, 729 serviceName = zk_service.name, 730 ), 731 ) 732 return self._cmd('hdfsEnableAutoFailover', data=args)
733
734 - def enable_hdfs_ha(self, active_name, active_shared_path, standby_name, 735 standby_shared_path, nameservice, start_dependent_services=True, 736 deploy_client_configs=True, enable_quorum_storage=False):
737 """ 738 Enable high availability for an HDFS NameNode. 739 This command is no longer supported with API v6 onwards. Use enable_nn_ha instead. 740 741 @param active_name: name of active NameNode. 742 @param active_shared_path: shared edits path for active NameNode. 743 Ignored if Quorum-based Storage is being enabled. 744 @param standby_name: name of stand-by NameNode. 745 @param standby_shared_path: shared edits path for stand-by NameNode. 746 Ignored if Quourm Journal is being enabled. 747 @param nameservice: nameservice for the HA pair. 748 @param start_dependent_services: whether to re-start dependent services. 749 @param deploy_client_configs: whether to re-deploy client configurations. 750 @param enable_quorum_storage: whether to enable Quorum-based Storage. Available since API v2. 751 Quorum-based Storage will be enabled for all 752 nameservices except those configured with NFS High 753 Availability. 754 @return: Reference to the submitted command. 755 """ 756 version = self._get_resource_root().version 757 758 args = dict( 759 activeName = active_name, 760 standByName = standby_name, 761 nameservice = nameservice, 762 startDependentServices = start_dependent_services, 763 deployClientConfigs = deploy_client_configs, 764 ) 765 766 if enable_quorum_storage: 767 if version < 2: 768 raise AttributeError("Quorum-based Storage is not supported prior to Cloudera Manager 4.1.") 769 else: 770 args['enableQuorumStorage'] = enable_quorum_storage 771 else: 772 if active_shared_path is None or standby_shared_path is None: 773 raise AttributeError("Active and standby shared paths must be specified if not enabling Quorum-based Storage") 774 args['activeSharedEditsPath'] = active_shared_path 775 args['standBySharedEditsPath'] = standby_shared_path 776 777 return self._cmd('hdfsEnableHa', data=args)
778
779 - def enable_nn_ha(self, active_name, standby_host_id, nameservice, jns, 780 standby_name_dir_list=None, qj_name=None, standby_name=None, 781 active_fc_name=None, standby_fc_name=None, zk_service_name=None, 782 force_init_znode=True, clear_existing_standby_name_dirs=True, clear_existing_jn_edits_dir=True):
783 """ 784 Enable High Availability (HA) with Auto-Failover for an HDFS NameNode. 785 @param active_name: Name of Active NameNode. 786 @param standby_host_id: ID of host where Standby NameNode will be created. 787 @param nameservice: Nameservice to be used while enabling HA. 788 Optional if Active NameNode already has this config set. 789 @param jns: List of Journal Nodes to be created during the command. 790 Each element of the list must be a dict containing the following keys: 791 - B{jnHostId}: ID of the host where the new JournalNode will be created. 792 - B{jnName}: Name of the JournalNode role (optional) 793 - B{jnEditsDir}: Edits dir of the JournalNode. Can be omitted if the config 794 is already set at RCG level. 795 @param standby_name_dir_list: List of directories for the new Standby NameNode. 796 If not provided then it will use same dirs as Active NameNode. 797 @param qj_name: Name of the journal located on each JournalNodes' filesystem. 798 This can be optionally provided if the config hasn't been already set for the Active NameNode. 799 If this isn't provided and Active NameNode doesn't also have the config, 800 then nameservice is used by default. 801 @param standby_name: Name of the Standby NameNode role to be created (Optional). 802 @param active_fc_name: Name of the Active Failover Controller role to be created (Optional). 803 @param standby_fc_name: Name of the Standby Failover Controller role to be created (Optional). 804 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 805 If HDFS service already depends on a ZooKeeper service then that ZooKeeper 806 service will be used for auto-failover and in that case this parameter 807 can either be omitted or should be the same ZooKeeper service. 808 @param force_init_znode: Indicates if the ZNode should be force initialized if it is 809 already present. Useful while re-enabling High Availability. (Default: TRUE) 810 @param clear_existing_standby_name_dirs: Indicates if the existing name directories for Standby NameNode 811 should be cleared during the workflow. 812 Useful while re-enabling High Availability. (Default: TRUE) 813 @param clear_existing_jn_edits_dir: Indicates if the existing edits directories for the JournalNodes 814 for the specified nameservice should be cleared during the workflow. 815 Useful while re-enabling High Availability. (Default: TRUE) 816 @return: Reference to the submitted command. 817 @since: API v6 818 """ 819 args = dict ( 820 activeNnName = active_name, 821 standbyNnName = standby_name, 822 standbyNnHostId = standby_host_id, 823 standbyNameDirList = standby_name_dir_list, 824 nameservice = nameservice, 825 qjName = qj_name, 826 activeFcName = active_fc_name, 827 standbyFcName = standby_fc_name, 828 zkServiceName = zk_service_name, 829 forceInitZNode = force_init_znode, 830 clearExistingStandbyNameDirs = clear_existing_standby_name_dirs, 831 clearExistingJnEditsDir = clear_existing_jn_edits_dir, 832 jns = jns 833 ) 834 return self._cmd('hdfsEnableNnHa', data=args, api_version=6)
835
836 - def disable_nn_ha(self, active_name, snn_host_id, snn_check_point_dir_list, 837 snn_name=None):
838 """ 839 Disable high availability with automatic failover for an HDFS NameNode. 840 841 @param active_name: Name of the NamdeNode role that is going to be active after 842 High Availability is disabled. 843 @param snn_host_id: Id of the host where the new SecondaryNameNode will be created. 844 @param snn_check_point_dir_list : List of directories used for checkpointing 845 by the new SecondaryNameNode. 846 @param snn_name: Name of the new SecondaryNameNode role (Optional). 847 @return: Reference to the submitted command. 848 @since: API v6 849 """ 850 args = dict( 851 activeNnName = active_name, 852 snnHostId = snn_host_id, 853 snnCheckpointDirList = snn_check_point_dir_list, 854 snnName = snn_name 855 ) 856 return self._cmd('hdfsDisableNnHa', data=args, api_version=6)
857
858 - def enable_jt_ha(self, new_jt_host_id, force_init_znode=True, zk_service_name=None, 859 new_jt_name=None, fc1_name=None, fc2_name=None):
860 """ 861 Enable high availability for a MR JobTracker. 862 863 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 864 If MapReduce service depends on a ZooKeeper service then that ZooKeeper 865 service will be used for auto-failover and in that case this parameter 866 can be omitted. 867 @param new_jt_host_id: id of the host where the second JobTracker 868 will be added. 869 @param force_init_znode: Initialize the ZNode used for auto-failover even if 870 it already exists. This can happen if JobTracker HA 871 was enabled before and then disabled. Disable operation 872 doesn't delete this ZNode. Defaults to true. 873 @param new_jt_name: Name of the second JobTracker role to be created. 874 @param fc1_name: Name of the Failover Controller role that is co-located with 875 the existing JobTracker. 876 @param fc2_name: Name of the Failover Controller role that is co-located with 877 the new JobTracker. 878 @return: Reference to the submitted command. 879 @since: API v5 880 """ 881 args = dict( 882 newJtHostId = new_jt_host_id, 883 forceInitZNode = force_init_znode, 884 zkServiceName = zk_service_name, 885 newJtRoleName = new_jt_name, 886 fc1RoleName = fc1_name, 887 fc2RoleName = fc2_name 888 ) 889 return self._cmd('enableJtHa', data=args)
890
891 - def disable_jt_ha(self, active_name):
892 """ 893 Disable high availability for a MR JobTracker active-standby pair. 894 895 @param active_name: name of the JobTracker that will be active after 896 the disable operation. The other JobTracker and 897 Failover Controllers will be removed. 898 @return: Reference to the submitted command. 899 """ 900 args = dict( 901 activeName = active_name, 902 ) 903 return self._cmd('disableJtHa', data=args)
904
905 - def enable_rm_ha(self, new_rm_host_id, zk_service_name=None):
906 """ 907 Enable high availability for a YARN ResourceManager. 908 909 @param new_rm_host_id: id of the host where the second ResourceManager 910 will be added. 911 @param zk_service_name: Name of the ZooKeeper service to use for auto-failover. 912 If YARN service depends on a ZooKeeper service then that ZooKeeper 913 service will be used for auto-failover and in that case this parameter 914 can be omitted. 915 @return: Reference to the submitted command. 916 @since: API v6 917 """ 918 args = dict( 919 newRmHostId = new_rm_host_id, 920 zkServiceName = zk_service_name 921 ) 922 return self._cmd('enableRmHa', data=args)
923
924 - def disable_rm_ha(self, active_name):
925 """ 926 Disable high availability for a YARN ResourceManager active-standby pair. 927 928 @param active_name: name of the ResourceManager that will be active after 929 the disable operation. The other ResourceManager 930 will be removed. 931 @return: Reference to the submitted command. 932 @since: API v6 933 """ 934 args = dict( 935 activeName = active_name 936 ) 937 return self._cmd('disableRmHa', data=args)
938
939 - def enable_oozie_ha(self, new_oozie_server_host_ids, new_oozie_server_role_names=None, 940 zk_service_name=None, load_balancer_host_port=None):
941 """ 942 Enable high availability for Oozie. 943 944 @param new_oozie_server_host_ids: List of IDs of the hosts on which new Oozie Servers 945 will be added. 946 @param new_oozie_server_role_names: List of names of the new Oozie Servers. This is an 947 optional argument, but if provided, it should 948 match the length of host IDs provided. 949 @param zk_service_name: Name of the ZooKeeper service that will be used for Oozie HA. 950 This is an optional parameter if the Oozie to ZooKeeper 951 dependency is already set. 952 @param load_balancer_host_port: Address and port of the load balancer used for Oozie HA. 953 This is an optional parameter if this config is already set. 954 @return: Reference to the submitted command. 955 @since: API v6 956 """ 957 args = dict( 958 newOozieServerHostIds = new_oozie_server_host_ids, 959 newOozieServerRoleNames = new_oozie_server_role_names, 960 zkServiceName = zk_service_name, 961 loadBalancerHostPort = load_balancer_host_port 962 ) 963 return self._cmd('oozieEnableHa', data=args, api_version=6)
964
965 - def disable_oozie_ha(self, active_name):
966 """ 967 Disable high availability for Oozie 968 969 @param active_name: Name of the Oozie Server that will be active after 970 High Availability is disabled. 971 @return: Reference to the submitted command. 972 @since: API v6 973 """ 974 args = dict( 975 activeName = active_name 976 ) 977 return self._cmd('oozieDisableHa', data=args, api_version=6)
978
979 - def failover_hdfs(self, active_name, standby_name, force=False):
980 """ 981 Initiate a failover of an HDFS NameNode HA pair. 982 983 This will make the given stand-by NameNode active, and vice-versa. 984 985 @param active_name: name of currently active NameNode. 986 @param standby_name: name of NameNode currently in stand-by. 987 @param force: whether to force failover. 988 @return: Reference to the submitted command. 989 """ 990 params = { "force" : "true" and force or "false" } 991 args = { ApiList.LIST_KEY : [ active_name, standby_name ] } 992 return self._cmd('hdfsFailover', data=[ active_name, standby_name ], 993 params = { "force" : "true" and force or "false" })
994
995 - def format_hdfs(self, *namenodes):
996 """ 997 Format NameNode instances of an HDFS service. 998 999 @param namenodes: Name of NameNode instances to format. 1000 @return: List of submitted commands. 1001 """ 1002 return self._role_cmd('hdfsFormat', namenodes)
1003
1004 - def init_hdfs_auto_failover(self, *controllers):
1005 """ 1006 Initialize HDFS failover controller metadata. 1007 1008 Only one controller per nameservice needs to be initialized. 1009 1010 @param controllers: Name of failover controller instances to initialize. 1011 @return: List of submitted commands. 1012 """ 1013 return self._role_cmd('hdfsInitializeAutoFailover', controllers)
1014
1015 - def init_hdfs_shared_dir(self, *namenodes):
1016 """ 1017 Initialize a NameNode's shared edits directory. 1018 1019 @param namenodes: Name of NameNode instances. 1020 @return: List of submitted commands. 1021 """ 1022 return self._role_cmd('hdfsInitializeSharedDir', namenodes)
1023
1024 - def roll_edits_hdfs(self, nameservice=None):
1025 """ 1026 Roll the edits of an HDFS NameNode or Nameservice. 1027 1028 @param nameservice: Nameservice whose edits should be rolled. 1029 Required only with a federated HDFS. 1030 @return: Reference to the submitted command. 1031 @since: API v3 1032 """ 1033 args = dict() 1034 if nameservice: 1035 args['nameservice'] = nameservice 1036 1037 return self._cmd('hdfsRollEdits', data=args)
1038
1039 - def upgrade_hdfs_metadata(self):
1040 """ 1041 Upgrade HDFS Metadata as part of a major version upgrade. 1042 1043 @return: Reference to the submitted command. 1044 @since: API v6 1045 """ 1046 return self._cmd('hdfsUpgradeMetadata', api_version=6)
1047
1048 - def upgrade_hbase(self):
1049 """ 1050 Upgrade HBase data in HDFS and ZooKeeper as part of upgrade from CDH4 to CDH5. 1051 1052 @return: Reference to the submitted command. 1053 @since: API v6 1054 """ 1055 return self._cmd('hbaseUpgrade', api_version=6)
1056
1057 - def upgrade_sqoop_db(self):
1058 """ 1059 Upgrade Sqoop Database schema as part of a major version upgrade. 1060 1061 @return: Reference to the submitted command. 1062 @since: API v6 1063 """ 1064 return self._cmd('sqoopUpgradeDb', api_version=6)
1065
1066 - def upgrade_hive_metastore(self):
1067 """ 1068 Upgrade Hive Metastore as part of a major version upgrade. 1069 1070 @return: Reference to the submitted command. 1071 @since: API v6 1072 """ 1073 return self._cmd('hiveUpgradeMetastore', api_version=6)
1074
1075 - def cleanup_zookeeper(self, *servers):
1076 """ 1077 Cleanup a ZooKeeper service or roles. 1078 1079 If no server role names are provided, the command applies to the whole 1080 service, and cleans up all the server roles that are currently running. 1081 1082 @param servers: ZK server role names (optional). 1083 @return: Command reference (for service command) or list of command 1084 references (for role commands). 1085 """ 1086 if servers: 1087 return self._role_cmd('zooKeeperCleanup', servers) 1088 else: 1089 return self._cmd('zooKeeperCleanup')
1090
1091 - def init_zookeeper(self, *servers):
1092 """ 1093 Initialize a ZooKeeper service or roles. 1094 1095 If no server role names are provided, the command applies to the whole 1096 service, and initializes all the configured server roles. 1097 1098 @param servers: ZK server role names (optional). 1099 @return: Command reference (for service command) or list of command 1100 references (for role commands). 1101 """ 1102 if servers: 1103 return self._role_cmd('zooKeeperInit', servers) 1104 else: 1105 return self._cmd('zooKeeperInit')
1106
1107 - def sync_hue_db(self, *servers):
1108 """ 1109 Synchronize the Hue server's database. 1110 1111 @param servers: Name of Hue Server roles to synchronize. 1112 @return: List of submitted commands. 1113 """ 1114 return self._role_cmd('hueSyncDb', servers)
1115
1116 - def enter_maintenance_mode(self):
1117 """ 1118 Put the service in maintenance mode. 1119 1120 @return: Reference to the completed command. 1121 @since: API v2 1122 """ 1123 cmd = self._cmd('enterMaintenanceMode') 1124 if cmd.success: 1125 self._update(_get_service(self._get_resource_root(), self._path())) 1126 return cmd
1127
1128 - def exit_maintenance_mode(self):
1129 """ 1130 Take the service out of maintenance mode. 1131 1132 @return: Reference to the completed command. 1133 @since: API v2 1134 """ 1135 cmd = self._cmd('exitMaintenanceMode') 1136 if cmd.success: 1137 self._update(_get_service(self._get_resource_root(), self._path())) 1138 return cmd
1139
1140 - def rolling_restart(self, slave_batch_size=None, 1141 slave_fail_count_threshold=None, 1142 sleep_seconds=None, 1143 stale_configs_only=None, 1144 unupgraded_only=None, 1145 restart_role_types=None, 1146 restart_role_names=None):
1147 """ 1148 Rolling restart the roles of a service. The sequence is: 1149 1. Restart all the non-slave roles 1150 2. If slaves are present restart them in batches of size specified 1151 3. Perform any post-command needed after rolling restart 1152 1153 @param slave_batch_size: Number of slave roles to restart at a time 1154 Must be greater than 0. Default is 1. 1155 For HDFS, this number should be less than the replication factor (default 3) 1156 to ensure data availability during rolling restart. 1157 @param slave_fail_count_threshold: The threshold for number of slave batches that 1158 are allowed to fail to restart before the entire command is considered failed. 1159 Must be >= 0. Default is 0. 1160 @param sleep_seconds: Number of seconds to sleep between restarts of slave role batches. 1161 Must be >=0. Default is 0. 1162 @param stale_configs_only: Restart roles with stale configs only. Default is false. 1163 @param unupgraded_only: Restart roles that haven't been upgraded yet. Default is false. 1164 @param restart_role_types: Role types to restart. If not specified, all startable roles are restarted. 1165 @param restart_role_names: List of specific roles to restart. 1166 If none are specified, then all roles of specified role types are restarted. 1167 @return: Reference to the submitted command. 1168 @since: API v3 1169 """ 1170 args = dict() 1171 if slave_batch_size: 1172 args['slaveBatchSize'] = slave_batch_size 1173 if slave_fail_count_threshold: 1174 args['slaveFailCountThreshold'] = slave_fail_count_threshold 1175 if sleep_seconds: 1176 args['sleepSeconds'] = sleep_seconds 1177 if stale_configs_only: 1178 args['staleConfigsOnly'] = stale_configs_only 1179 if unupgraded_only: 1180 args['unUpgradedOnly'] = unupgraded_only 1181 if restart_role_types: 1182 args['restartRoleTypes'] = restart_role_types 1183 if restart_role_names: 1184 args['restartRoleNames'] = restart_role_names 1185 1186 return self._cmd('rollingRestart', data=args)
1187
1188 - def create_replication_schedule(self, 1189 start_time, end_time, interval_unit, interval, paused, arguments, 1190 alert_on_start=False, alert_on_success=False, alert_on_fail=False, 1191 alert_on_abort=False):
1192 """ 1193 Create a new replication schedule for this service. 1194 1195 The replication argument type varies per service type. The following types 1196 are recognized: 1197 - HDFS: ApiHdfsReplicationArguments 1198 - Hive: ApiHiveReplicationArguments 1199 1200 @type start_time: datetime.datetime 1201 @param start_time: The time at which the schedule becomes active and first executes. 1202 @type end_time: datetime.datetime 1203 @param end_time: The time at which the schedule will expire. 1204 @type interval_unit: str 1205 @param interval_unit: The unit of time the `interval` represents. Ex. MINUTE, HOUR, 1206 DAY. See the server documentation for a full list of values. 1207 @type interval: int 1208 @param interval: The number of time units to wait until triggering the next replication. 1209 @type paused: bool 1210 @param paused: Should the schedule be paused? Useful for on-demand replication. 1211 @param arguments: service type-specific arguments for the replication job. 1212 @param alert_on_start: whether to generate alerts when the job is started. 1213 @param alert_on_success: whether to generate alerts when the job succeeds. 1214 @param alert_on_fail: whether to generate alerts when the job fails. 1215 @param alert_on_abort: whether to generate alerts when the job is aborted. 1216 @return: The newly created schedule. 1217 @since: API v3 1218 """ 1219 schedule = ApiReplicationSchedule(self._get_resource_root(), 1220 startTime=start_time, endTime=end_time, intervalUnit=interval_unit, interval=interval, 1221 paused=paused, alertOnStart=alert_on_start, alertOnSuccess=alert_on_success, 1222 alertOnFail=alert_on_fail, alertOnAbort=alert_on_abort) 1223 1224 if self.type == 'HDFS': 1225 if not isinstance(arguments, ApiHdfsReplicationArguments): 1226 raise TypeError, 'Unexpected type for HDFS replication argument.' 1227 schedule.hdfsArguments = arguments 1228 elif self.type == 'HIVE': 1229 if not isinstance(arguments, ApiHiveReplicationArguments): 1230 raise TypeError, 'Unexpected type for Hive replication argument.' 1231 schedule.hiveArguments = arguments 1232 else: 1233 raise TypeError, 'Replication is not supported for service type ' + self.type 1234 1235 return self._post("replications", ApiReplicationSchedule, True, [schedule], 1236 api_version=3)[0]
1237
1238 - def get_replication_schedules(self):
1239 """ 1240 Retrieve a list of replication schedules. 1241 1242 @return: A list of replication schedules. 1243 @since: API v3 1244 """ 1245 return self._get("replications", ApiReplicationSchedule, True, 1246 api_version=3)
1247
1248 - def get_replication_schedule(self, schedule_id):
1249 """ 1250 Retrieve a single replication schedule. 1251 1252 @param schedule_id: The id of the schedule to retrieve. 1253 @return: The requested schedule. 1254 @since: API v3 1255 """ 1256 return self._get("replications/%d" % schedule_id, ApiReplicationSchedule, 1257 api_version=3)
1258
1259 - def delete_replication_schedule(self, schedule_id):
1260 """ 1261 Delete a replication schedule. 1262 1263 @param schedule_id: The id of the schedule to delete. 1264 @return: The deleted replication schedule. 1265 @since: API v3 1266 """ 1267 return self._delete("replications/%s" % schedule_id, ApiReplicationSchedule, 1268 api_version=3)
1269
1270 - def update_replication_schedule(self, schedule_id, schedule):
1271 """ 1272 Update a replication schedule. 1273 1274 @param schedule_id: The id of the schedule to update. 1275 @param schedule: The modified schedule. 1276 @return: The updated replication schedule. 1277 @since: API v3 1278 """ 1279 return self._put("replications/%s" % schedule_id, ApiReplicationSchedule, 1280 data=schedule, api_version=3)
1281
1282 - def get_replication_command_history(self, schedule_id, limit=20, offset=0, 1283 view=None):
1284 """ 1285 Retrieve a list of commands for a replication schedule. 1286 1287 @param schedule_id: The id of the replication schedule. 1288 @param limit: Maximum number of commands to retrieve. 1289 @param offset: Index of first command to retrieve. 1290 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1291 @return: List of commands executed for a replication schedule. 1292 @since: API v4 1293 """ 1294 params = { 1295 'limit': limit, 1296 'offset': offset, 1297 } 1298 if view: 1299 params['view'] = view 1300 1301 return self._get("replications/%s/history" % schedule_id, 1302 ApiReplicationCommand, True, params=params, api_version=4)
1303
1304 - def trigger_replication_schedule(self, schedule_id, dry_run=False):
1305 """ 1306 Trigger replication immediately. Start and end dates on the schedule will be 1307 ignored. 1308 1309 @param schedule_id: The id of the schedule to trigger. 1310 @param dry_run: Whether to execute a dry run. 1311 @return: The command corresponding to the replication job. 1312 @since: API v3 1313 """ 1314 return self._post("replications/%s/run" % schedule_id, ApiCommand, 1315 params=dict(dryRun=dry_run), 1316 api_version=3)
1317
1318 - def create_snapshot_policy(self, policy):
1319 """ 1320 Create a new snapshot policy for this service. 1321 @param policy: The snapshot policy to create 1322 @return: The newly created policy. 1323 @since: API v6 1324 """ 1325 return self._post("snapshots/policies", ApiSnapshotPolicy, True, [policy], 1326 api_version=6)[0]
1327
1328 - def get_snapshot_policies(self, view=None):
1329 """ 1330 Retrieve a list of snapshot policies. 1331 1332 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1333 @return: A list of snapshot policies. 1334 @since: API v6 1335 """ 1336 return self._get("snapshots/policies", ApiSnapshotPolicy, True, 1337 params=view and dict(view=view) or None, api_version=6)
1338
1339 - def get_snapshot_policy(self, name, view=None):
1340 """ 1341 Retrieve a single snapshot policy. 1342 1343 @param name: The name of the snapshot policy to retrieve. 1344 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1345 @return: The requested snapshot policy. 1346 @since: API v6 1347 """ 1348 return self._get("snapshots/policies/%s" % name, ApiSnapshotPolicy, 1349 params=view and dict(view=view) or None, api_version=6)
1350
1351 - def delete_snapshot_policy(self, name):
1352 """ 1353 Delete a snapshot policy. 1354 1355 @param name: The name of the snapshot policy to delete. 1356 @return: The deleted snapshot policy. 1357 @since: API v6 1358 """ 1359 return self._delete("snapshots/policies/%s" % name, ApiSnapshotPolicy, api_version=6)
1360
1361 - def update_snapshot_policy(self, name, policy):
1362 """ 1363 Update a snapshot policy. 1364 1365 @param name: The name of the snapshot policy to update. 1366 @param policy: The modified snapshot policy. 1367 @return: The updated snapshot policy. 1368 @since: API v6 1369 """ 1370 return self._put("snapshots/policies/%s" % name, ApiSnapshotPolicy, data=policy, 1371 api_version=6)
1372
1373 - def get_snapshot_command_history(self, name, limit=20, offset=0, view=None):
1374 """ 1375 Retrieve a list of commands triggered by a snapshot policy. 1376 1377 @param name: The name of the snapshot policy. 1378 @param limit: Maximum number of commands to retrieve. 1379 @param offset: Index of first command to retrieve. 1380 @param view: View to materialize. Valid values are 'full', 'summary', 'export', 'export_redacted'. 1381 @return: List of commands triggered by a snapshot policy. 1382 @since: API v6 1383 """ 1384 params = { 1385 'limit': limit, 1386 'offset': offset, 1387 } 1388 if view: 1389 params['view'] = view 1390 1391 return self._get("snapshots/policies/%s/history" % name, ApiSnapshotCommand, True, 1392 params=params, api_version=6)
1393 1394
1395 - def install_oozie_sharelib(self):
1396 """ 1397 Installs the Oozie ShareLib. Oozie must be stopped before running this 1398 command. 1399 1400 @return: Reference to the submitted command. 1401 @since: API v3 1402 """ 1403 return self._cmd('installOozieShareLib', api_version=3)
1404
1405 - def create_oozie_db(self):
1406 """ 1407 Creates the Oozie Database Schema in the configured database. 1408 1409 @return: Reference to the submitted command. 1410 @since: API v2 1411 """ 1412 return self._cmd('createOozieDb', api_version=2)
1413
1414 - def upgrade_oozie_db(self):
1415 """ 1416 Upgrade Oozie Database schema as part of a major version upgrade. 1417 1418 @return: Reference to the submitted command. 1419 @since: API v6 1420 """ 1421 return self._cmd('oozieUpgradeDb', api_version=6)
1422
1424 """ 1425 Creates the Hive metastore tables in the configured database. 1426 Will do nothing if tables already exist. Will not perform an upgrade. 1427 1428 @return: Reference to the submitted command. 1429 @since: API v3 1430 """ 1431 return self._cmd('hiveCreateMetastoreDatabaseTables', api_version=3)
1432
1433 - def create_hive_warehouse(self):
1434 """ 1435 Creates the Hive warehouse directory in HDFS. 1436 1437 @return: Reference to the submitted command. 1438 @since: API v3 1439 """ 1440 return self._cmd('hiveCreateHiveWarehouse')
1441
1442 - def create_hive_userdir(self):
1443 """ 1444 Creates the Hive user directory in HDFS. 1445 1446 @return: Reference to the submitted command. 1447 @since: API v4 1448 """ 1449 return self._cmd('hiveCreateHiveUserDir')
1450
1452 """ 1453 Create the Hive Metastore Database. Only works with embedded postgresql 1454 database. This command should usually be followed by a call to 1455 create_hive_metastore_tables. 1456 1457 @return: Reference to the submitted command. 1458 @since: API v4 1459 """ 1460 return self._cmd('hiveCreateMetastoreDatabase', api_version=4)
1461
1463 """ 1464 Update Hive Metastore to point to a NameNode's Nameservice name instead of 1465 hostname. Only available when all Hive Metastore Servers are stopped and 1466 HDFS has High Availability. 1467 1468 Back up the Hive Metastore Database before running this command. 1469 1470 @return: Reference to the submitted command. 1471 @since: API v4 1472 """ 1473 return self._cmd('hiveUpdateMetastoreNamenodes', api_version=4)
1474
1476 """ 1477 Import MapReduce configuration into Yarn, overwriting Yarn configuration. 1478 1479 You will lose existing Yarn configuration. Read all MapReduce 1480 configuration, role assignments, and role configuration groups and update 1481 Yarn with corresponding values. MR1 configuration will be converted into 1482 the equivalent MR2 configuration. 1483 1484 Before running this command, Yarn must be stopped and MapReduce must exist 1485 with valid configuration. 1486 1487 @return: Reference to the submitted command. 1488 @since: API v6 1489 """ 1490 return self._cmd('importMrConfigsIntoYarn', api_version=6)
1491
1492 - def switch_to_mr2(self):
1493 """ 1494 Change the cluster to use MR2 instead of MR1. Services will be restarted. 1495 1496 Will perform the following steps: 1497 * Update all services that depend on MapReduce to instead depend on Yarn. 1498 * Stop MapReduce 1499 * Start Yarn (includes MR2) 1500 * Deploy Yarn (MR2) Client Configuration 1501 1502 Available since API v6. 1503 1504 @return: Reference to the submitted command. 1505 @since: API v6 1506 """ 1507 return self._cmd('switchToMr2', api_version=6)
1508
1509 - def role_command_by_name(self, command_name, *role_names):
1510 """ 1511 Executes a role command by name on the specified 1512 roles 1513 1514 @param command_name: The name of the command. 1515 @param role_names: The role names to execute this command on. 1516 @return: Reference to the submitted command. 1517 @since: API v6 1518 """ 1519 return self._role_cmd(command_name, role_names, api_version=6)
1520
1521 - def service_command_by_name(self, command_name):
1522 """ 1523 Executes a command on the service specified 1524 by name. 1525 1526 @param command_name: The name of the command. 1527 @return: Reference to the submitted command. 1528 @since: API v6 1529 """ 1530 return self._cmd(command_name, api_version=6)
1531
1532 - def list_commands_by_name(self):
1533 """ 1534 Lists all the commands that can be executed by name 1535 on the provided service. 1536 1537 @return: A list of command metadata objects 1538 @since: API v6 1539 """ 1540 return self._get("commandsByName", ApiCommandMetadata, True, 1541 api_version=6)
1542
1543 -class ApiServiceSetupInfo(ApiService):
1544 _ATTRIBUTES = { 1545 'name' : None, 1546 'type' : None, 1547 'config' : Attr(ApiConfig), 1548 'roles' : Attr(roles.ApiRole), 1549 } 1550
1551 - def __init__(self, name=None, type=None, 1552 config=None, roles=None):
1553 # The BaseApiObject expects a resource_root, which we don't care about 1554 resource_root = None 1555 # Unfortunately, the json key is called "type". So our input arg 1556 # needs to be called "type" as well, despite it being a python keyword. 1557 BaseApiObject.init(self, None, locals())
1558
1559 - def set_config(self, config):
1560 """ 1561 Set the service configuration. 1562 1563 @param config: A dictionary of config key/value 1564 """ 1565 if self.config is None: 1566 self.config = { } 1567 self.config.update(config_to_api_list(config))
1568
1569 - def add_role_type_info(self, role_type, config):
1570 """ 1571 Add a role type setup info. 1572 1573 @param role_type: Role type 1574 @param config: A dictionary of role type configuration 1575 """ 1576 rt_config = config_to_api_list(config) 1577 rt_config['roleType'] = role_type 1578 1579 if self.config is None: 1580 self.config = { } 1581 if not self.config.has_key(ROLETYPES_CFG_KEY): 1582 self.config[ROLETYPES_CFG_KEY] = [ ] 1583 self.config[ROLETYPES_CFG_KEY].append(rt_config)
1584
1585 - def add_role_info(self, role_name, role_type, host_id, config=None):
1586 """ 1587 Add a role info. The role will be created along with the service setup. 1588 1589 @param role_name: Role name 1590 @param role_type: Role type 1591 @param host_id: The host where the role should run 1592 @param config: (Optional) A dictionary of role config values 1593 """ 1594 if self.roles is None: 1595 self.roles = [ ] 1596 api_config_list = config is not None and config_to_api_list(config) or None 1597 self.roles.append({ 1598 'name' : role_name, 1599 'type' : role_type, 1600 'hostRef' : { 'hostId' : host_id }, 1601 'config' : api_config_list })
1602